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

Help to convert from double to int

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

    Help to convert from double to int

    I trying to build an indicator using Bollinger Bands with a variable period. The data I'm using for the variable period starts out as a double, and as you know, the period parameter of the Bollinger function will only accept an int (integer).

    Does anybody know how I can convert my double variable (data) to an int variable to be used in the following;

    Bollinger(1,data).Lower

    Any help would be greatly appreciated.

    Safetrading

    #2
    Try
    Code:
    Bollinger(1,[B](int)[/B]data).Lower
    mrlogik
    NinjaTrader Ecosystem Vendor - Purelogik Trading

    Comment


      #3
      Originally posted by mrlogik View Post
      Try
      Code:
      Bollinger(1,[B](int)[/B]data).Lower
      Thanks, I hope I can trouble once more. That worked great, but I still have a problem executing the code. It doesn't give an error, but it will not draw my indicator.

      The problem now is my two variables, PastHigh and PastLow. If I substitute numbers for them, it will draw the indicator, but when I try to use the variables, it draws nothing?

      if(CurrentBar<63) return;

      double PastHigh = HighestBar(SMA(63),24);
      double PastLow = LowestBar(SMA(63),24);
      double diff = Instrument.MasterInstrument.Round2TickSize(PastHig h - PastLow)/0.25;
      double data = 34 - (diff * 1.5);
      DrawRegion(
      "No Trade Zone", CurrentBar, 0, Bollinger(2, (int)data).Lower, Bollinger(2, (int)data).Upper, Color.Transparent, Color.HotPink, 2);

      Any thoughts?

      Safetrading

      Comment


        #4
        Safetrading, have you printed out the values to see what is actually going on? To verify what you think should be happening, you can do something like this:
        Code:
        [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] PastHigh = HighestBar(SMA([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]63[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]),[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]24[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);
        Print("PastHigh: " + PastHigh);
        [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] PastLow = LowestBar(SMA([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]63[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]),[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]24[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);
        Print("PastLow: " + PastLow);
        [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] diff = Instrument.MasterInstrument.Round2TickSize(PastHig  h - PastLow)/[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0.25[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];
        Print("diff: " + diff);
        [/SIZE][/FONT][/SIZE][/FONT]

        Then to view the output, you can open up the output window from the Tools menu.

        AustinNinjaTrader Customer Service

        Comment


          #5
          Thanks

          Thanks, I will give this a try.

          Originally posted by NinjaTrader_Austin View Post
          Safetrading, have you printed out the values to see what is actually going on? To verify what you think should be happening, you can do something like this:
          Code:
          [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] PastHigh = HighestBar(SMA([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]63[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]),[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]24[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]Print("PastHigh: " + PastHigh);[/FONT][/SIZE]
          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] PastLow = LowestBar(SMA([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]63[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]),[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]24[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]Print("PastLow: " + PastLow);[/FONT][/SIZE]
          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] diff = Instrument.MasterInstrument.Round2TickSize(PastHig  h - PastLow)/[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0.25[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]Print("diff: " + diff);[/FONT][/SIZE]
          [/SIZE][/FONT]

          Then to view the output, you can open up the output window from the Tools menu.

          Comment


            #6
            calcs using Integers should be double, but not

            having trouble with int and doubles

            tickPB is an int
            delta is a double

            delta = tickPB / 10; Print("delta "+delta.ToString());

            when tickPB=10, then delta is 1
            but when tickPB=9, delta is 0, should be 0.9

            what am i missing? tia

            Comment


              #7
              delta =(double) tickPB / 10;

              or

              delta = tickPB / 10.0;

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by AttiM, 02-14-2024, 05:20 PM
              12 responses
              213 views
              0 likes
              Last Post DrakeiJosh  
              Started by cre8able, 02-11-2023, 05:43 PM
              3 responses
              237 views
              0 likes
              Last Post rhubear
              by rhubear
               
              Started by frslvr, 04-11-2024, 07:26 AM
              8 responses
              116 views
              1 like
              Last Post NinjaTrader_BrandonH  
              Started by stafe, 04-15-2024, 08:34 PM
              10 responses
              47 views
              0 likes
              Last Post stafe
              by stafe
               
              Started by rocketman7, Today, 09:41 AM
              3 responses
              11 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X