Stop loss, Scale out and Trailing stop using the ATR

Forums ProRealTime English forum ProOrder support Stop loss, Scale out and Trailing stop using the ATR

Viewing 4 posts - 1 through 4 (of 4 total)
  • #121459

    Hello everybody first time on this forum I hope this is the right place for this discussion.

    I am having trouble coding a strategy to back test a number of different  algorithms ( combination of indicators). Below is what I have so far and it is not doing what I expect or more importantly what I want. I have commented where I think it is needed to help explain what I am trying to do.

    In summary I wish to have a stop loss 1.5 X the ATR at time of trade entry and when break even is reached I wish to close ½ the position and let the other half run (still with the same stop loss). When the trade reaches 2 X the ATR figure at trade entry in favour of my trade I wish to apply a trailing stop to move with  the trade as profit increases, that trailing stop is the same as the original stop loss (1.5 X ATR at trade entry).

    The trade is closed when either my stop loss is hit or my exit conditions (indicators) signal me to exit. You will see there is an entry condition I have named “continuation trade” this is simply to allow for re-traces (to exit the trade and then get back in if conditions are favourable).

    Any help is welcome however time is getting away from me and I really need to solve this quickly so I can get testing algo’s. Thanks in advance.

    P.S. from time to time I get an error message when I click the back

    test my system button. The message reads.

    Line 141 (the line number varies)

    One of the following characters would be more suitable than “End of code” : null

    However there is no code at this line even the line number does not appear, the code finishes two lines earlier and then the next lines number appears 1 line below where the code ends with again no code written.

    Once again thanks in advance.

    Regards 19robhfx60

    1 user thanked author for this post.
    #121461

    Lines 30-32 should be moved just below line 26, which is the first entry (if I correctly understood your code) and lines 91-93 should be moved to line 87.
    Lines 107-112 can be removed, since they are a duplicate of lines 45-50.
    Lines 51 and 113 have [1] next to keyword TRADEPRICE, replace it by (1).
    Negative values (-1) are NOT allowed anywhere as an index reference. If you want to refer to the value prior to (1) then you have to write (2). What do you want to do  with those lines?
    What use are lines 70-71 and 132-133?
    You never exit upon NEWSL, as it is in the original code where you read about that trailing stop. At the end you should append these lines:

    Partial positions CANNOT be closed in strategies. I know this can be done only when backtesting though I have never used it, thus I cannot tell you how to tell your code to close, say, only one out of two positions opened. Perhaps it’s just:

    #121522

    Hello Roberto. Thank you for the quick reply I was not expecting to get a reply so quickly. As you can tell by my code I’m new to this coding thing and that string of code was a combination of several other bits of coding from similar topics so there is some repeating myself going on there. I am aware about the closing of half positions situation, however I will  be trading manually to begin with so there many ways to solve that issue . I will implement the changes you have suggested and let you know the result Thank you for your knowledge and time and again thank you for the quick reply. oh I nearly forgot any ideas about the error message thing at the end of my post?

    Regards 19robhfx60

    #121535

    Tehere are so many errors… when you modify the code many of them will be corrected.

    I’ve been returned an error about the HullAverage since I have v10.3 which has not a built-in HULL average. If you have v11 this will not be the error you are talking about.

     

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

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