Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

incomprehensible behaviour of the EnterLongLimit() method

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

    incomprehensible behaviour of the EnterLongLimit() method

    Hello !
    I am trying to code a strategy takes trades based off touching a level 2 times.
    so first, i determine the level i want, then i check if the current bar has touched the level or not, if it did
    then i wait for the current candle to close first, then i place the order, so technically, the trade has to be taken
    on the second retest of a level.

    some context for what you see on the chart :" eventually i want to test the strategy on both green line and red line, each being a level ( high level, low level ) relative to a candle (the diamond in this case). for the purpose of debugging, i am limiting my algorithm to handle just one level at the moment which is the low level (green line).

    so as you can see on the chart, the first bar where the algorithm starts, the bar does not touch the green line, so all good, the next bar touches, we can confirm it did based off the logs, so all is good, we know now that the green level is tested we set that to true, now we have qualified a trade, the next candle that touches this level, needs to place a trade, that next candle is the one at 22:15 where my cursor is on the chart, however as you can see the trade is not taken, it is rather taken at the next one ..

    i have refactored my code a dozen time to debug this, this is the simplest way i have come up with, the issue seems to arise from the EnterLongLimit method(), not that I am blaming the method, of course it is me who's missing something, if anyone can elaborate on what am I doing wrong, much appreciate the help in advance !!
    here's a snippet of the script i have written, i can include more if needed.
    : "

    Click image for larger version  Name:	{88393965-0F79-41CB-8D89-3000D8F244E5}.png Views:	0 Size:	39.2 KB ID:	1330258

    "

    logs:
    Click image for larger version  Name:	{F5EE2E04-8983-4899-A734-C7EDCB12B437}.png Views:	0 Size:	15.3 KB ID:	1330256
    Click image for larger version  Name:	{09CE913D-2296-444D-BFA9-9F023BECA860}.png Views:	0 Size:	59.4 KB ID:	1330257​​
    Attached Files

    #2
    Hello greenberet,

    Do you see this working when testing in realtime? In a backtest fills always happen on the following bar after the condition had become true.

    Comment


      #3
      hello NinjaTrader_Jesse,
      I have no tried this strategy in realtime, however i found a primary fix at the moment, when checking whether the candle has touched or not, i am calling it on CurrentBar+1 and placing the long order at CurrentBar. it's behaving like I want it using this fix. i will update you when market opens to test out the previous attempt. thank you for the quick reply !!

      Comment


        #4
        Hello greenberet,

        I would suggest trying it in realtime to see if that is the case, if so that's an expected difference between backtesting and realtime.

        Comment


          #5
          Hi Jesse !
          i tried realtime, but i dont have much of a clue on how to refactor the code for realtime, i obviously cant use the onbarupdate correct? i ran the same code on the 1 second timeframe to test it out but nothing happened even the drawing didnt show

          Comment


            #6
            Hello greenberet,

            OnBarUpdate is used for both historical and realtime processing, that is the override that is called when a bar closes.

            If the script did not perform as expected in realtime you may need to use Print statements in the code to see which part is having a problem. When you apply the script it will first do a backtest over the bars that it was applied to and then it will enter realtime and continue processing from there.

            Comment

            Latest Posts

            Collapse

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