Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

IsFirstTickOfBar

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

    IsFirstTickOfBar

    I am trying to use IsFirstTickOfBar to reset a bool once per candle. I am also using calculate.OnPriceChange which seems to be conflicting some how as the bool is being reset on every price change not just on the first tick of each bar.

    Do I need to specify a dataseries or something for this?

    #2
    Here are my relevant snippets of code.

    Code:
    if (IsFirstTickOfBar)
    {
    Print("reset okToTrade to TRUE on first tick of bar");
    okToTrade = true;
    }
    Code:
    if (!isTradeActive)
    {
    EnterLongPositionsIfAllowed();
    Print("Entered Long " + Position.AveragePrice);
    okToTrade = false;
    Print("okToTrade = False");
    }


    I am printing Time[0] and this is on a 15m candle chart. You can see the bool is being reset every second or so.

    ​​Click image for larger version

Name:	image.png
Views:	116
Size:	7.7 KB
ID:	1303949

    Comment


      #3
      Hello sofortune,

      What bars type are you using? There are some bars types where IsFirstTickOfBar would be always true, that would include items like renko bars.

      Comment


        #4
        I am just using regular candlestick bars

        Comment


          #5
          Hello sofortune,

          For the given example I am unsure why that may be happening, I can see on my end this works to print only on the first tick of the bar when I test this in realtime on a 10 second bar series. I get 1 print per bar.

          Code:
          protected override void OnBarUpdate()
          {
               if(IsFirstTickOfBar)
               {
                    Print("FirstTick");
               } else {
                    Print("Not first tick");
               }
          }


          Keep in mind on historical bars IsFirstTickOfBar is always true so you should initially see that every bar IsFirstTickOfBar is true, only in realtime you will see that become false when its not the first tick.

          Comment


            #6
            Hello, I found the problem is because i have thsi tick data series.

            Code:
            AddDataSeries(BarsPeriodType.Tick, 1);      // Secondary series with tick bars (or any other desired granularity)
            I added this because I want the entry to occur in real time, I am not actually sure if it is necessary or not to achieve that, or is Calculate.OnPriceChange adequate?

            Or is there a way to specifiy the data series IsFirstTickOfBar refers to?

            Comment


              #7
              Hello sofortune,

              A 1 tick bar would mean that every tick is the first tick of its bar because there is only 1 tick per bar. The concept of firs tick of bar would only apply to bars that have at least more than 1 tick.

              If you are using OnPriceChange then you don't need a secondary 1 tick series, in realtime the script will work tick by tick but only process if there is a change in price.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Yesterday, 05:17 AM
              0 responses
              62 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              134 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              75 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              45 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              50 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X