Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

pivot indicator

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

    #16
    Thanks,

    My code is below but some still enters 2 twice per session, can you please check.

    {
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    // User defined variables (add any user defined variables below)
    #endregion

    private bool canTrade = true;

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    Add(Pivots(NinjaTrader.Data.PivotRange.Daily, NinjaTrader.Data.HLCCalculationMode.CalcFromIntrad ayData, 20));
    Add(Pivots(NinjaTrader.Data.PivotRange.Daily, NinjaTrader.Data.HLCCalculationMode.CalcFromIntrad ayData, 20));
    SetProfitTarget("", CalculationMode.Ticks, 20);
    SetStopLoss("", CalculationMode.Ticks, 30, false);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    if (SessionBreak)
    canTrade = true;

    // Condition set 1
    if (condition 1)
    {
    canTrade = false;
    EnterShort(DefaultQuantity, "");
    }

    // Condition set 2
    if (condition 2)
    {
    canTrade = false;
    EnterLong(DefaultQuantity, "");
    }




    Thanks,

    Andrew

    Comment


      #17
      Andrew,

      In your conditions you actually have to check against the bool variable.

      Code:
      if (canTrade != false && condition 1)
      {
           canTrade = false;
           EnterLong();
      }
      Josh P.NinjaTrader Customer Service

      Comment


        #18
        Thanks Josh,

        I entered as below:

        [IMG]file:///C:/Users/Andrew/AppData/Local/Temp/moz-screenshot.png[/IMG][IMG]file:///C:/Users/Andrew/AppData/Local/Temp/moz-screenshot-1.png[/IMG] /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
        if (SessionBreak)
        canTrade = true;

        // Condition set 1
        if (canTrade != false && Condition 1)
        {
        canTrade = false;
        EnterShort(DefaultQuantity, "");
        }

        // Condition set 2
        if (canTrade != false && condition 2)
        {
        canTrade = false;
        EnterLong(DefaultQuantity, "");



        But still some sessions enters more than 1 position as per attachments.

        Any other advice?

        Thanks,

        Andrew
        Attached Files

        Comment


          #19
          You will then need to debug your bool variable and track down the state of it along each step of the way. Please use Print() throughout your code.

          Josh P.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          673 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          379 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          111 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          577 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          582 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X