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

Entry not triggering at the MACD Crossover

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

    Entry not triggering at the MACD Crossover

    I'm trying to enter a trade as soon as the MACD Crossover occurs but the strategy is entering a bar later see attached screenshots. I have set MACD at bars 0 and crossover is happening between MACD and Avg. Is there a way to set it so I am able to enter the long position as soon as the crossover happens?
    Attached Files

    #2
    Hello pyraxic,
    It seems you're using Calculate = Calculate.OnBarClose in your strategy, change it to Calculate = OnEachTick or OnPriceChange. It should work as expected.
    Hope it helps!

    Comment


      #3
      Thank you. I tried using OnPriceChange and OnEachTick but it's still entering the trade 1 bar late.

      Comment


        #4
        Hello pyraxic,
        Here you get a sample macd cross strategy, it will plot arrow up / down on your chart @ macd cross signal. For me I can't see the lag as you're getting, you can test this with your parameters & confirm. I've used standard parameters which you can change as per your need. Also attaching the snapshot for reference.
        [ATTACH]n1127583[/ATTACH]
        Click image for larger version

Name:	sample macd cross.jpg
Views:	311
Size:	46.4 KB
ID:	1127584

        Comment


          #5
          Can you share the strategy you are using? I see the long/short at the correct bar. I would like to see what you are using in your strategy that I may not be using.

          Comment


            #6
            Hello pyraxic,
            I attached it but it seems some issue, let me attach it again. Here you get it.
            SampleMACDcross.zip

            Comment


              #7
              Hello pyraxic,
              Just one thing I am suspecting is that after making the change to Calculate = Calculate.OnEachTick you must reset your strategy or you can remove it & add again on your charts. Any changes made to State.SetDefaults don't reflect by refresh (F5).
              Last edited by s.kinra; 11-15-2020, 04:55 AM.

              Comment


                #8
                Odd. I am using your strategy and it still enters long one bar late (see attached)
                Attached Files

                Comment


                  #9
                  Hello pyraxic,

                  s.kinra would be correct in that Calculate would need to be .OnEachTick.

                  Below is a link to a forum post that discusses this.


                  I would expect that in real-time data, orders would appear on the same bar the cross occurred on.

                  In your screenshot are these real-time orders or historical orders?

                  That said, in historical data, TickReplay (using historical tick data) would also be required for the historical orders to also be placed intra-bar.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello pyraxic,
                    Can you share your strategy? Also, I would like to know when you used my sample strategy are you facing any issue like lag ?

                    Comment


                      #11
                      I'm probably doing something terribly wrong. I am apparently taking a lot of trades using OnEachTick (see attached)
                      Attached Files

                      Comment


                        #12
                        Originally posted by s.kinra View Post
                        Hello pyraxic,
                        Can you share your strategy? Also, I would like to know when you used my sample strategy are you facing any issue like lag ?
                        I'm not seeing the lag anymore. It seems that I am taking a lot of trades I mentioned above.

                        Comment


                          #13
                          It seems you're able to get rid of lag. You can place orders within a condition to avoid this. Use if loop is first tick of bar & place orders in this loop so your order is placed only once per bar.

                          Comment


                            #14
                            If I wrap it inside the IsFirstTickOfBar, it doesn't trigger buy orders every time it crosses. The strategy entered 4 trades in past 15 days.

                            Code:
                            protected override void OnBarUpdate()
                            {
                              if (BarsInProgress != 0)
                                return;
                            
                              if (CurrentBars[0] < 1)
                                return;
                            
                              if(IsFirstTickOfBar) {
                                if (CrossAbove(MACD1.Default, MACD1.Avg, 1))
                                {
                                  EnterLong(Convert.ToInt32(DefaultQuantity), @"Long");
                                }
                              }
                            }

                            Comment


                              #15
                              Hello,
                              You need to loop as below:

                              Code:
                              if (CrossAbove(MACD1.Default, MACD1.Avg, 1))
                              {[INDENT]if(IsFirstTickOfBar)
                              {[/INDENT][INDENT=2]EnterLong(Convert.ToInt32(DefaultQuantity), @"Long");[/INDENT][INDENT]}[/INDENT]
                               }

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by inanazsocial, Today, 01:15 AM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Started by rocketman7, Today, 02:12 AM
                              0 responses
                              8 views
                              0 likes
                              Last Post rocketman7  
                              Started by dustydbayer, Today, 01:59 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post dustydbayer  
                              Started by trilliantrader, 04-18-2024, 08:16 AM
                              5 responses
                              23 views
                              0 likes
                              Last Post trilliantrader  
                              Started by Davidtowleii, Today, 12:15 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Davidtowleii  
                              Working...
                              X