Entering trades after stop loss?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #20264 quote
    MattyJ
    Participant
    Junior

    Hi there, I hope someone can help me.

    Here is my very basic SMA system that I am trialling. I am having an issue with it putting me back into a trade once my stop loss has been hit rather than waiting for the cross over. Could you tell me why this might be happening?

    //-------------------------------------------------------------------------
    // Main code : Simple 50/221
    //-------------------------------------------------------------------------
    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1 = Average[50](close)
    indicator2 = Average[221](close)
    c1 = (indicator1 CROSSES OVER indicator2)
    
    IF c1 THEN
    BUY 1 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator3 = Average[50](close)
    indicator4 = Average[221](close)
    c2 = (indicator3 CROSSES UNDER indicator4)
    
    IF c2 THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    indicator5 = Average[50](close)
    indicator6 = Average[221](close)
    c3 = (indicator5 CROSSES UNDER indicator6)
    
    IF c3 THEN
    SELLSHORT 1 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    indicator7 = Average[50](close)
    indicator8 = Average[221](close)
    c4 = (indicator7 CROSSES OVER indicator8)
    
    IF c4 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    SET STOP LOSS 35
    #20643 quote
    Fei_
    Participant
    Junior

    Hi Mattyj,

    It is because your indicator is still valid.

    C1 condition still exist.

    You can try add a controlbits into your code:

    indicator1 = Average[50](close)
    
    indicator2 = Average[221](close)
    
    c1 = (indicator1 CROSSES OVER indicator2)
    
    c2 = (indicator1 CROSSES UNDER indicator2)
    
    if c1 and ControlBuy =0 then
    
    ControlBuy=1
    
    ControlSell=0
    
    BUY 1 PERPOINT AT MARKET
    
    elsif c2 and ControlSell=0 then
    
    ControlSell=1
    
    ControlBuy=0
    
    SELLSHORT 1 PERPOINT AT MARKET
    
    Endif
    Nicolas thanked this post
    #20686 quote
    MattyJ
    Participant
    Junior

    Thanks so much Chowfei, I’ll give that a try.

    Much appreciated.

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

Entering trades after stop loss?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
MattyJ @mattyj Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by MattyJ
9 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/09/2017
Status: Active
Attachments: No files
Logo Logo
Loading...