Francois
Pine Script Rookie
Pine Script Rookie
Posts: 2
Joined: March 4th, 2022
Contact: TradingView Profile

Lower time frames

Hi. I am having great difficulty working around lower time frames. What I am trying to achieve is the following. On the 15 minute chart, lookup the value of the calculation in the function on the 11 minute time frame. If the value is in range then return true. What is happening, is that it refuses to look at the previous 11 minute candle data, but keeps looking at the wrong 11 minute data. What is needed is that if the 15 minute closes, then if the 11 minute is unconfirmed look at the previous 11 minute close data. Below is what I am looking at. The chart is set to Timeframe 2 (15 minutes), once this candle closes, it runs the check on timeframe 2 and that is where I need to look at timeframe 1 (11 minutes), if the 11 minutes is closed, then use that value in calculation, if not closed, use previous 11 minute value in calculation. All your help will be really appreciated!!

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Money flow timeframe 1
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

usetf1 = input(true,title="Use TF1", group = "Use what TF",type=input.bool, inline='TF1')
resolutiontf1 = input("11",title="MFI Resolution for TF1", type = input.resolution,group="Use what TF", inline='TF1')
rsiMFIperiodtf1 = 60
rsiMFIMultipliertf1 = 150
rsiMFIPosYtf1 = 2.5

smatf1 = sma( ( (close-open) / (high-low) ) * rsiMFIMultipliertf1,rsiMFIperiodtf1) - rsiMFIPosYtf1

//rsiMFItf1 = security(syminfo.tickerid,resolutiontf1,smatf1[1])
rsiMFItf1 = security(syminfo.tickerid,resolutiontf1,smatf1[barstate.isconfirmed?0:1],lookahead = barmerge.lookahead_off)

//Green Moneyflow
gmfcounttf1 = 0.0
gmfsumtf1 = 0.0
gmfaveragetf1 = 0.0

gmfcounttf1 := rsiMFItf1 == rsiMFItf1[1] ? gmfcounttf1[1] : rsiMFItf1 > 0 ? gmfcounttf1[1] + 1 : 0
gmfsumtf1 := rsiMFItf1 == rsiMFItf1[1] ? gmfsumtf1 [1] : rsiMFItf1 > 0 ? gmfsumtf1[1] + rsiMFItf1 : 0
gmfaveragetf1 := rsiMFItf1 == rsiMFItf1[1] ? gmfaveragetf1[1] : rsiMFItf1 > 0 ? gmfsumtf1 / gmfcounttf1 : 0

//plot(rsiMFItf1 > 0 ? gmfaveragetf1 : na, color=color.yellow, style=plot.style_circles,title="TF1 GMF AVG")

//Red Moneyflow
rmfcounttf1 = 0.0
rmfsumtf1 = 0.0
rmfaveragetf1 = 0.0

rmfcounttf1 := rsiMFItf1 == rsiMFItf1[1] ? rmfcounttf1[1] : rsiMFItf1 < 0 ? rmfcounttf1[1] + 1 : 0
rmfsumtf1 := rsiMFItf1 == rsiMFItf1[1] ? rmfsumtf1 [1] : rsiMFItf1 < 0 ? rmfsumtf1[1] + rsiMFItf1 : 0
rmfaveragetf1 := rsiMFItf1 == rsiMFItf1[1] ? rmfaveragetf1[1] : rsiMFItf1 < 0 ? rmfsumtf1 / rmfcounttf1 : 0

//plot(rsiMFItf1 < 0 ? rmfaveragetf1 : na, color=color.yellow, style=plot.style_circles,title="TF% RMF AVG")

// Entry conditions
belowzeroaboveaveragetf1 = rsiMFItf1 > rmfaveragetf1 and rsiMFItf1 < 0
abovezeroaboveaveragetf1 = rsiMFItf1 >= gmfaveragetf1 and rsiMFItf1 > 0
abovezerobelowaveragetf1 = rsiMFItf1 < gmfaveragetf1 and rsiMFItf1 > 0
belowzerobelowaveragetf1 = rsiMFItf1 <= rmfaveragetf1 and rsiMFItf1 < 0

colortf1 = color.black
colortf1 := belowzeroaboveaveragetf1 ? color.yellow: abovezeroaboveaveragetf1 ? color.green : abovezerobelowaveragetf1 ? color.orange : belowzerobelowaveragetf1 ? color.red : na



//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Money flow timeframe 2
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

usetf2 = input(true,title="Use TF2", group = "Use what TF",type=input.bool, inline='TF2')
resolutiontf2 = input("15",title="MFI Resolution for TF2", type = input.resolution,group="Use what TF", inline='TF2')
rsiMFIperiodtf2 = 60
rsiMFIMultipliertf2 = 150
rsiMFIPosYtf2 = 2.5

smatf2 = sma( ( (close-open) / (high-low) ) * rsiMFIMultipliertf2,rsiMFIperiodtf2) - rsiMFIPosYtf2

rsiMFItf2 = security(syminfo.tickerid,resolutiontf2,smatf2[0],lookahead = barmerge.lookahead_on)

//plot(rsiMFItf2,color=color.white,style=plot.style_circles,title="TF2 Moneyflow")

//Green Moneyflow
gmfcounttf2 = 0.0
gmfsumtf2 = 0.0
gmfaveragetf2 = 0.0

gmfcounttf2 := rsiMFItf2 == rsiMFItf2[1] ? gmfcounttf2[1] : rsiMFItf2 > 0 ? gmfcounttf2[1] + 1 : 0
gmfsumtf2 := rsiMFItf2 == rsiMFItf2[1] ? gmfsumtf2 [1] : rsiMFItf2 > 0 ? gmfsumtf2[1] + rsiMFItf2 : 0
gmfaveragetf2 := rsiMFItf2 == rsiMFItf2[1] ? gmfaveragetf2[1] : rsiMFItf2 > 0 ? gmfsumtf2 / gmfcounttf2 : 0

//plot(rsiMFItf2 > 0 ? gmfaveragetf2 : na, color=color.yellow, style=plot.style_circles,title="TF2 GMF AVG")

//Red Moneyflow
rmfcounttf2 = 0.0
rmfsumtf2 = 0.0
rmfaveragetf2 = 0.0

rmfcounttf2 := rsiMFItf2 == rsiMFItf2[1] ? rmfcounttf2[1] : rsiMFItf2 < 0 ? rmfcounttf2[1] + 1 : 0
rmfsumtf2 := rsiMFItf2 == rsiMFItf2[1] ? rmfsumtf2 [1] : rsiMFItf2 < 0 ? rmfsumtf2[1] + rsiMFItf2 : 0
rmfaveragetf2 := rsiMFItf2 == rsiMFItf2[1] ? rmfaveragetf2[1] : rsiMFItf2 < 0 ? rmfsumtf2 / rmfcounttf2 : 0

//plot(rsiMFItf2 < 0 ? rmfaveragetf2 : na, color=color.yellow, style=plot.style_circles,title="TF% RMF AVG")

// Entry conditions
belowzeroaboveaveragetf2 = rsiMFItf2 > rmfaveragetf2 and rsiMFItf2 < 0
abovezeroaboveaveragetf2 = rsiMFItf2 >= gmfaveragetf2 and rsiMFItf2 > 0
abovezerobelowaveragetf2 = rsiMFItf2 < gmfaveragetf2 and rsiMFItf2 > 0
belowzerobelowaveragetf2 = rsiMFItf2 <= rmfaveragetf2 and rsiMFItf2 < 0

colortf2 = color.black
colortf2 := belowzeroaboveaveragetf2 ? color.yellow: abovezeroaboveaveragetf2 ? color.green : abovezerobelowaveragetf2 ? color.orange : belowzerobelowaveragetf2 ? color.red : na

processingclouds
Pine Script Master
Pine Script Master
Posts: 115
Joined: January 30th, 2022

Re: Lower time frames

I will quote Bjorgum from another forum :
"No we cannot reliably request data from below. This is because we reduce the resolution of that data. Historical data is OHLC, and in real time we are building candles in the same manner to have one close per 1hr bar. So data requested from a lower chart is subject to give us only the last value that the lower time frame was at the time of the higher time frame close. If we want all those time frames we must drop down and pull the data from above as we will have the resolution necessary to see all of the values."

i.e. he is saying view your chart in lower time frame and pull higher time frame data.

Return to “Pine Script Q&A”