Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Missing something very simple

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

    Missing something very simple

    Hi everyone , I know I'm missing something very simple here but I'm trying to print the result of a simple calculation and it always prints zero... can anyone help please:

    here's my snippet:

    Code:
    int countWins;
    int countAllTrades;
    countWins = 10;
    countAllTrades = 20;
    winPct = 100*(countWins/countAllTrades);
    Print("---- probabilities :-) ");
    Print("# countAllTrades = " + countAllTrades.ToString() + 
          ", countWins = " + countWins + " (" + winPct.ToString() + ")" );
    and here's what is printing..

    ---- probabilities :-)
    # countAllTrades = 20, countWins = 10 (0)

    not sure why I'm getting zero for the winPct...

    Can anyone help please?

    #2
    tradinghumble,

    You likely need to get your variable declaration out of OnBarUpdate(). Please declare your variables in the variable region of your code above the Initialize() method.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Josh View Post
      tradinghumble,

      You likely need to get your variable declaration out of OnBarUpdate(). Please declare your variables in the variable region of your code above the Initialize() method.

      Josh, I did that... put all the variable declarations outside of OnBarUpdate() using private ... still does not print. All the variables that I assign value they print ok but if there is calculation involved they won't print... very weird.

      Can you please shed a light?

      Comment


        #4
        Got the answer:

        winPct = 100*((float)countWins/(float)countAllTrades);

        thanks !!!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        152 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        89 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        131 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        127 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        107 views
        0 likes
        Last Post CarlTrading  
        Working...
        X