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

Indicator False Calculated Cross Causes Position Hold

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

    Indicator False Calculated Cross Causes Position Hold

    Utilizing a simple indicator cross to enter/exit position. Below is attached an image for visual explanation.

    1. Due to strategy Calculating "on tick change" it appears that the cross is being calculated or anticipated.
    2. The strategy anticipated a cross, so it exited long and entered short where the yellow arrow indicates, just perfectly as it should.
    3. However, as you can see after the next candle formed, historically the indicators never crossed. Instead of the strategy selling the long and switching direction, it held the long into larger than i'd like losses. I believe this is due to the strategy looking for a indicator cross back in the other direction, but since it never crossed in the first place it gets stuck holding the long when it should have been in a short.
    4. The strategy has to wait for the indicators to cross up (truly cross up) then cross back down before it can exit this previously wrong cross position.

    Click image for larger version

Name:	264791597_495139388478157_5906307925128813150_n.png
Views:	160
Size:	25.6 KB
ID:	1182170

    I changed the strategy to "calculate on bar close" and it seems like this is a solution but brings up a secondary issue. Having to wait till previous bars close, the strategy enters late or exits late sacrificing profitable time in position.

    Any assistance or recommendations would be appreciated on how to keep Calculate "on each tick" but force the strategy to almost confirm this. The strategy works very nicely other than about 1-2 times a week when the above scenario presents itself and we don't get a true cross.

    #2
    This sounds like a classic case of 'pick your poison'.

    If you feel the PnL from using OnEachTick is worth it, then stay
    the course.

    However,
    If the PnL is suffering too much for those 1-2 times a weeks when
    the anticipated cross fails to follow through at BarClose, well, then
    the usual remedy to fix that is: stop using OnEachTick for your entry
    logic.

    There is no crystal ball that is 100% accurate.

    Your current crystal ball to predict your entry is by looking at your
    entry conditions early, by using OnEachTick.

    That's not foolproof.

    If you want a `100% guarantee' that the cross has happened before
    you enter the trade, you'll have to become patient and wait for a
    BarClose to have that guarantee. That is, stop using OnEachTick
    as a crystal ball to find your entries.

    That said, there might be a hybrid solution you could use.
    The trick might be looking at multiple time frames.

    For ex, if you're strategy runs on 5-minute chart, you might try to code
    logic to allow OnEachTick to find cross overs in the last 60 seconds
    of the 5 minute bar. But, be careful, that's not foolproof either. The
    cross could still undo itself completely before the bar actually closes.

    See what I mean about 'pick your poison'?

    If the PnL with OnEachTick is awesome (despite 1-2 known failures
    per week), then stay with it.

    If the 1-2 losses per week are painful, and tend to put you in the red,
    or eat up most of your profit, then, yeah, you gotta abandon using
    OnEachTick as a crystal ball, or come up with a hybrid solution.

    In summary, if you want a 'true cross', you'll have to wait for the bar
    to completely close to make it true 100% of the time.

    Make sense?
    Last edited by bltdavid; 12-18-2021, 04:35 PM.

    Comment


      #3
      You might try studying this sample for some ideas.

      Comment


        #4
        Originally posted by joshmock89 View Post
        Utilizing a simple indicator cross to enter/exit position. Below is attached an image for visual explanation.

        1. Due to strategy Calculating "on tick change" it appears that the cross is being calculated or anticipated.
        2. The strategy anticipated a cross, so it exited long and entered short where the yellow arrow indicates, just perfectly as it should.
        3. However, as you can see after the next candle formed, historically the indicators never crossed. Instead of the strategy selling the long and switching direction, it held the long into larger than i'd like losses. I believe this is due to the strategy looking for a indicator cross back in the other direction, but since it never crossed in the first place it gets stuck holding the long when it should have been in a short.
        4. The strategy has to wait for the indicators to cross up (truly cross up) then cross back down before it can exit this previously wrong cross position.
        Another idea is this:

        If the strategy enters a position before bar close (due the anticipated cross seen
        during OnEachTick processing) -- then at the real bar close you need to confirm
        that the cross condition really happened.

        In other words, your strategy only stays in the trade if the cross over condition
        that was found during OnEachTick is still true at BarClose.

        If the cross condition has failed to follow through at BarClose, then exit the trade.

        Comment


          #5
          Hello joshmock89,

          bltdavid is providing great information.

          However, I further suggest fully understanding the issue by debugging the script using prints to work out the logic necessary to get the behavior you want.

          Below is a link to a forum post that demonstrates how to add prints and read them from the NinjaScript Output window.

          https://ninjatrader.com/support/foru...121#post791121

          Please print the time of the bar, the position, as well as all values used in the condition.

          Then save the output to a text file and attach this with your reply.

          I will be happy to assist with analyzing the output.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            The attached code posted here might give you some good ideas.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by sidlercom80, 10-28-2023, 08:49 AM
            168 responses
            2,262 views
            0 likes
            Last Post sidlercom80  
            Started by Barry Milan, Yesterday, 10:35 PM
            3 responses
            10 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by WeyldFalcon, 12-10-2020, 06:48 PM
            14 responses
            1,429 views
            0 likes
            Last Post Handclap0241  
            Started by DJ888, 04-16-2024, 06:09 PM
            2 responses
            9 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            41 views
            0 likes
            Last Post jeronymite  
            Working...
            X