Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to set quit the strategy if 3 conseq. stoplosses have been triggered ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to set quit the strategy if 3 conseq. stoplosses have been triggered ?

    protected override void Initialize()
    {
    SetStopLoss("", CalculationMode.Ticks, StopLoss, false);

    CalculateOnBarClose = true;
    ++Variable1;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (Close[0] > Open[0]
    && Close[0] > EMA(EMA1)[0]
    && Open[0] < EMA(EMA1)[0]
    && Position.MarketPosition == MarketPosition.Flat
    && Open[0] < EMA(EMA2)[0]
    && Close[0] > EMA(EMA2)[0]
    && Open[0] < EMA(EMA3)[0]
    && Close[0] > EMA(EMA3)[0]
    && Variable1 < Fail_Times)
    {
    EnterLong(DefaultQuantity, "");
    }

    // Condition set 2
    if (BarsSinceEntry() > WaitUntil
    && Close[1] < EMA(14)[1]
    && Position.MarketPosition == MarketPosition.Long)
    {
    ExitLong("", "");

    }

    // Condition set 3
    if (Close[0] < EMA(EMA1)[0]
    && Open[0] > EMA(EMA1)[0]
    && Position.MarketPosition == MarketPosition.Flat
    && Open[0] > EMA(EMA2)[0]
    && Close[0] < EMA(EMA2)[0]
    && Open[0] > EMA(EMA3)[0]
    && Close[0] < EMA(EMA3)[0]
    && Close[0] < Open[0]
    && Variable1 < Fail_Times)
    {
    EnterShort(DefaultQuantity, "");
    }

    // Condition set 4
    if (BarsSinceEntry() > WaitUntil
    && Close[1] > EMA(14)[1]
    && Position.MarketPosition == MarketPosition.Short)
    {
    ExitShort("", "");

    }
    }

    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int LookBack
    {
    get { return lookBack; }
    set { lookBack = Math.Max(1, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public int WaitUntil
    {
    get { return waitUntil; }
    set { waitUntil = Math.Max(1, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public int EMA1
    {
    get { return eMA1; }
    set { eMA1 = Math.Max(1, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public int EMA2
    {
    get { return eMA2; }
    set { eMA2 = Math.Max(1, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public int StopLoss
    {
    get { return stopLoss; }
    set { stopLoss = Math.Max(100, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public int EMA3
    {
    get { return eMA3; }
    set { eMA3 = Math.Max(1, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public int Fail_Times
    {
    get { return fail_Times; }
    set { fail_Times = Math.Max(2, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public int EMALength
    {
    get { return eMALength; }
    set { eMALength = Math.Max(10, value); }
    }
    #endregion
    }
    }

    #2
    here is what I tried . Not working.

    Comment


      #3
      Hello hamugela,

      Thank you for your post.

      I'd suggest taking a look at this example from our help guide which illustrates how to stop the strategy from trading until the next session if there are 3 consecutive losers in a row:



      Please let us know if we may be of further assistance to you.

      Comment


        #4
        thanks. It works

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        556 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X