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

Convert type void to double

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

    Convert type void to double

    I am trying to display a dot above the high or below the low when the close[0] crosses the Bollinger bands. Here is example of the code I wrote:

    Code:
    [FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] OnBarUpdate()
    {
    Upper.Set(SMA(Period)[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] + NumStdDev * StdDev(Period)[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]]);
    Middle.Set(SMA(Period)[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]]);
    Lower.Set(SMA(Period)[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] - NumStdDev * StdDev(Period)[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]]);[/SIZE][/FONT]
    [FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] upperBand = Bollinger.Upper([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]14[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] lowerBand = Bollinger.Lower([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]14[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
    [FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]// Paint a dot when price crosses Upper or Lower Bollinger band.
    [/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (Close[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] > upperBand)
    {
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]// Paints a red dot on the current bar 1 tick above the high
    [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]DrawDot([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"tag1"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], High[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] + TickSize, Color.Red);
    }
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (Close[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] < lowerBand)
    {
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]// Paints a blue dot on the current bar 1 tick below the low 
    [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]DrawDot([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"tag2"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], Low[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] - TickSize, Color.Blue);
    }
    [/SIZE][/FONT]
    My question is: Since I want to compare a value Close[0], which is a double, with a method how do I convert it to a double. Or is this the wrong approach to take. Thanks in advance.

    #2
    That will not compile. You need to do:
    Code:
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] upperBand = Bollinger[/SIZE][/FONT][FONT=Courier New][SIZE=2]([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]14[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT][FONT=Courier New][SIZE=2].Upper[0][/SIZE][/FONT][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
    The [] indexing is to access the double value stored by the Bollinger band.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh, that works

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by ChartTourist, 04-27-2024, 08:22 AM
      3 responses
      55 views
      0 likes
      Last Post ChartTourist  
      Started by r68cervera, Today, 04:45 AM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by AveryFlynn, 04-25-2024, 04:57 AM
      2 responses
      17 views
      0 likes
      Last Post RogerHall  
      Started by NJA_MC, 01-03-2021, 10:34 PM
      12 responses
      158 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by ageeholdings, Today, 05:22 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X