Optimization moving average crossing strategy

Viewing 15 posts - 151 through 165 (of 186 total)
  • Author
    Posts
  • #132260 quote
    nonetheless
    Participant
    Master

    I’ve been trying to amalgamate the codes I posted here #130635 as one itf, with cumulateorders =true and without the OTD condition, something like this:

    If time >=143000 and time <160500 then
    MAType = 54
    MATypeV2 = 14
    else
    if time >=160500 and time <174500 then
    MAType = 7
    MATypeV2 = 36
    else
    if time >=174500 and time <192000 then
    MAType = 2
    MATypeV2 = 63
    else
    if time >=192000 and time <210000 then
    MAType = 69
    MATypeV2 = 7
    endif
    endif
    endif
    endif
    

    Results are mixed, mainly because without the OTD (one trade per day) it allows multiple positions to be opened in each time slot. Is there a way to code this so as to have multiple positions, but max one from each time slot?

    bertrandpinoy thanked this post
    #132273 quote
    Roger
    Participant
    Veteran

    Hi, not sure but maybe something like this ?

    if time=000000 then
    count1=0
    count2=0
    count3=0
    count4=0
    endif
    
    If time >=143000 and time <160500 then
    MAType = 54
    MATypeV2 = 14
    condbuy1=... and count1=0
    if condbuy1 then
    buy at market
    count1=count1+1
    endif
    
    else
    ...
    nonetheless thanked this post
    #132280 quote
    nonetheless
    Participant
    Master

    Hi @Roger, is this what you meant?

    if time=000000 then
    count1=0
    count2=0
    count3=0
    count4=0
    endif
     
    //conditions to enter long
    If time >=143000 and time <160500 then
    MAType = 54
    MATypeV2 = 14
    if wAFR  > wAFRv2  and wAFR[1] < wAFRv2[1] and CndB and count1=0 then
    buy positionsize shares AT MARKET
    count1=count1+1
    endif
    else
    If time >=160500 and time <174500 then
    MAType = 7
    MATypeV2 = 36
    if wAFR  > wAFRv2  and wAFR[1] < wAFRv2[1] and CndB and count2=0 then
    buy positionsize shares AT MARKET
    count2=count2+1
    endif
    else
    If time >=174500 and time <192000 then
    MAType = 2
    MATypeV2 = 63
    if wAFR  > wAFRv2  and wAFR[1] < wAFRv2[1] and CndB and count3=0 then
    buy positionsize shares AT MARKET
    count3=count3+1
    endif
    else
    If time >=192000 and time <210000 then
    MAType = 69
    MATypeV2 = 7
    if wAFR  > wAFRv2  and wAFR[1] < wAFRv2[1] and CndB and count4=0 then
    buy positionsize shares AT MARKET
    count4=count4+1
    endif
    endif
    endif
    endif
    endif
    
    //conditions to enter short
    If time >=143000 and time <160500 then
    MAType = 54
    MATypeV2 = 14
    if wAFR < wAFRv2  and wAFR[1] > wAFRv2[1] and CndS and count1=0 then
    sellshort positionsize shares AT MARKET
    count1=count1+1
    endif
    else
    If time >=160500 and time <174500 then
    MAType = 7
    MATypeV2 = 36
    if wAFR < wAFRv2  and wAFR[1] > wAFRv2[1] and CndS and count2=0 then
    sellshort positionsize shares AT MARKET
    count2=count2+1
    endif
    else
    If time >=174500 and time <192000 then
    MAType = 2
    MATypeV2 = 63
    if wAFR < wAFRv2  and wAFR[1] > wAFRv2[1] and CndS and count3=0 then
    sellshort positionsize shares AT MARKET
    count3=count3+1
    endif
    else
    If time >=192000 and time <210000 then
    MAType = 69
    MATypeV2 = 7
    if wAFR < wAFRv2  and wAFR[1] > wAFRv2[1] and CndS and count4=0 then
    sellshort positionsize shares AT MARKET
    count4=count4+1
    endif
    endif
    endif
    endif
    endif

    That doesn’t actually help … but probably I’ve made mistakes?

    #132285 quote
    Roger
    Participant
    Veteran

    Yes thats it, im going to try to find a solution

    #132304 quote
    Roger
    Participant
    Veteran

    Well, I think that the problem is that PRC does not allow to manage each trade independently (partial closure is not allowed)

    nonetheless thanked this post
    #132307 quote
    nonetheless
    Participant
    Master

    Yes, I think you’re right. Even if we could get the opening right, the aggregate of positions would all be subject to the same stop loss, which won’t work.

    Never mind, they work perfectly well separately. Thanks for your help.

    #132393 quote
    nonetheless
    Participant
    Master

    This is the 2m version of my ongoing Corona project. Like the 5m it works as one basic strategy divided into 4 separate time slots. All values are identical except for a different pair of crossing averages as thrown up by @jan’s cross-finding engine. There is no other optimisation. The 4 need to be viewed together as 1 strategy; for example the results for (3) look poor but those months are balanced by stronger performance by 1,2 and 4.

    These work with a small SL of just .6% and a healthy risk/reward ratio. Unlike the 5m version, I’ve used @Paul’s ATR trail, but with a conventional break even at .1% This can be switched off, and in some cases that improves profit but with a lower Win%.

    Beware that the back test here is only about 13 months. WF results were very good as you’d expect with no optimisation. There is however the possibility of a sort of reverse curve-fit, ie not that the values are adjusted to fit a particular curve but that the cross-finding engine finds a curve to fit the values you give it. No idea whether that’s better or worse ??? but for my money it seems to be worth a punt. A starting position of €.2pp means a max single loss of around €30

    This can also be used as a template for other instruments, you just have to re-run the cross-finding engine for MAType

    swedshare thanked this post
    DJ-2m-Corona-OTD-atr-12.jpg DJ-2m-Corona-OTD-atr-12.jpg DJ-2m-Corona-OTD-atr-34.jpg DJ-2m-Corona-OTD-atr-34.jpg
    #132396 quote
    nonetheless
    Participant
    Master

    This is the code I added to @jan’s

    TIMEFRAME(10 minutes)
    Perioda= 20
    innera = 2*weightedaverage[round( Perioda/2)](typicalprice)-weightedaverage[Perioda](typicalprice)
    HULLa = weightedaverage[round(sqrt(Perioda))](innera)
    cnd1 = HULLa > HULLa[1]
    cnd2 = HULLa < HULLa[1]
    
    TIMEFRAME(6 minutes)// typically 2x or 3x default TF
    ST1 = SuperTrend[3,10]
    cnd3 = (close > ST1)
    cnd4 = (close < ST1)
    
    Periodb= 20
    innerb = 2*weightedaverage[round( Periodb/2)](typicalprice)-weightedaverage[Periodb](typicalprice)
    HULLb = weightedaverage[round(sqrt(Periodb))](innerb)
    cnd5 = HULLb > HULLb[1]
    cnd6 = HULLb < HULLb[1]
    
    TIMEFRAME(default)
    ST2 = SuperTrend[3,10]
    cnd7 = (close > ST2)
    cnd8 = (close < ST2)
    
    //Stochastic RSI | indicator 
    lengthRSI = 14 //RSI period
    lengthStoch = 14 //Stochastic period
    smoothK = 10 //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)
    K2 = average[smoothK](stochrsi)*100
    D2 = average[smoothD](K2)
    cnd9 = K2>D2
    cnd10 = K2<D2
    
    Periodc= 20
    innerc = 2*weightedaverage[round( Periodc/2)](typicalprice)-weightedaverage[Periodc](typicalprice)
    HULLc = weightedaverage[round(sqrt(Periodc))](innerc)
    cnd11 = HULLc > HULLc[1]
    cnd12 = HULLc < HULLc[1]
    
    CndB = cnd1 and cnd3 and cnd5 and cnd7 and cnd9 and cnd11
    CndS = cnd2 and cnd4 and cnd6 and cnd8 and cnd10 and cnd12
    
    //Profit and Loss
    SL = .6  // % STOP LOSS
    TP = 1.6  //% TARGET PROFIT
    CMM, bertrandpinoy and Sebastian Arsjo thanked this post
    DJ-2m-Corona-OTD-atr1.itf DJ-2m-Corona-OTD-atr2.itf DJ-2m-Corona-OTD-atr3.itf DJ-2m-Corona-OTD-atr4.itf
    #132405 quote
    Glums
    Participant
    Average

    Hello,


    @Nonetheless
    , I have been trying to setup your 5m-Corona code on the Wall Street Cash (thanks for sharing!) but for some reasons my Probacktest are giving me no value. I think there might be some reasons to that:

    • Based in Hong Kong so I changed the time for version “a” to: Ctime = time >=213000 and time <230000
    • The minimum order quantity I can set is 0.5, so I changed: ONCE startpositionsize = 0.5, ONCE minpositionsize = 0.5
    • I don’t have access to Wall Street Cash €1 but I have either Wall Street Cash £1 or Wall Street Cash $10. Not sure if you have anything in your code that specifies this market.

    So I don’t see where the problem might be coming from, and I wouldn’t mind some help 🙂

    Thanks

    WeChat-Screenshot_20200520193921.jpg WeChat-Screenshot_20200520193921.jpg
    #132410 quote
    nonetheless
    Participant
    Master

    The instrument (Wall St Cash £1 or $10) is not determined in the code, it will run on any chart you launch it from. For me it runs fine with your other settings so not sure where the problem is ???

    #132413 quote
    nonetheless
    Participant
    Master

    minimum order quantity I can set is 0.5

    Are you sure this is the min position? If I run mine with position size €.1 then I get the same result as you (my minimum is €.2)

    Try it with startpositionsize = 1

    #132416 quote
    Glums
    Participant
    Average

    The instrument (Wall St Cash £1 or $10) is not determined in the code, it will run on any chart you launch it from. For me it runs fine with your other settings so not sure where the problem is ???

    Yes that’s what I thought so all good.

    minimum order quantity I can set is 0.5

    Are you sure this is the min position? If I run mine with position size €.1 then I get the same result as you (my minimum is €.2)

    Try it with startpositionsize = 1

    Yes, I am sure about the minimum position, I have attached a screenshot for the sake of being 100% sure.

    I did some further test and weirdly if I change the time constraint and replace the “AND” by “OR”, I have a result.

    Ctime = time >=213000 OR time <230000

    But I am concerned that it may affect the results…

    MOQ.png MOQ.png Time-change.png Time-change.png
    #132422 quote
    nonetheless
    Participant
    Master

    I am sure about the minimum position

    your screenshot is the PRT chart, but the minimum position will be set by your broker. If you’re with IG, you have to go to their web platform and click on the info button, see attached image.

    My first thought about the time was to change AND to OR, but that wouldn’t be right as you’re still in the same day. OR would only be used if it were

    Ctime = time >=213000 OR time <010000

    ie the second time is less than the first.

    dj-info.jpg dj-info.jpg
    #132424 quote
    Glums
    Participant
    Average

    Yes, I understand and I assumed the OR would not be the solution.

    I am with IG and the minimum position is 0.25 but it does not work with the “OR” if I use anything less than 0.5

    May I attach the code “A” in here, maybe I am missing something…thanks for the help here!

    DEFPARAM cumulateOrders = False // Cumulating positions deactivate
    DEFPARAM preloadbars = 1000
    //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 = 55 // IG first tier margin limit
    ONCE maxpositionsize = 550 //  IG tier 2 margin limit
    ONCE minpositionsize = 0.5 // 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 >=213000 and time <230000
    
    ONCE MAType = 54
    ONCE MATypeV2 = 14
    once Period = 15  //period1 // // set fixed to limit possible combinations of optimisations
    once Period2 = 15 // period2 second set of 69 averages  // // set fixed to limit possible combinations of optimisations
    Series = (open+high+low+Close)/4  // kind of close of a bar
    Seriesv2 = (open+high+low+Close)/4 // kind of close of a bar
    OTD = Barindex - TradeIndex(1) > IntradayBarIndex  // limits the (opening) trades till  1 per day (OTD One Trade per Day)
    
    TIMEFRAME(15 minutes)
    ST1 = SAR[.015,.01,.15]
    cnd1 = (close > ST1)
    cnd2 = (close < ST1)
    
    mx1 = average[60,3](close)
    cnd3 = mx1 > mx1[1]
    cnd4 = mx1 < mx1[1]
    
    TIMEFRAME(default)
    ST2 = SuperTrend[3,10]
    cnd5 = (close > ST2)
    cnd6 = (close < ST2)
    
    //Stochastic RSI | indicator
    lengthRSI = 14 //RSI period
    lengthStoch = 14 //Stochastic period
    smoothK = 10 //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)
    K2 = average[smoothK](stochrsi)*100
    D2 = average[smoothD](K2)
    cnd7 = K2>D2
    cnd8 = K2<D2
    
    PeriodH2= 22
    innerH2 = 2*weightedaverage[round( PeriodH2/2)](typicalprice)-weightedaverage[PeriodH2](typicalprice)
    HULLb = weightedaverage[round(sqrt(PeriodH2))](innerH2)
    cnd9 = HULLb > HULLb[1]
    cnd10 = HULLb < HULLb[1]
    
    CndB = cnd1 and cnd3 and cnd5 and cnd7 and cnd9
    CndS = cnd2 and cnd4 and cnd6 and cnd8 and cnd10
    
    //Profit and Loss
    SL = 1  // % STOP LOSS
    TP = 2 //% TARGET PROFIT
    TST = .1//%trailing start
    ST = .001  //% trailing step
    #132433 quote
    Glums
    Participant
    Average

    I have tested the exact same in M15 and I get results for A and D, but nothing for B and C. If that ever helps.

    m15-test.png m15-test.png
Viewing 15 posts - 151 through 165 (of 186 total)
  • You must be logged in to reply to this topic.

Optimization moving average crossing strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 185 replies,
has 11 voices, and was last updated by slevinkelevra
3 years, 12 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/20/2020
Status: Active
Attachments: 66 files
Logo Logo
Loading...