Optimization moving average crossing strategy

Viewing 15 posts - 31 through 45 (of 186 total)
  • Author
    Posts
  • #122887 quote
    dnystrom
    Participant
    Average

    @dnystrom I dont think you would want an actual crossover in both time frames as that would be a fairly rare occurrence and, as you say, result in v few trades. Better would be to use some kind of trend indicator in the daily TF, then insert the part of the code i posted above (MACross finder) in the shorter TF and let it find the best crossover to work in conjunction with your daily filter.

    It’s possible of course to load it in both TFs and optimize them separately, but I wouldn’t expect it to work very well. (or maybe it would – try it and let us know!)

    Thank you, yes i will try it later today.
    I just need help it two things. How do i use Jans code with just the two averages that i want and its not do all the crossings each backtest? So I easily can change the averages on each timeframe, default and upper time frame?
    And how can I code the two averages on the upper time frame so when that condition fills in, then look for the trade in the default time frame?

    #122892 quote
    nonetheless
    Participant
    Master

    After you’ve run the program, add

    ONCE MAType = x
    ONCE MATypeV2 = y

    and enter the results. Then you can add another TF and do it all again.

    #122900 quote
    Jan
    Participant
    Veteran

    Hi dnystrom,

    Very interesting idea to try this crossing strategy in Multiple Time Frames.

    I am not sure if it much limits the trades using an optimum in both a long and short time frame, because there are many short time frames available for crossing when the long time frame crosses.

     

    (Theoretically) it would be possible to do so, but it can not be tested at once (70 x 70 x 70 x 70 = 24.010.000 variations, way too much), and you would have then 4 x 70 averages, which is a long code.

    Image you do this for proper testing on more then 100.000 bars (of the short time frame), I hope we do not get the RED FLAG from ProRealTime for overusing the server !

     

    The trading concept would be: (if I understand the idea of dnystrom correctly)

    if AvType1 (long time frame) crosses above AvType2 (long time frame)  and AvType3 (short time frame) crosses above AvType4 (short time frame), go long

    Vice versa  if AvType1 (long time frame) crosses under AvType2 (long time frame)  and AvType3 (short time frame) crosses under AvType4 (short time frame), go short

     

    I will work out a strategy like this and test it with a small range of variables  and let you know.  (Testing until the RED Flag will be given . . ), I can share the code.

    You may develop it yourself,  copy first range of averages (0-69) to Notepath,  find/replace MATpe to MAType3 /4, find/replace Series to Series3 /4,  find/replace Period to Period3 /4,  find/replace AFR to AFR3 /4, and add back the new averages, started those with the smaller time frame, start the original 2 ranges with the higher timeframe, and extend the smoothed averages and the crossings in the bottom lines of the code, and see and test what it delivers), Do not forget to add also AFR3 and AFR4 to the variables to be tested above the code.

    GraHal and CMM thanked this post
    #122909 quote
    nonetheless
    Participant
    Master

    I haven’t tested this but my instinct is that for 2 TFs, it might be better to use

    IF wAFR > wAFRv2 then

    in the longer TF, so that it’s more of a trend indicator than a crossover.

    Then have

    IF wAFR > wAFRv2 and wAFR[1] < wAFRv2[1] then

    in the shorter TF.

    What do you think?

    #122915 quote
    dnystrom
    Participant
    Average

    Thanks for the input.
    Exactly the way I was intended to test Jan. But i was thinking of first do a test on lets say a 2 or 4H chart then a separately test on the 15 min chart, and then run a test with thoose 4 avg that gives the best output. But your way seems so much better =)

    I will make some test later today with different kind of indicators for bull/bear on the upper TF then the optimisation on the lower.
    I let you know how it goes.

    GraHal thanked this post
    #122917 quote
    Jan
    Participant
    Veteran

    Nasty complicating factor is that ProRealTime requires unique variables per time frame.

    That’s no issue if you have 100 lines, but become pretty annoying when you have 1.700 lines with variables like a =   …. ,   then the Replace does not easily work and you have to check the proposed replacement one by one . . . . see how far I come.

    #122920 quote
    GraHal
    Participant
    Master

    Testing until the RED Flag will be given

    I know it was humour! 🙂

    PRT will have their own way of throttling / limiting our backtesting … you can tell, it’s like we get a second or so every minute sometimes?

    When I’ve been backtesting max combo’s 10,000 over 100k bars it can seem like it has stopped and then every minute or so 10 or so more results pop into the table … even at the start when the table is empty then 10 to 20 results appear after a minute or so?

    Anybody else seen / had this?

    #122921 quote
    Jan
    Participant
    Veteran

    Nonetheless,

    I do not know what concept is better in multiple time frames, nice to test.  So I have no comment on your gutfeeling.

    #122923 quote
    dnystrom
    Participant
    Average

    Isn’t it possible to copy out the code to a new “trading system” then search and replace, and then copy in that and so on for the 4 different numbers of avg?

    #122925 quote
    Jan
    Participant
    Veteran

    I did not tried 10.000 variations on 100.000 bars, I am too impatient,  amazing that PRT doses its usage.

    #123028 quote
    nonetheless
    Participant
    Master

    @Jan, in the coding of the entry conditions

    if time >= StartE And time <= StartL and OTD  then //and not onmarket then
    IF wAFR  > wAFRv2  and wAFR[1] < wAFRv2[1] then
    buy N shares AT MARKET
    SET STOP PLOSS TSL
    //SET STOP PTRAILING TSL
    //SET TARGET PPROFIT TSL
    else
    if wAFR < wAFRv2  and wAFR[1] > wAFRv2[1] then
    sellshort N shares at market
    SET STOP PLOSS TSL
    //SET STOP PTRAILING TSL
    //SET TARGET PPROFIT TSL
    endif
    endif
    endif

    does a reversal also constitute an exit?

    I tried adding

    if longonmarket and wAFR < wAFRv2 and wAFR[1] > wAFRv2[1] then
    sell at market
    ENDIF
    if shortonmarket and wAFR  > wAFRv2  and wAFR[1] < wAFRv2[1] then
    exitshort at market
    ENDIF

    but it made things worse.

    #123065 quote
    Jan
    Participant
    Veteran

    does a reversal also constitute an exit?

    Not necessarily, unless the set crossings is very volatile (eg when it generates a long crossing and after 3 bars a short,  when is possible on short time frames)   (Maybe a combi of long and short term is not that bad.)

    #123075 quote
    nonetheless
    Participant
    Master

    So (just to be clear) if longonmarket, the sellshort conditions do not close the existing long — it that right? (where OTD is active and no new position is to be opened)

    #123147 quote
    Jan
    Participant
    Veteran

     

    So (just to be clear) if longonmarket, the sellshort conditions do not close the existing long — it that right? (where OTD  is active and no new position is to be opened)  , YES when you add OTD to the exit code, but NO if leave OTD out of your code as your example below.  then it could be triggered already in the next bar (at a volatile crossing) .

    But if you add OTD to your code below, and it is initialized to tradeindex(1), it will not work untill the next trading day, which is also not what you want, presumably.  Alternatively you could try adding “and barindex – tradedindex > 4”, so that the trade stays at least 4 bars .

    if longonmarket and wAFR < wAFRv2 and wAFR[1] > wAFRv2[1] then
    sell at market
    ENDIF
    if shortonmarket and wAFR  > wAFRv2  and wAFR[1] < wAFRv2[1] then
    exitshort at market
    ENDIF
    #123148 quote
    Jan
    Participant
    Veteran

    I haven’t tested this but my instinct is that for 2 TFs, it might be better to use

    in the longer TF, so that it’s more of a trend indicator than a crossover.

     

    I agree with you, I have tested it and with a double change crossing (longer and shorter timeframes) very few trades are generated, so better use higher timeframes as a trend.

Viewing 15 posts - 31 through 45 (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...