Combining short/long strategies into 1 strategy issue

Forums ProRealTime English forum General trading discussions Combining short/long strategies into 1 strategy issue

Viewing 7 posts - 1 through 7 (of 7 total)
  • #226672

    Hi!

    I’m trying to combine a short and a long strategy in the same algo. However, the combined strategy backtest is different, compared to if I backtest the long and short strategies separately. If the long stategy gains 100$ and the short also gains 100$ during the same period, I would expect the combined to give a gain of 200$. This is not the case right now, so I wonder if something is wrong in my code or if I am missing something? Appreciate any help, thanks!

     

     

    #226676

    Hi there sandelius,

    Without judging your code : this is perfectly normal. This is because if a Long trade is running, it will occupy the “space” for the Short(s). Thus, both can not run at the same time.
    It can also easily happen that the Long + Short separately, bring only 80 instead of at least 100 what you might expect (let alone 200).

    Of course the code itself is related – e.g. how you optimized it. And although that could have been worked towards the both Long and Short together, nothing would be wrong with doing that.
    I hope it is clear a little ?

    Regards,
    Peter

     

     

    1 user thanked author for this post.
    #226677

    But also your code is not correct;

    You allow for both Long and Short at the same time. This means that a Short will cancel out a Long. This can happen in the one (bar-)call of the code, but also across bars (several bars later).
    If you include the condition “If Not OnMarket” for both cases, the problem across bars won’t be there. If you then also put the lot in an If/Else (so it will be *or* buy Long *or* sell short), the in the one (bar-) call cancellation will also not happen and all is good.

    The many more trades for both together vs. each on its own, is indicative for “error”.

    When you solved this, you will still not end at 200+. 😉

    1 user thanked author for this post.
    #226678

    The first thing I would do is change the “True” to “False”… then I would test whether a direct change between long and short helps, often this reduces the drawdown. Regardless, I would prefer bigger winners than losses, definitely in short trades. Depends on the instrument and the time frame.

    1 user thanked author for this post.
    #226679

    You can do two algo’s, one long and one short, but it depends on your broker.
    Here is a code for the long with 2 in spread

    1 user thanked author for this post.
    #226682
    JS

    Hi,

    The PRT “back test module” does not accept long and short positions at the same time…

    (so, you can’t back test your combined system (properly), hence the differences…)

    1 user thanked author for this post.
    #226713

    Thanks so much for all answers! Adding the “If Not OnMarket” instead of “if short onmarket/long onmarket” solved the issue and made the code behave as expected! Thanks!

Viewing 7 posts - 1 through 7 (of 7 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login