Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Code Issue?

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

    Code Issue?

    I am trying to get the MAX value for this variable since entry and when I try to compile I get the following two error messages. 1) The best overloaded method match for 'NinjaTrader.Strategy.Strategy.MAX(NinjaTrader.Dat a.IDataSeries, int)' has some invalid arguments and 2) Argument '1': cannot convert from 'double' to 'NinjaTrader.Data.IDataSeries'
    Any thoughts as to where I am going wrong? Thanks.

    GT

    Code:
    if(Position.MarketPosition == MarketPosition.Long) 
                    {
                        double MyVar = (Median[0] - ATR(14)[0]*2);
                        if(High[0] >= (Position.AvgPrice + .0030))
                        {
                            double MyVar2 = MAX(MyVar, BarsSinceEntry("LongEntry"))[0];
                            stopOrder = ExitLongStop(0, true, 1, MyVar2, "LongStop", "LongEntry");
                        }
                    }

    #2
    Hi GT, you pass a double in the MAX() which expects a dataseries input.

    Comment


      #3
      Originally posted by GreenTrade View Post
      I am trying to get the MAX value for this variable since entry and when I try to compile I get the following two error messages. 1) The best overloaded method match for 'NinjaTrader.Strategy.Strategy.MAX(NinjaTrader.Dat a.IDataSeries, int)' has some invalid arguments and 2) Argument '1': cannot convert from 'double' to 'NinjaTrader.Data.IDataSeries'
      Any thoughts as to where I am going wrong? Thanks.

      GT

      Code:
      if(Position.MarketPosition == MarketPosition.Long) 
                      {
                          double MyVar = (Median[0] - ATR(14)[0]*2);
                          if(High[0] >= (Position.AvgPrice + .0030))
                          {
                              double MyVar2 = MAX(MyVar, BarsSinceEntry("LongEntry"))[0];
                              stopOrder = ExitLongStop(0, true, 1, MyVar2, "LongStop", "LongEntry");
                          }
                      }
      GreenTrade,

      Try Making "MyVar" a dataseries instead of a double.

      RJay
      RJay
      NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

      Comment


        #4
        Thank you both for your help. I did make the change and made myVar a DataSeries then called the DataSeries later in the code. That part worked! Unfortunately I am having a problem I cannot seem to escape in my coding. The first time the stop is actually issued it takes the wrong value. I looking at the output window every other time it is called correctly just not the first time. I have tried changing when I call it by leaving it after the if statement or just calling the variable every bar and then calling it again after the if statement but nothing seems to fix it. Any ideas on how to fix this problem. It keeps coming up for me. Thank you both again!

        GT

        Comment


          #5
          You will have to debug what condition is happening at this bar provoking the unintended stop value in your order. I suggest you add Print() statements to your variable to understand better where the code does not hit home, see also this tip - http://www.ninjatrader-support2.com/...ead.php?t=3418

          Comment


            #6
            Thanks for your help Bertrand and rt6176. I have added print statements and TraceOrder = true to my code and I am working on debugging. One thing to note: I only get the error when using MAX and BarSinceEntry("LongEntry"). Would this have to do with MAX or because of using BarsSinceEntry("LongEntry")? Does this make sense to you. If I take this part out it works fine, just not what I really want it to. Any thoughts?

            GT

            Comment


              #7
              Hi GT, this can be related to missing checks when using BarsSinceEntry() on the bar of trade entry. Please use this code snippet below to check if BarsSinceEntry() contains a valid value to be referenced -

              Code:
              if (BarsSinceEntry() > 0 || BarsSinceEntry() == -1)
              {
              then determine the stop value with your MyVar2 code
              }
              Last edited by NinjaTrader_Bertrand; 01-22-2009, 02:05 PM.

              Comment


                #8
                Perfect! That did the job. I have never seen that before. Are there other "basic" checks that should be done like this? Thank you!

                GT

                Comment


                  #9
                  You are welcome - you will oftentimes need to check for 'improper' values from methods, basically you can see this when debugging your variable / calculation values with Print() and being on the lookout for erratic values. Unfortunately there is no comprehensive list available, as strategies and codes change and different implementations are needed. Thanks!

                  Comment


                    #10
                    Correction: Unfortunately it did not work in real-time this morning only on historical data yesterday. From the log file: 1) Stop price must not be 0 (Stop price must not be 0) and 2) Error on calling 'OnBarUpdate' method for strategy 'StrategyOne: Object reference not set to an instance of an object. I thought we had it. Any idea on things to check? Thanks!

                    GT

                    Comment


                      #11
                      Hi GT, then you will need another check if your MyVar2 is > 0 before submitting the stop. For the other error, please post your full code, so we can take a look at it. Thanks!

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      625 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      359 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
                      562 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      567 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X