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 argusthome, Yesterday, 10:06 AM
          0 responses
          17 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          16 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          14 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          9 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          36 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X