ProRealTIme not respecting stop loss

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #64405 quote
    grimweasel47
    Participant
    Senior

    Hi all.

    I had Nicolas code my strategy that all seemed to work fine in forward testing but not so trading live. An FX trade closed today at 3.5x the expected stop loss distance when it should have been only 0.6*ATR(24). The code for the part of the strategy is given below:

    if alreadytraded = 0 then
    //money management
    if case=1 then
    StopLoss = 0.5*ATR
    else
    StopLoss = 0.6*ATR
    endif
    Risk = riskpercent/100
    //calculate contracts
    equity = balance + StrategyProfit
    maxrisk = round(equity*Risk)
    size = max(minlot,abs(round((maxrisk/StopLoss)/PointValue)*pipsize))
    //in all cases put pending orders on market
    while case <> 0 and daytrading=1 and (time >= activationtime and time <=LimitHour) do
    if levelhi>0 then
    buy size contract at levelhi stop
    endif
    if levello>0 then
    sellshort size contract at levello stop
    endif
    wend
    endif
    // Friday 22:00 Close ALL operations.
    IF onmarket and (DayOfWeek = 5 AND time >= 220000) THEN
    SELL AT MARKET
    EXITSHORT AT MARKET
    ENDIF
    //set target and profit
    if onmarket then
    if case = 1 then
    set target pprofit 10
    set stop loss StopLoss
    endif
    if case = 2 or case = 3 then
    set target profit 2*ATR
    set stop loss StopLoss
    endif
    endif
    
    currentprofit = strategyprofit

    In this instance the trade opened live but instead of closing at the stop loss (which was 0.6*ATR[24] or 18 pips) it didn’t close until 62 pips later, which resulted in a much bigger than expected loss? Any ideas please?

    Grim

    #64414 quote
    Nicolas
    Keymaster
    Master

    The ‘ATR’ variable is not defined anywhere in the code, so StopLoss = 0.5*ATR = 0.5*0 = 0

    Wrong copy/paste?

    #64422 quote
    grimweasel47
    Participant
    Senior

    Hi Nicolas

    Thanks – the ATR is defined earlier in the code as atr=averagetruerange[24] but I didn’t want to paste the whole code as I had to pay you to produce it 😉

    I backtested the system this morning in demo mode and it produced the correct stop loss. For some reason in the live trading it didn’t work and closed at near double the ATR instead of x0.6 ATR??

    #64428 quote
    GraHal
    Participant
    Master

    Just a thought and I’m sure you haven’t got it wrong … but are you running it on the correct / intended TimeFrame that the Algo is optimised for??

    I have done that before … set one going and later realised I must have flicked to another TF??

    #64431 quote
    Eric
    Participant
    Master

    could it be some big temporary  spike in price?

    #64432 quote
    grimweasel47
    Participant
    Senior

    Hi Guys – thanks for the replies.

    Yes on the correct TF (H1) and there was no spike. Oddly it was in a much deeper loss during the 0800-0900 time but it seemed to close out when the H1 bar closed at 0900.

    #64434 quote
    GraHal
    Participant
    Master

    Don’t you need

    Set Stop PLoss StopLoss

    Not

    set stop loss StopLoss
    #64459 quote
    Nicolas
    Keymaster
    Master

    Please give more details about the trade: pair, open time, closed time, price entry, stoploss value, etc..

    #64467 quote
    grimweasel47
    Participant
    Senior

    Hi Nicolas

     

    EurJpy. Opened at 0800 at 12946 at £6 per pip. ATR was 31 at time so SL should have been 0.6*ATR[24] making 18. Actual trade closed out at 0900 at 13008. Should have only been £108 loss (18x£6) but actually closed with loss of £369 which was 62 pips (almost 2x ATR)

    #64494 quote
    grimweasel47
    Participant
    Senior

    Hi GraHal

    I thought set stop ploss was for pips ie stoploss =10 for example. When using a multiple of ATR do you not drop the p from loss?

    Thanks

    #64519 quote
    GraHal
    Participant
    Master

    Mmm well I got confused ages ago re Set Stop Loss so I called IG and he said it is the units of currency in which the trade is executed??

    Grim-1.jpg Grim-1.jpg
    #64544 quote
    Nicolas
    Keymaster
    Master

    set stop loss StopLoss is correct if we are using price units and not points/pips, and that’s the case with ATR.

    Did you look at your orders lists (CTRL+O) to see what happened at that time?

    #64611 quote
    grimweasel47
    Participant
    Senior

    Ok thanks Nicolas. Still bemused as to why it didn’t activate at all. The other pairs with the same code work, just with EurJpy this is the 2nd time this has happened!

    #64627 quote
    grimweasel47
    Participant
    Senior

    Hi Guys

     

    Is it possible in the code given above to close out partial positions? Could I set a target profit for 1*ATR for half the position and then ‘n’ ATR for the remaining half?

    With this strategy I have noted that if I target profit at say 1ATR the % of winning trades is higher, but of course the gain is much lower. It’s finding the right balance between setting a profit target far enough away to make the strategy profitable, but not so far away that it loses. Is there a more effective volatility based metric than using ATR perhaps?

    I’d be interested to see if closing x% of the position at x% target and leaving rest to run on a trailing ATR stop for example was more profitable? Any help appreciated!

    Best

    Grim

    #64633 quote
    GraHal
    Participant
    Master

    You can’t close partial positions, except with manual trading.

    How about running two Algos same code but with half lot size in each and then try your 1*ATR for half the position and then ‘n’ ATR for the other?

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.

ProRealTIme not respecting stop loss


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 14 replies,
has 4 voices, and was last updated by GraHal
8 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/05/2018
Status: Active
Attachments: 1 files
Logo Logo
Loading...