Re: Already Converted TradingView Indicators to MT4 Indicators

301
RodrigoRT7 wrote: Tue Feb 07, 2023 9:21 am Hello my friends! all good? Sorry to go back to this topic about this indicator, but it's the ones I liked the most that are not available for MT4, if anyone has the expertise to convert from Tradingview to MT4, I would be deeply grateful.

Thanks a lot, in advance. s2

NOTE: I am referring to cora wave :D
hello everybody!! i was reading some posts about this indicator and it looks like a member has it converted to MT4. If anyone can help me with this conversion I would be very grateful. :D

thank you very much in advance

obs: or if anyone has it and can send it or send it to me via private chat, I also really appreciate it.


Re: Already Converted TradingView Indicators to MT4 Indicators

302
louisforex wrote: Thu Mar 30, 2023 1:55 am Of all the indicators I've tested on tradingview. This is my favorite because even if its wrong in identifying the trend. It will take you out with a very small loss or even a gain. It also is great for a filter or confirmation paired with other indicators. Attached is a couple of pictures with the name and what it looks like on the chart. Ill also include the source code. I got a strategy coded and the results very promising but it was coded in the pinescript version 2 and when I try to convert it to the latest version of tradingview code language I ran into issues. I was hoping that one the great coders here can help me convert this into a metatrader 4 indicator. The indicator code has a youtube link in it that describes one of the strategies used with the indicator but Im sure it can be coded without that link to youtube.



//@version=2
study("TrendAlert", overlay=false)

// Trend and direction determination Step 1 en Step 2 method conform ZoneRecovery from 4x-dat.com Joseph Nemeth
//
// step 1 LongTerm timefram/resolution (LT) determine general direction
//• color last Heikenahsi bar gives is the general direction
// step 2 MidTerm timeframe/resolution determine trend
//• color last Heikenahsi bar must match Direction step 1 and
//• slope of 20EMA in direction step 1 and
//• price relation to EMA20: above = up, below=down
// Step 1 AND step 2 => TrendAlert (-1 for Short, 1 for Long, 0 for No trend)

//Heiken Ashi Candles
data = heikenashi(tickerid)
resLT = input(title="Res LT", type=resolution, defval="D")
resMT = input(title="Res MT", type=resolution, defval="240")


LTo = security(data, resLT, open)
LTc = security(data, resLT, close)
MTo = security(data, resMT, open)
MTc = security(data, resMT, close)

LTlong = LTc > LTo
LTshort = LTc < LTo
MTema20 = ema(MTc,20)
MTema20delta= change(MTema20)

MTlong = MTc > MTo and MTc > MTema20 and MTema20delta > 0
MTshort = MTc < MTo and MTc < MTema20 and MTema20delta < 0



Long = MTlong and LTlong
Short = MTshort and LTshort

plot(Long ? 1 : Short ? -1: 0, title="TrendAlert", color= Long ? lime : Short ? red : gray, style=columns )
Image

Image
These users thanked the author ffsss for the post (total 2):
RodrigoRT7, Akela

Re: Already Converted TradingView Indicators to MT4 Indicators

303
I haven’t seen a standalone Fair value gap indicator here yet. This one of my favorites in TradingView was wondering if someone could convert it to MT4 🙏🏽


//@version=5

indicator('muh fokkin gap!', shorttitle='〓', overlay = true, max_lines_count = 500, max_boxes_count=500)
tf = input.timeframe("", "",inline='1')

//Input Bool
BullX = input.int(1, '', inline='1')
pp_test0 = input.bool(false, 'delete mitigated', inline ='2')
exb = input.bool(false, "extend current", inline ='3')
tts = input.bool(true, "true to size", inline = '4')


//Input Color
pp_test1 = input.bool(true,'', group = 'Bull FVG', inline='1')
pp_test3 = input.bool(false, '', group ='Bull FVG', inline='2')

BullLineC = input.color( color.aqua, "", group='Bull FVG', inline='1')
arbullc2 = input.color(#00ff83, "", group='Bull FVG', inline='1')

arbullc1 = input.color(#00ff83, "", group='Bull FVG', inline='2')
arbullc = input.color(#00ff83, "", group='Bull FVG', inline='2')

//
pp_test2 = input.bool(true, '', group = 'Bear FVG', inline='2')
pp_test4 = input.bool(false, '', group ='Bear FVG', inline='1')

arbearc1 = input.color(#c90000, "", group='Bear FVG', inline='1')
arbearc = input.color(#c90000, "", group='Bear FVG', inline='1')

BearLineC = input.color( #c2185b, "", group='Bear FVG', inline='2')
arbearc2 = input.color(#c90000, "", group='Bear FVG', inline='2')


pp_test5 = input.bool(true,'', group = 'text', inline ='2')
textc1 = input.color(#ffffff, '', group='text', inline='2')
textc2 = input.color(#ffffff, '', group='text', inline='2')

exbc = exb ? extend.right : extend.none


//Data
L1 = request.security(syminfo.tickerid, tf, low, barmerge.gaps_on, barmerge.lookahead_on)
H3 = request.security(syminfo.tickerid, tf, high[2], barmerge.gaps_on, barmerge.lookahead_on)

H1 = request.security(syminfo.tickerid, tf, high, barmerge.gaps_on, barmerge.lookahead_on)
L3 = request.security(syminfo.tickerid, tf, low[2], barmerge.gaps_on, barmerge.lookahead_on)


//Calc

//Jesus converter big thanks to kodify and the manual
MTFstring = str.tostring(tf)


tfInMinutes(simple string tf = "") =>
float chartTf =
timeframe.multiplier * (
timeframe.isseconds ? 1. / 60 :
timeframe.isminutes ? 1. :
timeframe.isdaily ? 60. * 24 :
timeframe.isweekly ? 60. * 24 * 7 :
timeframe.ismonthly ? 60. * 24 * 30.4375 : na)
float result = tf == "" ? chartTf : request.security(syminfo.tickerid, tf, chartTf)

float chartTFInMinutes = tfInMinutes()
float inputTFInMinutes = tfInMinutes(tf)

n_bar_multiplier = 3
n_bars = 1 ? 2*inputTFInMinutes/chartTFInMinutes: inputTFInMinutes/chartTFInMinutes

// ? w ?
FVGUp = H3 < L1
bullbot = H3
bulltop = L1


FVGDown = L3 > H1
beartop = L3
bearbot = H1

//Lines

var l_bullbot = array.new_line(1)
var l_bulltop = array.new_line(1)
var box2 = array.new_box(1)

if array.size(l_bulltop) > 500
array.shift(l_bulltop)

if array.size(l_bullbot) > 500
array.shift(l_bullbot)

if array.size(box2) > 500
array.shift(box2)



k = 0

for i = 0 to array.size(l_bullbot) - 1
line_price1 = line.get_y1(array.get(l_bullbot, i - k))
if low < line_price1
line.delete(pp_test0 ? array.get(l_bullbot, i - k):na)
array.remove(l_bullbot, i - k)
line.delete(pp_test0 ? array.get(l_bulltop, i - k):na)
array.remove(l_bulltop, i - k)
box.delete(pp_test0 ? array.get(box2, i - k):na)
box.set_bgcolor(pp_test3 ? array.get(box2, i - k):na, arbullc)
array.remove(box2, i - k)
k := k + 1

k := 0
// revisit
for i = 0 to array.size(l_bulltop) - 1
line_price4 = line.get_y1(array.get(l_bulltop, i))
a_b2 = array.get(box2, i)
if low < line_price4
line.set_color(pp_test3 ? array.get(l_bulltop, i):na, arbullc1)
box.set_bgcolor(pp_test3 ? a_b2:na, pp_test0 ? color.new(color.black, 100): arbullc)
box.set_extend(a_b2, extend.none)
box.set_text(a_b2, pp_test5 ? "      " + MTFstring + " | BULL | " + str.tostring(line_price4):na)
box.set_text_color(a_b2, textc1)
line.set_extend(array.get(l_bulltop, i), extend.none)
line.set_color(pp_test3 ? array.get(l_bullbot, i):na, pp_test0 ? color.new(color.black, 100): BullLineC)


if FVGUp and pp_test1
array.push(l_bulltop, line.new(bar_index[tts ? n_bars: BullX], bulltop, bar_index, bulltop, xloc.bar_index, exbc, BullLineC, width =2))
array.push(l_bullbot, line.new(bar_index[tts ? n_bars: BullX], bullbot, bar_index, bullbot, color = color.new(color.white, 100), width =2))
array.push(box2, box.new(bar_index[tts ? n_bars: BullX], bulltop, bar_index, bullbot, color.new(color.white, 100), 0, line.style_solid, exbc, xloc.bar_index, arbullc2,pp_test5 ? "      " + MTFstring + " | BULL | " + str.tostring(bulltop): na, size.auto, textc1, text.align_right))


var l_bearbot = array.new_line(1)
var l_beartop = array.new_line(1)
var box1 = array.new_box(1)

if array.size(l_beartop) > 500
array.shift(l_beartop)

if array.size(l_bearbot) > 500
array.shift(l_bearbot)

if array.size(box1) > 500
array.shift(box1)



for i = 0 to array.size(l_beartop) - 1
line_price2 = line.get_y1(array.get(l_beartop, i - k))
if high > line_price2
line.delete(pp_test0 ? array.get(l_bearbot, i - k):na)
array.remove(l_bearbot, i - k)
line.delete(pp_test0 ? array.get(l_beartop, i - k):na)
array.remove(l_beartop, i - k)
box.set_bgcolor(pp_test4 ? array.get(box1, i - k):na, arbearc)
box.delete(pp_test0 ? array.get(box1, i - k):na)
array.remove(box1, i - k)
k := k + 1

k := 0


for i = 0 to array.size(l_bearbot) - 1
line_price3 = line.get_y1(array.get(l_bearbot, i))
a_b1 = array.get(box1, i)
if high > line_price3
line.set_color(pp_test4 ? array.get(l_bearbot, i):na, arbearc1)
box.set_bgcolor(pp_test4 ? a_b1:na, pp_test0 ? color.new(color.black, 100): arbearc)
box.set_extend(a_b1, extend.none)
box.set_text(a_b1, pp_test5 ?"      " + MTFstring + " | BEAR | " + str.tostring(line_price3): na)
box.set_text_color(a_b1, textc2)
line.set_extend(array.get(l_bearbot, i), extend.none)
line.set_color(pp_test4 ? array.get(l_beartop, i):na,pp_test0 ? color.new(color.black, 100): BearLineC)


if FVGDown and pp_test2
array.push(l_beartop, line.new(bar_index[tts ? n_bars: BullX], beartop, bar_index, beartop, color= color.new(color.white, 100), width =2))
array.push(l_bearbot, line.new(bar_index[tts ? n_bars: BullX], bearbot, bar_index, bearbot, xloc.bar_index, exbc, color = BearLineC, width =2))
array.push(box1, box.new(bar_index[tts ? n_bars: BullX], beartop, bar_index, bearbot, color.new(color.white, 100), 0, line.style_solid, exbc, xloc.bar_index, arbearc2, pp_test5 ? "      " + MTFstring + " | BEAR | " + str.tostring(bearbot): na, size.auto, textc2 , text.align_right))





//Boxes

DownloadRe: Already Converted TradingView Indicators to MT4 Indicators

304
ST ANY INDICATOR BY WBBURGIN
Hello coders, is it possible to get an mt5 version of this indictor from trading view with alerts when new signals are printed.
This indicator will generate a supertrend of your chosen configuration on any of the following indicators:
RSI
MFI
Accum/ Dist
Momentum
On Balance Volume
CCI

There is also a RANGE FILTER built into the scripts so that you can smooth the indicators for the supertrend. This is an optional configuration in the settings. Also, you can change the oversold/overbought bounds in the settings (they are removed entirely for indicators without bounds).
this is the code...

Code: Select all

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © wbburgin

import wbburgin/wbburgin_utils/1 as e

//@version=5
indicator("Supertrend ANY INDICATOR (RSI, MFI, CCI, etc.) + Range Filter",shorttitle="ST ANY INDICATOR [wbburgin]",overlay=false)

// This indicator will generate a supertrend of your chosen configuration on any of the following indicators:
    // RSI
    // MFI
    // ACCUMULATION / DISTRIBUTION
    // MOMENTUM
    // ON BALANCE VOLUME
    // CCI
    // Stochastic

// If you find this indicator useful, please boost it and follow! I am open to suggestions for adding new indicators
// to this script, it's very simple to add new ones, just suggest them in the comments.


// INPUTS ______________________________________________________________________________________________________________

sel = input.string("RSI","Indicator for Supertrend",
 options=["RSI","MFI","Accum/Dist","Momentum","OB Volume","CCI","Stochastic"],
  group="Main Settings")
indicator_length = input.int(14, "Indicator Length (if applicable)",group="Main Settings",
 tooltip = "Ignore if indicator does not have length inputs (i.e. Accum/Dist, OBV)")

atr_length = input.int(10, "Supertrend ATR Length",group="Main Settings")
atr_mult = input.float(3.0,"Supertrend ATR Mult",step=0.5,group="Main Settings")

use_range = input.bool(false,"Use Range Filter of Indicator",
 tooltip = "Use a range filter of the indicator instead of the indicator itself for calculations (for smoothing)",
  group="Range Filter")
sampling_period = input.int(50,"Range Filter Sampling Period (if applicable)",group="Range Filter")
range_mult = input.float(3,"Range Filter Multiple (if applicable)",group="Range Filter")

labels = input.bool(true,"Show Labels",group="Display")
highlighting = input.bool(true,"Display Highlighting",group="Display")
oversold = input.int(30,"Oversold Level (if applicable)",group="Display")
overbought = input.int(70,"Overbought Level (if applicable)",group="Display")

// CALCULATIONS ________________________________________________________________________________________________________

filt(source,sampling_period,range_mult) =>
    e.rngfilt(source,e.smoothrng(source,sampling_period,range_mult))

rsi = switch
    use_range == false => ta.rsi(close,indicator_length)
    => filt(ta.rsi(close,indicator_length),sampling_period,range_mult)

mfi = switch
    use_range == false => ta.mfi(close,indicator_length)
    => filt(ta.mfi(close,indicator_length),sampling_period,range_mult)

accdist = switch
    use_range == false => ta.accdist
    => filt(ta.accdist,sampling_period,range_mult)

mom = switch
    use_range == false => ta.mom(close,indicator_length)
    => filt(ta.mom(close,indicator_length),sampling_period,range_mult)

obv = switch
    use_range == false => ta.obv
    => filt(ta.obv,sampling_period,range_mult)

cci = switch
    use_range == false => ta.cci(close,indicator_length)
    => filt(ta.cci(close,indicator_length),sampling_period,range_mult)

stoch = switch
    use_range == false => ta.stoch(close,high,low,indicator_length)
    => filt(ta.stoch(close,high,low,indicator_length),sampling_period,range_mult)

indicator = switch
    sel == "RSI" => rsi
    sel == "MFI" => mfi
    sel == "Accum/Dist" => accdist
    sel == "Momentum" => mom
    sel == "OB Volume" => obv
    sel == "CCI" => cci
    sel == "Stochastic" => stoch

not_bound = indicator==accdist or indicator==obv

[supertrend,dir] = e.supertrend_anysource(indicator,atr_mult,atr_length)
supertrend_up = dir == -1 ? supertrend : na
supertrend_dn = dir == 1 ? supertrend : na
supertrend_up_start = dir == -1 and dir[1] == 1 ? supertrend : na
supertrend_dn_start = dir == 1 and dir[1] == -1 ? supertrend : na

linecolor = dir == -1 ? color.green : color.red
fillcolor = dir == -1 ? color.new(color.green,88) : color.new(color.red,88)

sup = plot(supertrend_up,title="Up Supertrend",color=linecolor,style=plot.style_linebr,linewidth=2)
sdn = plot(supertrend_dn,title="Down Supertrend",color=linecolor,style=plot.style_linebr,linewidth=2)
mid=plot(indicator,color=color.white)

plotshape(supertrend_up_start,title="Supertrend Up Start",style=shape.circle,location=location.absolute,
 color=color.green, size=size.tiny)
plotshape(supertrend_dn_start,title="Supertrend Down Start",style=shape.circle,location=location.absolute,
 color=color.red, size=size.tiny)
plotshape(labels==false?na:supertrend_up_start,title="Supertrend Buy Label",style=shape.labelup,location=location.absolute,
 color=color.green,textcolor=color.white,text = "Buy")
plotshape(labels==false?na:supertrend_dn_start,title="Supertrend Sell Label",style=shape.labeldown,location=location.absolute,
 color=color.red,textcolor=color.white,text = "Sell")

fill(sup,mid,highlighting==true ? fillcolor : na)
fill(sdn,mid,highlighting==true ? fillcolor : na)

hiPlot=plot(not_bound ? na : oversold,title="Oversold Level",color=color.new(color.white,75),style=plot.style_circles)
loPlot=plot(not_bound ? na : overbought,title="Overbought Level",color=color.new(color.white,75),style=plot.style_circles)

fill(hiPlot,loPlot,color=highlighting==true ? color.new(color.purple,95):na)

alertcondition(supertrend_up_start,"Supertrend Any Indicator Buy")
alertcondition(supertrend_dn_start,"Supertrend Any Indicator Sell")
Hoping to get some feedback on this. Thanks.
These users thanked the author keringet for the post:
RodrigoRT7

Re: Already Converted TradingView Indicators to MT4 Indicators

305
;) HI, masters! Is it possible to convert this indicator to MT4?
This TradingView Indicator Predicts The Next Candlestick

Breakout Probability is a valuable indicator that calculates the probability of a new high or low and displays it as a level with its percentage. The probability of a new high and low is backtested, and the results are shown in a table— a simple way to understand the next candle's likelihood of a new high or low. In addition, the indicator displays an additional four levels above and under the candle with the probability of hitting these levels.

The indicator helps traders to understand the likelihood of the next candle's direction, which can be used to set your trading bias.

█ Calculations

The algorithm calculates all the green and red candles separately depending on whether the previous candle was red or green and assigns scores if one or more lines were reached. The algorithm then calculates how many candles reached those levels in history and displays it as a percentage value on each line.

█ Settings

Percentage Step
The space between the levels can be adjusted with a percentage step. 1% means that each level is located 1% above/under the previous one.

Disable 0.00% values
If a level got a 0% likelihood of being hit, the level is not displayed as default. Enable the option if you want to see all levels regardless of their values.

Number of Lines
Set the number of levels you want to display.

Show Statistic Panel
Enable this option if you want to display the backtest statistics for that a new high or low is made. (Only if the first levels have been reached or not)

█ Any Alert function call

An alert is sent on candle open, and you can select what should be included in the alert. You can enable the following options:

Ticker ID
Bias
Probability percentage
The first level high and low price

█ How to use

This indicator is a perfect tool for anyone that wants to understand the probability of a breakout and the likelihood that set levels are hit.

The indicator can be used for setting a stop loss based on where the price is most likely not to reach.

The indicator can help traders to set their bias based on probability. For example, look at the daily or a higher timeframe to get your trading bias, then go to a lower timeframe and look for setups in that direction.

Script is nested
These users thanked the author dmnik for the post (total 4):
Chickenspicy, allan, Abdi, RodrigoRT7
Who knows others is wise
Who knows himself is enlightened


Re: Already Converted TradingView Indicators to MT4 Indicators

306
no idea if this is possible on mt4 but this would be a top sentiment indicator if coders can create
just an ideda

Chickenspicy wrote: Sat Apr 08, 2023 11:48 am

Code: Select all

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TradingNerd

//@version=5
indicator('COT Report Indicator', format=format.volume, precision=0)

// Variables {
table t = table.new(position.middle_right, 7, 6, color.rgb(19, 23, 34), color.white, 2, color.white, 2)
color textCl = color.white
color clCom     = color.gray
color clNoncom  = color.blue
color clSpec    = color.orange
// }

// INPUTS {
i_dataSource = input.string('Futures Only', 'Data', ['Futures Only', 'Futures and Options'])
i_showCom = input.bool(true, 'Show Commercials')
// }

// Functions {
f_getCl(value) =>
    if value > 0
        color.lime
    else if value < 0
        color.red
    else
        color.white 
// }

// Request {
sHead = 'QUANDL:CFTC/'
sData = i_dataSource == 'Futures Only' ? '_F_L_ALL|' : '_FO_L_ALL|'

// Financial Markets (Commercial)
comColumnLong = '4'
comColumnShort = '5'

// Non-Commercials (large Speculators)
noncomColumnLong = '1'
noncomColumnShort = '2'

// Non-Reportable (small Speculators)
specColumnLong = '8'
specColumnShort = '9'

// CFTC Market Codes
// Codes from https://data.nasdaq.com/data/CFTC-commodity-futures-trading-commission-reports

f_getCode(pair) =>
    string code = switch pair
        'USD' => '098662'       // USD Index
        'EUR' => '099741'
        'AUD' => '232741'
        'GBP' => '096742'
        'CAD' => '090741'
        'JPY' => '097741'
        'CHF' => '092741'
        'NZD' => '112741'
        'BTC' => '133741'
        'GOLD' => '088691'
        'SILVER' => '084691'
        'PLATINUM' => '076651'
        'PALLADIUM' => '075651'
        'ALUMINUM' => '191651'
        'COPPER' => '085692'
        'CRUDE OIL' => 'T'
        'SOYBEAN OIL' => '007601'
        'S&P 500' => '13874P'
        'S&P 500 Mini' => '13874A'
        'Dow Jones' => '12460P'
        'NIKKEI' => '240741'
        'NASDAQ' => '20974P'
        'RUSSELL 2000' => '239777'
        'Volatility S&P 500' => '1170E1'
        => ''
    code

f_getTicker() =>
    switch syminfo.ticker
        'GOLD' => 'GOLD'
        'GOLD1!' => 'GOLD'
        'XAU' => 'GOLD'
        'XAUUSD' => 'GOLD'
        'SILVER' => 'SILVER'
        'SILVER1!' => 'SILVER'
        'PLATINUM' => 'PLATINUM'
        'PALLADIUM' => 'PALLADIUM'
        'COPPER' => 'COPPER'
        'ALUMINUM' => 'ALUMINUM'
        'OIL' => 'CRUDE OIL'
        'CL1!' => 'CRUDE OIL'
        'SOYUSD' => 'SOYBEAN OIL'
        'ZL1!' => 'SOYBEAN OIL'
        'SPX' => 'S&P 500'
        'ES1!' => 'S&P 500'
        'XSP' => 'S&P 500 Mini'
        'NKD' => 'NIKKEI'
        'NKD1!' => 'NIKKEI'
        'NK225' => 'NIKKEI'
        'NK2251!' => 'NIKKEI'
        'DJI' => 'Dow Jones'
        'US30' => 'Dow Jones'
        'NASDAQ' => 'NASDAQ'
        'US100' => 'NASDAQ'
        'RUT' => 'RUSSELL 2000'
        'RTY' => 'RUSSELL 2000'
        'VIX' => 'Volatility S&P 500'
        => ''

f_getCurrency(curr) =>
    if curr == ''
        f_getTicker()
    else
        curr

f_getCurrencyAB(base, quote) => 
    retBase = f_getCurrency(base)
    retQuote = f_getCurrency(quote)

    // find a correlating currency for that ticker
    if retBase == retQuote or retQuote == ''
        retQuote := switch retBase
            'S&P 500' => 'USD'
            'S&P 500 Mini' => 'USD'
            => quote

    [retBase, retQuote]

// Data functions
// Commercials
dLong(asCode) =>
    request.security(sHead + asCode + sData + comColumnLong, 'W', close, lookahead=barmerge.lookahead_on)
dShort(asCode) =>
    request.security(sHead + asCode + sData + comColumnShort, 'W', close, lookahead=barmerge.lookahead_on)

// large - Non Commercials
dLong2(asCode2) =>
    request.security(sHead + asCode2 + sData + noncomColumnLong, 'W', close, lookahead=barmerge.lookahead_on)
dShort2(asCode2) =>
    request.security(sHead + asCode2 + sData + noncomColumnShort, 'W', close, lookahead=barmerge.lookahead_on)

// small - Non-Reportable
dLong3(asCode3) =>
    request.security(sHead + asCode3 + sData + specColumnLong, 'W', close, lookahead=barmerge.lookahead_on)
dShort3(asCode3) =>
    request.security(sHead + asCode3 + sData + specColumnShort, 'W', close, lookahead=barmerge.lookahead_on)

f_getData(code) =>
    comLong = dLong(code)
    comShort = dShort(code)
    noncomLong = dLong2(code)
    noncomShort = dShort2(code)
    specLong = dLong3(code)
    specShort = dShort3(code)
    
    [comLong, comShort, noncomLong, noncomShort, specLong, specShort]

f_calcNet(comLong, comShort, noncomLong, noncomShort, specLong, specShort) =>
    netCom = comLong - comShort
    netNoncom = noncomLong - noncomShort
    netSpec = specLong - specShort
    
    [netCom, netNoncom, netSpec]
// }


// Calculations {
[currencyA, currencyB] = f_getCurrencyAB(syminfo.basecurrency, syminfo.currency)

codeA = f_getCode(currencyA)
codeB = f_getCode(currencyB)

[pairA_coms_long, pairA_coms_short, pairA_noncoms_long, pairA_noncoms_short, pairA_spec_long, pairA_spec_short] = f_getData(codeA)
[pairB_coms_long, pairB_coms_short, pairB_noncoms_long, pairB_noncoms_short, pairB_spec_long, pairB_spec_short] = f_getData(codeB)


// Calc net
[net_comA, net_noncomA, net_specA] = f_calcNet(pairA_coms_long, pairA_coms_short, pairA_noncoms_long, pairA_noncoms_short, pairA_spec_long, pairA_spec_short)
[net_comB, net_noncomB, net_specB] = f_calcNet(pairB_coms_long, pairB_coms_short, pairB_noncoms_long, pairB_noncoms_short, pairB_spec_long, pairB_spec_short)

net_comApercentLong = pairA_coms_long / (pairA_coms_long + pairA_coms_short) * 100
net_comBpercentLong = pairB_coms_long / (pairB_coms_long + pairB_coms_short) * 100

net_noncomApercentLong = pairA_noncoms_long / (pairA_noncoms_long + pairA_noncoms_short) * 100
net_noncomBpercentLong = pairB_noncoms_long / (pairB_noncoms_long + pairB_noncoms_short) * 100

net_specApercentLong = pairA_spec_long / (pairA_spec_long + pairA_spec_short) * 100
net_specBpercentLong = pairB_spec_long / (pairB_spec_long + pairB_spec_short) * 100

// --------------


// // percent calculation
symbol_com_sum = pairA_coms_long + pairA_coms_short + pairB_coms_long + pairB_coms_short
symbol_com_long = (pairA_coms_long + pairB_coms_short) / symbol_com_sum * 100
symbol_com_short = (pairA_coms_short + pairB_coms_long) / symbol_com_sum * 100

symbol_noncom_sum = pairA_noncoms_long + pairA_noncoms_short + pairB_noncoms_long + pairB_noncoms_short
symbol_noncom_long = (pairA_noncoms_long + pairB_noncoms_short) / symbol_noncom_sum * 100
symbol_noncom_short = (pairA_noncoms_short + pairB_noncoms_long) / symbol_noncom_sum * 100


symbol_spec_sum = pairA_spec_long + pairA_spec_short + pairB_spec_long + pairB_spec_short
symbol_spec_long = (pairA_spec_long + pairB_spec_short) / symbol_spec_sum * 100
symbol_spec_short = (pairA_spec_short + pairB_spec_long) / symbol_spec_sum * 100
// }


// Plots {
plot_com = i_showCom ? symbol_com_long : na

plotStyle = if (timeframe.isweekly or timeframe.ismonthly) 
    plot.style_line 
else
    plot.style_stepline

plot(plot_com, "Commercials", clCom, 3, plotStyle, histbase=0)
plot(symbol_noncom_long, "Non-Commercials", clNoncom, 3, plotStyle, histbase=0)
plot(symbol_spec_long, "Retail Traders", clSpec, 3, plotStyle, histbase=0)

// Labels
if i_showCom
    label comLabel = label.new(bar_index+1, symbol_com_long, 'Commercials', xloc.bar_index, yloc.price, clCom, label.style_label_left)
    label.delete(comLabel[1])

label noncomLabel = label.new(bar_index+1, symbol_noncom_long, 'Non-Commercials', xloc.bar_index, yloc.price, clNoncom, label.style_label_left)
label specLabel = label.new(bar_index+1, symbol_spec_long, 'Retail Traders', xloc.bar_index, yloc.price, clSpec, label.style_label_left)

label.delete(noncomLabel[1])
label.delete(specLabel[1])

// Table
f_textCell(col, row, txt) =>
    table.cell(t, col, row, txt, text_color=textCl)

f_fillCell(col, row, value) =>
    valueStr = str.tostring(value, format.volume)

    cl = f_getCl(value)
    table.cell(t, col, row, valueStr, text_color=cl)
    
f_fillPercent(col, row, value, isLong) =>
    valueStr = str.tostring(value, format.volume) + '%'

    cl = if isLong and value > 50
        color.lime
    else if not isLong and value > 50
        color.red
    else
        color.white
    table.cell(t, col, row, valueStr, text_color=cl)

// Merge cells
table.merge_cells(t, 1, 0, 3, 0)
table.merge_cells(t, 4, 0, 6, 0)

f_textCell(1, 0, currencyA)
f_textCell(4, 0, currencyB)

f_textCell(1, 1, 'Net Contracts')
f_textCell(2, 1, 'Long')
f_textCell(3, 1, 'Short')

f_textCell(4, 1, 'Net Contracts')
f_textCell(5, 1, 'Long')
f_textCell(6, 1, 'Short')

if i_showCom
    table.cell(t, 0, 2, 'Commercials', text_color=textCl)
    f_fillCell(1, 2, net_comA)
    f_fillCell(4, 2, net_comB)
    f_fillPercent(2, 2, net_comApercentLong, true)
    f_fillPercent(3, 2, 100-net_comApercentLong, false)
    f_fillPercent(5, 2, net_comBpercentLong, true)
    f_fillPercent(6, 2, 100-net_comBpercentLong, false)

table.cell(t, 0, 3, 'Institutional', text_color=textCl)
f_fillCell(1, 3, net_noncomA)
f_fillCell(4, 3, net_noncomB)

f_fillPercent(2, 3, net_noncomApercentLong, true)
f_fillPercent(3, 3, 100-net_noncomApercentLong, false)
f_fillPercent(5, 3, net_noncomBpercentLong, true)
f_fillPercent(6, 3, 100-net_noncomBpercentLong, false)

table.cell(t, 0, 4, 'Retail Traders', text_color=textCl)
f_fillCell(1, 4, net_specA)
f_fillCell(4, 4, net_specB)

f_fillPercent(2, 4, net_specApercentLong, true)
f_fillPercent(3, 4, 100-net_specApercentLong, false)
f_fillPercent(5, 4, net_specBpercentLong, true)
f_fillPercent(6, 4, 100-net_specBpercentLong, false)


hplot0 = hline(0)
hplot50 = hline(50)
hplot100 = hline(100)

color clShort = color.new(color.red, 90)
color clLong = color.new(color.green, 90)

fill(hplot0, hplot50, clShort)
fill(hplot50, hplot100, clLong)

// }
0 + 0 = 0
Infinite / Infinite = 1
1 way to Heaven & it matters

Re: Already Converted TradingView Indicators to MT4 Indicators

307
also not sure if this is possible, it is the open interest profile very very good
the one in the picture is what it should look like but there wasnt source code for it so this is leviathancapital , he makes good free ones

Code: Select all

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Leviathan

// Some elements of generating Profiles are inspired by @LonesomeTheBlue's volume profile script

//@version=5
indicator("Open Interest Profile - By Leviathan", overlay=true, max_boxes_count=500, max_bars_back=1000)

//==========================
//Inputs
//==========================
sessionType = input.string('Weekly', 'Session / Lookback', options=['Tokyo','London','New York','Daily','Weekly', 'Monthly'])

dispMode = input.string('Mode 3', 'OI Profile Mode', ['Mode 1', 'Mode 2', 'Mode 3'], group='Display')
showVAb = input.bool(false, 'Show OI Value Area', group='Display')
showSbox = input.bool(false, 'Show Session Box', group='Display')
showProf = input.bool(true, 'Show Profile', group='Display')
showCur = input.bool(true, 'Show Current Session', group='Display')
showLabels = input.bool(false, 'Show Session Lables', group='Display')
resolution = input.int(50, 'Resolution', minval=5, tooltip='The higher the value, the more refined of a profile, but less profiles shown on chart', group='Profile Settings')
volType = input.string('Open Interest', 'Profile Data Type', options=['Open Interest'], group='Profile Settings')
VAwid = input.int(60, 'OI Value Area %', minval=1, maxval=100, group='Profile Settings')
smoothVol = input.bool(false, 'Smooth OI Data', tooltip='Useful for assets that have very large spikes in volume over large bars, helps create better profiles', group='Profile Settings')
dataTf = ''

bullCol = input.color(color.rgb(76, 175, 79, 50), 'OI Increase', group='Appearance')
bearCol = input.color(color.rgb(255, 82, 82, 50), 'OI Decrease', group='Appearance')
VAbCol = input.color(color.rgb(107, 159, 255, 90), 'Value Area Box', group='Appearance' )
boxWid = input.int(1, 'Session Box Thickness', group='Appearance')

//==========================
//Constants / Variable Declaration
//========================== 
var int zoneStart = 0
var int tokyoStart = 0
var int londonStart = 0
var int nyStart = 0
int lookback = bar_index - zoneStart
var activeZone = false

// Defining arrays that store the information
var vpGreen = array.new_float(resolution, 0) // Sum of volume on long bars
var vpRed = array.new_float(resolution, 0) // Same thing but with red bars
var zoneBounds = array.new_float(resolution, 0) // array that stores the highest value that can be in a zone

//Values to store current intra bar data
var float[] ltfOpen =  array.new_float(0)
var float[] ltfClose =  array.new_float(0)
var float[] ltfHigh =  array.new_float(0)
var float[] ltfLow =  array.new_float(0)
var float[] ltfVolume = array.new_float(0)

//Getting OI Data
string userSymbol = syminfo.prefix + ":" + syminfo.ticker
string openInterestTicker = str.format("{0}_OI", userSymbol)
string timeframe = syminfo.type == "futures" and timeframe.isintraday ? "1D" : timeframe.period
deltaOi = request.security(openInterestTicker, timeframe, close-close[1], ignore_invalid_symbol = true)

//Selecting what vol type to use
vol() =>
    out = smoothVol ? ta.ema(volume, 5) : volume
    if volType == 'Open Interest'
        out := deltaOi
    out

//Getting intrabar intial data
[dO, dC, dH, dL, dV] = request.security_lower_tf(syminfo.tickerid, dataTf, [open, close, high, low, vol()])

//==========================
//Functions
//==========================
resetProfile(enable) =>
    if enable
        array.fill(vpGreen, 0)
        array.fill(vpRed, 0)
        array.clear(ltfOpen)
        array.clear(ltfHigh)
        array.clear(ltfLow)
        array.clear(ltfClose)
        array.clear(ltfVolume)

profHigh = ta.highest(high, lookback+1)[1]
profLow = ta.lowest(low, lookback+1)[1]

tr = ta.atr(1)
atr = ta.atr(14)

get_vol(y11, y12, y21, y22, height, vol) =>
    nz(math.max(math.min(math.max(y11, y12), math.max(y21, y22)) - math.max(math.min(y11, y12), math.min(y21, y22)), 0) * vol / height)

profileAdd(o, h, l, c, v, g, w) =>
    //Array to store how much to distribute in each zone, on scale of 1 for full gap size to 0
    zoneDist = array.new_float(resolution, 0)
    distSum = 0.0
    // Going over each zone
    for i = 0 to array.size(vpGreen) - 1
        // Checking to see if cur bar is in zone
        zoneTop = array.get(zoneBounds, i)
        zoneBot = zoneTop - g

        body_top = math.max(c, o)
        body_bot = math.min(c, o)
        itsgreen = c >= o

        topwick = h - body_top
        bottomwick = body_bot - l
        body = body_top - body_bot

        bodyvol = body * v / (2 * topwick + 2 * bottomwick + body)
        topwickvol = 2 * topwick * v / (2 * topwick + 2 * bottomwick + body)
        bottomwickvol = 2 * bottomwick * v / (2 * topwick + 2 * bottomwick + body)

        if volType == 'Volume'
            array.set(vpGreen, i, array.get(vpGreen, i) + (itsgreen ? get_vol(zoneBot, zoneTop, body_bot, body_top, body, bodyvol) : 0) + get_vol(zoneBot, zoneTop, body_top, h, topwick, topwickvol) / 2 + get_vol(zoneBot, zoneTop, body_bot, l, bottomwick, bottomwickvol) / 2)
            array.set(vpRed, i, array.get(vpRed, i) + (itsgreen ? 0 : get_vol(zoneBot, zoneTop, body_bot, body_top, body, bodyvol)) + get_vol(zoneBot, zoneTop, body_top, h, topwick, topwickvol) / 2 + get_vol(zoneBot, zoneTop, body_bot, l, bottomwick, bottomwickvol) / 2)
        else if volType == 'Open Interest'
            if v > 0    
                array.set(vpGreen, i, array.get(vpGreen, i) + get_vol(zoneBot, zoneTop, body_bot, body_top, body, v))// + get_vol(zoneBot, zoneTop, body_top, h, topwick, topwickvol) / 2 + get_vol(zoneBot, zoneTop, body_bot, l, bottomwick, bottomwickvol) / 2)
            if v < 0
                array.set(vpRed, i, array.get(vpRed, i) + get_vol(zoneBot, zoneTop, body_bot, body_top, body, -v))// + get_vol(zoneBot, zoneTop, body_top, h, topwick, topwickvol) / 2 + get_vol(zoneBot, zoneTop, body_bot, l, bottomwick, bottomwickvol) / 2)

calcSession(update) =>
    array.fill(vpGreen, 0)
    array.fill(vpRed, 0)
    if bar_index > lookback and update
        gap = (profHigh - profLow) / resolution

        // Defining profile bounds
        for i = 0 to resolution - 1
            array.set(zoneBounds, i, profHigh - gap * i)

        // Putting each bar inside zone into the volume profile array
        if array.size(ltfOpen) > 0
            for j = 0 to array.size(ltfOpen) - 1    
                profileAdd(array.get(ltfOpen, j), array.get(ltfHigh, j), array.get(ltfLow, j), array.get(ltfClose, j), array.get(ltfVolume, j), gap, 1)

pocLevel() =>
    float maxVol = 0
    int levelInd = 0
    for i = 0 to array.size(vpRed) - 1
        if array.get(vpRed, i) + array.get(vpGreen, i) > maxVol
            maxVol := array.get(vpRed, i) + array.get(vpGreen, i)
            levelInd := i
    
    float outLevel = na
    if levelInd != array.size(vpRed) - 1
        outLevel := array.get(zoneBounds, levelInd) - (array.get(zoneBounds, levelInd) - array.get(zoneBounds, levelInd+1)) / 2
    outLevel

valueLevels(poc) =>
    float gap = (profHigh - profLow) / resolution
    float volSum = array.sum(vpRed) + array.sum(vpGreen)
    float volCnt = 0
    
    float vah = profHigh
    float val = profLow

    //Finding poc index
    int pocInd = 0
    for i = 0 to array.size(zoneBounds)-2
        if array.get(zoneBounds, i) >= poc and array.get(zoneBounds, i + 1) < poc
            pocInd := i
    
    volCnt += (array.get(vpRed, pocInd) + array.get(vpGreen, pocInd))
    for i = 1 to array.size(vpRed)
        if pocInd + i >= 0 and pocInd + i < array.size(vpRed)    
            volCnt += (array.get(vpRed, pocInd + i) + array.get(vpGreen, pocInd + i))
            if volCnt >= volSum * (VAwid/100)   
                break 
            else
                val := array.get(zoneBounds, pocInd + i) - gap
        if pocInd - i >= 0 and pocInd - i < array.size(vpRed)    
            volCnt += (array.get(vpRed, pocInd - i) + array.get(vpGreen, pocInd - i))
            if volCnt >= volSum * (VAwid/100)    
                break 
            else
                vah := array.get(zoneBounds, pocInd - i)

    [val, vah]

drawNewZone(update) =>
    if bar_index > lookback and update and array.sum(vpGreen) + array.sum(vpRed) > 0
        gap = (profHigh - profLow) / resolution
        float leftMax = bar_index[lookback]
        float rightMax = bar_index[int(lookback / 1.4)]
        float rightMaxVol = array.max(vpGreen)+array.max(vpRed)
        float buffer = gap / 10
        if showLabels
            label.new((bar_index - 1 + int(leftMax))/2, profHigh, sessionType, color=color.rgb(0,0,0,100), textcolor=chart.fg_color)
        if showProf
            for i = 0 to array.size(vpRed) - 1
                greenEnd = int(leftMax + (rightMax - leftMax) * (array.get(vpGreen, i) / rightMaxVol))
                redEnd = int(greenEnd + (rightMax - leftMax) * (array.get(vpRed, i) / rightMaxVol))
                if dispMode == 'Mode 2'
                    box.new(int(leftMax), array.get(zoneBounds, i) - buffer, greenEnd, array.get(zoneBounds, i) - gap + buffer, bgcolor=bullCol, border_width=0)
                    box.new(greenEnd, array.get(zoneBounds, i) - buffer, redEnd, array.get(zoneBounds, i) - gap + buffer, bgcolor=bearCol, border_width=0)
                else if dispMode == 'Mode 1'
                    box.new(int(leftMax), array.get(zoneBounds, i) - buffer, greenEnd, array.get(zoneBounds, i) - gap + buffer, bgcolor=bullCol, border_width=0)
                else 
                    box.new(int(leftMax), array.get(zoneBounds, i) - buffer, greenEnd, array.get(zoneBounds, i) - gap + buffer, bgcolor=bullCol, border_width=0)
                    box.new(int(leftMax)-redEnd+greenEnd, array.get(zoneBounds, i) - buffer, int(leftMax), array.get(zoneBounds, i) - gap + buffer, bgcolor=bearCol, border_width=0)

        poc = pocLevel()
        [val, vah] = valueLevels(poc)
        if showVAb
            box.new(int(leftMax), vah, bar_index-1, val, border_color=color.rgb(54, 58, 69, 100), bgcolor=VAbCol)
        if showSbox
            box.new(int(leftMax), profHigh, bar_index-1, profLow, chart.fg_color, boxWid, line.style_dashed, bgcolor=color.rgb(0,0,0,100))


    //if update    
    //    resetProfile(true)

drawCurZone(update, delete) =>
    var line pocLine = na
    var line vahLine = na
    var line valLine = na
    var box outBox = na
    var label sessionLab = na

    var redBoxes = array.new_box(array.size(vpRed), na)
    var greenBoxes = array.new_box(array.size(vpRed), na)

    if bar_index > lookback and update and array.sum(vpGreen) + array.sum(vpRed) > 0
        //Clearing the previous boxes and array
        if not na(pocLine)
            line.delete(pocLine)
        if not na(vahLine)
            line.delete(vahLine)
        if not na(valLine)
            line.delete(valLine)
        if not na(outBox)
            box.delete(outBox)
        if not na(sessionLab)
            label.delete(sessionLab)

        for i = 0 to array.size(redBoxes) - 1
            if not na(array.get(redBoxes, i))
                box.delete(array.get(redBoxes, i))
                box.delete(array.get(greenBoxes, i))

        
        gap = (profHigh - profLow) / resolution
        float leftMax = bar_index[lookback]
        float rightMax = bar_index[int(lookback / 1.4)]
        float rightMaxVol = array.max(vpGreen)+array.max(vpRed)
        float buffer = gap / 10
        if showLabels
            sessionLab := label.new((bar_index - 1 + int(leftMax))/2, profHigh, sessionType, color=color.rgb(0,0,0,100), textcolor=chart.fg_color)
        if showProf
            for i = 0 to array.size(vpRed) - 1
                greenEnd = int(leftMax + (rightMax - leftMax) * (array.get(vpGreen, i) / rightMaxVol))
                redEnd = int(greenEnd + (rightMax - leftMax) * (array.get(vpRed, i) / rightMaxVol))
                if dispMode == 'Mode 2'
                    array.set(greenBoxes, i, box.new(int(leftMax), array.get(zoneBounds, i) - buffer, greenEnd, array.get(zoneBounds, i) - gap + buffer, bgcolor=bullCol, border_width=0))
                    array.set(redBoxes, i, box.new(greenEnd, array.get(zoneBounds, i) - buffer, redEnd, array.get(zoneBounds, i) - gap + buffer, bgcolor=bearCol, border_width=0))
                else if dispMode == 'Mode 1'
                    array.set(greenBoxes, i, box.new(int(leftMax), array.get(zoneBounds, i) - buffer, greenEnd, array.get(zoneBounds, i) - gap + buffer, bgcolor=bullCol, border_width=0))
                else 
                    array.set(greenBoxes, i, box.new(int(leftMax), array.get(zoneBounds, i) - buffer, greenEnd, array.get(zoneBounds, i) - gap + buffer, bgcolor=bullCol, border_width=0))
                    array.set(redBoxes, i, box.new(int(leftMax)-redEnd+greenEnd, array.get(zoneBounds, i) - buffer, int(leftMax), array.get(zoneBounds, i) - gap + buffer, bgcolor=bearCol, border_width=0))
        

        poc = pocLevel()
        [val, vah] = valueLevels(poc)
        if showVAb
            box.new(int(leftMax), vah, bar_index-1, val, border_color=color.rgb(54, 58, 69, 100), bgcolor=VAbCol)
        if showSbox
            box.new(int(leftMax), profHigh, bar_index-1, profLow, chart.fg_color, boxWid, line.style_dashed, bgcolor=color.rgb(0,0,0,100))

    if delete
        box.delete(outBox)
        line.delete(pocLine)
        line.delete(vahLine)
        line.delete(valLine)
        for i = 0 to array.size(greenBoxes)-1
            box.delete(array.get(greenBoxes, i))
        for i = 0 to array.size(redBoxes)-1
            box.delete(array.get(redBoxes, i))

drawForexBox(startBar, title, top, bottom) =>
    box.new(int(startBar), top, bar_index-1, bottom, chart.fg_color, 2, line.style_dashed, bgcolor=color.rgb(0,0,0,100))
    if showLabels    
        label.new((bar_index - 1 + int(startBar))/2, top, title, color=color.rgb(0,0,0,100), textcolor=chart.fg_color)

combArray(arr1, arr2) =>
    out = array.copy(arr1)
    if array.size(arr2) > 0
        for i = 0 to array.size(arr2) - 1
            array.push(out, array.get(arr2, i))
    out

updateIntra(o, h, l, c, v) =>
    if array.size(o) > 0
        for i = 0 to array.size(o) - 1
            array.push(ltfOpen, array.get(o, i))
            array.push(ltfHigh,array.get(h, i)) 
            array.push(ltfLow,array.get(l, i)) 
            array.push(ltfClose,array.get(c, i)) 
            array.push(ltfVolume,array.get(v, i))
    

//==========================
//Calculations
//==========================
//Detecting different start dates
newDaily = dayofweek != dayofweek[1]
newWeekly = (dayofweek != dayofweek[1] + 1) and (dayofweek != dayofweek[1])
newMonthly = (dayofmonth != dayofmonth[1] + 1) and (dayofmonth != dayofmonth[1])

utcHour = hour(time(timeframe.period, '0000-2400', 'GMT'), 'GMT')

newTokyo = utcHour != utcHour[1] + 1 and utcHour != utcHour[1]
endTokyo = utcHour >= 9 and utcHour[1] < 9

newLondon = utcHour >= 7 and utcHour[1] < 7
endLondon = utcHour >= 16 and utcHour[1] < 16

newNewYork = utcHour >= 13 and utcHour[1] < 13
endNewYork = utcHour >= 22 and utcHour[1] < 22

newSession = switch sessionType
    'Tokyo' => newTokyo
    'London' => newLondon
    'New York' => newNewYork
    'Daily' => newDaily
    'Weekly' => newWeekly
    'Monthly' => newMonthly
    => newDaily

zoneEnd = switch sessionType
    'Tokyo' => endTokyo
    'London' => endLondon
    'New York' => endNewYork
    'Daily' => newDaily
    'Weekly' => newWeekly
    'Monthly' => newMonthly
    => newDaily

isForex = sessionType == 'FX Session'

//Re calculating and drawing zones
calcSession((zoneEnd or (barstate.islast and showCur)) and not isForex)
drawNewZone(zoneEnd and not isForex)
drawCurZone(barstate.islast and not zoneEnd and showCur and activeZone and not isForex, zoneEnd)

//Reseting profie at start of new zone
resetProfile(newSession)

//Updating data arrays
updateIntra(dO, dH, dL, dC, dV)

//Reseting zone start value
if zoneEnd 
    activeZone := false

if newSession
    zoneStart := bar_index
    activeZone := true
0 + 0 = 0
Infinite / Infinite = 1
1 way to Heaven & it matters

Re: Already Converted TradingView Indicators to MT4 Indicators

308
Jedidiah wrote: Wed Nov 09, 2022 9:25 pm

Code: Select all

// © Dreadblitz
//@version=4
study(shorttitle="AAFLI", title="Angle Attack Follow Line Indicator ", overlay=false, max_bars_back=1000)

//INPUTS ————————————————————————————————————————————————————————————
FL            = input(title  = "🔰🔰🔰🔰 FOLLOW LINE CURRENT CHART RESOLUTION 🔰🔰🔰🔰", defval = true, type = input.bool)

BBperiod      = input(defval = 21,   title = "Period",    type = input.integer, minval = 1)
BBdeviations  = input(defval = 1.00, title = "Deviations",    type = input.float, minval = 0.1, step=0.05)
UseATRfilter  = input(defval = true, title = "ATR Filter",  type = input.bool)
ATRperiod     = input(defval = 5,    title = "ATR Period",    type = input.integer, minval = 1)

FLH           = input(title  = "🔰🔰🔰🔰🔰 FOLLOW LINE HIGHER TIME FRAME 🔰🔰🔰🔰🔰", defval = true, type = input.bool)

AIB           = input(defval = true, title = "Activate Indicator Background",  type = input.bool)
TYPE          = input(title  ="Type Of MA", defval="SMA", options=["RMA", "SMA", "EMA", "WMA", "VWMA", "SMMA", "KMA", "TMA", "HullMA", "DEMA", "TEMA", "CTI"])
RES           = input("240", type=input.resolution, title="Resolution")
LEN           = input(21, title = "Period", type=input.integer)
BBdeviations_ = input(defval = 1.00,title = "Deviations",    type = input.float, minval = 0.1, step=0.05)
ATRperiod_    = input(defval = 5,title = "ATR Period",    type = input.integer, minval = 1)
SOUR          = input(type=input.source,title = "Source", defval=close)

MD            = input(title  = "🔰🔰🔰🔰🔰🔰🔰🔰🔰🔰🔰 MODE 🔰🔰🔰🔰🔰🔰🔰🔰🔰🔰🔰🔰", defval = true, type = input.bool)

MODE          = input(title  ="Type Of Mode", defval="NO FILTER HIGHER TIME FRAME", options=["NO FILTER HIGHER TIME FRAME", "FILTER HIGHER TIME FRAME"])

AC            = input(title  = "🔰🔰🔰🔰🔰🔰🔰🔰 ANGLE CONFIGURATION 🔰🔰🔰🔰🔰🔰🔰", defval = true, type = input.bool)

i_lookback    = input(8,     "Angle Period", input.integer, minval = 1)
i_atrPeriod   = input(10,    "ATR Period",   input.integer, minval = 1)

BSA           = input(title  = "🔰🔰🔰🔰🔰🔰🔰🔰🔰🔰 BUY/SELL 🔰🔰🔰🔰🔰🔰🔰🔰🔰🔰", defval = true, type = input.bool)

Buy_0         = input(defval = true, title = "Buy Change Follow Line",  type = input.bool)
Sell_0        = input(defval = true, title = "Sell Change Follow Line",  type = input.bool)

OTA           = input(title  = "🔰🔰🔰🔰🔰🔰🔰🔰🔰 OPTIONS TO ADD 🔰🔰🔰🔰🔰🔰🔰🔰", defval = true, type = input.bool)

Add_Buy_0     = input(defval = true, title = "Option 1 to Add Buy",  type = input.bool)
Add_Sell_0    = input(defval = true, title = "Option 1 to Add Sell",  type = input.bool)
Add_Buy_1     = input(defval = false, title = "Option 2 to Add Buy",  type = input.bool)
Add_Sell_1    = input(defval = false, title = "Option 2 to Add Sell",  type = input.bool)
Add_Buy_2     = input(defval = false, title = "Option 3 to Add Buy",  type = input.bool)
Add_Sell_2    = input(defval = false, title = "Option 3 to Add Sell",  type = input.bool)

OTR           = input(title  = "🔰🔰🔰🔰🔰🔰🔰🔰 OPTIONS TO REDUCE 🔰🔰🔰🔰🔰🔰🔰🔰", defval = true, type = input.bool)

Max_level_1   = input(defval = 40,   title = "Max Angle Level 1",    type = input.integer, minval = 1)
Max_level_2   = input(defval = 65,   title = "Max Angle Level 2",    type = input.integer, minval = 1)
Min_level_1   = input(defval = -40,  title = "Min Angle Level 1",    type = input.integer, minval = -100)
Min_level_2   = input(defval = -65,  title = "Min Angle Level 2",    type = input.integer, minval = -100)
Red_Buy_0     = input(defval = true, title = "Option 1 to Reduce Buy Max Angle Level 1",  type = input.bool)
Red_Buy_1     = input(defval = true, title = "Option 2 to Reduce Buy Max Angle Level 2",  type = input.bool)
Red_Buy_2     = input(defval = false,title = "Option 3 to Reduce Buy 2 Bars Above Max Angle Level 2",  type = input.bool)
Red_Buy_3     = input(defval = true, title = "Option 4 to Reduce Buy 3 Bars Above Max Angle Level 2",  type = input.bool)
Red_Buy_4     = input(defval = false,title = "Option 5 to Reduce Buy 4 Bars Above Max Angle Level 2",  type = input.bool)
Red_Sell_0    = input(defval = true, title = "Option 1 to Reduce Sell Min Angle Level 1",  type = input.bool)
Red_Sell_1    = input(defval = true, title = "Option 2 to Reduce Sell Min Angle Level 1",  type = input.bool)
Red_Sell_2    = input(defval = false,title = "Option 3 to Reduce Sell 2 bars Below Min Angle Level 2",  type = input.bool)
Red_Sell_3    = input(defval = true, title = "Option 4 to Reduce Sell 3 bars Below Min Angle Level 2",  type = input.bool)
Red_Sell_4    = input(defval = false,title = "Option 5 to Reduce Sell 4 bars Below Min Angle Level 2",  type = input.bool)


OTH           = input(title  = "🔰🔰🔰🔰🔰🔰🔰🔰🔰🔰 OTHERS 🔰🔰🔰🔰🔰🔰🔰🔰🔰🔰🔰", defval = true, type = input.bool)

i_barColor    = input(true, "Bar Color?")
h_lables      = input(false, "Hide Labels")


// FOLLOW LINE —————————————————————————————————————————————————————

BBUpper=sma (close,BBperiod)+stdev(close, BBperiod)*BBdeviations
BBLower=sma (close,BBperiod)-stdev(close, BBperiod)*BBdeviations
TrendLine = 0.0
iTrend = 0.0
BBSignal = close>BBUpper? 1 : close<BBLower? -1 : 0
if BBSignal == 1 and UseATRfilter == 1
    TrendLine:=low-atr(ATRperiod)
    if TrendLine<TrendLine[1] 
        TrendLine:=TrendLine[1]
if BBSignal == -1 and UseATRfilter == 1
    TrendLine:=high+atr(ATRperiod)
    if TrendLine>TrendLine[1]
        TrendLine:=TrendLine[1]
if BBSignal == 0 and UseATRfilter == 1
    TrendLine:=TrendLine[1]
if BBSignal == 1 and UseATRfilter == 0
    TrendLine:=low
    if TrendLine<TrendLine[1] 
        TrendLine:=TrendLine[1]
if BBSignal == -1 and UseATRfilter == 0
    TrendLine:=high
    if TrendLine>TrendLine[1]
        TrendLine:=TrendLine[1]
if BBSignal == 0 and UseATRfilter == 0
    TrendLine:=TrendLine[1]
iTrend:=iTrend[1]
if TrendLine>TrendLine[1] 
    iTrend:=1
if TrendLine<TrendLine[1] 
    iTrend:=-1

// FOLLOW LINE HIGHER TIME FRAME ——————————————————————————————

cd = 0.0
cti(sm, src, cd) =>
    di = (sm - 1.0) / 2.0 + 1.0
    c1 = 2 / (di + 1.0)
    c2 = 1 - c1
    c3 = 3.0 * (cd * cd + cd * cd * cd)
    c4 = -3.0 * (2.0 * cd * cd + cd + cd * cd * cd)
    c5 = 3.0 * cd + 1.0 + cd * cd * cd + 3.0 * cd * cd
    i1 = 0.0
    i2 = 0.0
    i3 = 0.0
    i4 = 0.0
    i5 = 0.0
    i6 = 0.0
    i1 := c1*src + c2*nz(i1[1])
    i2 := c1*i1 + c2*nz(i2[1])
    i3 := c1*i2 + c2*nz(i3[1])
    i4 := c1*i3 + c2*nz(i4[1])
    i5 := c1*i4 + c2*nz(i5[1])
    i6 := c1*i5 + c2*nz(i6[1])
        
    bfr = -cd*cd*cd*i6 + c3*(i5) + c4*(i4) + c5*(i3)
    bfr

smma(src, len) =>
    smma = 0.0
    smma := na(smma[1]) ? sma(src, len) : (smma[1] * (len - 1) + src) / len
    smma

ma(smoothing, src, length) => 
    if smoothing == "RMA"
        rma(src, length)
    else
        if smoothing == "SMA"
            sma(src, length)
        else 
            if smoothing == "EMA"
                ema(src, length)
            else 
                if smoothing == "WMA"
                    wma(src, length)
				else
					if smoothing == "VWMA"
						vwma(src, length)
					else
						if smoothing == "SMMA"
						    smma(src, length)
						else
							if smoothing == "HullMA"
								wma(2 * wma(src, length / 2) - wma(src, length), round(sqrt(length)))
							else
								if smoothing == "LSMA"
									src
								else
								    if smoothing == "KMA"
								        xPrice = src
                                        xvnoise = abs(xPrice - xPrice[1])
                                        nfastend = 0.666
                                        nslowend = 0.0645
                                        nsignal = abs(xPrice - xPrice[length])
                                        nnoise = sum(xvnoise, length)
                                        nefratio = iff(nnoise != 0, nsignal / nnoise, 0)
                                        nsmooth = pow(nefratio * (nfastend - nslowend) + nslowend, 2) 
                                        nAMA = 0.0
                                        nAMA := nz(nAMA[1]) + nsmooth * (xPrice - nz(nAMA[1]))
                                        nAMA
								    else
								        if smoothing == "TMA"
									        sma(sma(close, length), length)
						                else
							                if smoothing == "DEMA"
							                    emaValue = ema(src, length)
                                                2 * emaValue - ema(emaValue, length)
							                else
							                    if smoothing == "TEMA"
							                        ema1 = ema(src, length)
                                                    ema2 = ema(ema1, length)
                                                    ema3 = ema(ema2, length)
                                                    (3 * ema1) - (3 * ema2) + ema3
							                    else
						                            if smoothing == "CTI"
                                                        cti(length, src, cd)
	    								            else
		    							                src

MA = ma(TYPE, SOUR, LEN)
MA_MTF = security(syminfo.tickerid, RES, MA)
close_ = security(syminfo.tickerid, RES, close)
low_ = security(syminfo.tickerid, RES, low)
high_ = security(syminfo.tickerid, RES, high)
atr_ = security(syminfo.tickerid, RES, atr(ATRperiod_))

BBUpper_=MA_MTF+stdev(close_, LEN)*BBdeviations_
BBLower_=MA_MTF-stdev(close_, LEN)*BBdeviations_

TrendLine_MTF = 0.0
iTrend_ = 0.0

BBSignal_ = close_>BBUpper_? 1 : close_<BBLower_? -1 : 0
 
if BBSignal_ == 1 
    TrendLine_MTF:=low_-atr_
    if TrendLine_MTF<TrendLine_MTF[1] 
        TrendLine_MTF:=TrendLine_MTF[1]
if BBSignal_ == -1 
    TrendLine_MTF:=high_+atr_
    if TrendLine_MTF>TrendLine_MTF[1]
        TrendLine_MTF:=TrendLine_MTF[1]
if BBSignal_ == 0 
    TrendLine_MTF:=TrendLine_MTF[1]

iTrend_:=iTrend_[1]
if TrendLine_MTF>TrendLine_MTF[1] 
    iTrend_:=1
if TrendLine_MTF<TrendLine_MTF[1] 
    iTrend_:=-1

// ANGLE FL———————————————————————————————————————————————————————————— 

f_angle(_src, _lookback, _atrPeriod) =>
    rad2degree = 180 / 3.14159265359
    ang = rad2degree * atan((_src[0] - _src[_lookback]) / atr(_atrPeriod))
    ang
    
_angle_fl = f_angle(TrendLine, i_lookback, i_atrPeriod)


// BUY/SELL AND NO FILTER HIGHER TIME FRAME  ————————————————————————————————————————————————————————————

buy_0 = iTrend[1] < 0 and iTrend > 0 and Buy_0 and MODE == "NO FILTER HIGHER TIME FRAME" ? 1 :0 
sell_0 = iTrend[1] > 0 and iTrend < 0 and Sell_0 and MODE == "NO FILTER HIGHER TIME FRAME"? 1 :0 

// BUY/SELL AND FILTER HIGHER TIME FRAME  ————————————————————————————————————————————————————————————

buy_0_A = iTrend[1] < 0 and iTrend > 0 and Buy_0 and MODE == "FILTER HIGHER TIME FRAME" and iTrend_==1 ? 1 :0 
sell_0_A = iTrend[1] > 0 and iTrend < 0 and Sell_0 and MODE == "FILTER HIGHER TIME FRAME" and iTrend_==-1? 1 :0 


//ADD AND NO FILTER HIGHER TIME FRAME ————————————————————————————————————————————————————————————

add_buy_1 = _angle_fl [2] > 0 and _angle_fl [1] == 0 and _angle_fl == 0 and iTrend > 0 and Add_Buy_0 and MODE == "NO FILTER HIGHER TIME FRAME" ? 1 :0 

add_sell_1 = _angle_fl [2] < 0 and _angle_fl [1] == 0 and _angle_fl == 0 and iTrend < 0 and Add_Sell_0 and MODE == "NO FILTER HIGHER TIME FRAME" ? 1 :0 

add_buy_2 = _angle_fl [5] > 0 and _angle_fl [4] == 0 and _angle_fl[3] == 0 and _angle_fl[2] == 0 and _angle_fl[1] == 0 and _angle_fl == 0 and iTrend > 0 and Add_Buy_1 and MODE == "NO FILTER HIGHER TIME FRAME" ? 1 :0 

add_sell_2 = _angle_fl [5] < 0 and _angle_fl [4] == 0 and _angle_fl[3] == 0 and _angle_fl[2] == 0 and _angle_fl[1] == 0 and _angle_fl == 0 and iTrend < 0 and Add_Sell_1 and MODE == "NO FILTER HIGHER TIME FRAME" ? 1 :0 

add_buy_3 = _angle_fl [8] > 0 and _angle_fl [7] == 0 and _angle_fl[6] == 0 and _angle_fl[5] == 0 and _angle_fl[4] == 0 and _angle_fl[3] == 0 and _angle_fl[2] == 0 and _angle_fl[1] == 0 and _angle_fl == 0 and iTrend > 0 and Add_Buy_2 and MODE == "NO FILTER HIGHER TIME FRAME" ? 1 :0 

add_sell_3 = _angle_fl [8] < 0 and _angle_fl [7] == 0 and _angle_fl[6] == 0 and _angle_fl[5] == 0 and _angle_fl[4] == 0 and _angle_fl[3] == 0 and _angle_fl[2] == 0 and _angle_fl[1] == 0 and _angle_fl == 0 and iTrend < 0 and Add_Sell_2 and MODE == "NO FILTER HIGHER TIME FRAME" ? 1 :0 

//ADD AND FILTER HIGHER TIME FRAME ————————————————————————————————————————————————————————————

add_buy_1_A = _angle_fl [2] > 0 and _angle_fl [1] == 0 and _angle_fl == 0 and iTrend > 0 and Add_Buy_0 and MODE == "FILTER HIGHER TIME FRAME" and iTrend_==1? 1 :0 

add_sell_1_A = _angle_fl [2] < 0 and _angle_fl [1] == 0 and _angle_fl == 0 and iTrend < 0 and Add_Sell_0 and MODE == "FILTER HIGHER TIME FRAME"and iTrend_==-1? 1 :0 

add_buy_2_A = _angle_fl [5] > 0 and _angle_fl [4] == 0 and _angle_fl[3] == 0 and _angle_fl[2] == 0 and _angle_fl[1] == 0 and _angle_fl == 0 and MODE == "FILTER HIGHER TIME FRAME" and iTrend_==1 and Add_Buy_1? 1 :0 

add_sell_2_A = _angle_fl [5] < 0 and _angle_fl [4] == 0 and _angle_fl[3] == 0 and _angle_fl[2] == 0 and _angle_fl[1] == 0 and _angle_fl == 0 and MODE == "FILTER HIGHER TIME FRAME" and iTrend_==-1 and Add_Sell_1 ? 1 :0 

add_buy_3_A = _angle_fl [8] > 0 and _angle_fl [7] == 0 and _angle_fl[6] == 0 and _angle_fl[5] == 0 and _angle_fl[4] == 0 and _angle_fl[3] == 0 and _angle_fl[2] == 0 and _angle_fl[1] == 0 and _angle_fl == 0 and MODE == "FILTER HIGHER TIME FRAME" and iTrend_==1 and Add_Buy_2? 1 :0 

add_sell_3_A = _angle_fl [8] < 0 and _angle_fl [7] == 0 and _angle_fl[6] == 0 and _angle_fl[5] == 0 and _angle_fl[4] == 0 and _angle_fl[3] == 0 and _angle_fl[2] == 0 and _angle_fl[1] == 0 and _angle_fl == 0 and MODE == "FILTER HIGHER TIME FRAME" and iTrend_==-1 and Add_Sell_2 ? 1 :0 


//REDUCE AND NO FILTER HIGHER TIME FRAME ————————————————————————————————————————————————————————————

Redu_buy_1 = _angle_fl [1] < Max_level_1 and _angle_fl > Max_level_1 and Red_Buy_0 and MODE == "NO FILTER HIGHER TIME FRAME"? 1 :0 
Redu_buy_2 = _angle_fl [1] < Max_level_2 and _angle_fl > Max_level_2 and Red_Buy_1 and MODE == "NO FILTER HIGHER TIME FRAME"? 1 :0 
Redu_buy_3 = _angle_fl [2] < Max_level_2 and _angle_fl [1] > Max_level_2 and _angle_fl > Max_level_2 and Red_Buy_2 and MODE == "NO FILTER HIGHER TIME FRAME"? 1 :0 
Redu_buy_4 = _angle_fl [3] < Max_level_2 and _angle_fl [2] > Max_level_2 and _angle_fl [1] > Max_level_2 and _angle_fl > Max_level_2 and Red_Buy_3 and MODE == "NO FILTER HIGHER TIME FRAME"? 1 :0 
Redu_buy_5 = _angle_fl [4] < Max_level_2 and _angle_fl [3] > Max_level_2 and _angle_fl [2] > Max_level_2 and _angle_fl [1] > Max_level_2 and _angle_fl > Max_level_2 and Red_Buy_4 and MODE == "NO FILTER HIGHER TIME FRAME"? 1 :0 

Redu_sell_1 = _angle_fl [1] > Min_level_1 and _angle_fl < Min_level_1 and Red_Sell_0 and MODE == "NO FILTER HIGHER TIME FRAME"? 1 :0 
Redu_sell_2 = _angle_fl [1] > Min_level_2 and _angle_fl < Min_level_2 and Red_Sell_1 and MODE == "NO FILTER HIGHER TIME FRAME"? 1 :0 
Redu_sell_3 = _angle_fl [2] > Min_level_2 and _angle_fl [1] < Min_level_2 and _angle_fl < Min_level_2 and Red_Sell_2 and MODE == "NO FILTER HIGHER TIME FRAME"? 1 :0 
Redu_sell_4 = _angle_fl [3] > Min_level_2 and _angle_fl [2] < Min_level_2 and _angle_fl [1] < Min_level_2 and _angle_fl < Min_level_2 and Red_Sell_3 and MODE == "NO FILTER HIGHER TIME FRAME"? 1 :0 
Redu_sell_5 = _angle_fl [4] > Min_level_2 and _angle_fl [3] < Min_level_2 and _angle_fl [2] < Min_level_2 and _angle_fl [1] < Min_level_2 and _angle_fl < Min_level_2 and Red_Sell_4 and MODE == "NO FILTER HIGHER TIME FRAME"? 1 :0 

//REDUCE AND FILTER HIGHER TIME FRAME ————————————————————————————————————————————————————————————

Redu_buy_1_A = _angle_fl [1] < Max_level_1 and _angle_fl > Max_level_1 and Red_Buy_0 and MODE == "FILTER HIGHER TIME FRAME" and iTrend_==1? 1 :0 
Redu_buy_2_A = _angle_fl [1] < Max_level_2 and _angle_fl > Max_level_2 and Red_Buy_1 and MODE == "FILTER HIGHER TIME FRAME" and iTrend_==1? 1 :0 
Redu_buy_3_A = _angle_fl [2] < Max_level_2 and _angle_fl [1] > Max_level_2 and _angle_fl > Max_level_2 and Red_Buy_2 and MODE == "FILTER HIGHER TIME FRAME" and iTrend_==1? 1 :0 
Redu_buy_4_A = _angle_fl [3] < Max_level_2 and _angle_fl [2] > Max_level_2 and _angle_fl [1] > Max_level_2 and _angle_fl > Max_level_2 and Red_Buy_3 and MODE == "FILTER HIGHER TIME FRAME" and iTrend_==1? 1 :0 
Redu_buy_5_A = _angle_fl [4] < Max_level_2 and _angle_fl [3] > Max_level_2 and _angle_fl [2] > Max_level_2 and _angle_fl [1] > Max_level_2 and _angle_fl > Max_level_2 and Red_Buy_4 and MODE == "FILTER HIGHER TIME FRAME" and iTrend_==1? 1 :0 

Redu_sell_1_A = _angle_fl [1] > Min_level_1 and _angle_fl < Min_level_1 and Red_Sell_0 and MODE == "FILTER HIGHER TIME FRAME" and iTrend_==-1? 1 :0 
Redu_sell_2_A = _angle_fl [1] > Min_level_2 and _angle_fl < Min_level_2 and Red_Sell_1 and MODE == "FILTER HIGHER TIME FRAME" and iTrend_==-1? 1 :0 
Redu_sell_3_A = _angle_fl [2] > Min_level_2 and _angle_fl [1] < Min_level_2 and _angle_fl < Min_level_2 and Red_Sell_2 and MODE == "FILTER HIGHER TIME FRAME" and iTrend_==-1? 1 :0 
Redu_sell_4_A = _angle_fl [3] > Min_level_2 and _angle_fl [2] < Min_level_2 and _angle_fl [1] < Min_level_2 and _angle_fl < Min_level_2 and Red_Sell_3 and MODE == "FILTER HIGHER TIME FRAME" and iTrend_==-1? 1 :0 
Redu_sell_5_A = _angle_fl [4] > Min_level_2 and _angle_fl [3] < Min_level_2 and _angle_fl [2] < Min_level_2 and _angle_fl [1] < Min_level_2 and _angle_fl < Min_level_2 and Red_Sell_4 and MODE == "FILTER HIGHER TIME FRAME" and iTrend_==-1? 1 :0 

// PLOT ————————————————————————————————————————————————————————————

_color_fl = iTrend > 0?color.blue:color.red

plot(_angle_fl,"Angle Follow Line", _color_fl, 3, plot.style_line)
plot(_angle_fl,"Angle Follow Line Histogram", _color_fl, 3, plot.style_histogram)

hline(Max_level_1, title='Max Angle Level 1', color=color.blue, linestyle=hline.style_dotted, linewidth=1)
hline(Max_level_2, title='Max Angle Level 2', color=color.blue, linestyle=hline.style_dotted, linewidth=1)
hline(Min_level_1, title='Min Angle Level 1', color=color.red, linestyle=hline.style_dotted, linewidth=1)
hline(Min_level_2, title='Min Angle Level 2', color=color.red, linestyle=hline.style_dotted, linewidth=1)


plotshape(h_lables == false and (sell_0 or sell_0_A) ? 5 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white,transp=0)
plotshape(h_lables == false and (buy_0 or buy_0_A)? -5 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.blue, textcolor=color.white,transp=0)

plotshape(h_lables == false and (add_sell_1 or add_sell_1_A or add_sell_2 or add_sell_3 or add_sell_2_A or add_sell_3_A) ? _angle_fl +5 : na, title="Add Sell 1", text="Add", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white,transp=0)
plotshape(h_lables == false and (add_buy_1 or add_buy_1_A or add_buy_2 or add_buy_3 or add_buy_2_A or add_buy_3_A) ? _angle_fl -5 : na, title="Add Buy 1", text="Add", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.blue, textcolor=color.white,transp=0)

plotshape(h_lables == false and (Redu_buy_1 or Redu_buy_1_A)? _angle_fl +5 : na, title="Reduce Buy 1", text="Red", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.blue, textcolor=color.white,transp=0)
plotshape(h_lables == false and (Redu_buy_2 or Redu_buy_2_A)? _angle_fl +5 : na, title="Reduce Buy 2", text="Red", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.blue, textcolor=color.white,transp=0)
plotshape(h_lables == false and (Redu_buy_3 or Redu_buy_3_A)? _angle_fl +5 : na, title="Reduce Buy 3", text="Red", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.blue, textcolor=color.white,transp=0)
plotshape(h_lables == false and (Redu_buy_4 or Redu_buy_4_A)? _angle_fl +5 : na, title="Reduce Buy 4", text="Red", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.blue, textcolor=color.white,transp=0)
plotshape(h_lables == false and (Redu_buy_5 or Redu_buy_5_A)? _angle_fl +5 : na, title="Reduce Buy 5", text="Red", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.blue, textcolor=color.white,transp=0)

plotshape(h_lables == false and (Redu_sell_1 or Redu_sell_1_A) ? _angle_fl -5 : na, title="Reduce Sell 1", text="Red", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.red, textcolor=color.white,transp=0)
plotshape(h_lables == false and (Redu_sell_2 or Redu_sell_2_A)? _angle_fl -5 : na, title="Reduce Sell 2", text="Red", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.red, textcolor=color.white,transp=0)
plotshape(h_lables == false and (Redu_sell_3 or Redu_sell_3_A)? _angle_fl -5 : na, title="Reduce Sell 3", text="Red", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.red, textcolor=color.white,transp=0)
plotshape(h_lables == false and (Redu_sell_4 or Redu_sell_4_A)? _angle_fl -5 : na, title="Reduce Sell 4", text="Red", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.red, textcolor=color.white,transp=0)
plotshape(h_lables == false and (Redu_sell_5 or Redu_sell_5_A)? _angle_fl -5 : na, title="Reduce Sell 5", text="Red", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.red, textcolor=color.white,transp=0)

bgcolor(iTrend_ > 0 and AIB? color.blue : iTrend_ < 0 and AIB? color.red:na, transp=70)

barcolor(iTrend > 0?color.blue:color.red)

// ALERTS————————————————————————————————————————————————————————————

alertcondition(sell_0 or sell_0_A,title="Sell",message="Sell")
alertcondition(buy_0 or buy_0_A,title="Buy",message="Buy")

alertcondition(add_sell_1 or add_sell_1_A or add_sell_2 or add_sell_3 or add_sell_2_A or add_sell_3_A,title="Add Sell",message="Add Sell")
alertcondition(add_buy_1 or add_buy_1_A or add_buy_2 or add_buy_3 or add_buy_2_A or add_buy_3_A,title="Add Buy",message="Add Buy")

alertcondition(Redu_buy_1 or Redu_buy_1_A or Redu_buy_2 or Redu_buy_2_A or Redu_buy_3 or Redu_buy_3_A or Redu_buy_4 or Redu_buy_4_A or Redu_buy_5 or Redu_buy_5_A,title="Reduce Buy",message="Reduce Buy")
alertcondition(Redu_sell_1 or Redu_sell_1_A or Redu_sell_2 or Redu_sell_2_A or Redu_sell_3 or Redu_sell_3_A or Redu_sell_4 or Redu_sell_4_A or Redu_sell_5 or Redu_sell_5_A,title="Reduce Sell",message="Reduce Sell")

alertcondition(sell_0 or sell_0_A or buy_0 or buy_0_A or add_sell_1 or add_sell_1_A or add_sell_2 or add_sell_3 or add_sell_2_A or add_sell_3_A or add_buy_1 or add_buy_1_A or add_buy_2 or add_buy_3 or add_buy_2_A or add_buy_3_A or Redu_buy_1 or Redu_buy_1_A or Redu_buy_2 or Redu_buy_2_A or Redu_buy_3 or Redu_buy_3_A or Redu_buy_4 or Redu_buy_4_A or Redu_buy_5 or Redu_buy_5_A or Redu_sell_1 or Redu_sell_1_A or Redu_sell_2 or Redu_sell_2_A or Redu_sell_3 or Redu_sell_3_A or Redu_sell_4 or Redu_sell_4_A or Redu_sell_5 or Redu_sell_5_A ,title="Buy/Sell/Add/Reduce",message="Buy/Sell/Add/Reduce")

Image



What a great find, thanks for sharing.

Ask our favorite Mr tools to help us implement the MT4 version of it



https://tw.tradingview.com/script/t3aX6 ... Indicator/
Hoping this request get fulfilled 🙏 would be fantastic!
These users thanked the author Chickenspicy for the post:
Akela
0 + 0 = 0
Infinite / Infinite = 1
1 way to Heaven & it matters

DownloadRe: Already Converted TradingView Indicators to MT4 Indicators

309
Hello Programmers,
would it be possible to convert Arun_K_Bhaskar's "GANN Square Of 9 Pivots" Tradingview Indicator to mt4?
The indicator with its codes are here: https://my.tradingview.com/script/qNQyF ... -9-Pivots/
Since this indicator works well on price values such as indices and gold, it would be great to also include a multiplier for forex values... But I can't claim everything.
Thanks for your work.

https://my.tradingview.com/script/qNQyF ... -9-Pivots/

Code: Select all

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Arun_K_Bhaskar

//Formula based on "SuTrading Gann Levels By Naresh from nareshksuruvu" & "Gann Square of 9 By pequet"
//https://www.tradingview.com/script/Gn6BexU7-SuTrading-Gann-Levels-By-Naresh/
//https://www.tradingview.com/script/i10gxonX-Gann-Square-of-9/


//@version=4


study(title="GANN Square Of 9 Pivots", shorttitle="GANN 9 Pivots", overlay=true)

show_gann = input("Basic", title="Gann Levels", options=["Basic", "Extended"])
timeframe = input(defval="D", title="Timeframe", options=["1", "3", "5", "15", "30", "45", "60", "120", "180", "240", "D", "5D", "W", "2W", "3W", "M", "3M", "6M", "12M"])
source = input("VWAP Day Open", title="Source", options=["Custom", "LTP", "Day Open", "PD Close", "PD HL2", "PD HLC3", "VWAP", "VWAP Day Open", "VWAP PD Close", "TWAP", "TWAP Day Open", "TWAP PD Close"])
custom = input(defval=0, title="Enter Price (If Source is Custom)", minval=0, type=input.float)


////////////////////////////////////////////////////// OHLC

day_open = security(syminfo.tickerid, timeframe, open, lookahead = barmerge.lookahead_on)
pd_high = security(syminfo.tickerid, timeframe, high[1], lookahead = barmerge.lookahead_on)
pd_low = security(syminfo.tickerid, timeframe, low[1], lookahead = barmerge.lookahead_on)
pd_close = security(syminfo.tickerid, timeframe, close[1], lookahead = barmerge.lookahead_on)


////////////////////////////////////////////////////// VWAP

t = time(timeframe)
debut = na(t[1]) or t > t[1]

addsource = hl2 * volume
addvol = volume
addsource :=  debut ? addsource : addsource + addsource[1]
addvol :=  debut ? addvol : addvol + addvol[1]
vwap_level = addsource / addvol

//Previous Day VWAP Close
pd_vwap_close = 0.0
pd_vwap_close := iff(debut, vwap_level[1], pd_vwap_close[1])

//Day VWAP Open
d_vwap_open = 0.0
d_vwap_open := iff(debut, vwap_level[0], d_vwap_open[1])


////////////////////////////////////////////////////// TWAP

addsource_twap = hl2 * time
addtime_twap = time
addsource_twap :=  debut ? addsource_twap : addsource_twap + addsource_twap[1]
addtime_twap :=  debut ? addtime_twap : addtime_twap + addtime_twap[1]
twap_level = addsource_twap / addtime_twap

//Previous Day TWAP Close
pd_twap_close = 0.0
pd_twap_close := iff(debut, twap_level[1], pd_twap_close[1])

//Day TWAP Open
d_twap_open = 0.0
d_twap_open := iff(debut, twap_level[0], d_twap_open[1])


price_input = source == "LTP" ? close : 
  source == "Day Open"      ? day_open : 
  source == "PD Close"      ? pd_close : 
  source == "PD HL2"        ? avg(pd_high, pd_low) : 
  source == "PD HLC3"       ? avg(pd_high, pd_low, pd_close) : 
  source == "VWAP"          ? vwap_level : 
  source == "VWAP Day Open" ? d_vwap_open :
  source == "VWAP PD Close" ? pd_vwap_close :
  source == "TWAP"          ? twap_level : 
  source == "TWAP Day Open" ? d_twap_open :
  source == "TWAP PD Close" ? pd_twap_close : na  

price_option = source == "Custom" ? custom : price_input

gpL = "Basic Levels"

r_color = input(color.rgb(38, 166, 154), title="", group=gpL, inline="01")
show_r1 = input(defval=true, title="R1", group=gpL, inline="01")
show_r2 = input(defval=true, title="R2", group=gpL, inline="01")
show_r3 = input(defval=false, title="R3", group=gpL, inline="01")

s_color = input(color.rgb(240, 83, 80), title="", group=gpL, inline="02")
show_s1 = input(defval=true, title="S1", group=gpL, inline="02")
show_s2 = input(defval=true, title="S2", group=gpL, inline="02")
show_s3 = input(defval=false, title="S3", group=gpL, inline="02")

_extend = input(defval="Left", title='Extend', options=["None", "Left", "Right", "Both"], group=gpL, inline="04")
_ln_extend = _extend == "None" ? extend.none :
     _extend == "Left" ? extend.left :
     _extend == "Right" ? extend.right :
     _extend == "Both" ? extend.both : na


////////////////////////////////////////////////////// GANN Square Of 9 Calculation (Basic Levels)

sq_root = sqrt(price_option)
round_number = floor(sq_root)
//intarr = [round_number-1,round_number,round_number+1,round_number+2]
//inc_value = 0.125

long_above=0.00
short_below=0.00
r_1=0.00
r_2=0.00
r_3=0.00
s_1=0.00
s_2=0.00
s_3=0.00

gannsq_33 = (round_number-1)*(round_number-1)

gannsq_32 = ((round_number-1)+(0.125*1))*((round_number-1)+(0.125*1))
gannsq_22 = ((round_number-1)+(0.125*2))*((round_number-1)+(0.125*2))
gannsq_23 = ((round_number-1)+(0.125*3))*((round_number-1)+(0.125*3))
gannsq_24 = ((round_number-1)+(0.125*4))*((round_number-1)+(0.125*4))
gannsq_34 = ((round_number-1)+(0.125*5))*((round_number-1)+(0.125*5))
gannsq_44 = ((round_number-1)+(0.125*6))*((round_number-1)+(0.125*6))
gannsq_43 = ((round_number-1)+(0.125*7))*((round_number-1)+(0.125*7))
gannsq_42 = ((round_number-1)+(0.125*8))*((round_number-1)+(0.125*8))

gannsq_31 = ((round_number)+(0.125*1))*((round_number)+(0.125*1))
gannsq_11 = ((round_number)+(0.125*2))*((round_number)+(0.125*2))
gannsq_13 = ((round_number)+(0.125*3))*((round_number)+(0.125*3))
gannsq_15 = ((round_number)+(0.125*4))*((round_number)+(0.125*4))
gannsq_35 = ((round_number)+(0.125*5))*((round_number)+(0.125*5))
gannsq_55 = ((round_number)+(0.125*6))*((round_number)+(0.125*6))
gannsq_53 = ((round_number)+(0.125*7))*((round_number)+(0.125*7))
gannsq_51 = ((round_number)+(0.125*8))*((round_number)+(0.125*8))

gannsq_30 = ((round_number+1)+(0.125*1))*((round_number+1)+(0.125*1))
gannsq_00 = ((round_number+1)+(0.125*2))*((round_number+1)+(0.125*2))
gannsq_03 = ((round_number+1)+(0.125*3))*((round_number+1)+(0.125*3))
gannsq_06 = ((round_number+1)+(0.125*4))*((round_number+1)+(0.125*4))
gannsq_36 = ((round_number+1)+(0.125*5))*((round_number+1)+(0.125*5))
gannsq_66 = ((round_number+1)+(0.125*6))*((round_number+1)+(0.125*6))
gannsq_63 = ((round_number+1)+(0.125*7))*((round_number+1)+(0.125*7))
gannsq_60 = ((round_number+1)+(0.125*8))*((round_number+1)+(0.125*8))

if(price_option > gannsq_31 and price_option < gannsq_11)
    long_above := gannsq_11
    short_below := gannsq_31
    r_1 := gannsq_13* 0.9995
    r_2 := gannsq_15* 0.9995
    r_3 := gannsq_35* 0.9995
    s_1 := gannsq_42* 1.0005
    s_2 := gannsq_43* 1.0005
    s_3 := gannsq_44* 1.0005

if(price_option > gannsq_11 and price_option < gannsq_13)
    long_above := gannsq_13
    short_below := gannsq_11
    r_1 := gannsq_15* 0.9995
    r_2 := gannsq_35* 0.9995
    r_3 := gannsq_55* 0.9995
    s_1 := gannsq_31* 1.0005
    s_2 := gannsq_42* 1.0005
    s_3 := gannsq_43* 1.0005

if(price_option > gannsq_13 and price_option < gannsq_15)
    long_above := gannsq_15
    short_below := gannsq_13
    r_1 := gannsq_35* 0.9995
    r_2 := gannsq_55* 0.9995
    r_3 := gannsq_53* 0.9995
    s_1 := gannsq_11* 1.0005
    s_2 := gannsq_31* 1.0005
    s_3 := gannsq_42* 1.0005

if(price_option > gannsq_15 and price_option < gannsq_35)
    long_above := gannsq_35
    short_below := gannsq_15
    r_1 := gannsq_55* 0.9995
    r_2 := gannsq_53* 0.9995
    r_3 := gannsq_51* 0.9995
    s_1 := gannsq_13* 1.0005
    s_2 := gannsq_11* 1.0005
    s_3 := gannsq_31* 1.0005

if(price_option > gannsq_35 and price_option < gannsq_55)
    long_above := gannsq_55
    short_below := gannsq_35
    r_1 := gannsq_53* 0.9995
    r_2 := gannsq_51* 0.9995
    r_3 := gannsq_30* 0.9995
    s_1 := gannsq_15* 1.0005
    s_2 := gannsq_13* 1.0005
    s_3 := gannsq_11* 1.0005

if(price_option > gannsq_55 and price_option < gannsq_53)
    long_above := gannsq_53
    short_below := gannsq_55
    r_1 := gannsq_51* 0.9995
    r_2 := gannsq_30* 0.9995
    r_3 := gannsq_00* 0.9995
    s_1 := gannsq_35* 1.0005
    s_2 := gannsq_15* 1.0005
    s_3 := gannsq_13* 1.0005

if(price_option > gannsq_53 and price_option < gannsq_51)
    long_above := gannsq_51
    short_below := gannsq_53
    r_1 := gannsq_30* 0.9995
    r_2 := gannsq_00* 0.9995
    r_3 := gannsq_03* 0.9995
    s_1 := gannsq_55* 1.0005
    s_2 := gannsq_35* 1.0005
    s_3 := gannsq_15* 1.0005

if(price_option < gannsq_51 and price_option < gannsq_31)
    long_above := gannsq_31
    short_below := gannsq_42
    r_1 := gannsq_11* 0.9995
    r_2 := gannsq_13* 0.9995
    r_3 := gannsq_15* 0.9995
    s_1 := gannsq_43* 1.0005
    s_2 := gannsq_44* 1.0005
    s_3 := gannsq_34* 1.0005

//Plot

//Position
chper = time - time[1]
chper := change(chper) > 0 ? chper[1] : chper

//Start & End Time for Today
bar_start = time[74]
bar_end = time+chper*0

if show_gann == "Basic"
    price_line = line.new(x1=bar_start, y1=price_option, x2=bar_end, y2=price_option, color=color.gray, style=line.style_dashed, width=1, extend=_ln_extend, xloc=xloc.bar_time)
    line.delete(price_line[1])
    long_line = line.new(x1=bar_start, y1=long_above, x2=bar_end, y2=long_above, color=r_color, style=line.style_solid, width=2, extend=_ln_extend, xloc=xloc.bar_time)
    line.delete(long_line[1])
    short_line = line.new(x1=bar_start, y1=short_below, x2=bar_end, y2=short_below, color=s_color, style=line.style_solid, width=2, extend=_ln_extend, xloc=xloc.bar_time)
    line.delete(short_line[1])
    
    if show_r1
        r1_line = line.new(x1=bar_start, y1=r_1, x2=bar_end, y2=r_1, color=r_color, style=line.style_dotted, width=2, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(r1_line[1])
    if show_r2
        r2_line = line.new(x1=bar_start, y1=r_2, x2=bar_end, y2=r_2, color=r_color, style=line.style_dotted, width=2, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(r2_line[1])
    if show_r3
        r3_line = line.new(x1=bar_start, y1=r_3, x2=bar_end, y2=r_3, color=r_color, style=line.style_dotted, width=2, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(r3_line[1])
        
    if show_s1
        s1_line = line.new(x1=bar_start, y1=s_1, x2=bar_end, y2=s_1, color=s_color, style=line.style_dotted, width=2, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(s1_line[1])
    if show_s2
        s2_line = line.new(x1=bar_start, y1=s_2, x2=bar_end, y2=s_2, color=s_color, style=line.style_dotted, width=2, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(s2_line[1])
    if show_s3
        s3_line = line.new(x1=bar_start, y1=s_3, x2=bar_end, y2=s_3, color=s_color, style=line.style_dotted, width=2, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(s3_line[1])

// Percentage Formula
price_percent = abs(((price_option - close)/price_option)*100)
long_percent = abs(((long_above - close)/long_above)*100)
short_percent = abs(((short_below - close)/short_below)*100)
r1_percent = abs(((r_1 - close)/r_1)*100)
r2_percent = abs(((r_2 - close)/r_2)*100)
r3_percent = abs(((r_3 - close)/r_3)*100)
s1_percent = abs(((s_1 - close)/s_1)*100)
s2_percent = abs(((s_2 - close)/s_2)*100)
s3_percent = abs(((s_3 - close)/s_3)*100)

// Labels

var label price_label = na, var label long_label = na, var label short_label = na, var label r1_label = na, var label r2_label = na, var label r3_label = na, var label s1_label = na, var label s2_label = na, var label s3_label = na
label.delete(price_label), label.delete(long_label), label.delete(short_label), label.delete(r1_label), label.delete(r2_label), label.delete(r3_label), label.delete(s1_label), label.delete(s2_label), label.delete(s3_label)

x_pos = time + chper * 0
l_col = color.new(color.white, 100)

if show_gann == "Basic"
    price_label := label.new(x=x_pos, y=price_option, text=tostring(price_option, '#.##') + " (" + tostring(price_percent, '#.##') + "%)", textcolor=color.gray, textalign=text.align_left, color=l_col, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
    long_label := label.new(x=x_pos, y=long_above, text=tostring(long_above, '#.##') + " (" + tostring(long_percent, '#.##') + "%)", textcolor=r_color, textalign=text.align_left, color=l_col, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
    if show_r1
        r1_label := label.new(x=x_pos, y=r_1, text=tostring(r_1, '#.##') + " (" + tostring(r1_percent, '#.##') + "%)", textcolor=r_color, textalign=text.align_left, color=l_col, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
    if show_r2
        r2_label := label.new(x=x_pos, y=r_2, text=tostring(r_2, '#.##') + " (" + tostring(r2_percent, '#.##') + "%)", textcolor=r_color, textalign=text.align_left, color=l_col, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
    if show_r3
        r3_label := label.new(x=x_pos, y=r_3, text=tostring(r_3, '#.##') + " (" + tostring(r3_percent, '#.##') + "%)", textcolor=r_color, textalign=text.align_left, color=l_col, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
        
    short_label := label.new(x=x_pos, y=short_below, text=tostring(short_below, '#.##') + " (" + tostring(short_percent, '#.##') + "%)", textcolor=s_color, textalign=text.align_left, color=l_col, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
    if show_s1
        s1_label := label.new(x=x_pos, y=s_1, text=tostring(s_1, '#.##') + " (" + tostring(s1_percent, '#.##') + "%)", textcolor=s_color, textalign=text.align_left, color=l_col, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
    if show_s2
        s2_label := label.new(x=x_pos, y=s_2, text=tostring(s_2, '#.##') + " (" + tostring(s2_percent, '#.##') + "%)", textcolor=s_color, textalign=text.align_left, color=l_col, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
    if show_s3
        s3_label := label.new(x=x_pos, y=s_3, text=tostring(s_3, '#.##') + " (" + tostring(s3_percent, '#.##') + "%)", textcolor=s_color, textalign=text.align_left, color=l_col, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)


////////////////////////////////////////////////////// GANN Square Of 9 Calculation (Extended Levels)

gpEx = "Extended Levels"

show_1st_l = input(defval=false, title="1st", group=gpEx, inline="01")
show_2nd_l = input(defval=true, title="2nd", group=gpEx, inline="01")
show_3rd_l = input(defval=false, title="3rd", group=gpEx, inline="01")
show_4th_l = input(defval=false, title="4th", group=gpEx, inline="01")
show_5th_l = input(defval=false, title="5th", group=gpEx, inline="01")

round_no = floor(sq_root) - 1

level_00 = pow(round_no, 2)             // Center
level_01 = pow(round_no + 1 * 0.125, 2) // Rotate 45 degrees
level_02 = pow(round_no + 2 * 0.125, 2)
level_03 = pow(round_no + 3 * 0.125, 2)
level_04 = pow(round_no + 4 * 0.125, 2)
level_05 = pow(round_no + 5 * 0.125, 2)
level_06 = pow(round_no + 6 * 0.125, 2)
level_07 = pow(round_no + 7 * 0.125, 2)
level_08 = pow(round_no + 8 * 0.125, 2) // First level
level_09 = pow(round_no + 9 * 0.125, 2)
level_10 = pow(round_no + 10 * 0.125, 2)
level_11 = pow(round_no + 11 * 0.125, 2)
level_12 = pow(round_no + 12 * 0.125, 2)
level_13 = pow(round_no + 13 * 0.125, 2)
level_14 = pow(round_no + 14 * 0.125, 2)
level_15 = pow(round_no + 15 * 0.125, 2)
level_16 = pow(round_no + 16 * 0.125, 2) // Second level
level_17 = pow(round_no + 17 * 0.125, 2)
level_18 = pow(round_no + 18 * 0.125, 2)
level_19 = pow(round_no + 19 * 0.125, 2)
level_20 = pow(round_no + 20 * 0.125, 2)
level_21 = pow(round_no + 21 * 0.125, 2)
level_22 = pow(round_no + 22 * 0.125, 2)
level_23 = pow(round_no + 23 * 0.125, 2)
level_24 = pow(round_no + 24 * 0.125, 2) // Third level
level_25 = pow(round_no + 25 * 0.125, 2)
level_26 = pow(round_no + 26 * 0.125, 2)
level_27 = pow(round_no + 27 * 0.125, 2)
level_28 = pow(round_no + 28 * 0.125, 2)
level_29 = pow(round_no + 29 * 0.125, 2)
level_30 = pow(round_no + 30 * 0.125, 2)
level_31 = pow(round_no + 31 * 0.125, 2)
level_32 = pow(round_no + 32 * 0.125, 2) // Fourth level
level_33 = pow(round_no + 33 * 0.125, 2)
level_34 = pow(round_no + 34 * 0.125, 2)
level_35 = pow(round_no + 35 * 0.125, 2)
level_36 = pow(round_no + 36 * 0.125, 2)
level_37 = pow(round_no + 37 * 0.125, 2)
level_38 = pow(round_no + 38 * 0.125, 2)
level_39 = pow(round_no + 39 * 0.125, 2)
level_40 = pow(round_no + 40 * 0.125, 2) // Fifth level

// Plot

col = color.rgb(38, 166, 154)

if show_gann == "Extended"
    price_line = line.new(x1=bar_start, y1=price_option, x2=bar_end, y2=price_option, color=s_color, style=line.style_dashed, width=1, extend=_ln_extend, xloc=xloc.bar_time)
    line.delete(price_line[1])
    if show_1st_l
        level_00_line = line.new(x1=bar_start, y1=level_00, x2=bar_end, y2=level_00, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_00_line[1])
        level_01_line = line.new(x1=bar_start, y1=level_01, x2=bar_end, y2=level_01, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_01_line[1])
        level_02_line = line.new(x1=bar_start, y1=level_02, x2=bar_end, y2=level_02, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_02_line[1])
        level_03_line = line.new(x1=bar_start, y1=level_03, x2=bar_end, y2=level_03, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_03_line[1])
        level_04_line = line.new(x1=bar_start, y1=level_04, x2=bar_end, y2=level_04, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_04_line[1])
        level_05_line = line.new(x1=bar_start, y1=level_05, x2=bar_end, y2=level_05, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_05_line[1])
        level_06_line = line.new(x1=bar_start, y1=level_06, x2=bar_end, y2=level_06, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_06_line[1])
        level_07_line = line.new(x1=bar_start, y1=level_07, x2=bar_end, y2=level_07, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_07_line[1])
        level_08_line = line.new(x1=bar_start, y1=level_08, x2=bar_end, y2=level_08, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_08_line[1]) // First level
    if show_2nd_l
        level_09_line = line.new(x1=bar_start, y1=level_09, x2=bar_end, y2=level_09, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_09_line[1])
        level_10_line = line.new(x1=bar_start, y1=level_10, x2=bar_end, y2=level_10, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_10_line[1])
        level_11_line = line.new(x1=bar_start, y1=level_11, x2=bar_end, y2=level_11, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_11_line[1])
        level_12_line = line.new(x1=bar_start, y1=level_12, x2=bar_end, y2=level_12, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_12_line[1])
        level_13_line = line.new(x1=bar_start, y1=level_13, x2=bar_end, y2=level_13, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_13_line[1])
        level_14_line = line.new(x1=bar_start, y1=level_14, x2=bar_end, y2=level_14, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_14_line[1])
        level_15_line = line.new(x1=bar_start, y1=level_15, x2=bar_end, y2=level_15, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_15_line[1])
        level_16_line = line.new(x1=bar_start, y1=level_16, x2=bar_end, y2=level_16, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_16_line[1]) // Second level
    if show_3rd_l
        level_17_line = line.new(x1=bar_start, y1=level_17, x2=bar_end, y2=level_17, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_17_line[1])
        level_18_line = line.new(x1=bar_start, y1=level_18, x2=bar_end, y2=level_18, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_18_line[1])
        level_19_line = line.new(x1=bar_start, y1=level_19, x2=bar_end, y2=level_19, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_19_line[1])
        level_20_line = line.new(x1=bar_start, y1=level_20, x2=bar_end, y2=level_20, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_20_line[1])
        level_21_line = line.new(x1=bar_start, y1=level_21, x2=bar_end, y2=level_21, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_21_line[1])
        level_22_line = line.new(x1=bar_start, y1=level_22, x2=bar_end, y2=level_22, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_22_line[1])
        level_23_line = line.new(x1=bar_start, y1=level_23, x2=bar_end, y2=level_23, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_23_line[1])
        level_24_line = line.new(x1=bar_start, y1=level_24, x2=bar_end, y2=level_24, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_24_line[1]) // Third level
    if show_4th_l
        level_25_line = line.new(x1=bar_start, y1=level_25, x2=bar_end, y2=level_25, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_25_line[1])
        level_26_line = line.new(x1=bar_start, y1=level_26, x2=bar_end, y2=level_26, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_26_line[1])
        level_27_line = line.new(x1=bar_start, y1=level_27, x2=bar_end, y2=level_27, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_27_line[1])
        level_28_line = line.new(x1=bar_start, y1=level_28, x2=bar_end, y2=level_28, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_28_line[1])
        level_29_line = line.new(x1=bar_start, y1=level_29, x2=bar_end, y2=level_29, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_29_line[1])
        level_30_line = line.new(x1=bar_start, y1=level_30, x2=bar_end, y2=level_30, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_30_line[1])
        level_31_line = line.new(x1=bar_start, y1=level_31, x2=bar_end, y2=level_31, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_31_line[1])
        level_32_line = line.new(x1=bar_start, y1=level_32, x2=bar_end, y2=level_32, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_32_line[1]) // Fourth level
    if show_5th_l
        level_33_line = line.new(x1=bar_start, y1=level_33, x2=bar_end, y2=level_33, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_33_line[1])
        level_34_line = line.new(x1=bar_start, y1=level_34, x2=bar_end, y2=level_34, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_34_line[1])
        level_35_line = line.new(x1=bar_start, y1=level_35, x2=bar_end, y2=level_35, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_35_line[1])
        level_36_line = line.new(x1=bar_start, y1=level_36, x2=bar_end, y2=level_36, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_36_line[1])
        level_37_line = line.new(x1=bar_start, y1=level_37, x2=bar_end, y2=level_37, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_37_line[1])
        level_38_line = line.new(x1=bar_start, y1=level_38, x2=bar_end, y2=level_38, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_38_line[1])
        level_39_line = line.new(x1=bar_start, y1=level_39, x2=bar_end, y2=level_39, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_39_line[1])
        level_40_line = line.new(x1=bar_start, y1=level_40, x2=bar_end, y2=level_40, color=r_color, style=line.style_solid, width=1, extend=_ln_extend, xloc=xloc.bar_time)
        line.delete(level_40_line[1]) // Fifth level
These users thanked the author Kondrad for the post:
Akela

Re: Already Converted TradingView Indicators to MT4 Indicators

310
can you guys try to find a good setting ? I modified an existing indicator, extracted parameters and removed unused parts
I got good results on some TF and some pairs

if you find a good set file I'll make a MT4 version

Code: Select all

//@version=5
strategy('EZ CRYPTO$ mod IonOne', overlay=true)
emaFastPeriod = input.int(5)
emaSlowPeriod = input.int(30)
ATRPeriod = input.int(6)
ATRMul = input.float(0.01)

per1 = input.int(140)
per2 = input.int(2)

bb1 = input.int(7)
bb2 = input.int(1)

emaFast = ta.ema(close, emaFastPeriod)
emaSlow = ta.ema(close, emaSlowPeriod)
emaDiff = emaFast - emaSlow
emaBull = emaDiff > ATRMul * ta.atr(ATRPeriod) 
emaBear = emaDiff < -ATRMul * ta.atr(ATRPeriod)

val = ta.linreg(close - math.avg(math.avg(ta.highest(high, per1), ta.lowest(low, per1)), ta.sma(close, per1)), per1, 0)
mom_green = val > nz(val[bb1])
mom_red = val < nz(val[bb1])

val1 = ta.linreg(close - math.avg(math.avg(ta.highest(high, per2), ta.lowest(low, per2)), ta.sma(close, per2)), per2, 0)
mom_green1 = val1 > nz(val1[bb2]) 
mom_red1 = val1 < nz(val1[bb2]) 

var isLong = false 
buy_bull = emaBull and mom_green and mom_red1
sell_bear = emaBear and mom_red and mom_green1
isBuy = not isLong and buy_bull
isSell = isLong and sell_bear 
isLong := isBuy ? true : isSell ? false : isLong
plotshape(isBuy, text='Buy', color=color.new(color.green, 0), textcolor=color.new(color.white, 0), style=shape.labelup, size=size.normal, location=location.belowbar)
plotshape(isSell, text='Sell', color=color.new(color.red, 0), textcolor=color.new(color.white, 0), style=shape.labeldown, size=size.normal, location=location.abovebar)
if (isBuy)
    strategy.entry("long", strategy.long, qty=1000)
if (isSell)
    strategy.entry("short", strategy.short, qty=1000)
These users thanked the author ionone for the post:
Chickenspicy


Who is online

Users browsing this forum: Amazon [Bot], Applebot [Crawler], Bing [Bot], Majestic-12 [Bot], Mickey Abi, sdsdzk, Sogou [Bot], Tbot [Bot], YeungKwan and 85 guests