Is it possible to add multiple trendlines based on different time frames to this Pine Script?

Viewed 22

I have been using this pine script recently, but I would like to be able to have multiple iterations of it on the same chart just from different time frames.

Is this something that can be easily done?

//Fill Arrays with latest LOWS/HIGHS
//Get highest HIGH and lowest LOW values from the arrays.
//Do Average between X highest highs and X lowest lows and plot line (Length can be modified)
//If price LOW is above line, Up Trending (Green) (Source can be modified)
//If price HIGH is below line, Down Trending (Red) (Source can be modified)
//If neither above, slow down in trend / reversal might occur (White)
//Follow for more indicators: https://www.tradingview.com/u/dman103/#published-scripts
//@version=4
study("Low - High Simple Tracker",overlay=true)
////==================Inputs
length = input(8)
length_avg = input(8)
up_Trend_Condition = input(high)
down_Trend_Condition = input(low)

////==================Array setup and calculations
lowArray = array.new_float(0)
highArray = array.new_float(0)

//Fill Lows to an array
for i = 0 to length-1
    array.push(highArray,high[i])
//Fill Highs to an array
for i = 0 to length-1
    array.push(lowArray,low[i])
    
//Get the highest value from the high array
maxValue= array.max(highArray)
//Get the lowest value from the low array
minValue= array.min(lowArray)

//Average between highest and lowest (length can be modifed)
highLowAvg =(sum(maxValue,length_avg)  +  sum(minValue,length_avg))  / (length_avg*2)

////////==================Plotting
colorHL = down_Trend_Condition > highLowAvg ? color.green : up_Trend_Condition < highLowAvg ? color.red : color.white
plot(highLowAvg, color =colorHL, style = plot.style_line, linewidth = 2)
1 Answers

If you convert to v5 (there is a conversion tool in the editor), then u can use the parameter timeframe="" in the indicator() line ( study() in prior versions), and then use the input dialog to select the desired timeframe to run the indicator. That is the easiest way. You can run multiple copies of the same indicator each using a different timeframe.

Related