Announcement

Collapse
No announcement yet.

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.

    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.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          44 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          124 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          65 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X