Algo not exiting trade on sell signal

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #151100 quote
    AleksLi
    Participant
    Junior

    Hello folks,

    Here’s my code:

    DEFPARAM CumulateOrders = False
    
    //dynamic position sizing
    INITIALCAPITAL = 10000
    d = (INITIALCAPITAL/close)
    if d < 0.2 then
    d = 0.2
    endif
    //end dynamic position sizing
    
    indicator1 = SAR[0.3,0.3,0.1]
    c1 = (close > indicator1)
    indicator2 = RSI[4](close)
    c2 = (indicator2 < 80)
    c3 = (close >= open)
    indicator3 = AroonUp[15]
    c4 = (indicator3 > 5)
    
    IF c1 AND c2 AND c3 AND c4 THEN
    BUY d PERPOINT AT MARKET
    ENDIF
    
    indicator4 = SAR[0.3,0.1,0.1]
    c5 = (indicator4 > close)
    indicator5 = RSI[4](close)
    c6 = (indicator5 > 80)
    
    set stop $loss 800
    
    IF c5 OR c6 THEN
    SELL AT MARKET
    ENDIF
    

    As you can see, one of the sell rules is:

    indicator4 = SAR[0.3,0.1,0.1]
    c5 = (indicator4 > close)

    However, once these conditions where satisfied last night, the algo did not exit my trade. What am I missing?

    I’ve looked over my code five times and I’m starting to think I’m going crazy. I’d appreciate any help.

    Thanks,

    Aleks

    1-1.jpg 1-1.jpg
    #151106 quote
    robertogozzi
    Moderator
    Master

    In your chart I can’t see where it was supposed to exit.

    Append

    GRAPH c5
    GRAPH c6

    then, after backtesting, check the variables’window to see what value they retain candle by candle. If their value is not, then conditions are not met.

    #151112 quote
    AleksLi
    Participant
    Junior

    Hi Robert, thanks for your answer. After including the graph commands, here’s what I get:

     

    As you can see, the parabolic SAR gives off a sell signal, however, the system stays long.

    2.jpg 2.jpg
    #151114 quote
    robertogozzi
    Moderator
    Master

    Your pic shows that on the bar where your mouse is sitting there were no trades open!

    #151167 quote
    AleksLi
    Participant
    Junior

    Hi Roberto,

    The blue bars bellow the graphed variables show that a position of 0.66 lots was open.

    Thanks,

    Aleks

    #151168 quote
    GraHal
    Participant
    Master

    Does the SAR on your Price Chart have same settings as the SAR in your Algo at Line 23 – (SAR[0.3,0.1,0.1] )

    #151169 quote
    AleksLi
    Participant
    Junior

    Yep, I checked for that and it seems like both the SAR on the chart and the system are the same.

    #151170 quote
    GraHal
    Participant
    Master

    So you must have changed the SAR on the Price Chart because the default settings are – SAR[0.02,0.02,0.2]

    Odd you say … ‘seems they are the same’ … either they are the same or they are not the same? 🙂

    #151171 quote
    GraHal
    Participant
    Master

    Anyway your condition c5 = (indicator4 > close) occurs on the bar marked with the red arrows on attached and so the Sell will occur at the open of the next bar … as indeed it does??

    Or maybe you just haven’t shown any more bars??

    Forgive my brusque comment in my previous post … I have one eye on the tv and I’ve had a beer! 🙂

    Aleks.jpg Aleks.jpg
    #151174 quote
    Vonasi
    Moderator
    Master

    The GRAPH shows that C5 was true at the close of the second to last bar so the trade should be closed at the open of the last bar shown on the chart. I think we will not see the true backtest actions until this latest bar is actually closed and the backtest engine can see what trading actions would have occurred in that last bar. It is a back test and not live trading and actions are not real time.

    I’ve not been back testing for a while so might be a bit rusty and talking rubbish though!

    GraHal thanked this post
    #151175 quote
    AleksLi
    Participant
    Junior

    Hi GraHal,

    Thanks for your answer. All good- personally I’m nursing quite a hard hangover from yesterday, so my English might not be as clear as I’d like it to be. I apologise for any miscommunication.

     

    In my last screenshot, my cursor hides the first red dot that appeared on the 19th of November. The trade should’ve been closed on the opening of the 20th of November.

     

    I thought I might also add that this system was actually live while these trades where on, and I thought that the system would’ve exited me out of my trade in real time?

     

    Thanks,

    Aleks

    GraHal thanked this post
    2__01.jpg 2__01.jpg
    #151178 quote
    robertogozzi
    Moderator
    Master

    Try using this as line 30:

    IF c5 <> 0 OR c6 <> 0 THEN

    it’s the same as the original one but… never say never!

    #151179 quote
    Vonasi
    Moderator
    Master

    You can’t use the GRAPH instruction in live trading. Are you sure that you mean live and not just a currently running backtest?

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

Algo not exiting trade on sell signal


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
AleksLi @aleksli Participant
Summary

This topic contains 12 replies,
has 4 voices, and was last updated by Vonasi
5 years, 3 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/20/2020
Status: Active
Attachments: 4 files
Logo Logo
Loading...