Mother of Dragons trading strategy…

Viewing 15 posts - 391 through 405 (of 523 total)
  • Author
    Posts
  • #148620 quote
    nonetheless
    Participant
    Master

    The backtests seem fine to me but could be an issue with positionsize. Minimum for demo is 1, minimum live is .5

    #148633 quote
    nonetheless
    Participant
    Master

    But didn’t obtain same variables as you

    Probably because mine is optimized with 200k of data. But also, I don’t necessarily choose variables for max profit, sometimes I think it’s better to go for a higher %win esp if it gives higher number of trades. Sometimes it’s based on VRT results.

    As for adapting to other instruments, you really just have to go through all the variables for each timeframe top to bottom. You’ll have to do this 2 or 3 times as one change effects another. I have tried versions for DAX, CAC, SP500, FTSE, ASX – cant remember what else. Some of them are still limping along in demo but the DJ and NAS are the only ones I have faith in. If anything else might work, I would start with the DAX and try to bang that into shape, using DJ v5 as a template.

    #148640 quote
    josef1604
    Participant
    Senior

    @nonetheless  It is the same time as in Spain that comes in “NAS 5m MoD v4S” On November 1 the time changes in the US and then it will be necessary to put if not onmarket or (time <= 153000 – USDLS and time> = 220000 – USDLS) and it keeps giving me the same failure with the MM activated and I have 1 lotti in demo. Doesn’t it give you an error?

    once longStep = 0
    once openStrongShort = 0
    if not onmarket or (time <= 143000 - USDLS and time >= 210000 - USDLS) then
    longStep = 0
    openStrongShort = 0
    endif
    //detect strong direction for market open
    once rangeOK = 50
    once tradeMin = 500
    IF (time >= 144000 - USDLS) AND (time <= 144000 + tradeMin - USDLS) THEN
    openStrongShort = close < open AND open - close > rangeOK
    ENDIF
    
    #148643 quote
    nonetheless
    Participant
    Master

    It tests fine for me, both with or without MM. If the problem only occurs with MM you could try using a higher factor, like 5 0r 10, or try it with volpiemanuele’s MM

    josef1604 thanked this post
    #148651 quote
    josef1604
    Participant
    Senior

    You are right, putting a factor of 5 does not give an error. Could you put what result gives you in 200k of candles with factor 3, please? thanks

    #148653 quote
    nonetheless
    Participant
    Master

    I really wouldn’t worry about it, any factor below 10 will give a result in the millions – it’s only something to dream about. But if factor 3 blows up over the past 100k then that can also happen over the coming 100k. I will change mine to 5; if the algo succeeds then positionsize will increase dramatically enough.

    josef1604 thanked this post
    #148740 quote
    StingRe
    Participant
    Junior

    @volpiemanuele @nonetheless (ps. still searching for you)

    Can you think of any reason why MM v5 and V.5a would be giving me these blank results. I am literally using the code that you both posted.

    DJI MOD v5 works perfectly (see attached). It’s really strange.

    This is DJI v5a + MM

    // Definition of code parameters
    DEFPARAM CumulateOrders = false // Cumulating positions deactivated
    DEFPARAM preloadbars = 5000
    //Money Management DOW
    MM = 1 // = 0 for optimization
    
    
    
    
    
    if mm = 1 then
    prof    = 0
    ddpp    = 212// max dd per point
    ddm     = 2   // multiples of max drawdowns to factor into positionsize
    capital = 350 //starting bank
    dpct    = 5   //% margin for deposit
    deposit = (open/100)*dpct //margin per point
    pri     = 1   // percent to reinvest as a decimal
    positionsize = (capital +((strategyprofit + prof)*pri))/((ddm*ddpp)+deposit)
    if positionsize < 0.25 then
    positionsize = 0.2
    endif
    else
    once positionsize = 0.2
    endif
    
    TIMEFRAME(2 hours,updateonclose)
    Period= 495
    inner = 2*weightedaverage[round( Period/2)](typicalprice)-weightedaverage[Period](typicalprice)
    HULLa = weightedaverage[round(sqrt(Period))](inner)
    c1 = HULLa > HULLa[1]
    c2 = HULLa < HULLa[1]
    
    indicator1 = SuperTrend[8,4]
    c3 = (close > indicator1)
    c4 = (close < indicator1)
    
    ma = average[60,3](close)
    c11 = ma > ma[1]
    c12 = ma < ma[1]
    
    //Stochastic RSI | indicator
    lengthRSI = 15 //RSI period
    lengthStoch = 9 //Stochastic period
    smoothK = 10 //Smooth signal of stochastic RSI
    smoothD = 5 //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)
    c13 = K>D
    c14 = K<D
    
    TIMEFRAME(30 minutes,updateonclose)
    indicator5 = Average[2](typicalPrice)
    indicator6 = Average[7](typicalPrice)
    c15 = (indicator5 > indicator6)
    c16 = (indicator5 < indicator6)
    
    
    
    TIMEFRAME(15 minutes,updateonclose)
    indicator2 = Average[4](typicalPrice)
    indicator3 = Average[8](typicalPrice)
    c7 = (indicator2 > indicator3)
    c8 = (indicator2 < indicator3)
    
    Periodc= 22
    innerc = 2*weightedaverage[round( Periodc/2)](typicalprice)-weightedaverage[Periodc](typicalprice)
    HULLc = weightedaverage[round(sqrt(Periodc))](innerc)
    c9 = HULLc > HULLc[1]
    c10 = HULLc < HULLc[1]
    
    TIMEFRAME(10 minutes)
    indicator4 = SuperTrend[2,6]
    indicator4a = SAR[0.025,0.025,0.1]
    c19 = (close > indicator4) or (close > indicator4a)
    c20 = (close < indicator4) or (close < indicator4a)
    
    TIMEFRAME(5 minutes)
    //Stochastic RSI | indicator
    lengthRSIa = 3 //RSI period
    lengthStocha = 6 //Stochastic period
    smoothKa = 9 //Smooth signal of stochastic RSI
    smoothDa = 3 //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)
    c23 = Ka>Da
    c24 = Ka<Da
    
    ma3 = average[15,3](typicalPrice)
    c21 = ma3 > ma3[1]
    c22 = ma3 < ma3[1]
    
    Periodb= 15
    innerb = 2*weightedaverage[round( Periodb/2)](typicalprice)-weightedaverage[Periodb](typicalprice)
    HULLb = weightedaverage[round(sqrt(Periodb))](innerb)
    c5 = HULLb > HULLb[1]and HULLb[1]<HULLb[2]
    c6 = HULLb < HULLb[1]and HULLb[1]>HULLb[2]
    
    // Conditions to enter long positions
    IF dhigh(0)-high<300 and c1 AND C3 AND C5 and c7 and c9 and c11 and c13 and c15 and c19 and c21 and c23 THEN
    BUY positionsize CONTRACT AT MARKET
    SET STOP %LOSS 1.5
    SET TARGET %PROFIT 2.5
    ENDIF
     
    // Conditions to enter short positions
    IF low-dlow(0)<600 and c2 AND C4 AND C6 and c8 and c10 and c12 and c14 and c16 and c20 and c22 and c24 THEN
    SELLSHORT positionsize CONTRACT AT MARKET
    SET STOP %LOSS 2
    SET TARGET %PROFIT 2.2
    ENDIF
    
    //================== exit in profit
    if longonmarket and C6 and c8 and close>positionprice then
    sell at market
    endif
    
    If shortonmarket and C5 and c7 and close<positionprice then
    exitshort at market
    endif
    
    //==============exit at loss
    if longonmarket AND c2 and c6 and close<positionprice then
    sell at market
    endif
    If shortonmarket and c1 and c5 and close>positionprice then
    exitshort at market
    endif
    
    //%trailing stop function
    once trailingpercentlong  = 0.21 // %
    once trailingpercentshort = 0.24 // %
    once accelerator     = 0.05 // 1 = default; always > 0 (i.e. 0.5-3)
    once accelerator2     = 0.01 // 1 = default; always > 0 (i.e. 0.5-3)
    once ts2sensitivity  = 2 // [0]close;[1]high/low;[2]low;high
    //====================
    once steppercentlong  = (trailingpercentlong/10)*accelerator
    once steppercentshort = (trailingpercentshort/10)*accelerator2
    if onmarket then
    trailingstartlong = tradeprice(1)*(trailingpercentlong/100)
    trailingstartshort = tradeprice(1)*(trailingpercentshort/100)
    
    trailingsteplong = tradeprice(1)*(steppercentlong/100)
    trailingstepshort = tradeprice(1)*(steppercentshort/100)
    endif
    if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
    newsl=0
    endif
    if ts2sensitivity=1 then
    ts2sensitivitylong=high
    ts2sensitivityshort=low
    elsif ts2sensitivity=2 then
    ts2sensitivitylong=low
    ts2sensitivityshort=high
    else
    ts2sensitivitylong=close
    ts2sensitivityshort=close
    endif
    if longonmarket then
    if newsl=0 and ts2sensitivitylong-tradeprice(1)>=trailingstartlong then
    newsl = tradeprice(1)+trailingsteplong
    endif
    if newsl>0 and ts2sensitivitylong-newsl>trailingsteplong then
    newsl = newsl+trailingsteplong
    endif
    endif
    if shortonmarket then
    if newsl=0 and tradeprice(1)-ts2sensitivityshort>=trailingstartshort then
    newsl = tradeprice(1)-trailingstepshort
    endif
    if newsl>0 and newsl-ts2sensitivityshort>trailingstepshort then
    newsl = newsl-trailingstepshort
    endif
    endif
    if barindex-tradeindex>1 then
    if longonmarket then
    if newsl>0 then
    sell at newsl stop
    endif
    if newsl>0 then
    if low crosses under newsl then
    sell at market
    endif
    endif
    endif
    if shortonmarket then
    if newsl>0 then
    exitshort at newsl stop
    endif
    if newsl>0 then
    if high crosses over newsl then
    exitshort at market
    endif
    endif
    endif
    endif
    
    
    //************************************************************************
    IF longonmarket and barindex-tradeindex>1900 and close<positionprice then
    sell at market
    endif
    IF shortonmarket and barindex-tradeindex>580 and close>positionprice then
    exitshort at market
    endif
    //=============================================
    if longonmarket and abs(open-close)<1 and high[1]>high and close>positionprice and high-close>13 then
    sell at market
    endif
    if shortonmarket and abs(open-close)<1 and low[1]>low and close-low>9 and close<positionprice then
    exitshort at market
    endif
    //===================================
    myrsiM5=rsi[14](close)
    //
    if myrsiM5<20 and barindex-tradeindex>1 and longonmarket and close>positionprice then
    sell at market
    endif
    if myrsiM5>70 and barindex-tradeindex>1 and shortonmarket and close<positionprice then
    exitshort at market
    endif
    
    // ---------   US DAY LIGHT SAVINGS MONTHS      ---------------- //
    mar = month = 3 // MONTH START
    nov = month = 11 // MONTH END
    IF (month > 3 AND month < 11) OR (mar AND day>14) OR (mar AND day-dayofweek>7) OR (nov AND day<=dayofweek AND day<7) THEN
    USDLS=010000
    ELSE
    USDLS=0
    ENDIF
    
    once shortStep = 0
    once longStep = 0
    once openStrongLong = 0
    once openStrongShort = 0
    if not onmarket or (time <= 143000 - USDLS and time >= 210000 - USDLS) then
    shortStep = 0
    longStep = 0
    openStrongLong = 0
    openStrongShort = 0
    endif
    
    //detect strong direction for market open
    once rangeOK = 45
    once tradeMin = 500
    IF (time >= 144000 - USDLS) AND (time <= 144000 + tradeMin - USDLS) THEN
    openStrongLong = close > open AND close - open > rangeOK
    openStrongShort = close < open AND open - close > rangeOK
    ENDIF
    
    once bollperiod = 20
    once bollMAType = 1
    once s = 2
    once BollLevel = 90
    once BollSR = 50
    
    bollMA = average[bollperiod, bollMAType](close)
    STDDEV = STD[bollperiod]
    bollUP = bollMA + s * STDDEV
    bollDOWN = bollMA - s * STDDEV
    IF bollUP = bollDOWN THEN
    bollPercent = 50
    ELSE
    bollPercent = 100 * (close - bollDOWN) / (bollUP - bollDOWN)
    ENDIF
    
    //Market spike up
    IF shortonmarket AND shortStep = 0 AND bollPercent > BollLevel THEN
    shortStep = 1
    ENDIF
    //Market slowly come down
    IF shortonmarket AND shortStep = 1 AND bollPercent < 100 - BollLevel THEN
    shortStep = 2
    ENDIF
    //Market still go back to bullish and supported after strong bull open, exit
    IF shortonmarket AND shortStep = 2 AND bollPercent > BollSR AND openStrongLong THEN
    exitshort at market
    ENDIF
    
    //Market shoot down
    IF longonmarket AND longStep = 0 AND bollPercent < 100 - BollLevel THEN
    longStep = 1
    ENDIF
    //Market slowly go back up
    IF longonmarket AND longStep = 1 AND bollPercent > BollLevel THEN
    longStep = 2
    ENDIF
    //Market still go back to bearish and resisted after strong bear open, exit
    IF longonmarket AND longStep = 2 AND bollPercent < 100 - BollSR AND openStrongShort THEN
    sell at market
    ENDIF
    
    once trendPeriod = 70
    once trendPeriodResume = 30
    once trendGap = 3
    once trendResumeGap = 6
    if not onmarket then
    fullySupported = 0
    fullyResisteded = 0
    endif
    //Market supported in the wrong direction
    IF shortonmarket AND fullySupported = 0 AND summation[trendPeriod](bollPercent > 50) >= trendPeriod - trendGap THEN
    fullySupported = 1
    ENDIF
    
    //Market pull back but continue to be supported
    IF shortonmarket AND fullySupported = 1 AND bollPercent[trendPeriodResume + 1] < 0 AND summation[trendPeriodResume](bollPercent > 50) >= trendPeriodResume - trendResumeGap THEN
    exitshort at market
    ENDIF
    
    //Market resisted in wrong direction
    IF longonmarket AND fullyResisteded = 0 AND summation[trendPeriod](bollPercent < 50) >= trendPeriod - trendGap THEN
    fullyResisteded = 1
    ENDIF
    
    //Market pull back but continue to be resisted
    IF longonmarket AND fullyResisteded = 1 AND bollPercent[trendPeriodResume + 1] > 100 AND summation[trendPeriodResume](bollPercent < 50) >= trendPeriodResume - trendResumeGap THEN
    sell at market
    ENDIF
    
    //Started real wrong direction
    once strongTrend = 70
    once strongPeriod = 6
    IF shortonmarket and openStrongLong and barindex - tradeindex < 12 and summation[strongPeriod](bollPercent > strongTrend) = strongPeriod then
    exitshort at market
    ENDIF
    
    IF longonmarket and openStrongShort and barindex - tradeindex < 12 and summation[strongPeriod](bollPercent < 100 - strongTrend) = strongPeriod then
    sell at market
    ENDIF
    

    This is DJI MOD v5a code that I am using:

    // Definition of code parameters
    DEFPARAM CumulateOrders = false // Cumulating positions deactivated
    DEFPARAM preloadbars = 5000
    //Money Management DOW
    MM = 1 // = 0 for optimization
    if MM = 0 then
    positionsize=15
    ENDIF
    if MM = 1 then
    ONCE startpositionsize = .4
    ONCE factor = 5 // 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 = 55 // DOW €1 IG first tier margin limit
    ONCE maxpositionsize = 550 // DOW €1 IG tier 2 margin limit
    ONCE minpositionsize = .2 // 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
    
    TIMEFRAME(2 hours,updateonclose)
    Period= 495
    inner = 2*weightedaverage[round( Period/2)](typicalprice)-weightedaverage[Period](typicalprice)
    HULLa = weightedaverage[round(sqrt(Period))](inner)
    c1 = HULLa > HULLa[1]
    c2 = HULLa < HULLa[1]
    
    indicator1 = SuperTrend[8,4]
    c3 = (close > indicator1)
    c4 = (close < indicator1)
    
    ma = average[60,3](close)
    c11 = ma > ma[1]
    c12 = ma < ma[1]
    
    //Stochastic RSI | indicator
    lengthRSI = 15 //RSI period
    lengthStoch = 9 //Stochastic period
    smoothK = 10 //Smooth signal of stochastic RSI
    smoothD = 5 //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)
    c13 = K>D
    c14 = K<D
    
    TIMEFRAME(30 minutes,updateonclose)
    indicator5 = Average[2](typicalPrice)
    indicator6 = Average[7](typicalPrice)
    c15 = (indicator5 > indicator6)
    c16 = (indicator5 < indicator6)
    
    
    
    TIMEFRAME(15 minutes,updateonclose)
    indicator2 = Average[4](typicalPrice)
    indicator3 = Average[8](typicalPrice)
    c7 = (indicator2 > indicator3)
    c8 = (indicator2 < indicator3)
    
    Periodc= 22
    innerc = 2*weightedaverage[round( Periodc/2)](typicalprice)-weightedaverage[Periodc](typicalprice)
    HULLc = weightedaverage[round(sqrt(Periodc))](innerc)
    c9 = HULLc > HULLc[1]
    c10 = HULLc < HULLc[1]
    
    TIMEFRAME(10 minutes)
    indicator4 = SuperTrend[2,6]
    indicator4a = SAR[0.025,0.025,0.1]
    c19 = (close > indicator4) or (close > indicator4a)
    c20 = (close < indicator4) or (close < indicator4a)
    
    TIMEFRAME(5 minutes)
    //Stochastic RSI | indicator
    lengthRSIa = 3 //RSI period
    lengthStocha = 6 //Stochastic period
    smoothKa = 9 //Smooth signal of stochastic RSI
    smoothDa = 3 //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)
    c23 = Ka>Da
    c24 = Ka<Da
    
    ma3 = average[15,3](typicalPrice)
    c21 = ma3 > ma3[1]
    c22 = ma3 < ma3[1]
    
    Periodb= 15
    innerb = 2*weightedaverage[round( Periodb/2)](typicalprice)-weightedaverage[Periodb](typicalprice)
    HULLb = weightedaverage[round(sqrt(Periodb))](innerb)
    c5 = HULLb > HULLb[1]and HULLb[1]<HULLb[2]
    c6 = HULLb < HULLb[1]and HULLb[1]>HULLb[2]
    
    // Conditions to enter long positions
    IF dhigh(0)-high<300 and c1 AND C3 AND C5 and c7 and c9 and c11 and c13 and c15 and c19 and c21 and c23 THEN
    BUY positionsize CONTRACT AT MARKET
    SET STOP %LOSS 1.5
    SET TARGET %PROFIT 2.5
    ENDIF
     
    // Conditions to enter short positions
    IF low-dlow(0)<600 and c2 AND C4 AND C6 and c8 and c10 and c12 and c14 and c16 and c20 and c22 and c24 THEN
    SELLSHORT positionsize CONTRACT AT MARKET
    SET STOP %LOSS 2
    SET TARGET %PROFIT 2.2
    ENDIF
    
    //================== exit in profit
    if longonmarket and C6 and c8 and close>positionprice then
    sell at market
    endif
    
    If shortonmarket and C5 and c7 and close<positionprice then
    exitshort at market
    endif
    
    //==============exit at loss
    if longonmarket AND c2 and c6 and close<positionprice then
    sell at market
    endif
    If shortonmarket and c1 and c5 and close>positionprice then
    exitshort at market
    endif
    
    //%trailing stop function
    trailingpercentlong  = 0.21 // %
    trailingpercentshort = 0.24 // %
    once acceleratorlong = 0.05 // [1] default; always > 0 (i.e. 0.5-3)
    once acceleratorshort= 0.01 // 1 = default; always > 0 (i.e. 0.5-3)
    ts2sensitivity  = 3 // [1] default [2] hl [3] lh (not use once)
    //====================
    once steppercentlong  = (trailingpercentlong/10)*acceleratorlong
    once steppercentshort = (trailingpercentshort/10)*acceleratorshort
    if onmarket then
    trailingstartlong = positionprice*(trailingpercentlong/100)
    trailingstartshort = positionprice*(trailingpercentshort/100)
     
    trailingsteplong = positionprice*(steppercentlong/100)
    trailingstepshort = positionprice*(steppercentshort/100)
    endif
     
    if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
    newsl           = 0
    mypositionprice = 0
    endif
    positioncount = abs(countofposition)
    if newsl > 0 then
    if positioncount > positioncount[1] then
    if longonmarket then
    newsl = max(newsl,positionprice * newsl / mypositionprice)
    else
    newsl = min(newsl,positionprice * newsl / mypositionprice)
    endif
    endif
    endif
    if ts2sensitivity=1 then
    ts2sensitivitylong=close
    ts2sensitivityshort=close
    elsif ts2sensitivity=2 then
    ts2sensitivitylong=high
    ts2sensitivityshort=low
    elsif ts2sensitivity=3 then
    ts2sensitivitylong=low
    ts2sensitivityshort=high
    endif
    if longonmarket then
    if newsl=0 and ts2sensitivitylong-positionprice>=trailingstartlong*pipsize then
    newsl = positionprice+trailingsteplong*pipsize
    endif
    if newsl>0 and ts2sensitivitylong-newsl>=trailingsteplong*pipsize then
    newsl = newsl+trailingsteplong*pipsize
    endif
    endif
    if shortonmarket then
    if newsl=0 and positionprice-ts2sensitivityshort>=trailingstartshort*pipsize then
    newsl = positionprice-trailingstepshort*pipsize
    endif
    if newsl>0 and newsl-ts2sensitivityshort>=trailingstepshort*pipsize then
    newsl = newsl-trailingstepshort*pipsize
    endif
    endif
    if barindex-tradeindex>1 then
    if longonmarket then
    if newsl>0 then
    sell at newsl stop
    endif
    if newsl>0 then
    if low crosses under newsl then
    sell at market
    endif
    endif
    endif
    if shortonmarket then
    if newsl>0 then
    exitshort at newsl stop
    endif
    if newsl>0 then
    if high crosses over newsl then
    exitshort at market
    endif
    endif
    endif
    endif
    mypositionprice = positionprice
    
    
    
    //************************************************************************
    IF longonmarket and barindex-tradeindex>1900 and close<positionprice then
    sell at market
    endif
    IF shortonmarket and barindex-tradeindex>580 and close>positionprice then
    exitshort at market
    endif
    //=============================================
    if longonmarket and abs(open-close)<1 and high[1]>high and close>positionprice and high-close>13 then
    sell at market
    endif
    if shortonmarket and abs(open-close)<1 and low[1]>low and close-low>9 and close<positionprice then
    exitshort at market
    endif
    //===================================
    myrsiM5=rsi[14](close)
    //
    if myrsiM5<20 and barindex-tradeindex>1 and longonmarket and close>positionprice then
    sell at market
    endif
    if myrsiM5>70 and barindex-tradeindex>1 and shortonmarket and close<positionprice then
    exitshort at market
    endif
    
    // ---------   US DAY LIGHT SAVINGS MONTHS      ---------------- //
    mar = month = 3 // MONTH START
    nov = month = 11 // MONTH END
    IF (month > 3 AND month < 11) OR (mar AND day>14) OR (mar AND day-dayofweek>7) OR (nov AND day<=dayofweek AND day<7) THEN
    USDLS=010000
    ELSE
    USDLS=0
    ENDIF
    
    once shortStep = 0
    once longStep = 0
    once openStrongLong = 0
    once openStrongShort = 0
    if not onmarket or (time <= 143000 - USDLS and time >= 210000 - USDLS) then
    shortStep = 0
    longStep = 0
    openStrongLong = 0
    openStrongShort = 0
    endif
    
    //detect strong direction for market open
    once rangeOK = 45
    once tradeMin = 500
    IF (time >= 144000 - USDLS) AND (time <= 144000 + tradeMin - USDLS) THEN
    openStrongLong = close > open AND close - open > rangeOK
    openStrongShort = close < open AND open - close > rangeOK
    ENDIF
    
    once bollperiod = 20
    once bollMAType = 1
    once s = 2
    once BollLevel = 90
    once BollSR = 50
    
    bollMA = average[bollperiod, bollMAType](close)
    STDDEV = STD[bollperiod]
    bollUP = bollMA + s * STDDEV
    bollDOWN = bollMA - s * STDDEV
    IF bollUP = bollDOWN THEN
    bollPercent = 50
    ELSE
    bollPercent = 100 * (close - bollDOWN) / (bollUP - bollDOWN)
    ENDIF
    
    //Market spike up
    IF shortonmarket AND shortStep = 0 AND bollPercent > BollLevel THEN
    shortStep = 1
    ENDIF
    //Market slowly come down
    IF shortonmarket AND shortStep = 1 AND bollPercent < 100 - BollLevel THEN
    shortStep = 2
    ENDIF
    //Market still go back to bullish and supported after strong bull open, exit
    IF shortonmarket AND shortStep = 2 AND bollPercent > BollSR AND openStrongLong THEN
    exitshort at market
    ENDIF
    
    //Market shoot down
    IF longonmarket AND longStep = 0 AND bollPercent < 100 - BollLevel THEN
    longStep = 1
    ENDIF
    //Market slowly go back up
    IF longonmarket AND longStep = 1 AND bollPercent > BollLevel THEN
    longStep = 2
    ENDIF
    //Market still go back to bearish and resisted after strong bear open, exit
    IF longonmarket AND longStep = 2 AND bollPercent < 100 - BollSR AND openStrongShort THEN
    sell at market
    ENDIF
    
    once trendPeriod = 70
    once trendPeriodResume = 30
    once trendGap = 3
    once trendResumeGap = 6
    if not onmarket then
    fullySupported = 0
    fullyResisteded = 0
    endif
    //Market supported in the wrong direction
    IF shortonmarket AND fullySupported = 0 AND summation[trendPeriod](bollPercent > 50) >= trendPeriod - trendGap THEN
    fullySupported = 1
    ENDIF
    
    //Market pull back but continue to be supported
    IF shortonmarket AND fullySupported = 1 AND bollPercent[trendPeriodResume + 1] < 0 AND summation[trendPeriodResume](bollPercent > 50) >= trendPeriodResume - trendResumeGap THEN
    exitshort at market
    ENDIF
    
    //Market resisted in wrong direction
    IF longonmarket AND fullyResisteded = 0 AND summation[trendPeriod](bollPercent < 50) >= trendPeriod - trendGap THEN
    fullyResisteded = 1
    ENDIF
    
    //Market pull back but continue to be resisted
    IF longonmarket AND fullyResisteded = 1 AND bollPercent[trendPeriodResume + 1] > 100 AND summation[trendPeriodResume](bollPercent < 50) >= trendPeriodResume - trendResumeGap THEN
    sell at market
    ENDIF
    
    //Started real wrong direction
    once strongTrend = 70
    once strongPeriod = 6
    IF shortonmarket and openStrongLong and barindex - tradeindex < 12 and summation[strongPeriod](bollPercent > strongTrend) = strongPeriod then
    exitshort at market
    ENDIF
    
    IF longonmarket and openStrongShort and barindex - tradeindex < 12 and summation[strongPeriod](bollPercent < 100 - strongTrend) = strongPeriod then
    sell at market
    ENDIF
    
    Screen-Shot-2020-10-27-at-9.05.25-PM.png Screen-Shot-2020-10-27-at-9.05.25-PM.png Screen-Shot-2020-10-27-at-9.08.17-PM.png Screen-Shot-2020-10-27-at-9.08.17-PM.png Screen-Shot-2020-10-27-at-9.17.39-PM.png Screen-Shot-2020-10-27-at-9.17.39-PM.png
    #148744 quote
    StingRe
    Participant
    Junior

    @nonetheless – I just realized that in v5a you have MM switched on for some reason?

    That’s what seems to be breaking it for me. Is there any variables in MM that would be tied to the instrument or currency? 

    As soon as I switch MM off it works again, which would also explain why the MM version is not working.

    // Definition of code parameters
    DEFPARAM CumulateOrders = false // Cumulating positions deactivated
    DEFPARAM preloadbars = 5000
    //Money Management DOW
    MM = 1 // = 0 for optimization
    if MM = 0 then
    positionsize=1
    ENDIF
    if MM = 1 then
    ONCE startpositionsize = .4
    ONCE factor = 5 // 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 = 55 // DOW €1 IG first tier margin limit
    ONCE maxpositionsize = 550 // DOW €1 IG tier 2 margin limit
    ONCE minpositionsize = .2 // 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
    bertholomeo thanked this post
    #148745 quote
    volpiemanuele
    Participant
    Veteran
    MM = 0 // = 0 for optimization
    
    
    
    
    
    if mm = 1 then
    prof    = 0
    ddpp    = 212// max dd per point
    ddm     = 2   // multiples of max drawdowns to factor into positionsize
    capital = 350 //starting bank
    dpct    = 5   //% margin for deposit
    deposit = (open/100)*dpct //margin per point
    pri     = 1   // percent to reinvest as a decimal
    positionsize = (capital +((strategyprofit + prof)*pri))/((ddm*ddpp)+deposit)
    if positionsize < 0.25 then
    positionsize = 0.2
    endif
    endif
    if mm = 0 then
    positionsize = 0.2
    endif

    @StingeRe My code run ok in my PRT (demo or live version). Try to change MM inserting this code. If MM = 0 you have fixed position and if MM = 1 you have the MM. I see that your currency is AUD. You can insert the correct value in AUD in this variable “ddpp” and “capital”. My currency is EURO. Thanks

    #148746 quote
    volpiemanuele
    Participant
    Veteran

    @SitngeRe…first change the value in AUD….for me the problem is this….the code is correct….

    #148766 quote
    nonetheless
    Participant
    Master

    I just realized that in v5a you have MM switched on for some reason?

    MM is entirely optional, for me it tests correctly both with or without. If yours wont run with MM=1 you can try altering the positionsize, the factor or both.

    #148783 quote
    Ryugin
    Participant
    Senior

    @nonetheless, I have some issues with the TS, it just adjusts to BE but does not follow the price forward to cover the open positions. Do you have any idea why? Thanks in advance!

    #148785 quote
    nonetheless
    Participant
    Master

    Yeah, I just noticed that as well, I’ll look into it.

    josef1604 thanked this post
    #148835 quote
    nonetheless
    Participant
    Master

    Hopefully this fixes the TS problem.  NAS to follow…

    StingRe, Andrew74, BobOgden and 4 others thanked this post
    DJ-5m-MoD-v5.1.itf DJ-5m-MoD-v5.1.jpg DJ-5m-MoD-v5.1.jpg
    #148850 quote
    StingRe
    Participant
    Junior

    Thanks @nonetheless, I noticed this last night as well when I was forward testing 4.xx vs 5.

    Interesting they both ended up taking similar profits in the end though.

    Thanks kindly for the fix.

Viewing 15 posts - 391 through 405 (of 523 total)
  • You must be logged in to reply to this topic.

Mother of Dragons trading strategy…


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 522 replies,
has 50 voices, and was last updated by LaurentBZH35
4 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/21/2020
Status: Active
Attachments: 195 files
Logo Logo
Loading...