Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Resetting a variable

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

    Resetting a variable

    Hi
    I am trying to reset a variable after price pass above or below a certain point. For example if price crosses above or below yesterdays close reset this variable. I tried using the cross above/below function but I got errors.

    I tried this

    if (CrossBelow(High[0],PriorDayOHLC().PriorClose[0]))
    tradeCount = 0;

    But got a error message saying "No overload for method CrossBelow take 2 arguments.

    How can get this to work?

    Thanks

    #2
    What am I doing wrong? I am trying to get the program to only take one trade until price crosses the close of the previous day or a new trading session begins. Aften then it is allowed to take another trade.

    private int tradeCounter = 0;


    if (tradeCounter == 1)
    return;

    if (Low[0]>=PriorDayOHLC().PriorClose[0])
    tradeCounter = 0;

    if (High[0] >= PriorDayOHLC().PriorClose[0] )
    tradeCounter = 0;
    if (Bars.FirstBarOfSession && FirstTickOfBar)
    tradeCounter = 0;


    if ( blah blah. )
    EnterLong ;
    tradeCounter++;


    if (blah blah)
    EnterLong ;
    traderCounter++;

    Comment


      #3
      Hello,

      If this is at the top of OnBarUpdate() then the rest of the code will never work if you have one trade open. You want the rest of the code to work all the time right?:
      if (tradeCounter == 1)
      return;

      Don't you want EnterLong and tradeCounter in brackets like this so the counter only counts when a trade is executed?:

      if ( blah blah. )
      {
      EnterLong ;
      tradeCounter++;
      }
      DenNinjaTrader Customer Service

      Comment


        #4
        Ok thanks I got it. I have another problem. I am trying to reset the same variable after price pass above or below the previous day close. For example if price crosses above or below yesterdays close reset this variable. I tried using the cross above/below function with High[0]/Low[0] and priordayHOLC indicator but that did not work. I am now using cross above/below with priordayHOLC and a 1 period sma. That works but it does do the job fully. If the Low/High of a bar move below/above the prior days close the 1 period sma will not touch or cross the previous days closing price and the variable does not get reset. How can I program this ?

        Thanks

        Comment


          #5
          trader413,

          What have you tried originally?

          CrossAbove(High, PriorDayOHLC().PriorClose[0], 1)
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            I tried those two and got an error.

            CrossAbove(High[0], PriorDayOHLC().PriorClose[0], 1)
            CrossBelow(Low[0], PriorDayOHLC().PriorClose[0], 1)

            Comment


              #7
              Which error exactly did you get trader413?

              Comment


                #8
                I am not on my trading computer right now but I think the error I got was
                "Argument '2': cannot convert from 'double' to 'NinjaTrader.Data.IDataSeries"

                Comment


                  #9
                  Remove the [0] on the High and Low. You need to check DataSeries to double value not double value vs another double value.
                  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
                  633 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  364 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  105 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  567 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  568 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X