Multi timeframe – MTF indicators for ProRealTime
Forums › ProRealTime English forum › ProBuilder support › Multi timeframe – MTF indicators for ProRealTime
- This topic has 150 replies, 49 voices, and was last updated 1 week ago by robertogozzi.
Tagged: mtf, mtf indicators
-
-
07/08/2024 at 9:51 AM #23492407/08/2024 at 10:31 AM #234929
Place your code related to the 60-minutes timeframe under this statement:
1TIMEFRAME(1 hour, updateonclose) //use update on close or not?and the rest, about the 1-minute conditions below this:
1TIMEFRAME(default)Default is the current timeframe of the chart.
07/08/2024 at 2:22 PM #234950HI, dos not work . My code (not even finished at that stage) is looking like . The idea is to check few indicators during a 1 hour timeframe ad if one of the indicator is correctly responding, then to generate immedately an order during the 1 minute timeframe… It means i need to get the expected signal during the 60 minutes timeframe and immediately react under the 1 mn timeframe. It also means i cannot wait the 1 hour TF is closed and restart ….thats probably the issue. I also tested the condition all conditions = order or 1 of the conditions )= order. without success.
DEFPARAM CumulateOrders = False // Cumul des positions désactivé
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
// Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d’une position avant l’heure spécifiée
noEntryBeforeTime = 003000
timeEnterBefore = time >= noEntryBeforeTime
// Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d’une position après l’heure spécifiée
noEntryAfterTime = 215500
timeEnterAfter = time < noEntryAfterTime
// Conditions pour ouvrir une position acheteuse
timeframe (60 minutes)
indicator1 = xxxx[x]
c1 = (indicator1 > x)
indicator2 = xxxxxx[x]
indicator3 = xxxxx[x](open)
c2 = (indicator2 CROSSES OVER indicator3)
indicator4 = xxxxx[x](totalPrice)
indicator5 = xxxxxxx[x](totalPrice)
c3 = (indicator4 CROSSES OVER indicator5)
indicator6 = xxxxxx[x](totalPrice)
indicator7 = xxxxx[x](totalPrice)
c4 = (indicator6 CROSSES OVER indicator7)
indicator8 = xxxxxxxxx[x,y](close)
indicator9 = xxxxxxx[x](xxxxxxxxxx[x,y](close))
c5 = (indicator8 CROSSES OVER indicator9)
indicator10 = xxxxxxxx[x](xxxxxxxxxxxxxxxx[x,y](close))
c6 = (indicator10[1] CROSSES OVER indicator10)
c7 = (indicator2[1] CROSSES OVER indicator3)
timeframe(1 minute,default)
IF (c1 AND c2 AND c3 AND c4 AND c5 AND c6 And 7) AND not daysForbiddenEntry THEN
BUY 1 SHARES AT MARKET
ENDIF
07/08/2024 at 3:34 PM #234956Hmmm
Lolzzzz
Anyway, your want an indicator on the 1hr timeframe to trigger a buy or sell on the 1 minute timeframe…
It wont happen, becuase you may have to wait a minute for the close of the 1 minute… so here’s an example code, but for an immediate reaction run on the 1 second timeframe not 1 minute…Let me give you a code for running a code on 1 second chart only using the values or results from 5 or 10 minutes chart.
So once you have the variable triggered in the HTF the in the below case it retains the value of the close, otherwise it updates all the time and messes up the trail… sotimeframe (1hour, updateonclose)
If not onmarket then
mytrigger=0
endif
if movingaverageA crossesovermoving averageB then
Mytrigger=1
else
mytrigger=0
endif
timeframe (1 second)
If not onmarket and mytrigger=1 then
sell myamount contracts at market
endif// If you use the 1 minute chart, you may have to await the end of bar, so for immediate execution use the 1 second timeframe for execution of trades and HTFs for conditions determination
Timeframe (10 minute, updateonclose) //this will ensure only the close value is taken and it doesnt constantly update on the deafault timeframe//
Timeframe (10 minute, updateonclose)
if close[0] then
close10min=close[0]
endifTimeframe (5 minute, updateonclose)
if close[0] then
close5min=close[0]
endiftimeframe (default)//you can put this as 5 minutes, or whatever but the code runs on the 1 second chart and runs the dax trail perfectly well
if daxtrail5mins=1 then
once m=0
IF Not OnMarket THEN
trailpausecount=0
TrailStart = 8 //10 Start trailing profits from this point
BasePerCent = 0.100 //10.0% Profit to keep
StepSize = 3 //6 Pips chunks to increase Percentage
PerCentInc = 0.100 //10.0% PerCent increment after each StepSize chunk
RoundTO = -0.5 //-0.5 rounds to Lower integer, +0.4 rounds to Higher integer
PriceDistance = 7 * pipsize//8.9 minimun distance from current price
y1 = 0
y2 = 0
ProfitPerCent = BasePerCent
endif
If onmarket and m=0 then
m=1
ENDIF
If not onmarket and m=1 THEN
QUIT
endif
If trailtimeframe=5 then
close5=close5min
elsif trailtimeframe=10 THEN
close5=close10min
endif
If onmarket and close5 then
IF LongOnMarket AND close5 > (TradePrice + (y1 * pipsize)) THEN //LONG
x1 = (close5 – tradeprice) / pipsize //convert price to pips
IF x1 >= TrailStart THEN //go ahead only if N+ pips
Diff1 = abs(TrailStart – x1)
Chunks1 = max(0,round((Diff1 / StepSize) + RoundTO))
ProfitPerCent = BasePerCent + (BasePerCent * (Chunks1 * PerCentInc))
ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent))
y1 = max(x1 * ProfitPerCent, y1) //y = % of max profit
ENDIF
ELSIF ShortOnMarket AND close5 < (TradePrice - (y2 * pipsize)) THEN//SHORT x2 = (tradeprice - close5) / pipsize //convert price to pips IF x2 >= TrailStart THEN //go ahead only if N+ pips
Diff2 = abs(TrailStart – x2)
Chunks2 = max(0,round((Diff2 / StepSize) + RoundTO))
ProfitPerCent = BasePerCent + (BasePerCent * (Chunks2 * PerCentInc))
ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent))
y2 = max(x2 * ProfitPerCent, y2) //y = % of max profit
ENDIF
ENDIF
IF y1 THEN //Place pending STOP order when y>0
SellPrice = Tradeprice + (y1 * pipsize) //convert pips to price
IF abs(close5 – SellPrice) > PriceDistance THEN
IF close5 >= SellPrice THEN
SELL AT SellPrice STOP
ELSE
SELL AT SellPrice LIMIT
ENDIF
ELSE
SELL AT Market
ENDIF
If not onmarket and m=1 THEN
QUIT
endif
ENDIF
IF y2 THEN //Place pending STOP order when y>0
ExitPrice = Tradeprice – (y2 * pipsize) //convert pips to price
IF abs(close5 – ExitPrice) > PriceDistance THEN
IF close5 <= ExitPrice THEN EXITSHORT AT ExitPrice STOP ELSE EXITSHORT AT ExitPrice LIMIT ENDIF ELSE EXITSHORT AT Market ENDIF If not onmarket and m=1 THEN quit endif ENDIF endif endif
07/08/2024 at 3:42 PM #234957U know I didnt have insrt PRT code in my before window, so sorry abo that, thought something had changed, but now its there again…. Hmmm
Heres the codes again
multi timeframe events causing trigger in LTF12345678910111213timeframe (1hour, updateonclose)If not onmarket thenmytrigger=0endifif movingaverageA crossesovermoving averageB thenMytrigger=1elsemytrigger=0endiftimeframe (1 second)If not onmarket and mytrigger=1 thensell myamount contracts at marketendifquit as its ran on a manual entry program on 1 seconds12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182if close[0] thenclose10min=close[0]endifTimeframe (5 minute, updateonclose)if close[0] thenclose5min=close[0]endiftimeframe (default)//you can put this as 5 minutes, or whatever but the code runs on the 1 second chart and runs the dax trail perfectly wellif daxtrail5mins=1 thenonce m=0IF Not OnMarket THENtrailpausecount=0TrailStart = 8 //10 Start trailing profits from this pointBasePerCent = 0.100 //10.0% Profit to keepStepSize = 3 //6 Pips chunks to increase PercentagePerCentInc = 0.100 //10.0% PerCent increment after each StepSize chunkRoundTO = -0.5 //-0.5 rounds to Lower integer, +0.4 rounds to Higher integerPriceDistance = 7 * pipsize//8.9 minimun distance from current pricey1 = 0y2 = 0ProfitPerCent = BasePerCentendifIf onmarket and m=0 thenm=1ENDIFIf not onmarket and m=1 THENQUITendifIf trailtimeframe=5 thenclose5=close5minelsif trailtimeframe=10 THENclose5=close10minendifIf onmarket and close5 thenIF LongOnMarket AND close5 > (TradePrice + (y1 * pipsize)) THEN //LONGx1 = (close5 – tradeprice) / pipsize //convert price to pipsIF x1 >= TrailStart THEN //go ahead only if N+ pipsDiff1 = abs(TrailStart – x1)Chunks1 = max(0,round((Diff1 / StepSize) + RoundTO))ProfitPerCent = BasePerCent + (BasePerCent * (Chunks1 * PerCentInc))ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent))y1 = max(x1 * ProfitPerCent, y1) //y = % of max profitENDIFELSIF ShortOnMarket AND close5 < (TradePrice - (y2 * pipsize)) THEN//SHORT x2 = (tradeprice - close5) / pipsize //convert price to pips IF x2 >= TrailStart THEN //go ahead only if N+ pipsDiff2 = abs(TrailStart – x2)Chunks2 = max(0,round((Diff2 / StepSize) + RoundTO))ProfitPerCent = BasePerCent + (BasePerCent * (Chunks2 * PerCentInc))ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent))y2 = max(x2 * ProfitPerCent, y2) //y = % of max profitENDIFENDIFIF y1 THEN //Place pending STOP order when y>0SellPrice = Tradeprice + (y1 * pipsize) //convert pips to priceIF abs(close5 – SellPrice) > PriceDistance THENIF close5 >= SellPrice THENSELL AT SellPrice STOPELSESELL AT SellPrice LIMITENDIFELSESELL AT MarketENDIFIf not onmarket and m=1 THENQUITendifENDIFIF y2 THEN //Place pending STOP order when y>0ExitPrice = Tradeprice – (y2 * pipsize) //convert pips to priceIF abs(close5 – ExitPrice) > PriceDistance THENIF close5 <= ExitPrice THEN EXITSHORT AT ExitPrice STOPELSEEXITSHORT AT ExitPrice LIMITENDIFELSEEXITSHORT AT MarketENDIFIf not onmarket and m=1 THENquitendifENDIFendifendif08/22/2024 at 9:59 PM #236623I would like to make an indicator with different timeframes. To give an example: If I wanted to observe if the RSI is oversold in a time frame of 1 second, let me know with a signal in a time frame of 5 minutes, which is where I usually work. My goal is to be able to save time and not have to change time frames.
This you think can be achieved. I’ve been thinking about it for a while but I can’t do it.Thank you.
08/23/2024 at 9:11 AM #236629The support for multiple time frames implies that on a 1-second TF you can check conditions on a 5-minute TF, not the other way round.
The TF on your chart must always be the smallest one. Of course you can have both the 1-second and 5-minute TF on your chart, but the indicator needs to be added to the 1-second TF.
1 user thanked author for this post.
08/23/2024 at 9:22 PM #23666510/14/2024 at 1:17 PM #23897510/16/2024 at 11:49 AM #239054is it possible to get hold of a value returned by a personal indicator placed on a 3600 tick chart inside a 3 minute chart? This would be the difference between finding intraday trades 5 days a week and not finding one trade, on time, in a week.
10/16/2024 at 3:15 PM #239079If your thinking of back-testing and automatic trading I think the answer is no.
But if just as an indicator and manual trading, then very loosely Maybe.
Arrays update on each tick, in a indicator, so you could count/accumulate the data.
Storing it, and aligning to what was on the tick chart would be tricky but I think doable.
However , when a chart is built, it appears to use OHLC bar data until current bar where ticks available.
Therefore you couldn’t gain access or look back for the ticks before current bar when chart opened.
So either you would have to wait to accumulated enough tick data and/or open chart substantially earlier than you need.
The automatic closing of PRT would lose the tick data gathered on close/reboot.
Also, if the chart window was re-calculated and updated, for any reason while open, the data would get lost.
So though it maybe possible, it would be a nightmare to use.
The simple reason would be, you can not store user data in the program which would be available the next time its run/opened.
Now it maybe easier to build the 3min time frame on the 3600 tick chart.
All 3min indicators would have to be converted.
One limiting factor would be the number of bar needed in the chart to calculate the 3min indicators.
Its hard to say yes with out knowing the full details of what your doing.
Which ever way, it’s an out of the box, programming challenge.
https://www.prorealcode.com/topic/show-5-minute-candlestick-in-1-minute-chart/
11/30/2024 at 7:20 AM #240929Good morning everyone. I ask for help please: I don’t know if I’m doing something wrong, but I used the multitimeframe mode to draw my indicator on the same graph, applying it to two different timeframes, but checking the result I noticed that the result does not coincide with the data of the indicator normally drawn on the single timeframe. In particular it seems that it’s wrong in drawing the double periods (for example the two-weekly tf on the weekly chart and so on …).
How can I resolve this inconvenience? Do any of you know the problem? Am I the one making a mistake or is it a system bug?
Thanks in advance11/30/2024 at 8:43 AM #240931Make an example (code snippet) to test it.
12/01/2024 at 5:57 PM #240951Thanks for replying Roberto.
For example on the 2 months TF my indicator value is 5527,76 while if I charge it on the monthly TF with indication at beginning of code TIMEFRAME (2 MONTHS) the value it returns is 5312,08
The code is as follows (ignore colors and colorbetween I don’t use):
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282timeframe (2 months, default)period = 13deviation1 = 1deviation2 = 2deviation3 = 3longupper= 30longmiddle=20longlower=10shortlower=-30shortmiddle=-20shortupper=-10rem up = 1rem down = -1rem begin = 1// (i) indicatorsiSTD1 = deviation1 * STD[period](close)iSTD2 = deviation2 * STD[period](close)iSTD3 = deviation3 * STD[period](close)iSMA = Average[period,0](close)sma25 = Average[25,0](close)sma50 = Average[50,0](close)// (c) conditionscUpperBand3 = iSMA + iSTD3 // ----3----cUpperBand2 = iSMA + iSTD2 // ----2----cUpperBand1 = iSMA + iSTD1 // ----1----cMiddleBand = iSMA // ----0----cLowerBand1 = iSMA - iSTD1 // ----1----cLowerBand2 = iSMA - iSTD2 // ----2----cLowerBand3 = iSMA - iSTD3 // ----3----// delay startif barindex < period then // hold off till enough bar presentts = Undefined // removes ts tangent line from 0 til real value availableendif// logic operation// setup block --> When 'begin' = 0, executes next block.// Since 'trend' default = 0, being set to 1 or -1 will// allow the 'following' logic code blocks to be executed// Bollinger Logic -----------// initial, set trend, trend only changed by iSTD1if trend=0 and close crosses over cUpperband1 thentrend = longupperelsif trend=0 and close crosses under cLowerBand1 thentrend = shortlowerendif// following from first time after trend set!// change of trendif trend = longupper and close crosses under cUpperBand1 thentrend = longmiddleendifif trend=longmiddle thenif close crosses under cMiddleBand thentrend=longlowerelsif close crosses over cUpperBand2 thentrend=longupperelsetrend = longmiddleendifendifif trend=longlower thenif close crosses under cLowerBand1 thentrend=shortlowerelsif close crosses over cUpperBand1 and close < cUpperBand2 thentrend = longmiddleelsif close crosses over cUpperBand2 thentrend=longupperelsetrend=longlowerendifendifif trend=shortlower and Close crosses over cLowerBand1 thentrend=shortmiddleendifif trend=shortmiddle thenif close crosses over cMiddleBand thentrend=shortupperelsif close crosses under cLowerBand2 thentrend = shortlowerelsetrend=shortmiddleendifendifif trend = shortupper thenif close crosses over cUpperBand1 thentrend=longupperelsif close crosses under cLowerBand1 and close > cLowerBand2 thentrend=shortmiddleelsif close crosses under cLowerBand2 thentrend=shortlowerelsetrend = shortupperendifendif// set 'ts' values to appropriate band threshold levelif trend = longupper or trend = shortupper thents = cUpperBand1elsif trend = longmiddle or trend = shortmiddle thents = cMiddleBandelsif trend = longlower or trend = shortlower thents = cLowerBand1endif// color settingsif trend = longupper or trend = longmiddle or trend = longlower thenr = 0g = 255 // set all colorbetween's greena1 = 20 // on upperband 3a2 = 15 // on upperband 2a3 = 10 // on upperband 1a4 = 5 // on lowerband 1a5 = 15 // off lowerBand 2a6 = 20 // off lowerBand 3elsif trend = shortupper or trend=shortmiddle or trend=shortlower thenr = 255 // set all colorbetween's redg = 0a1 = 20 // off upperband 3a2 = 15 // off upperband 2a3 = 5 // on upperBand 1a4 = 10 // on lowerBand 1a5 = 15 // on lowerBand 2a6 = 20 // on lowerBand 3endif////////////if close >= cMiddleBand thenr0=0g0=255elsif close < cMiddleBand thenr0=255g0=0endifif close >= cUpperBand1 thenr11 =0g11=255elsif close < cUpperBand1 thenr11 =255g11=0endifif close >= cUpperBand2 thenr21 =0g21=255elsif close < cUpperBand2 thenr21 =255g21=0endifif close >= cUpperBand3 thenr51 =0g51=255elsif close < cUpperBand3 thenr51 =255g51=0endifif close <= cLowerBand1 thenr31=255g31=0elsif close > cLowerBand1 thenr31 =0g31=255endifif close <= cLowerBand2 thenr41=255g41=0elsif close > cLowerBand2 thenr41 =0g41=255endifif close <= cLowerBand3 thenr61 =255g61 =0elsif close > cLowerBand3 thenr61 =0g61 =255endifIF cMiddleBand < sma25 thenr71=255g71=0elsif cMiddleBand >= sma25 thenr71=0g71=255endifIF sma25 < sma50 thenr81=255g81=0elsif sma25 >= sma50 thenr81=0g81=255endif//colorbetween(cUpperBand2,cUpperBand3, 0,255,0,a1) // upperBand3 green - trend up//colorbetween(cUpperBand1,cUpperBand2, 0,255,0,a2) // upperBand2 green - trend up//colorbetween(cMiddleBand,cUpperBand1, r,g,0,a3) // upperBand1 green/red - trend up/down//colorbetween(cMiddleBand,cLowerBand1, r,g,0,a4) // lowerBand1 green/red - trend up/down//colorbetween(cLowerBand1,cLowerBand2, 255,0,0,a5) // lowerBand2 red - trend down//colorbetween(cLowerBand2,cLowerBand3, 255,0,0,a6) // lowerBand3 red - trend downREM colorbetween (cMiddleBand,sma25, r71,g71,0,15)REM colorbetween (sma25,sma50, r81,g81,0,10)return ts coloured(r,g,0) style(line,1) as "BTrend 2 months" ,cMiddleBand coloured (r0,g0,0) style (dottedline,1) as "SMA (13)", sma25 coloured (255,255,0) style (dottedline,1) as "SMA (25)", sma50 coloured (255,102,255) style (dottedline,1) as "SMA (50)" rem , cUpperBand1 coloured (r11 ,g11 ,0) style (DOTTEDLINE4 ,1) as "Upper1", cUpperBand2 coloured (r21 ,g21 ,0) style (DOTTEDLINE4 ,1) as "Upper2", cUpperBand3 coloured (r51 ,g51 ,0) style (DOTTEDLINE4 ,1) as "Upper3", cLowerBand1 coloured (r31 ,g31 ,0) style (DOTTEDLINE4 ,1) as "Lower1", cLowerBand2 coloured (r41 ,g41 ,0) style (DOTTEDLINE4 ,1) as "Lower2", cLowerBand3 coloured (r61 ,g61 ,0) style (DOTTEDLINE4 ,1) as "Lower3"12/02/2024 at 2:56 AM #240959I tested it on intraday TF and seems to work well …
I meant on s&p500 INDEX when I wrote … “For example on the 2 months TF my indicator value is 5527,76 while if I charge it on the monthly TF with indication at beginning of code TIMEFRAME (2 MONTHS) the value it returns is 5312,08” …
-
AuthorPosts