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 with print in barsinprogress 2

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

    help with print in barsinprogress 2

    Hi i have the following code inside onbarupdate scope but its not printing in output. It only prints in historical

    region Bars in progress 2
    else if (BarsInProgress == 2)
    {
    if (CurrentBars[0] < 2 || CurrentBars[2] < 2)
    return;
    if(Close[1] > Open[1] && Close[2] < Open[2])
    {
    HTFBull = true;
    if (IsFirstTickOfBar)
    {
    Print("HTFBull "+HTFBull);
    Print("bullCandlePercent:" + bullCandlePercent + ": Time :" + Time[1] + "high[1]" + High[1]);
    }

    }
    else
    {
    HTFBull = false;
    }

    if(Close[1] < Open[1] && Close[2] > Open[2])
    {
    HTFBear = true;
    if (IsFirstTickOfBar)
    {
    Print("HTFBear"+HTFBear);
    Print("bearCandlePercent:"+bearCandlePercent + ": Time :" + Time[1] + "low[1]" + Low[1]);
    }

    }
    else
    {
    HTFBear = false;
    }

    }
    #endregion​​

    #2
    Hello tkaboris,

    Thank you for your note.

    Do you mean that it is not printing once the script reaches State.Realtime? You mentioned that it does print in historical. Have you tried printing the state of the script? You could add a print in the beginning of OnStateChange() that shows the state, then determine when the prints are working from within OnBarUpdate():
    Code:
    protected override void OnStateChange()
    {​
    Print("State changed.  State: " + State);
    // the rest of your OnStateChange logic
    }
    Please try adding this, then attach your output to your response. You may save the output to a text file by right-clicking the NinjaScript Output window then Save As.

    Do you see any errors in the Log tab of the Control Center? If so, what do the errors report?

    I look forward to your reply.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      thank you its working now I had to mark in strategy itself.
      How can I make sure that It prints only once onfirsttickofbar.
      Right now my barsinprogress =2 is 5 min and main strategy is on ticks
      but it prints several times during those 5 mins.

      Comment


        #4
        hmm..
        my output is alterating between bear and bull true and its not correct. Current barsinprogresss=2 5 mins are all bulls not bears....
        What is going on?
        Thank you

        HTFBearTrue
        bearCandlePercent:0: Time :8/11/2023 2:06:46 PMlow[1]15105.75
        HTFBull True
        bullCandlePercent:0.0704225352112676: Time :8/11/2023 2:08:05 PMhigh[1]15101
        HTFBearTrue
        bearCandlePercent:0: Time :8/11/2023 2:08:37 PMlow[1]15095​

        Comment


          #5
          Hello tkaboris,

          Thank you for your reply.

          Since the condition to set HTFBear to true or HTFBull to true relies on the values of Close[1], Open[1], Close[2], and Open[2] you will need to add those values to additional print statements. I suggest printing the value of BarsInProgress to see when OnBarUpdate is processing which BarsInProgress (and ensure your logic is only running on the desired BarsInProgress) as well as printing those values for the open and close of 1 bar ago and 2 bars ago to better understand whether HTFBear and HTFBull should be true or false. You can also print the value of IsFirstTickOfBar to see which prints are printing when that is true, and which prints might be printing when that is false. This will let you know if you need to enclose prints into additional conditions checking for IsFirstTickOfBar to be true.

          Please let me know if I may be of further assistance.
          Emily C.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by jxs_xrj, 01-12-2020, 09:49 AM
          6 responses
          3,290 views
          1 like
          Last Post jgualdronc  
          Started by Touch-Ups, Today, 10:36 AM
          0 responses
          8 views
          0 likes
          Last Post Touch-Ups  
          Started by geddyisodin, 04-25-2024, 05:20 AM
          8 responses
          61 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by Option Whisperer, Today, 09:55 AM
          0 responses
          8 views
          0 likes
          Last Post Option Whisperer  
          Started by halgo_boulder, 04-20-2024, 08:44 AM
          2 responses
          24 views
          0 likes
          Last Post halgo_boulder  
          Working...
          X