Stop Loss/Target Profit linked to ATR

Forums ProRealTime English forum ProOrder support Stop Loss/Target Profit linked to ATR

Viewing 13 posts - 1 through 13 (of 13 total)
  • #97836

    Hi,

    I am not very familiar with coding but I am trying to learn PRT as quickly as I can and I am benefiting of the “simplified creation” in the meantime.

    The PRT code below has been created through simplified creation but I have a problem with the ATR indicator because I would like to have the Stop Loss/Target Profit defined with an ATR value that is calculated at the time the position is started, and does not change as long as the position is open.

    At the moment, in my code below, the Stop Loss/ Target Profit are linked to ATR, but that indicator is trailing with the current price.

    Would anyone be able to tell me how to code a Stop Loss/Target Profit linked to the ATR calculated at the time the position is started?

    Any help is very much appreciated

     

    #97842

    You need to store the values at the same time as the order is placed and then ensure that if you are on the market those instructions are not used again even if the entry conditions become true again.

     

    1 user thanked author for this post.
    #97854

    Thanks Vonasi, I very much appreciate your quick reply

    #97877

    I have tested the code for the Stop Loss/Target Profit ATR and it works perfectly.

    The only small issue now is that when a signal to close a position is generated, only the closing position trade is produced. I would have expected the code to generate two trades simultaneously, the closing position trade and the trade for the new position.

    At the moment, when a trade is closed, the new position in the opposite direction is only triggered if an additional signal is generated during a successive time frame.

    I tried to modify the code inputting “SELL 2 SHARES AT MARKET” among the conditions to exit long positions, but that did not work.

    I would appreciate if someone could help me in sorting this out.

     

     

     

    #97882

    Try removing:

    This instruction prevents any orders going to market at the close of a bar if you already have an open position. Cumulate positions can also be avoided by using the following in your conditions which we are now doing:

     

    1 user thanked author for this post.
    #97884

    Thanks for the reply.

    Removing “DEFPARAM CumulateOrders = False” didn’t work.

    My issue is actually the opposite, I need two positions to be started at the same time whenever there is a Buy(Exit) or Sell(Exit) signal triggered. In other words, the Buy(Exit) and the Buy(Entry) trades should happen at the same time.

    As can be seen in the attached Printscreen, at the moment the code produces the Exit order but not the Entry one, which is generated only in a following cycle if an additional Buy(Entry) or Sell(Entry) signal is generated.

    I am trying to find a way to have the Exit and Entry orders generated at the same time and I would really appreciate any advice on how to do it.

    #97888

    I do not fully understand your last post but maybe the following helps:

    If a strategy sends a SELL order to the market to exit a long position but at the same time also sends a BUY order to the market then they cancel each other out and nothing happens. If they didn’t cancel each other out then you would just be closing a trade and opening a trade and paying the spread every time.

    Strategies can never be long and short at the same time so any order to enter in an opposite direction to the current open positions closes all trades.

    1 user thanked author for this post.
    #97892

    Many thanks for the quick reply.

    I need to be able to generate two SELL orders at the same time; one SELL order to the market to exit a long position and another SELL order to start a new position.

    At the moment, the second SELL order, the one that starts the new position, is generated only in a successive cycle.

    The attached Printscreen shows that the SELL(Exit) order is generated at 5:05 and the SELL(Entry) is generated only at 5:15.

    I would like to be able to generate the SELL(Exit) and SELL(Entry) at the same time to get the same price.

    Thanks

    #97895

    What you have described is what will happen whenever a SELLSHORT order is sent to the market while you have a long position open. All long positions will be closed and a short position opened at the same time.

    I can only assume that your strategy is closing the short position because either the stop loss or target profit are hit and not because short entry conditions have been met. My platform is not open at the moment for me to test anything.

    I notice that you have instructions to close a long trade that are identical to your instructions to open a short trade. Try removing them like this:

     

     

    1 user thanked author for this post.
    #97963

    I modified the code replacing as follow:

    Conditions to exit long positions

    SELL AT MARKET was replaced with SELLSHORT 1 SHARES AT MARKET

     

    Conditions to exit short positions

    EXITSHORT AT MARKET was replaced with BUY 1 SHARES AT MARKET

    As I wanted, when a SELLSHORT order is sent to the market while there is a long position open, all long positions are closed and a short position is opened at the same time.

     

    However, the problem I have now is that my STOP LOSS and TARGET PROFIT conditions are not triggered when the SELLSHORT is inserted in the “Conditions to exit long positions” (the same happens with BUY 1 SHARES AT MARKET inserted in the “Conditions to exit shorts positions”).

    I think that the cause may be the “not on market” condition. As the code sees an open position, it jumps my indicator9 and indicator10.

    Is there any way to have the code going through STOP LOSS and TARGET PROFIT conditions also after a position is opened with a SELLSHORT command?

    Thanks

     

     

    #97999

    I don’t understand. Did you try my code in the previous post? It opens a long or a short position if entry conditions are met. It fixes take profit at whatever ATR * 2 was at the time of entry and stop loss at whatever ATR was at the time of entry. If your conditions to reverse the trade (which are identical to your conditions to close a trade) are met then it closes the trade and opens one in the opposite direction. It only allows one position to be open at any time. Is this not what you have asked for?

    Here is a cleaner version of it with all the ‘rubbish’ removed:

     

    1 user thanked author for this post.
    #98021

    I’ve just realised that this is a strategy discussion in the ProBuilder forum which is for indicator discussions. I will move it to the ProOrder forum. Please try to post in the correct forum with future topics.

    1 user thanked author for this post.
    #98097

    I have now tried and tested your “simplified” code and it works fine and as expected; the problems which affected the previous version have now been resolved.

    Thanks so much for your help and apologies for having posted in the wrong forum

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

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