How to change timeframes in multi timeframe codes
Forums › ProRealTime English forum › ProOrder support › How to change timeframes in multi timeframe codes
- This topic has 2 replies, 2 voices, and was last updated 2 years ago by robertogozzi.
-
-
05/13/2021 at 1:52 PM #169576
I would like to understand how to change default timeframe in multi timeframe codes, below is an example of multi timeframe code “Nas 5m mother of dragons v3” with default time frame at 5 ‘.
For example: I would like to set the default timeframe to 2h.
Can anyone help me.
Thank you123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113// Definition of code parametersDEFPARAM CumulateOrders = false // Cumulating positions deactivatedDEFPARAM preloadbars = 5000//Money ManagementMM = 0 // = 0 for optimizationif MM = 0 thenpositionsize=0.5ENDIFif MM = 1 thenONCE startpositionsize = 0.5ONCE factor = 10 // factor of 10 means margin will increase/decrease @ 10% of strategy profit; factor 20 = 5% etcONCE margin = (close*.005) // tier 1 margin value of 1 contract in instrument currency; change decimal according to available leverageONCE margin2 = (close*.01)// tier 2 margin value of 1 contract in instrument currency; change decimal according to available leverageONCE tier1 = 280 // IG first tier margin limitONCE maxpositionsize = 2800 // IG tier 2 margin limitONCE minpositionsize = 1 // enter minimum position allowedIF Not OnMarket THENpositionsize = startpositionsize + Strategyprofit/(factor*margin)ENDIFIF Not OnMarket THENIF startpositionsize + Strategyprofit/(factor*margin) > tier1 thenpositionsize = (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 //incorporating tier 2 marginENDIFIF Not OnMarket THENif startpositionsize + Strategyprofit/(factor*margin) < minpositionsize THEN positionsize = minpositionsize //keeps positionsize from going below allowed minimum ENDIF IF (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 > maxpositionsize thenpositionsize = maxpositionsize// keeps positionsize from going above IG tier 2 margin limitENDIFENDIFENDIFENDIFCtime = time >= 0 and time < 230000 TIMEFRAME(2 hours,updateonclose) Period= 450 inner = 2*weightedaverage[round( Period/2)](typicalprice)-weightedaverage[Period](typicalprice) HULLa = weightedaverage[round(sqrt(Period))](inner) c1 = HULLa > HULLa[1]c2 = HULLa < HULLa[1] ST1 = SuperTrend[2.5,7] c3 = (close > ST1)c4 = (close < ST1) ma1 = average[55,3](close) c5 = ma1 > ma1[1]c6 = ma1 < ma1[1] //Stochastic RSI | indicator lengthRSI = 12 //RSI period lengthStoch = 12 //Stochastic period smoothK = 8 //Smooth signal of stochastic RSI smoothD = 3 //Smooth signal of smoothed stochastic RSI myRSI = RSI[lengthRSI](close) MinRSI = lowest[lengthStoch](myrsi) MaxRSI = highest[lengthStoch](myrsi) StochRSI = (myRSI-MinRSI) / (MaxRSI-MinRSI) K = average[smoothK](stochrsi)*100 D = average[smoothD](K) c7 = K>Dc8 = K mab[1]c10 = mab < mab[1] TIMEFRAME(15 minutes,updateonclose) mac = average[45,1](close) c11 = mac > mac[1]c12 = mac < mac[1] Periodc= 16 innerc = 2*weightedaverage[round( Periodc/2)](typicalprice)-weightedaverage[Periodc](typicalprice) HULLc = weightedaverage[round(sqrt(Periodc))](innerc) c13 = HULLc > HULLc[1]c14 = HULLc < HULLc[1] TIMEFRAME(5 minutes) //Stochastic RSI | indicator lengthRSIa = 12 //RSI period lengthStocha = 6 //Stochastic period smoothKa = 12 //Smooth signal of stochastic RSI smoothDa = 2 //Smooth signal of smoothed stochastic RSI myRSIa = RSI[lengthRSIa](close) MinRSIa = lowest[lengthStocha](myrsia) MaxRSIa = highest[lengthStocha](myrsia) StochRSIa = (myRSIa-MinRSIa) / (MaxRSIa-MinRSIa) Ka = average[smoothKa](stochrsia)*100 Da = average[smoothDa](Ka) c15 = Ka>Dac16 = Ka HULLb[1]and HULLb[1]<HULLb[2]c20 = HULLb < HULLb[1]and HULLb[1]>HULLb[2]// Conditions to enter long positionsIF Ctime and c1 AND C3 AND C5 and c7 and c9 and c11 and c13 and c15 and c19 THENBUY positionsize CONTRACT AT MARKETSET STOP %LOSS 1.2SET TARGET %PROFIT 0.7ENDIF// Conditions to enter short positionsIF Ctime and c2 AND C4 AND C6 and c8 and c10 and c12 and c14 and c16 and c20 THENSELLSHORT positionsize CONTRACT AT MARKETSET STOP %LOSS 1.2SET TARGET %PROFIT 0.7ENDIF//================== exit in profitif longonmarket and C12 and c20 and close>positionprice thensell at marketendifIf shortonmarket and C11 and c19 and close exitshort at marketendif//==============exit at lossif longonmarket AND c2 and c20 and closepositionprice thenexitshort at marketendif//%trailing stop functiontrailingPercent = .28stepPercent = .01if onmarket thentrailingstart = tradeprice(1)*(trailingpercent/100) //trailing will start @trailingstart points profittrailingstep = tradeprice(1)*(stepPercent/100) //% step to move the stoplossendif//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart THENnewSL = tradeprice(1)+trailingstepENDIF//next movesIF newSL>0 AND close-newSL>trailingstep THENnewSL = newSL+trailingstepENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart THENnewSL = tradeprice(1)-trailingstepENDIF//next movesIF newSL>0 AND newSL-close>trailingstep THENnewSL = newSL-trailingstepENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//************************************************************************05/13/2021 at 2:03 PM #169578Always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read.
Thank you 🙂
1 user thanked author for this post.
05/13/2021 at 2:12 PM #169579The DEFAULT timeframe is the one on the chart and it must be the SMALLEST timeframe among those you are using in your code.
In addition, ALL other timeframes used in your code must (each one of them) be a multiple of the default one.
To set the default TF to 2 hours, set it on your chart first, then make sure ALL timeframes used in your code are multiples of 2 hours. You will not be able to use any TF lower than 2 hours, nor a, say, 3h TF as it’s not a multiple of the default one.
For more info and examples you can search this forum for MTF.
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on