How to code target and stop ?

Forums ProRealTime English forum ProOrder support How to code target and stop ?

Viewing 5 posts - 1 through 5 (of 5 total)
  • #16076

    A request that was addressed to ProRealTime:

    Hi. I’m new to PRT and to coding and I’m creating my first trading system. I have just started a Premium subscription. The entry for my system seems to be working however I don’t know where to start with coding the targets and stops. I’ve read the trading system manual and have looked through the 22 pages of trading support conversations but can’t find what I’m after. The closest thing I found is here but this doesn’t give me exactly what I want: http://www.prorealcode.com/blog/learning/breakeven-code-automated-trading-strategy/

    Example here is where I have a long position in the Bund but same would apply (but opposite) if I was short. The three steps are set out. Idea is to have a position with 2 target prices and then a trailing stop for the remaining position (in this instance, Targets 1 and 2 to cover 2/3s of the position and then running remaining 1/3).

    Price
    e.g. long 3 lots Bund @ 162.40

    1 Stop (3 lots) -4 ticks 162.36
    Target 1: 1 lot at +4 ticks 162.44
    Target 2: 1 lot at +8 ticks 162.48

    2 Price moves up to Target 1 162.44
    Stop (now 2 lots) moves to break even 162.40
    Target 2 unchanged 162.48

    3 Price moves up to Target 2 162.48
    1 lot remaining which I want to run
    Stop (for 1 lot) becomes a trailing stop (-4 ticks) 162.44

    Suggestion for an anwser:

     

    1 user thanked author for this post.
    #16124

    Henry. Many many thanks for the help. Really appreciated. I’m having a problem with it but I suspect it could be how I’ve incorporated it into the system. I’ve looked at a short position today (so swapped your code around). When I back tested it it seemed to hit the stop 4 away (as it should), flatten the position (again as it should), but then it took a 1 lot long position. Could it be that the covers

    are being left in the market after the stop is hit? Reason I think this is the system went short the Bund at 162.13, stop got hit in the next bar at 162.17 (4 units away, as it should) but it then went long at 162.09 (which would equate with inprice of 162.13 – (4*0.01)).? The market then reversed so didn’t get chance to see if an order was left at 162.13 – (8*0.01)).

    Here is the code that I used (which incorporated your suggestion) although I excluded the “If NOT LongOnMarket THEN” (or” If NOT ShortOnMarket THEN” in my case as I went short)

     

     

    Many thanks again for your help.

     

    #16492

    Hi JonJon,

    You can find below the code modified.

     

    1 user thanked author for this post.
    #16566

    Thanks Henry. That looks like it does exactly what I need. Really appreciated.

    #16782

    Hi Henry

    It’s me again (unfortunately). I’ve been testing the code all week. Works really well however one question and one observation:

    1) Can PRT update the orders mid bar? The strategy looks at 15min bars (I know, a lot can happen in 15min). For example,

    Triggers and sells 3 @ 160.94

    1st cover: buys 1 @ 160.90 (as it should) (-4 ticks away)

    2nd cover: 1 buys @ 160.86 (as it should) (-8 ticks away).

    net position: -1…all happening in the first 15 min. At the moment I think the code switches to:

     

     

    at the beginning of the second bar instead of partway through the first bar as ideally it should. I think the answer is “no” as I understand that PRT only recalculates at the end of each bar? Just checking.

    2) I’ve spotted an “nuance” which repeats itself every now and again. Happens where we get triggered and only 1 cover in first 15min as follows:

    15min #1

    Triggers and sells 3 @ 161.20

    1st cover: buys 1 @ 160.16 (as it should) (-4 ticks away)

    net position: -2

     

    15min #2

    Market continues to fall so stop does not get triggered (stop now at inprice of 161.20 which is as it should and is great).

    Bar open at 161.14

    System puts in 2 covers:

    Buys 1 @ 161.10 (-4 from bar open)

    Buys 1 @ 161.06 (-8 from bar open)

    net position = 0

    a) It is almost as if it doesn’t recognise that the countofshortshares is 2 at the start of this bar and places the two covers which flattens the position when they are hit. Unfortunately this means that I am not able to run the last 1 lot with a trailing stop which is the intention.

    b) these covers are placed based on the opening price of the second 15min bar (in this example 161.14, and -4 and -8 ticks below this) instead of the inprice of 161.20 which was the intention. This is actually in my favour when the market is falling however just pointing it out….

    I’ve tried playing with the code for days however same results. Any help you can give will be very appreciated.

    Thanks for all your help thus far.

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

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