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

How to make my entry after the second bar?

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

    How to make my entry after the second bar?

    I am in the demo account now and playing with the Strategy Development. I am not expecting these strategies to work, but I am more just trying to learn how the strategy development works and get hands on with it.

    For example, right now, I am just trying to implement a very basic strategy of go long above a moving average and when the open of a new candle breaks the moving average, close the position and go short.

    Obviously in choppy times, this strategy will get eaten alive. How would I tell it that, I only want to go long or short after the close of the second candle above the moving average? This would cut some of the choppiness out.

    Also, for some reason, when it goes short on me, I am in for 2 contracts instead of one. I am not sure why that is. The voice says "Order Filled" when going from long to short, but "Order Cancelled" when going from short to long.

    Thanks for any help, like I said, I am not looking for this strategy to actually work, just some of the thoughts that I have on how I think it would help me understand the strategy developer.


    #2
    Hello mkil5,

    Thank you for your note.

    Are you creating this strategy in the Strategy Builder, or coding the strategy manually?

    To go long only after the second bar closes above the moving average, you'd want to check that the close of both the current bar and the previous bar were above the average. For example, if I was using a 14 period SMA as my moving average:

    if (Close[0] > SMA(14)[0] && Close[1] > SMA(14)[1])
    {
    // order entry logic goes here
    }

    In the Strategy Builder, that would look like this:

    Click image for larger version

Name:	2020-05-08_0940.png
Views:	161
Size:	71.0 KB
ID:	1098815

    As far as why it's doubling your short entry, are you calling ExitLong() before EnterShort()? EnterShort() will automatically submit an order to close your long position before submitting a short entry. Calling ExitLong() on the same bar will cause two exit orders to be sent, one from ExitLong() and the one from EnterShort(). If you just want to reverse your position, all you need to do is call the entry order for the other direction.

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thanks, I'll give this a shot. I was using the strategy builder and the code was:
      CrossAbove(Close,EMA9(14),1)
      Default input[0]>Default input[1]

      I could not figure out how to make the values tie into each other.

      Comment


        #4
        Originally posted by NinjaTrader_Kate View Post
        Hello mkil5,

        Thank you for your note.

        Are you creating this strategy in the Strategy Builder, or coding the strategy manually?

        To go long only after the second bar closes above the moving average, you'd want to check that the close of both the current bar and the previous bar were above the average. For example, if I was using a 14 period SMA as my moving average:

        if (Close[0] > SMA(14)[0] && Close[1] > SMA(14)[1])
        {
        // order entry logic goes here
        }

        In the Strategy Builder, that would look like this:

        Click image for larger version

Name:	2020-05-08_0940.png
Views:	161
Size:	71.0 KB
ID:	1098815

        As far as why it's doubling your short entry, are you calling ExitLong() before EnterShort()? EnterShort() will automatically submit an order to close your long position before submitting a short entry. Calling ExitLong() on the same bar will cause two exit orders to be sent, one from ExitLong() and the one from EnterShort(). If you just want to reverse your position, all you need to do is call the entry order for the other direction.

        Thanks in advance; I look forward to assisting you further.
        Is there a way to see where the trades would have been for a backtested period? I have created a strategy, tested it over the last few days, and I do not see where some of the results were coming from. I think if I am able to see it on a chart, it may help me know what I have done incorrectly.
        Thanks

        Comment


          #5
          Hello mkil5,

          Thank you for your reply.

          You have a number of options for backtesting. You can run a backtest using historical data using the Strategy Analyzer, though this is subject to some limitations and may not match real time performance exactly. This is because on historical data, all that is known about a bar is the OHLC, and so all strategies will be run OnBarClose. If your strategy regularly is run OnBarClose you may not see much difference between real time and historical results, but a strategy running OnEachTick would show significant differences.

          You can also download Market Replay data for the days in question and use the Playback connection to run the strategy pretty much as it would have run over the same data in real time.

          Lastly, you can apply the strategy to a chart with the days in question loaded, and view the historical trades it would have taken if it was running at the time. Since this would also be historical data, the drawbacks of this would be the same as running a backtest using the Strategy Analyzer. The Strategy Analyzer offers a Chart display where it shows the trades that were calculated on a chart within the Analyzer.

          Here's some links to our help guide on the Strategy Analyzer and Playback Connection:





          Please let us know if we may be of further assistance to you.
          Kate W.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by XXtrader, Yesterday, 11:30 PM
          2 responses
          11 views
          0 likes
          Last Post XXtrader  
          Started by Waxavi, Today, 02:10 AM
          0 responses
          6 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by TradeForge, Today, 02:09 AM
          0 responses
          11 views
          0 likes
          Last Post TradeForge  
          Started by Waxavi, Today, 02:00 AM
          0 responses
          2 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by elirion, Today, 01:36 AM
          0 responses
          7 views
          0 likes
          Last Post elirion
          by elirion
           
          Working...
          X