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 you
// Definition of code parameters
DEFPARAM CumulateOrders = false // Cumulating positions deactivated
DEFPARAM preloadbars = 5000
//Money Management
MM = 0 // = 0 for optimization
if MM = 0 then
positionsize=0.5
ENDIF
if MM = 1 then
ONCE startpositionsize = 0.5
ONCE factor = 10 // factor of 10 means margin will increase/decrease @ 10% of strategy profit; factor 20 = 5% etc
ONCE margin = (close*.005) // tier 1 margin value of 1 contract in instrument currency; change decimal according to available leverage
ONCE margin2 = (close*.01)// tier 2 margin value of 1 contract in instrument currency; change decimal according to available leverage
ONCE tier1 = 280 // IG first tier margin limit
ONCE maxpositionsize = 2800 // IG tier 2 margin limit
ONCE minpositionsize = 1 // enter minimum position allowed
IF Not OnMarket THEN
positionsize = startpositionsize + Strategyprofit/(factor*margin)
ENDIF
IF Not OnMarket THEN
IF startpositionsize + Strategyprofit/(factor*margin) > tier1 then
positionsize = (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 //incorporating tier 2 margin
ENDIF
IF Not OnMarket THEN
if 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 then
positionsize = maxpositionsize// keeps positionsize from going above IG tier 2 margin limit
ENDIF
ENDIF
ENDIF
ENDIF
Ctime = 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>D
c8 = 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>Da
c16 = Ka HULLb[1]and HULLb[1]<HULLb[2]
c20 = HULLb < HULLb[1]and HULLb[1]>HULLb[2]
// Conditions to enter long positions
IF Ctime and c1 AND C3 AND C5 and c7 and c9 and c11 and c13 and c15 and c19 THEN
BUY positionsize CONTRACT AT MARKET
SET STOP %LOSS 1.2
SET TARGET %PROFIT 0.7
ENDIF
// Conditions to enter short positions
IF Ctime and c2 AND C4 AND C6 and c8 and c10 and c12 and c14 and c16 and c20 THEN
SELLSHORT positionsize CONTRACT AT MARKET
SET STOP %LOSS 1.2
SET TARGET %PROFIT 0.7
ENDIF
//================== exit in profit
if longonmarket and C12 and c20 and close>positionprice then
sell at market
endif
If shortonmarket and C11 and c19 and close exitshort at market
endif
//==============exit at loss
if longonmarket AND c2 and c20 and closepositionprice then
exitshort at market
endif
//%trailing stop function
trailingPercent = .28
stepPercent = .01
if onmarket then
trailingstart = tradeprice(1)*(trailingpercent/100) //trailing will start @trailingstart points profit
trailingstep = tradeprice(1)*(stepPercent/100) //% step to move the stoploss
endif
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart THEN
newSL = tradeprice(1)+trailingstep
ENDIF
//next moves
IF newSL>0 AND close-newSL>trailingstep THEN
newSL = newSL+trailingstep
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart THEN
newSL = tradeprice(1)-trailingstep
ENDIF
//next moves
IF newSL>0 AND newSL-close>trailingstep THEN
newSL = newSL-trailingstep
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
//************************************************************************
Always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read.
Thank you 🙂
The 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.