How to manage consecutive stop orders in a program ?

Forums ProRealTime English forum ProOrder support How to manage consecutive stop orders in a program ?

Viewing 15 posts - 1 through 15 (of 15 total)
  • #70725

    Hi,

    Many thanks in advance for the time you will take to read, understand and hopefully answer this post.

    Well I am trying to program something I am often doing while I am manually trading.

    The idea is simple :

    • I enter a trade with quite a lot of confidence on the chance that the trade has a big pontential :
      • I put 4 lots on DAX for example TimeFrame=30 minutes
      • As I am reasonably optimistic I place a LIMIT and a STOP, at +75 points (target) and -50 points (loss).
      • Let’s imagine that my trade is a LONG one (for the purpose of the example) : I immediately place a BUY STOP of 2 lots at +30 points above my entry value (let’s say I entered at 13 000, so here at 13 030)
    • Then I wait, and there is 2 alternatives :
      • 1- I am stop at my STOP LOSS (sad, but easy…)
      • 2- My BUY stop order is executed
    • If case 2- happens, I am IMMEDIATELY doing the following :
      • I move up my original stop loss at the breakeven point : from 12950 to 13010 in my example
      • I place a LIMIT at the same LIMIT than the 1st order : at 13 075 in my example
      • so that I have now 6 lots with a STOP LOSS at 13 010 and a TARGET PROFIT at 13 075
      • and I also immediately place last a BUY STOP of 1 lot at +50 points above my entry value (so here at 13 050)
    • Then I wait, and there is again 2 alternatives :
      • 1- I am stop at my STOP LOSS (with no loss and no gain : breakeven)
      • 2- My last BUY stop order is executed
    • If case 2- happens, I am IMMEDIATELY doing the following :
      • I move up my original stop loss at the breakeven point of order#2 and order#3 : from 13010 to 13036.7 in my example
      • I place a LIMIT at the same LIMIT than the 1st order : at 13 075 in my example
      • so that I have now 7 lots with a STOP LOSS at 13 036.7 and a TARGET PROFIT at 13 075
    • Then I wait, and there a 2 final alternatives which will make me out of the program :
      • 1- I am stop at my STOP LOSS (with gain of my order#1 and no pain no gain on my orders #2 and #3 “which protect each other”)
      • 2- I am stop at my LIMIT with full gain on my 7 positions
    • NB – On DAX I will close all positions whatever happens at 9.30pm and will not open any position before 8am.

    I join hereafter the beginning of the corresponding piece of code. But I do not know how to manage the consecutive STOP ORDERS and STOP LOSS modifications and TARGET PROFITS as well…

    If you could help, that would be great and you will enjoy in return a nice piece of winning trading methodology I think.

    BR,

     

    #70736

    It’s not possible to set a  STOP LOSS/TARGET PROFIT at different points, it will always be the same for ALL the contracts you have bought, no matter when and at what price you traded them.

    For  breakeven and trailing stops you may find useful codes and suggestions here:

    https://www.prorealcode.com/blog/learning/breakeven-code-automated-trading-strategy/

    https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/

     

    #70738

    Thanks for your answer Robertogozzi.

    Maybe the fact that I wrote about “TARGET PROFIT” was a bit misleading in my explanation. Because you should understand from it that all my consecutive orders have the same exits points (but that points are changing according to new orders coming in) ; so I should rather speak about LIMIT/STOP ORDERS (in profit or loss) rather than about TARGET PROFIT/STOP LOSS.

    You will find hereafter again my explanation with less misslideading words I hope :

     

     

    The idea is simple :

    • I enter a trade with quite a lot of confidence on the chance that the trade has a big pontential :
      • I put 4 lots on DAX for example TimeFrame=30 minutes (Order #1)
      • As I am reasonably optimistic I add a LIMIT order and a STOP order for these 4 lots : at +75 points (this is my objective) and -50 points (this is my protection).
      • Let’s imagine that my trade is a LONG one (for the purpose of the example) : I immediately place a BUY STOP order of 2 lots at +30 points above my initial entry value (let’s say I entered at 13 000, so here at 13 030). Note that my BUY STOP is above my initial entry value (obvious), but below my objective.
    • Then I wait, and there are 2 alternatives :
      • 1- I am stopped at my protection level -50 points below my entry point (sad, but easy…)
      • 2- My BUY stop order is executed (Order #2)
    • If case 2- happens, I am IMMEDIATELY doing the following :
      • I move up my protection at the breakeven point : from 12950 to 13010 in my example (this becomes my protection level for both Orders #1 and #2)
      • I place a LIMIT at the same LIMIT than the 1st order : at 13 075 in my example
      • so that I have now 6 lots with a protection at 13 010 and an objective at 13 075
      • and I also immediately place last a BUY STOP order of 1 lot at +50 points above my very initial entry value (so here at 13 050)
    • Then I wait, and there are again 2 alternatives :
      • 1- I am stopped at my protection level (with no loss and no gain : breakeven)
      • 2- My last BUY stop order is executed (Order #3)
    • If case 2- happens, I am IMMEDIATELY doing the following :
      • I move up my protection at the breakeven point of order#2 and order#3 : from 13010 to 13036.7 in my example ((this becomes my protection level for both Orders #1, #2 and #3)
      • I place a LIMIT at the same LIMIT than the 1st and 2nd order : at 13 075 in my example
      • so that I have now 7 lots with a protection at 13 036.7 and an objective at 13 075
    • Then I wait, and there a 2 final alternatives which will make me out of the program :
      • 1- I am stopped at my protection level (with gain of my order#1 and no pain no gain on my orders #2 and #3 “which protect each other”)
      • 2- I am stopped at my objective with full gain on my 7 positions
    • NB – On DAX I will close all positions whatever happens at 9.30pm and will not open any position before 8am.

    I join hereafter the beginning of the corresponding piece of code. But I do not know how to manage the consecutive STOP and LIMIT orders

     

    If you could help, that would be great and you will enjoy in return a nice piece of winning trading methodology I think.

    BR,

    #70740

    If you want different take profits for 4 contracts

    then use 2 systems (same code) instead of 1 (or 4 instead of 1)

    and also trailing stop

    #70741

    Thanks Eric.

    And/but again to be clear, I DON’T “want” different take profits.

    I would like my orders to have the same limit (the initial one) and a protection which evolves while number of orders is increasing.

    #70743

    I’m working on it, will be back within 20-30 minutes.

    #70747

    This what I managed to arrange

     

     

    1 user thanked author for this post.
    #70748

    I only tested it for syntax, let me know about logic issues.

     

    #70750

    I use pipsize, despite not necessary when trading DAX, to make code portable so that you can use it for other instruments letting ProOrder to take care of conversions.

    #70751

    Tx a lot Robertogozzi !

    I will try it “against” my manual practice and will let you know in case I would see something not matching.

    #70759
    Leo

    Comulate Order = true

    #70895
    #70918

     

    #70937

    Whenever you manually modify a trade opened by ProOrder, the strategy is immediately quit.

    #70980

    I changed CUMULATEORDERS to TRUE as suggested by Leo and also added a new line after lines 41 and 55 to accomodate for the 7 orders, in case on the following (just opening) bar ALL the three need to be entered.

     

     

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

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