Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.

    BertrandNinjaTrader Customer Service

    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
          BertrandNinjaTrader Customer Service

          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.
              BertrandNinjaTrader Customer Service

              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!
                  BertrandNinjaTrader Customer Service

                  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!
                      BertrandNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Vulgoth_t_Destroyer, 05-09-2022, 04:45 PM
                      55 responses
                      5,449 views
                      0 likes
                      Last Post BartMan
                      by BartMan
                       
                      Started by DawnTreader, 05-08-2024, 05:58 PM
                      16 responses
                      52 views
                      0 likes
                      Last Post DawnTreader  
                      Started by tradingnasdaqprueba, 05-07-2024, 03:42 AM
                      15 responses
                      60 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by kevinenergy, Yesterday, 12:01 PM
                      8 responses
                      28 views
                      0 likes
                      Last Post kevinenergy  
                      Started by nightstalker, Today, 01:32 PM
                      1 response
                      12 views
                      0 likes
                      Last Post NinjaTrader_Zachary  
                      Working...
                      X