Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © Ontra02
- //@version=5
- indicator("Advanced Lookback Checker From Philip", shorttitle = "AVC")
- //Getting Inputs
- Startlookbackperiod = input.int(0, "Start Period", 0, 10000, 1, tooltip = "When the Counter starts to count (0 = current Bar, 1 = Previous Bar etc.)")
- Lookbackperiod = input.int(defval = 10, title = "Lookbackperiod", minval = 1, maxval = 10000, step = 1, tooltip = "How many bars get referenced in the Lookback System")
- ColumnsOn = input.bool(true,"Columns On/Off", "If the Columns get shown ( The EMAs are based on these Columns)", group = "Columns")
- //Barcolor Change Input
- BothEmacolorBar = input.bool(true, "Both EMA (Average) ", "Both EMA in an Average ", group = "Color Change (Only One can work at one Time)")
- TwoEmacolorBar = input.bool(false, "Both EMA", "Both EMA need to be in one Direction for a Green/Red Signal", group = "Color Change (Only One can work at one Time)")
- Emacolorbar = input.bool(false, "EMA Color Bar change", "The Bars change Colors if Ema is showing a Trend", group="Color Change (Only One can work at one Time)")
- EmaColumnscolorbar = input.bool(false, "EMA Columns Color Bar change", "The Bars change Colors if the EMA Columns is showing a Trend.", group = "Color Change (Only One can work at one Time)")
- Columnscolorbar = input.bool(false, "Columns Color Bar change", "The Bars change Colors if the Columns are showing a Trend.", group="Color Change (Only One can work at one Time)")
- MacdcolorBar = input.bool(false, "Macd Color Bar change", "The Bars change Colors if the Macd shows a Trend", group="Color Change (Only One can work at one Time)")
- Bothandmacd = input.bool(false, "Both EMa and Macd", tooltip = "Only a Signal if the Ema and the Macd are negative")
- BOthandEmaMacd = input.bool(false, "Both EMA and MAcd EMA", "Only a Signal if the Trend is up and the EMA for the MAcd is up")
- //Ema Input Settings for the Columns Strength
- EmaOn = input.bool(defval=true, title = "Ema On/Off", tooltip = "An Ema on the Columns for elimination of false Signals", group = "Ema")
- EmaLength = input.int(defval = 10, title = "Ema Length", tooltip = "Length of the Ema", group = "Ema", minval = 1)
- EmaWidth = input.int(defval = 2, title = "Ema Width", tooltip = "How width the Line of Ema is", options = [1,2,3,4,5], group = "Ema")
- EmaColorup = input.color(defval = color.green, title = "Ema Color Up Trend", tooltip = "Which Color gets shown on the Ema if the TrendDirection is positive", group = "Ema")
- EmaColorDown = input.color(defval = color.red, title = "Ema Color Down Trend", tooltip = "Which Color gets shown on the Ema if the TrendDirection is negative", group = "Ema")
- //Ema Input Settings for how many Columns green and red
- EmaOnColumns = input.bool(true, "EMÁ For Columns", "This is different to the other Ema.On this one gets checked how many Bars were positive and negative and not how strong they are.",
- group = "Ema Columns")
- EmaOnColumnsLentgh = input.int(5, "EMA For Columns Length", tooltip = "Length of the Ema for the Columns", group = "Ema Columns")
- EmaColumnsWidth = input.int(defval = 3, title = "Ema Columns Width", tooltip = "How width the Line of Ema Columns is", options = [1,2,3,4,5], group = "Ema Columns")
- EmaColumnsColorup = input.color(defval = color.blue, title = "Ema Columns Color Up Trend", tooltip = "Which Color gets shown on the Ema Columns if the TrendDirection is positive", group = "Ema Columns")
- EmaColumnsColorDown = input.color(defval = color.purple, title = "Ema Columns Color Down Trend", tooltip = "Which Color gets shown on the Ema Columns if the TrendDirection is negative", group = "Ema Columns")
- //Both EMA Input Settings
- BothEmaON = input.bool(true, "Both EMA ", tooltip = "Both EMA together shown on Chart", group = "Both EMA")
- BothEmaColorup = input.color(defval = color.gray, title = "Both EMA Color Up Trend", tooltip = "Which Color gets shown on the Both Ema if the TrendDirection is positive", group = "Both EMA")
- BothEmaColorDown = input.color(defval = color.orange, title = "Both EMA Color Down Trend", tooltip = "Which Color gets shown on the Both EMA if the TrendDirection is negative", group = "Both EMA")
- BothEmaWidth = input.int(3,"Both Ema Width", tooltip = "How Width the Average of both Ema is" ,options = [1,2,3,4,5], group = "Both EMA")
- //MACD Input Settings
- ShowMacd = input.bool(true, "Show Macd", "If the Macd based on the Slow and Fast Macd get shown", group = "Show Macd")
- ShowFastandSlowMacd = input.bool(false, "Show the Ma for Macd", "If the Slow and Fast Macd get shown", group = "Show Macd")
- MaTypeSlow = input.string("EMA", "Moving Average Slow Type", ["EMA", "SMA", "RMA", "HMA", "SWMA", "WMA"], "Which MA gets used in the Slow Macd", group = "Slow Macd")
- MaTypeFast = input.string("EMA", "Moving Average Fast Type", ["EMA", "SMA", "RMA", "HMA", "SWMA", "WMA"], "Which MA gets used in the Fast MAcd", group = "Fast Macd")
- SlowMacd = input.int(10, "Slow MA for Macd", tooltip = "The Length of the Slow MA of the Macd for the Columns", group = "Slow Macd")
- FastMAcd = input.int(5, "Fast MA for Macd", tooltip = "The Length of the Fast MA of the Macd for the Columns", group = "Fast Macd")
- PlotMacdAverage = input.bool(false,"MA for the Macd", "This is the MA of the Macd Columns", group = "Macd Average")
- MacdAveragelength = input.int(5,"Length for the MA", tooltip = "The Length for the Average of the Macd", group = "Macd Average")
- MacdAverageType = input.string("SMA", "Moving Average Type", ["EMA", "SMA", "RMA", "HMA", "SWMA", "WMA"], group = "Macd Average")
- //Input Settings for significance of different Events happening in the Loop (for Counter)
- WhatisaPoint = input.bool(false, "What is a Point?", "The System is build on Points. So if something of the Conditions are met, The choosen Number of Coins get Added if it is bullish and subtracted if negative
- If Everything is added we have an overall Point which is the Direction of the Trend. You can choose down below how many Points get added if the Condition is true. Only Positive Numbers please!!!(0,1,2,3,4,5 etc.) ", group = "Significance of previous Bar Action ")
- Bull_BearBar = input.int( 15,title = "Bar Bullish or Bearish", tooltip = "How many Points get Added if the Bar is Bullish or Bearish",group = "Significance of previous Bar Action ")
- LastBarBullorBear = input.int( 10,title = "Last Bars Direction", tooltip = "How many Points get Added if the Bar last Bar is Bullish or Bearish",group = "Significance of previous Bar Action ")
- CloseishigherthanpreviousBarhigh_low = input.int( 1,title = "Bar closed higher/lower than previous Bar", tooltip = "How many Points get Added if the Bar closed higher/lower than previous Bar", group = "Significance of previous Bar Action ")
- BarclosedtwotimesbiggerthanpreciousBar = input.int( 1,title = "Bar closed 2 times bigger than previous Bar", tooltip = "How many Points get Added if the Bar closed 2 times bigger than previous Bar", group = "Significance of previous Bar Action ")
- BarclosedfivetimesbiggerthanpreciousBar = input.int( 1,title = "Bar closed 5 times bigger than previous Bar", tooltip = "How many Points get Added if the Bar closed 5 times bigger than previous Bar", group = "Significance of previous Bar Action ")
- BarishigherthanfiveBarsago = input.int( 1,title = "Bar closed higher/lower than 5 Bars ago", tooltip = "How many Points get Added if the Bar closed higher than 5 Bars ago", group = "Significance of previous Bar Action ")
- BarishigherthantenBarsago = input.int( 1,title = "Bar closed higher/lower than 10 Bars ago", tooltip = "How many Points get Added if the Bar closed higher/lower than 10 Bars ago", group = "Significance of previous Bar Action ")
- TwoBarsinrow = input.int( 2,title = "Two Bars in the Same Direction in Row", tooltip = "How many Points get Added if Two Bars in row are in one Direction", group = "Significance of previous Bar Action ")
- ThreeBarsinrow = input.int( 1,title = "Three Bars in the Same Direction in Row", tooltip = "How many Points get Added if Three Bars in row are in one Direction", group = "Significance of previous Bar Action ")
- FiveBarsinrow = input.int( 1,title = "Five Bars in the Same Direction in Row", tooltip = "How many Points get Added if Five Bars in row are in one Direction", group = "Significance of previous Bar Action ")
- HighestorlowestBar = input.int( 1,title = "Highest or Lowest Bar over the past Bars", tooltip = "How many Points get Added if the Current Bar is the highest or Lowest Point over the past Price Action", group = "Significance of previous Bar Action ")
- HighestorlowestBarLength = input.int( 10,title = "Highest or Lowest Bar over this Length", tooltip = "The Price needs to be above/below the highest/lowest Price over these Past (1 = one Bar)", group = "Significance of previous Bar Action ")
- HowmuchChangeforInvalidationofCandle = input.float(0.00, "Invalidation", tooltip = "How much one Candle needs to move to work in the System. In % but you need to type 0.01 = 1% etc.", step = 0.0001, group = "Significance of previous Bar Action")
- EmadslowLength = input.int(21, "Slow EMA", tooltip = "Length of the small EMA" ,group = "Significance of previous Bar Action")
- Emadfastlength = input.int(14, "Slow EMA", tooltip = "Length of the Fast EMA" ,group = "Significance of previous Bar Action")
- EMAcrossover = input.int(10, "Ema Crossover", tooltip = "How my Points get Added if the EMa crosses)", group = "Significance of previous Bar Action ")
- //Different TF Inputs
- AdvancedLookbackCheckerondifferentTF = input.bool(true, "AVC on differrent TF", "You can turn on that the Indicator uses Data from other Timeframes so that you have faster Signals or a Longer Term bias", group = "Different TF")
- DifferentTF = input.timeframe("D", "Different Timeframe", tooltip = "Which Timeframe is used for the different Timeframe", group = "Different TF")
- DifferentTFsignificanceofPoints = input.int( 1,title = "Different Timeframe Points", tooltip = "How many Points get Added if the other set Timeframe is Bullish or Bearish",group ="Different TF")
- DifferentTFplot = input.bool(false, "Show different Timeframe", "If the EMA of the different Timeframe gets shown", group ="Different TF")
- // Variables
- PositiveTrend = 0
- Negativetrend = 0
- PreviousbarBull = close[1] > open[1]
- PreviousbarBear = close[1] < open[1]
- PreviousBarHigh = high[1]
- PreviousBarLow = low[1]
- PreviousBarcloseminusopen = close[1] - open[1]
- PreviousBaropenminusclose = open[1] - close[1]
- CurrentBarBull = close > open
- CurrentBarBear = close < open
- FiveBarsAgo = close[5]
- TenBarsAgo = close[5]
- TwoBarsPositiveinRow = close > open and close[1] > open[1]
- TwoBarsNegativeinRow = close < open and close[1] < open[1]
- ThreeBarsPositiveinRow = close > open and close[1] > open[1] and close[2] > open[2]
- ThreeBarsNegativeinRow = close < open and close[1] < open[1] and close[2] < open[2]
- FiveBarsPositiveinRow = close > open and close[1] > open[1] and close[2] > open[2] and close[3] > open[3] and close[4] > open[4]
- FiveBarsNegativeinRow = close < open and close[1] < open[1] and close[2] < open[2] and close[3] < open[3] and close[4] < open[4]
- Barisverysmalldown = (open - close) < open * HowmuchChangeforInvalidationofCandle
- Barisverysmallup = (close - open) < open * HowmuchChangeforInvalidationofCandle
- highestpoint = ta.highest(close, HighestorlowestBarLength)
- lowestpoint = ta.lowest(close, HighestorlowestBarLength)
- //Loop for Creation of Lookback System
- for Counter = Startlookbackperiod to Lookbackperiod
- if not Barisverysmallup or not Barisverysmalldown
- if open[Counter] < close[Counter]
- PositiveTrend := PositiveTrend + Bull_BearBar
- if close[Counter] < open[Counter]
- Negativetrend := Negativetrend + Bull_BearBar
- if PreviousbarBull[Counter]
- PositiveTrend := PositiveTrend + LastBarBullorBear
- if PreviousbarBear[Counter]
- Negativetrend := Negativetrend + LastBarBullorBear
- if close[Counter] > PreviousBarHigh[Counter]
- PositiveTrend := PositiveTrend + CloseishigherthanpreviousBarhigh_low
- if close[Counter] < PreviousBarLow[Counter]
- Negativetrend := Negativetrend + CloseishigherthanpreviousBarhigh_low
- if CurrentBarBull
- if (close[Counter] - open[Counter]) > PreviousBarcloseminusopen[Counter] *2
- PositiveTrend := PositiveTrend + BarclosedtwotimesbiggerthanpreciousBar
- if CurrentBarBear
- if (open[Counter] - close[Counter]) < PreviousBaropenminusclose *2
- Negativetrend := Negativetrend + BarclosedtwotimesbiggerthanpreciousBar
- if CurrentBarBull
- if (close[Counter] - open[Counter]) > PreviousBarcloseminusopen[Counter] *5
- PositiveTrend := PositiveTrend + BarclosedfivetimesbiggerthanpreciousBar
- if CurrentBarBear
- if (open[Counter] - close[Counter]) < PreviousBaropenminusclose *5
- Negativetrend := Negativetrend + BarclosedfivetimesbiggerthanpreciousBar
- if CurrentBarBull
- if close[Counter] > FiveBarsAgo[Counter]
- PositiveTrend := PositiveTrend + BarishigherthanfiveBarsago
- if CurrentBarBear
- if close[Counter] <FiveBarsAgo[Counter]
- Negativetrend := Negativetrend + BarishigherthanfiveBarsago
- if CurrentBarBull
- if close[Counter] > TenBarsAgo[Counter]
- PositiveTrend := PositiveTrend + BarishigherthantenBarsago
- if CurrentBarBear
- if close[Counter] < TenBarsAgo[Counter]
- Negativetrend := Negativetrend + BarishigherthantenBarsago
- if TwoBarsPositiveinRow[Counter]
- PositiveTrend := PositiveTrend + TwoBarsinrow
- if TwoBarsNegativeinRow[Counter]
- Negativetrend := Negativetrend +TwoBarsinrow
- if ThreeBarsPositiveinRow[Counter]
- PositiveTrend := PositiveTrend + ThreeBarsinrow
- if ThreeBarsNegativeinRow[Counter]
- Negativetrend := Negativetrend +ThreeBarsinrow
- if FiveBarsPositiveinRow[Counter]
- PositiveTrend := PositiveTrend + FiveBarsinrow
- if FiveBarsNegativeinRow[Counter]
- Negativetrend := Negativetrend +FiveBarsinrow
- if highestpoint
- PositiveTrend := PositiveTrend + HighestorlowestBar
- if lowestpoint
- Negativetrend := Negativetrend + HighestorlowestBar
- if (ta.ema(close, EmadslowLength) > ta.ema(close, Emadfastlength))
- Negativetrend := Negativetrend + EMAcrossover
- if (ta.ema(close, EmadslowLength) < ta.ema(close, Emadfastlength))
- PositiveTrend := PositiveTrend + EMAcrossover
- //Variable for Trend Direction
- TrendDirection0 = PositiveTrend - Negativetrend
- Direction0 = 0
- if TrendDirection0 > 0
- Direction0 := 2
- if TrendDirection0 < 0
- Direction0 := -2
- //Direction Average of Both Emas for TwoEmaCo
- DirectionforBothEma0 = ((ta.ema(TrendDirection0, EmaLength) + ta.ema(Direction0, EmaOnColumnsLentgh)) /2)
- //Switch for Macd MaType = input.string("EMA", "Moving Average Type", ["EMA", "SMA", "RMA", "HMA", "SWMA", "WMA"])
- MAtypeswitchslow = switch MaTypeSlow
- "EMA" => ta.ema(TrendDirection0, SlowMacd)
- "SMA" => ta.sma(TrendDirection0, SlowMacd)
- "RMA" => ta.rma(TrendDirection0, SlowMacd)
- "HMA" => ta.hma(TrendDirection0, SlowMacd)
- "SWMA"=> ta.swma(TrendDirection0)
- "WNA" => ta.wma(TrendDirection0, SlowMacd)
- MAtypeswitchfast = switch MaTypeFast
- "EMA" => ta.ema(TrendDirection0, FastMAcd)
- "SMA" => ta.sma(TrendDirection0, FastMAcd)
- "RMA" => ta.rma(TrendDirection0,FastMAcd)
- "HMA" => ta.hma(TrendDirection0, FastMAcd)
- "SWMA"=> ta.swma(TrendDirection0)
- "WNA" => ta.wma(TrendDirection0, FastMAcd)
- //Create a Macd
- Macd = MAtypeswitchfast - MAtypeswitchslow
- MacdAverageTypeswitch = switch MacdAverageType
- "EMA" => ta.ema(Macd, MacdAveragelength)
- "SMA" => ta.sma(Macd, MacdAveragelength)
- "RMA" => ta.rma(Macd,MacdAveragelength)
- "HMA" => ta.hma(Macd, MacdAveragelength)
- "SWMA"=> ta.swma(Macd)
- "WNA" => ta.wma(Macd, MacdAveragelength)
- //New Loop for beacuse we need the Data
- RequestedTFData = request.security(syminfo.tickerid, DifferentTF, DirectionforBothEma0)
- if AdvancedLookbackCheckerondifferentTF
- if RequestedTFData > 0
- PositiveTrend := PositiveTrend + DifferentTFsignificanceofPoints
- if RequestedTFData < 0
- Negativetrend := Negativetrend + DifferentTFsignificanceofPoints
- //Variable for Trend Direction
- TrendDirection = PositiveTrend - Negativetrend
- Direction = 0
- if TrendDirection > 0
- Direction := 2
- if TrendDirection < 0
- Direction := -2
- DirectionAddition = Direction
- //Direction Average of Both Emas for TwoEmaCo
- DirectionforBothEma = ((ta.ema(TrendDirection, EmaLength) + ta.ema(Direction, EmaOnColumnsLentgh)) /2)
- //plot Data to Chart
- plot(ColumnsOn ? TrendDirection : na, title = "Trend Direction", color = TrendDirection > 0 ? color.rgb(0,255,0,70) : color.rgb(255,0,0, 70),
- style = plot.style_columns)
- plot(EmaOn ? ta.ema(TrendDirection, EmaLength) : na, title = "EMA Plot", color = ta.ema(TrendDirection, EmaLength) > 0 ? EmaColorup : EmaColorDown , linewidth = EmaWidth)
- plot(EmaOnColumns ? ta.ema(Direction, EmaOnColumnsLentgh) : na, title = "EMA for Columns Plot", linewidth = EmaColumnsWidth, color = ta.ema(Direction, EmaOnColumnsLentgh) > 0 ?
- EmaColumnsColorup : EmaColumnsColorDown )
- plot(BothEmaON ? DirectionforBothEma : na, "Both Ema Together", color = DirectionforBothEma > 0 ? BothEmaColorup : BothEmaColorDown , linewidth = BothEmaWidth)
- plot(DifferentTFplot ? RequestedTFData : na, "Plot different Time Frame Data", RequestedTFData > 0 ? color.green : color.red)
- //Plot macd
- plot(ShowMacd ? Macd : na, "Macd", color = Macd > 0 ? color.green : color.red, style = plot.style_columns)
- plot(ShowFastandSlowMacd ? MAtypeswitchfast : na, "Fast MA", color = MAtypeswitchfast > 0 ? color.green: color.red)
- plot(ShowFastandSlowMacd ? MAtypeswitchslow: na , "Fast MA", color = MAtypeswitchslow > 0 ? color.green: color.red, linewidth = 4)
- plot(PlotMacdAverage ? MacdAverageTypeswitch : na, "Macd Average", MacdAverageTypeswitch > MacdAverageTypeswitch[1] ? color.green : color.red, 4)
- //change the Color of a Bar depending on Trend Direction for the EMA
- barcolor(Emacolorbar ? (ta.ema (TrendDirection, EmaLength) > 0 ? color.green : color.red) : na)
- //change the Color of a Bar depending on Trend Direction for the Columns
- barcolor(Columnscolorbar ? (TrendDirection > 0 ? color.green : color.red) : na)
- //change the Color of a Bar depending on Trend Direction of EMA Columns
- barcolor(EmaColumnscolorbar ? (ta.ema(Direction, EmaOnColumnsLentgh) > 0 ? color.green : color.red) : na)
- //change the Color of a Bar if Both EMAs are in one Diretion
- barcolor (TwoEmacolorBar and (ta.ema(Direction, EmaOnColumnsLentgh)) > 0 and ta.ema(TrendDirection, EmaLength) > 0 ? color.green : na)
- barcolor (TwoEmacolorBar and (ta.ema(Direction, EmaOnColumnsLentgh)) < 0 and ta.ema(TrendDirection, EmaLength) < 0 ? color.red : na)
- //change the Color of a Bar depending on the Average of both EMA
- barcolor(BothEmacolorBar ? (DirectionforBothEma > 0 ? color.green : color.red) : na)
- barcolor(MacdcolorBar ? (Macd > 0 ? color.green : color.red) : na)
- //Change the colorof a bar depending on if Both ema and the Macd are in one Direction
- barcolor(Bothandmacd ? (Macd > 0 and DirectionforBothEma > 0 ? color.green : na):na)
- barcolor(Bothandmacd ? (Macd < 0 and DirectionforBothEma < 0 ? color.red : na):na)
- barcolor(not BOthandEmaMacd ? na : DirectionforBothEma > 0 and MacdAverageTypeswitch > MacdAverageTypeswitch[1] ? color.green : na)
- barcolor( not BOthandEmaMacd ? na : DirectionforBothEma < 0 and MacdAverageTypeswitch < MacdAverageTypeswitch[1] ? color.red : na)
- //Alert Variables
- BuySignalforDirectionforBothEma = ta.crossover(DirectionforBothEma, 0)
- SellSignalforDirectionforBothEma = ta.crossunder(DirectionforBothEma, 0)
- //Create Alerts
- alertcondition(BuySignalforDirectionforBothEma, "AVCV Positive", "AVCV zeigt Positiven Trend " )
- alertcondition(SellSignalforDirectionforBothEma, "AVCV Negative", "AVCV zeigt Negativen Trend ")
Advertisement
Comments
-
- they are giving all types of premium tradingview indicators codes available on telegram - https://t.me/tradingview_premium_indicator
Add Comment
Please, Sign In to add comment
Advertisement