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

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 sidlercom80, 10-28-2023, 08:49 AM
        172 responses
        2,279 views
        0 likes
        Last Post sidlercom80  
        Started by Irukandji, Yesterday, 02:53 AM
        2 responses
        17 views
        0 likes
        Last Post Irukandji  
        Started by adeelshahzad, Today, 03:54 AM
        0 responses
        4 views
        0 likes
        Last Post adeelshahzad  
        Working...
        X