Announcement

Collapse
No announcement yet.

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.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    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.
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by MiCe1999, Today, 06:49 AM
          0 responses
          7 views
          0 likes
          Last Post MiCe1999  
          Started by gaz0001, 12-12-2023, 09:36 AM
          13 responses
          282 views
          0 likes
          Last Post kevinenergy  
          Started by timwey, Today, 06:01 AM
          0 responses
          6 views
          0 likes
          Last Post timwey
          by timwey
           
          Started by patrickgeys7, Today, 06:01 AM
          0 responses
          2 views
          0 likes
          Last Post patrickgeys7  
          Started by ayham12, Today, 05:42 AM
          0 responses
          11 views
          0 likes
          Last Post ayham12
          by ayham12
           
          Working...
          X