Entering trades after stop loss?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #20264 quote
    MattyJMattyJ
    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_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
    MattyJMattyJ
    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.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

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 MattyJMattyJ
9 years, 8 months ago.

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