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

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:	47
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.

      JesseNinjaTrader Customer Service

      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.
          JesseNinjaTrader Customer Service

          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.
              JesseNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by oneybuchi2, Today, 03:48 PM
              0 responses
              3 views
              0 likes
              Last Post oneybuchi2  
              Started by Graci117, 06-19-2024, 01:39 PM
              6 responses
              53 views
              0 likes
              Last Post Graci117  
              Started by farawayz, Today, 01:20 PM
              0 responses
              11 views
              0 likes
              Last Post farawayz  
              Started by rjm1903, Today, 01:10 PM
              0 responses
              6 views
              0 likes
              Last Post rjm1903
              by rjm1903
               
              Started by AH369, 06-21-2024, 11:09 AM
              3 responses
              21 views
              0 likes
              Last Post AH369
              by AH369
               
              Working...
              X