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

GetBar values cant be divided by another.

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

    GetBar values cant be divided by another.

    Hi. Aparently GetBar values cant be divided by another and will always output 1

    I used
    int max2 = Bars.GetBar(savedMax[savedMax.Count-2].Time);
    int min2 = Bars.GetBar(savedMin[savedMin.Count-2].Time);
    Print (min2);
    Print (max2);
    Print (min2-max2);
    Print (min2/max2);
    Print ("stop");
    and what i got was this?
    704
    683
    21
    1
    stop
    1418
    1404
    14
    1
    stop
    3317
    3282
    35
    1
    stop
    3990
    3950
    40
    1
    stop
    4020
    3998
    22
    1
    stop
    6415
    6373
    42
    1
    stop
    6517
    6450
    67
    1
    stop
    8159
    8116
    43
    1
    stop
    9114
    9043
    71
    1
    stop
    9740
    9711
    29
    1
    stop
    10568
    10546
    22
    1
    stop
    10611
    10580
    31
    1
    stop

    anyone knows how to fix this?

    EDIT: oopsy, this was supposed to go in general programming, but i guess it doesnt make much of a diffrence.
    Last edited by BigRo; 11-12-2015, 12:18 PM.

    #2
    Hello,

    I believe you are just running into trying to divide Integer's which are not able to be divided. Instead you would need to cast these as doubles or:

    Print ((double)min2/(double)max2);

    Or as a result:

    double result = (double)min2 / (double)max2;

    Please try this and see if you now get a result in your script.


    I look forward to being of further assistance .
    JesseNinjaTrader Customer Service

    Comment


      #3
      9114
      9043
      71
      1,0078513767555
      stop
      9740
      9711
      29
      1,00298630419112
      stop
      10568
      10546
      22
      1,00208609899488
      stop
      10611
      10580
      31
      1,00293005671078
      stop


      chi ching
      thanks

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by lightsun47, Today, 03:51 PM
      0 responses
      4 views
      0 likes
      Last Post lightsun47  
      Started by 00nevest, Today, 02:27 PM
      1 response
      8 views
      0 likes
      Last Post 00nevest  
      Started by futtrader, 04-21-2024, 01:50 AM
      4 responses
      44 views
      0 likes
      Last Post futtrader  
      Started by Option Whisperer, Today, 09:55 AM
      1 response
      13 views
      0 likes
      Last Post bltdavid  
      Started by port119, Today, 02:43 PM
      0 responses
      9 views
      0 likes
      Last Post port119
      by port119
       
      Working...
      X