Entry, Stop Loss and Profit Target coding question

Forums ProRealTime English forum ProOrder support Entry, Stop Loss and Profit Target coding question

Viewing 14 posts - 1 through 14 (of 14 total)
  • #95358

    Hello,

    I tried to code a trading system and started with the Simplified Creation but this doesn’t allow me to do all the things I want.

    I need some help with a few coding questions.

    1. My first issue is, once all my conditions are met, I would like to sell short 1 pip below of the signal candle.
    2. For my exit condition (c6), I want it to trigger only after the close of the current bar?
    3. I would like to create the following Stop Loss, Profit Target and Trailing Stop Loss:

    Stop Loss: Entry + 2 x AverageTrueRange (14)

    Profit Target: Entry – 2.5 x AverageTrueRange (14)

    Trailing Stop Loss: When Entry – 2x AverageTrueRange(14) is reached, move Stop Loss to Entry – 1pip.

    How do I code these conditions?

    Below you can find the code I have created so far with Simplified Creation.

     

    I appreciate every help.

    Thank you.

    Sascha

    #95371

    Points 1,2 and 3 included in the below version. Not tested since I don’t have any of the indicators you are calling in your program.

     

    #95378

    Hello Nicolas,

    Thank you very much for the super fast reply. That’s amazing.

    How do I code the Trailing Stop Loss in point 3.)

    Trailing Stop Loss: When Entry – 2x AverageTrueRange(14) is reached, move Stop Loss to Entry – 1pip.  (meaning 1 pip in profit)

     

    Also, I always try to understand the code so I can learn something. As I don’t fully understand the conditions you created with barindex and barorder,

    I tried to find the meaning of barindex and found in an older post the following definition:  Bar Index is the number of bars the System has been running

    So does the condition   barindexbarorder>=1    make the system wait until the end of the bar?

    Why do we add   barorder>0    (line 29)   and  then barorder=0  (in line 31)?

     

    Thanks so much.

    Sascha

    #95381

    Because we want to make sure at least 1 bar is elapsed since the opening of the order and that we are trying to close the current running order and not an “old one”.

    #95406

    Hi Nicolas,

    Thanks for your comment.

    Meanwhile I’ve been reading in various posts about Stop Losses and it’s surprising how difficult it seems to implement in PRT code what seems like a simple one step stop loss adjustment.

    So far I haven’t found any solution for how to code my Stop loss change to breakeven + 1 pip profit.

    Stop Loss: When Entry – 2x AverageTrueRange(14) is reached, move Stop Loss to Entry – 1pip.  (meaning 1 pip in profit)

    The question is how do you capture or code the moment of entry and then tell PRT to move the stop loss in the desired way?

     

    Any feedback is highly appreciated.

    Thank you.

    Sascha

    #95677

    how difficult it seems to implement in PRT code what seems like a simple one step stop loss adjustment.

    Because there are billions of variants and way to code it. What you ask if a never seen before feature.

    Simple breakeven code here: https://www.prorealcode.com/topic/move-sl-during-current-candle/#post-79130

    Should be adapted to move the stoploss to breakeven when the 2x AverageTrueRange(14) is reached though, so you have to save that value when you launch an order and use it to put the order to BE. Let me know if you are in trouble.

    #95924

    Hi Nicolas,

    Thank you for your reply and sending me the link to the code.

    I looked through it and tried to implement it.

    Attached I send you how it looks like in my code. I am not sure if I adjusted it correctly in terms of saving the value when I launch an order, as you said.

    I would appreciate if you could take a quick look at it.

    Is there a difference between  Averagetruerange[14]  and Averagetrurange[14](close)?

    By the way, I created the code for the long side as well. I assume I can just put it beneath the code for the short trade?

     

    Thanks again.

    Sascha

     

    #96761

    Hi Nicolas,

    I have a question regarding barindex and barorder that you created for me two weeks ago.

    I added another exit condition which says if there is a Key Reversal bar (e3) then exit.

    However, in one trade example the condition was met right the first candle after entry and the trade was not exited.

    When I deleted the condition:  (barindex-barorder>=1 and barorder>0     the trade was exited. So I assume something would need to be adjusted with this condition.

    Does this condition not allow  other conditions to work the bar after entry?

     

    #96763

    Hi Nicolas,

    A quick update:

    I just changed   (barindexbarorder>=1 and barorder>0)  to   (barindexbarorder>=1 and barorder>=0).

    All I changed was   barorder>=0.

    Now the trade was exited after the first bar, but I am not sure if that changes the original purpose of this condition?

    #96765

    With just

    you’ll save a lot of time debugging a simple condition 🙂

    #96788

    Hi Nicolas,

    I’ll try to understand your comment. Maybe I’ll find another article that helps me understand it. First I need to fully understand the condition.

    In a recent comment regarding   (barindexbarorder>=1 and barorder>0)   that you added to my code, you said:

    ”   Because we want to make sure at least 1 bar is elapsed since the opening of the order and that we are trying to close the current running order and not an “old one”.  ”

    So,  barindexbarorder>=1  makes sure at least 1 bar is elapsed?

    And   barorder>0   would close the current running order and not an “old one”?  I guess I am struggling to understand this part. What if I set it to barorder>=0,  would it still close the current running order? In my example mentioned, changing it to barorder>=0 closed the trade after the first candle in the trade, and leaving it at barorder>0 the trade was not exited. But I don’t understand why because I don’t understand the condition.

    In the code your wrote   barorder = barindex, so can barorder ever be 0?

    I would say no as barindex is the current bar loaded buy a trading system, so I would think at the time of a trading signal the barindex is not 0.

    I guess you can see that I am confused. I’m sorry.

    #96789

    I’ll try to understand your comment. Maybe I’ll find another article that helps me understand it.

    Nicolas is referring to this instruction:

    https://www.prorealcode.com/documentation/graph/

    It and information and examples of all instructions can be found by hovering over help and clicking on ‘ProBuilder language documentation’ which will take you to here:

    https://www.prorealcode.com/prorealtime-documentation/

    #96795

    Thanks Vonasi!

    In the meantime I had searched for the meaning of the GRAPH function and I was able to draw the variable.

    I think my problem is that Nicolas gave me a little piece of code and I don’t fully understand it.

    When I use the GRAPH function to draw   Barorder, then I see that this variable only jumps from 0 to the value of Barindex in the moment when my conditions are met and with the next candle it drops back to 0 and stays there all the time until next signal.

    This means that the piece of code from Nicolas    Barorder>0  can never be true for my exits as it is always zero accept on the signal day. Consequently my exit conditions should never work.

    However, they do work. That’s the confusing part. When I look at trade examples, trades are exited with my conditions (for example when condition d6 was met). Therefore I don’t understand it.

    How can that be?

     

    #96805

    I’ve not looked in detail at your code (not enough coffee!) but my first thought was that you might want to try adding NOT ONMARKET to your entry IF THEN conditions and ONMARKET to your IF THEN exit conditions because without this even though you do not enter market because you are already on market and CUMULATEORDERS = FALSE any variable values will still be changed if your conditions are met.

     

     

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

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