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 charlesugo_1, 05-26-2026, 05:03 PM
          0 responses
          57 views
          0 likes
          Last Post charlesugo_1  
          Started by DannyP96, 05-18-2026, 02:38 PM
          1 response
          143 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 05-11-2026, 05:56 AM
          0 responses
          161 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 05-10-2026, 08:12 PM
          0 responses
          97 views
          0 likes
          Last Post CarlTrading  
          Started by Hwop38, 05-04-2026, 07:02 PM
          0 responses
          276 views
          0 likes
          Last Post Hwop38
          by Hwop38
           
          Working...
          X