Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
      Kate W.NinjaTrader Customer Service

      Comment


        #4
        thanks. It works

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Stanfillirenfro, Today, 07:23 AM
        1 response
        2 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by cmtjoancolmenero, Yesterday, 03:58 PM
        2 responses
        19 views
        0 likes
        Last Post cmtjoancolmenero  
        Started by olisav57, Yesterday, 07:39 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by cocoescala, 10-12-2018, 11:02 PM
        7 responses
        943 views
        0 likes
        Last Post Jquiroz1975  
        Started by oviejo, Today, 12:28 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X