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

Error with my bool?

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

    Error with my bool?

    Hello,

    I have been spinning my tires on this and I can't seem to figure out what is going wrong here. I have a strategy that, when I compile, there are no errors. However, when I try to enable my strategy it attempts to and then does nothing. When I review my output this is the error which is posted

    "Strategy 'Tagalong5open': Error on calling 'OnBarUpdate' method on bar 90: Unable to cast object of type 'NinjaTrader.NinjaScript.Series`1[System.Double]' to type 'System.IConvertible'."

    When I block off the following code (which is found under the "OnBarUpdate" section) within my strategy it will enable. This leads me to believe that this is where the problem lies

    if(Close[0] > Convert.ToInt32(Bollinger(Close,2,BB_Length).Upper )) {UBB_Cross = true; LBB_Cross = false;}
    if(Close[0] < Convert.ToInt32(Bollinger(Close,2,BB_Length).Middl e)) {UBB_Cross = false; MBB_Cross_Dn = true;}
    if(Close[0] < Convert.ToInt32(Bollinger(Close,2,BB_Length).Lower )) {LBB_Cross = true; UBB_Cross = false;}
    if(Close[0] > Convert.ToInt32(Bollinger(Close,2,BB_Length).Middl e)) {LBB_Cross = false; MBB_Cross_Up = true;}

    Essentially, what I am attempting to accomplish is to have my strategy react differently once it crosses different points within a specified Bollinger Band. I am using the above code to update bools to keep track of when the price closes beyond the upper band, lower band, and middle band.

    Can anyone recognize what is holding me up here?...

    Thanks for your help.

    #2
    Hello Kensonprib,

    Thank you for your post.

    The Bollinger Bands indicator is a Series<double> which means that it must be indexed to get a value.

    Code:
    if(Close[0] > Convert.ToInt32(Bollinger(Close,2,BB_Length).Upper[0] )) {UBB_Cross = true; LBB_Cross = false;}
    See the help guide documentation for more information.
    Bollinger Bands - https://ninjatrader.com/support/help...nger_bands.htm

    Let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hey BrandonH,

      Thanks for the feedback. Unfortunately, this did not resolve the issue. Could there be anything else?

      Kenson

      Comment


        #4
        I have now separated out the Bollinger portion and replaced it with the following UBB, MBB, and LBB variables.

        UBB = Bollinger(Close,2,BB_Length).Upper[0];
        MBB = Bollinger(Close,2,BB_Length).Middle[0];
        LBB = Bollinger(Close,2,BB_Length).Lower[0];

        The portion above works and allows it to enable. The following code doesn't allow it to enable...

        if(Close[0] > UBB) {UBB_Cross = true; LBB_Cross = false;}
        if(Close[0] < MBB) {UBB_Cross = false; MBB_Cross_Dn = true;}
        if(Close[0] < LBB) {LBB_Cross = true; UBB_Cross = false;}
        if(Close[0] > MBB) {LBB_Cross = false; MBB_Cross_Up = true;}

        Does anyone see anything amiss? The LBB_Cross, UBB_Cross and MBB_Cross variables are all type bool and the UBB, MBB, and LBB are all type double.

        Comment


          #5
          Hello Kensonprib,

          Thank you for your note.

          When testing the following code I was able to add the strategy to the chart and enable it without issue.

          Code:
          if(Close[0] > Convert.ToInt32(Bollinger(Close,2,BB_Length).Upper[0] )) {UBB_Cross = true; LBB_Cross = false;}
          if(Close[0] < Convert.ToInt32(Bollinger(Close,2,BB_Length).Middle[0])) {UBB_Cross = false; MBB_Cross_Dn = true;}
          if(Close[0] < Convert.ToInt32(Bollinger(Close,2,BB_Length).Lower[0])) {LBB_Cross = true; UBB_Cross = false;}
          if(Close[0] > Convert.ToInt32(Bollinger(Close,2,BB_Length).Middle[0])) {LBB_Cross = false; MBB_Cross_Up = true;}
          See the attached script, TestStrategy2, which demonstrates this. The example script uses the above code and also prints out the values of the bools.

          Let us know if we may further assist.
          Attached Files
          Last edited by NinjaTrader_BrandonH; 05-14-2021, 11:02 AM.
          Brandon H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by algospoke, Today, 06:40 PM
          0 responses
          9 views
          0 likes
          Last Post algospoke  
          Started by maybeimnotrader, Today, 05:46 PM
          0 responses
          7 views
          0 likes
          Last Post maybeimnotrader  
          Started by quantismo, Today, 05:13 PM
          0 responses
          7 views
          0 likes
          Last Post quantismo  
          Started by AttiM, 02-14-2024, 05:20 PM
          8 responses
          168 views
          0 likes
          Last Post jeronymite  
          Started by cre8able, Today, 04:22 PM
          0 responses
          10 views
          0 likes
          Last Post cre8able  
          Working...
          X