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

Printing in a Private Bool

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

    Printing in a Private Bool

    If the following Custom Method tested as FALSE, should the "ManyThingsCount" counter iterate and the print statement print to the output window?
    Code:
    private bool BarRises()
    {
            if ((Highs[2][1] - Lows[2][1]) < (Lows[2][1] * 0.13))
                return true;
        else
            return false;
            ManyThingsCount++;
            Print (Instrument.FullName + "  "+Times[0][0].ToString("MM/dd/yy  HH:mm:ss")+" : "+ManyThingsCount);
    }
    My goal is try to get a running count of my Custom Methods that are testing FALSE as they are calculated. (In this case, tick-by-tick.)

    If all of my custom methods iterate to the "ManyThingsCount", will this give tick-by-tick count I am looking for? If not, could you suggest a working version?

    Thanks in advance.
    Last edited by ArmKnuckle; 05-10-2019, 03:22 AM.

    #2
    Hello ArmKnuckle,

    Thanks for your post.

    When the code hits either return statement the counter would not be updated and the print statement would not be executed.

    When you have an if/else condition and you want to process multiple actions in one state of the other (or both), you would need to enclose those actions in "{ }". Any action to perform would have to be done before the return statement is hit. For example:

    private bool BarRises()
    {
    if ((Highs[2][1] - Lows[2][1]) < (Lows[2][1] * 0.13)
    {
    return true; // when true do not increment counter, do not print.
    }
    else
    {
    ManyThingsCount++; // Increment only when false
    Print (Instrument.FullName + " false "+Times[0][0].ToString("MM/dd/yy HH:mm:ss")+" : "+ManyThingsCount); // Print only when false
    return false;
    }
    }
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      I have constructed the Custom Method as you specified. The print statement to check on the counter total is not working when FALSE.

      I have also placed a counter and print statement for when the Custom Method is TRUE. The print statement is not working there, either.

      Being that the Custom Method is being evaluated on every tick, I should have numerous prints in the output window. FWIW, Custom Methods are placed outside of OnBarUpdate().

      Why isn't it working?
      Last edited by ArmKnuckle; 05-10-2019, 07:10 PM.

      Comment


        #4
        Originally posted by ArmKnuckle View Post
        I have constructed the Custom Method as you specified. The print statement to check on the counter total is not working when FALSE.

        I have also placed a counter and print statement for when the Custom Method is TRUE. The print statement is not working there, either.

        Being that the Custom Method is being evaluated on every tick, I should have numerous prints in the output window. FWIW, Custom Methods are placed outside of OnBarUpdate().

        Why isn't it working?
        Have you accounted for escaping the first bar? You need an escape for CurrentBars[2] < 1.
        What is the error in your log?
        Last edited by koganam; 05-10-2019, 10:56 PM.

        Comment


          #5
          Hello ArmKnuckle,

          Thanks for your reply.

          As member koganam asks, in the OnBarUpdate() are you checking for at least 2 bars to be loaded, in the 2nd added data series) before processing further? (Do you have any errors in the "log" tab of the NT8 control center).

          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by merzo, 06-25-2023, 02:19 AM
          10 responses
          823 views
          1 like
          Last Post NinjaTrader_ChristopherJ  
          Started by frankthearm, Today, 09:08 AM
          5 responses
          15 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          43 views
          0 likes
          Last Post jeronymite  
          Started by yertle, Today, 08:38 AM
          5 responses
          16 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by adeelshahzad, Today, 03:54 AM
          3 responses
          20 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X