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

Enter order delayed 1 bar on range bars strategy

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

    Enter order delayed 1 bar on range bars strategy

    I created a custom indicator and now I’m trying to write a strategy to test it.
    The indicator runs on range bars (6 range or 4 range), and once a certain condition is achieved, will print a dot in the bar. I will enter at the opening of the following bar. This is a pseudo code:

    CUSTOM INDICATOR:
    If (condition) and FirstTickOfBar
    {
    DrawDot ( bar[1]);
    BullIndication.Set(true);
    }

    Then in my strategy I do the following:
    Initialize()
    {
    CalculateOnBarClose = false;
    CustomIndicator = customIndicator( parameters…);
    Add(CustomIndicator);
    }
    OnBarUpdate()
    {
    If (CustomIndicator.BullIndication[0])
    {
    EnterLong(“LONG”);
    }
    }

    The problem I’m having is that the strategy is entering 1 bar delayed. I was supposed to enter at the close of the bar with the DOT, and instead it’s sending the EnterLong signal a bar after that, which produces very wrong results to the entire scalping strategy since it’s too late.
    Anybody knows how to solve this problem and oblige my strategy to issue the “EnterLong” at the close of the bar with the dot?
    Thanks!

    #2
    Hello,

    Are you seeing this in historical back testing, or do you also see the delay in processing in real-time?

    If you put the DrawDot function on the strategy itself when the condition is true, does it plot where you would expect, or is this also a bar behind?
    MatthewNinjaTrader Product Management

    Comment


      #3
      Historical backtesting for the last 3 months using the strategy analyzer.

      I haven't run the strategy real time.

      Comment


        #4
        Originally posted by ds1111 View Post
        I created a custom indicator and now I’m trying to write a strategy to test it.
        The indicator runs on range bars (6 range or 4 range), and once a certain condition is achieved, will print a dot in the bar. I will enter at the opening of the following bar. This is a pseudo code:

        CUSTOM INDICATOR:
        If (condition) and FirstTickOfBar
        {
        DrawDot ( bar[1]);
        BullIndication.Set(true);
        }

        Then in my strategy I do the following:
        Initialize()
        {
        CalculateOnBarClose = false;
        CustomIndicator = customIndicator( parameters…);
        Add(CustomIndicator);
        }
        OnBarUpdate()
        {
        If (CustomIndicator.BullIndication[0])
        {
        EnterLong(“LONG”);
        }
        }

        The problem I’m having is that the strategy is entering 1 bar delayed. I was supposed to enter at the close of the bar with the DOT, and instead it’s sending the EnterLong signal a bar after that, which produces very wrong results to the entire scalping strategy since it’s too late.
        Anybody knows how to solve this problem and oblige my strategy to issue the “EnterLong” at the close of the bar with the dot?
        Thanks!
        What is the COBC setting for the indicator that the strategy is calling?

        Comment


          #5
          Both strategy and indicator: COBC = false;

          Comment


            #6
            Originally posted by ds1111 View Post
            Both strategy and indicator: COBC = false;
            That may be the problem .I see that you are using a named instance of the indicator in your strategy. Explicitly set the COBC property on that instance.

            Comment


              #7
              Ok... this is what I did in my strategy code:

              Initialize()
              {
              CalculateOnBarClose = false;
              CustomIndicator = customIndicator( parameters…);
              Add(CustomIndicator);
              CustomIndicator.CalculateOnBarClose = false;
              }

              Still I didn't see any difference in the behavior when I run the strategy. See picture attached. I'm still delayed 1 bar.

              PS: btw, my indicator is a multi-timeframe strategy. That's why I'm using FirstTickOfBar in the indicator code to print the entry dots. Not sure if there is anything to do with this problem (and I believe it doesn't), but just would like to add this info out there.
              Attached Files
              Last edited by ds1111; 04-23-2012, 12:31 PM.

              Comment


                #8
                Hello,

                The added series is likley a factor here.

                Can you please clarify what interval the strategy runs on and which interval you have Add() to the strategy? 6 range or 4 range?

                Under what BarsInProgress are you submitting the order? BarsInProgress == 0?

                If you're not familiar with BIP, please take a look at the following link under 'How Bar Data is Referenced' and True Event Driven OnBarUpdate() Method

                MatthewNinjaTrader Product Management

                Comment


                  #9
                  Just the indicator is using multitime frame, not the strategy.

                  I use a higher timeframe with 8 range bars to do some calculations, but the indicator runs on 6 range bars. All the logic that will trigger the 'dot' printing (and an entry) is processed in BIP = 0. As said, I use BIP = 1 just for some basic calculations, the results is passed to the code under BIP = 0.

                  Thanks for any help... I'm really puzzled by this... maybe the solution is to remove the entire higher time frame code to check if it's what is causing the problem.

                  Comment


                    #10
                    Hello,

                    Thanks for the clarification - unfortunately there is not enough information here to know exactly what is occuring. I can only recommend that you do remove the higher time frame and continue to debug the strategy.

                    If you have not yet, please review our forum post for some ideas on debugging your custom NinjaScript code:

                    MatthewNinjaTrader Product Management

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by michi08, 10-05-2018, 09:31 AM
                    5 responses
                    741 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by The_Sec, Today, 02:29 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post The_Sec
                    by The_Sec
                     
                    Started by tsantospinto, 04-12-2024, 07:04 PM
                    4 responses
                    62 views
                    0 likes
                    Last Post aligator  
                    Started by sightcareclickhere, Today, 01:55 PM
                    0 responses
                    1 view
                    0 likes
                    Last Post sightcareclickhere  
                    Started by Mindset, 05-06-2023, 09:03 PM
                    9 responses
                    259 views
                    0 likes
                    Last Post ender_wiggum  
                    Working...
                    X