Widen stoploss overnight

Forums ProRealTime English forum ProOrder support Widen stoploss overnight

Viewing 15 posts - 1 through 15 (of 21 total)
  • #77849
    Seb

    Hello, I am trying to code a stoploss that widens when the DAX futures market closes. I have set the chart of the DAX CFD from IG to custom trading hours 08:00:00 – 22:00:00 (because this is the data I want to use for indicators). I tried it with this code:

    As can be seen in the picture in the attachment (this is activity from the demo account), the code doesn’t do what it’s supposed to do. It widens the stoploss at 21:55 and at 22:00 it takes the stoploss out entirely. Than at 01:00 it puts back the wide stop and 08:05 it goes back to the tight stop. Ideal would be stoploss wider at 22:00 and stoploss back to tight at 08:00, when the DAX futures open. Can it be done?

    #77851

    Why not use a SET order to place the orders just once and then modify them at the desired time?

    If you have a limited risk account then your variable stop distance will not work because you cannot move a stop further away on a limited risk account.

    #77854
    Seb

    Thank you for your reply Vonasi, The reason that I don’t use the ploss function is because I use an indicator based trailing stop. I tried coding with the ploss function in the past, but I believe the reason I didn’t use it is that it set faulty stops when there was a gap between the open and close of two candles.

    #77857

    If you calculate the number of pips in the stop distance with POSITIONPRICE – (your indicators stop price) then it would be set at the correct level. 

    It would not be possible to calculate this for one bar so you could use a STOP order for the first bar and then use the SET instruction afterwards just to widen and narrow the stop distance twice a day.

    #77861
    Seb

    Thanks I will try it! So this also works with a trailing stop based on for example a moving average?

    #77862

    Yes – no reason why not.

    POSITIONPRICE is the average of all open positions. TRADEPRICE is the price of the last position opened. You need to be aware that if you have multiple positions open then when using the SET instruction each one will have a separate stop order set at whatever distance you calculate. With the pending STOP order you were first using then just one level is set and all positions closed at this price.

    #77864
    Seb

    So if you scale into a long position on different entry levels, set stop ploss (POSITIONPRICE – moving average) would trail correctly and close the position if price reaches the moving average?

    #77869
    Seb

    To make my question more concrete, how can you achieve the trailing stoploss of the following code with the SET STOP PLOSS function? (to be able to widen the stop at 22:00)

     

    #77873

    Sorry but I’m a bit too busy at the moment to look into your code with too much detail but I think it is as I explained before.  Every time your buy condition is met then the stop loss levels for all of the already open positions will be altered to the newly calculated level from their opening prices – so they will all have different levels of stops. For your example due to the scaling in SET is not the right instruction to use.

    You will need to go back to pending stop orders and work out why they are not working for you.

    #77934
    Seb

    Alright, that’s a shame. The documentation quotes “Set a stop loss x units from the average position price.” for the SET STOP LOSS function. This is a bit confusing than, since “average” position price suggests the position consists of multiple prices (a scaled-in position).

    #77935

    Your line 12-13

    works with DAX, but not with FX pairs, since PLOSS requires PIPS, while SL is a difference in price. You should either use, in line 13:

    or use LOSS, instead:

    Moreover, line 22 is trying to exit a LONG position SELLing at a difference in price (say 0085), instead of a price (say 12510). Pending orders require a PRICE to enter/exit at some point.  

    #77943
    Seb

    Thank you Roberto, I’m testing with DAX, so the FX issue is not causing any problems. For stoplosses I’ve up ’till now used the technique from the code I posted yesterday, which I got from a PRC blog post (link is above the code). (i.e.:)

    This works fine for indicator based trailing stops (that only move your way) in combination with scaling in. I just define at what price level SL has to be and than the whole position closes at that level if price gets there.

    From Vonasi’s posts I believe that with the SET STOP function indicator based trailing stops can be achieved, but not if you scale-in. I’m testing it in my demo account now, but this takes a while.

    #77948
    Seb

    My logic is that if you want to make an indicator based trailing stop with the SET STOP function, (Positionprice – trailing indicator level) becomes a negative amount if the trailing indicator gets beyond your entry price (for a long). You are using a negative number for SET STOP than. Because you are not taking a loss but a profit at the trailing level. Correct?

    #77951

    That’s correct. You can use ABS() to make sure you have a positive result.

     

    #77952
    Seb

    But if you use ABS() you have a trailing stop that never takes a profit I assume, which is not the intention of a trailing stop.

     

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

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