Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Not even sure what to title this

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

    Not even sure what to title this

    The following line of code is running in a strategy, with the instrument being the CL:

    if(revToLong == true && High[0] >= Highs[0][0]+ 0.04)

    The primary series is a range bar and the secondary series is a 1 tick bar. Overall, the strategy has been doing what it's supposed to, with a glitch once in a while. What the code is doing is effecting a block (with the entry orders) to execute when the High[0] (the tick series) is above or equal to the high of the most recently completed primary series bar plus 0.04.

    Here is what the chart looks like:

    Click image for larger version

Name:	first.png
Views:	1
Size:	3.8 KB
ID:	898316

    The point at the blue arrow shows a previous stop out, but it is also 4 ticks above the high of the prior bar.

    If I use this code:

    if(revToLong == true && High[0] >= Highs[0][0]+ 0.0399999)

    or this:

    if(revToLong == true && High[0] + 0.00001 >= Highs[0][0]+ 0.04)

    Then the chart looks correct like this...

    Click image for larger version

Name:	second.png
Views:	1
Size:	5.2 KB
ID:	898317

    It seems like somehow the values in the data series are not evaluating at exactly what they should. I also noticed that by playing with the fudge factors in the two lines of code above, it can make my reversals plot correctly, even though the fudge factors are several decimal places smaller than the tick increment of the instrument.

    Any idea what's going on and how to resolve?

    Thanks.

    #2
    Coolmoss,

    How are you separating by bars in progress?

    High[0] >= Highs[0][0]+ 0.0399999

    May never be true or sometimes true unless you handle it right.

    What is your COBC setting? What is the expiry for CL?
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      This is how I have it set up. Nothing exists outside these two blocks. Thanks much for your help.

      if(BarsInProgress == 0)
      {
      //code
      }

      if(BarsInProgress == 1)
      {
      if( revToShort == true && Close[0] <= Lows[0][0]-entryOffset*TickSize )
      {
      Print("begin short reversal block");

      }
      if(revToLong == true && Close[0] >= Highs[0][0]+ entryOffset*TickSize)
      {
      Print("begin long reversal block");
      }
      }

      Comment


        #4
        Hi coolmoss, I'm not exactly sure what 'fugde factors' are but, have you considered rounding your values used for comparison to the tick size of the used instrument?

        Comment


          #5
          Hi Bertrand,

          What would I round? The code has only High[0] and the number 0.04, which is same number of decimal places as the instrument.

          Is my partitioning of the barsinprogress okay?

          Comment


            #6
            I would suggest to try rounding this whole statement here -

            Lows[0][0]-entryOffset*TickSize

            so

            Instrument.MasterInstrument.Round2TickSize(Lows[0][0]-entryOffset*TickSize)

            Comment


              #7
              Thanks Bertrand. That seems to have resolved the issue. This will probably fix some other issues too. I didn't realize that something like this could need rounding. Another great lesson learned

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              647 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              368 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              108 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              571 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              573 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X