Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EMA Cross Strategy

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

    EMA Cross Strategy

    I seem to get an error when I run a strategy and It buys let's say, 100 shares when the EMA's cross.
    Then at a point (when the EMA's cross again) it should sell the 100 shares and short 100 shares.

    That's where I get the error. It will close the first position and not open
    the new one. See below code. Is this not correct? It works great in
    back test mode, but for some reason I get errors when it is live and
    the strategy stops.

    // Condition set 1
    if (CrossAbove(EMA(Fast), EMA(Slow), 1))
    {
    EnterLong(Shares, "EMA System Long");
    PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\Alert4.wav");
    }
    else if (CrossBelow(EMA(Fast), EMA(Slow), 1))
    {
    EnterShort(Shares, "EMA System Short");
    PlaySound(@"C:\Program Files\NinjaTrader
    6.5\sounds\Alert4.wav");
    }

    #2
    Please be more specific as to what errors you are getting. Thank you.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Strategy ‘SRSSYSTEM’ submitted an order that generated the following error ‘OrderRejected’. Strategy has sent cancel requests, attempted to close the position and terminated itsef.


      Multiple open sell/buy cover orders in this security may result in an oversold/overbought position in your account. Affecte4d Order BuyToCover 100 Market

      Comment


        #4
        Live? Sim? What brokerage connection are you using?
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Live. TDAmeritrade.

          Comment


            #6
            For TDA, you may need to explicitly exit and then enter with ExitLong() and then EnterShort().
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              I was thinking that, but how do I handle if I don't have any shares... like for the first trade of the day? Can you help me? Would I just add ExitLong() before the EnterShort()?

              Comment


                #8
                Here's what I have now:

                // Condition set 1
                if (CrossAbove(EMA(Fast), EMA(Slow), 1))
                {
                ExitShort("Exit Short", "EMA System Short");
                EnterLong(Shares, "EMA System Long");
                PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\Alert4.wav");
                }
                else if (CrossBelow(EMA(Fast), EMA(Slow), 1))
                {
                ExitLong("Exit Long", "EMA System Long");
                EnterShort(Shares, "EMA System Short");
                PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\Alert4.wav");
                }
                }

                Comment


                  #9
                  An Exit order is ignored if no position is previously held. There should be no problems there.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    I get an error on NINJA but it does execute. A pop up boxes pops up and I click everything is ok. Seems like the ExitLong() is messing things up if there is no position open.

                    Comment


                      #11
                      Hello,

                      Josh's post is correct. However provide us with a screen shot of your error and/or send us your log and trade files from Help>Mail to support and reference this thread link.
                      DenNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      558 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      324 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      101 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      545 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      547 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X