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

EMA crossing then EnterLong does work but with SMA corssing it's not

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

    EMA crossing then EnterLong does work but with SMA corssing it's not

    Hi,
    While developping a strategy I had a problem to place an entry order.
    So I used the builder to make sure I was not doing something wrong. I made it simple with 2 diffferent strategy to check:

    If fast EMA cross above slow EMA then place order
    If fast SMA cross above slow SMA then place order

    if (CrossAbove(EMA1, EMA2, 1))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }

    if (CrossAbove(SMA1, SMA2, 1))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }

    Everything is fine with EMA crossing but nothing happen with SMA (in playback).

    Any idea why when SMA is crossing there is no order placed ?
    Thank you

    #2
    Hello Ben01660,
    I feel you can use both crossover in a single strategy.
    Use below code :
    Code:
    if (CrossAbove(EMA1, EMA2, 1) || CrossAbove(SMA1, SMA2, 1))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }
    Possibly, when running separate strategies, one is getting disabled.
    Last edited by s.kinra; 11-01-2020, 09:01 AM. Reason: missed some details

    Comment


      #3
      Hello kinra,
      Thank you for your help.

      Yes at the beginning I had a strategy based on different EMA and SMA condition.
      But as soon as there is a condition with a SMA, no order entry is happening.
      I ran the 2 strategy one at a time to avoid any conflict.

      Just with SMA condition the order is not placed, I put a "Print" and I can see the text on the output, so the condition is true and work properly but no order submitted, with SMA crossing.

      Code:
      if (CrossAbove(SMA1, SMA2, 1))
      {
      EnterLong(Convert.ToInt32(DefaultQuantity), "");
      Print(string.Format("SMA crossing"));
      }
      And then if I change the code with EMA conditions, then the order is placed with the output text as well without issue.
      I'm really confused, as it is a very simple script. I might have a deeper problem hiden somewhere out of the code.

      Comment


        #4
        Hello Ben01660,
        Try to use SampleMACrossOver Strategy included with NT8, it should work for you. This is a SMA cross over strategy.

        Comment


          #5
          Hello Ben01660,

          Use prints to understand why the condition is not evaluating as true.

          Print the time of the bar, print the value of the sma on the previous and current bar, print the values of the second series on the previous and current bar.

          Below is a link to a forum post that demonstrates. Please watch the video 'Debugging using prints with the Strategy Builder'.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hello, Kinra and Chelsea

            Kinra: yes the SampleMACrossOver is working
            Chelsea: below the print output message.

            The traceorder helped me a lot I think.
            Compare to SampleMA, I am only go long because I want to set up the script step by step.
            Could the reason be that I don't have a proper trade exit strategy yet ? Just going long everytime, no stop loss no take profit no short order to take over.


            19/10/2020 06:30:03 Strategy 'MySMAcrossingUnlocked/212749565': Entered internal SubmitOrderManaged() method at 19/10/2020 06:30:03: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
            19/10/2020 06:30:03 Strategy 'MySMAcrossingUnlocked/212749565': Ignored SubmitOrderManaged() method at 19/10/2020 06:30:03: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Buy' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'


            I tried with a stop loss and take profit and it did then place an order everytime.
            I will build my strategy by handling exit from the begining.

            Thank you a lot for your support

            Comment


              #7
              Hello Ben01660,
              Strange that EMA is working for you & SMA is not, can you just check & confirm while enabling the strategy in settings Exit on session close is selected for both EMA & SMA strategy. Quite possible for EMA trade is closing everyday but for SMA this is unchecked so the trade is still open & no new trade can be executed as entries per direction would be 1. The print statement is referring 19 Oct 2020.

              Comment


                #8
                Yes it was the standard builder set up. 30 sec before session close for both.

                I just tried the EMA crossing with another date, and I found the same problem as SMA. So yes trade was open. It crossed at the reoppening and the playack started on a new day, so I didn't see the order.
                Looking back on the output I can see that one order has been placed then a lot of Ignored for exceeding entry signals limit.

                All fine now, since I make sure to have an exit trade strategy in place, I can enter new crossing point. (ie Stop loss 5 ticks, take profit 5 ticks, just to try the crossing)
                Thank you

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Belfortbucks, Today, 09:29 PM
                0 responses
                6 views
                0 likes
                Last Post Belfortbucks  
                Started by zstheorist, Today, 07:52 PM
                0 responses
                7 views
                0 likes
                Last Post zstheorist  
                Started by pmachiraju, 11-01-2023, 04:46 AM
                8 responses
                151 views
                0 likes
                Last Post rehmans
                by rehmans
                 
                Started by mattbsea, Today, 05:44 PM
                0 responses
                6 views
                0 likes
                Last Post mattbsea  
                Started by RideMe, 04-07-2024, 04:54 PM
                6 responses
                33 views
                0 likes
                Last Post RideMe
                by RideMe
                 
                Working...
                X