Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator data for strategy not same as charts

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

    Indicator data for strategy not same as charts

    Testing different strategies. New to NT. I have a test strategy that enters a trade on a MACD Crossover, but the trade does not enter at the same time the chart shows a crossover. Is there a reason as to why the data isn't matching?

    #2
    Hello Lumbeezl,

    Thanks for your post.

    Are the MACD settings the same in the strategy as they are on the chart?

    Are the entry's 1 bar after the crossover?

    What "calculate" mode are you using, like Calculate.OnBarClose?

    Can you provide a screenshot that shows the trade relative to the MACd cross and showing the time base of the chart?
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      So here's the code and the chart with entries, indicator, but it's not entering correctly.
      Attached Files

      Comment


        #4
        Hello Lumbeezl,

        Thanks for your reply.

        The strategy is running Calculate.OnEachTick. This means that the index [0] is the current tick/price and [1] represents the last closed bar.

        Your condition is to see if the last bar of the Macd average line (red line) is below zero and if the current tick/bar is above zero on the Macd average line. If so then you are entering a long limit order at the Close[0] price which is the current tick.

        A limit order may or may not fill.

        The screenshot seems to confirm the coding.

        Please clarify what specifically is not correct about what it is doing or rather what it is you want it to do.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          I appreciate the help. I would just like to be able to enter the trade when the MACD on the chart crosses above 0. I'm just trying to figure out how to create strategies. Not sure what I would need to code for it correlate with what I see in the chart. The chart is 25 tick

          Comment


            #6
            Hello Lumbeezl,

            Thanks for your reply.

            Are you wanting to work directly in Ninjascript or are you working with the strategy builder?

            When you say MACD do you mean the actual MACD line or the MACD average line (red line)?

            You current code is looking at the MACD average line.

            In the strategy builder, when working with the MACD, make sure you select the line to use in the section "Value Plot".

            In Ninjascript, if you want to use the actual MACD line you could use:

            if ((MACD1.Default[0] > 0) && MACD1.default[1] < 0)

            If you want to enter immediately then use a market type order via EnterLong() and while this will fill immediately it may not be at your preferred price.

            Because you are using Calculate.OnEachTick, it is possible that more than one order can be placed because your code will execute on each tick and it takes time for orders to actually get processed (an asynchronous event) so you may need to add code to only allow one entry. You can limit the entry by checking if the tick is occuring in the same bar, for example:

            if ((MACD1.Default[0] > 0) && MACD1.default[1] < 0 && entryBar != CurrentBar)
            {
            EnterLong();
            entryBar = CurrentBar; // save the bar number to prevent entry in same bar
            }

            In the above example, entryBar is an integer variable you would create. CurrentBar is a system int that hold the current bar number. Reference: https://ninjatrader.com/support/help...currentbar.htm
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Ok. It has been sending in multiple orders, but that last section of code really solves a lot of issues. I'd like to work with the MACD Avg line and do this in NinjaScript. In the chart when the average crosses above 0, I'd just like it so send in a long order. I'm just not sure if the MACD is calculating the bar for 25 ticks each.

              Comment


                #8
                Hello Lumbeezl,

                Thanks for your reply and clarifications.

                Your strategy and the indicator instance MACD it is using are being calculated OnEachTick.

                The chart MACD instance, unless added by/through the strategy can be running on a different calculate mode and perhaps this is what you are running into. By default, most chart indicators will run Calculate.OnBarClose. You can change the chart indicator to run either OnEachTick or OnPriceChange both of which will provide the lastest information with the OnpriceChange using less CPU resources.
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Ok. Makes sense. Where would I create the int entryBar? Would I create it inOnBarUpdate()?

                  Comment


                    #10
                    Hello Lumbeezl,

                    Thanks for your reply.

                    I would suggest creating it at the class level, for example:

                    public class Example : Indicator
                    {
                    private double runningMax;
                    private int runningMaxBar;
                    private double runningMin;
                    private int runningMinBar;
                    private int entryBar
                    ;

                    protected override void OnStateChange()
                    {
                    Paul H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by FrancisMorro, Today, 03:24 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post FrancisMorro  
                    Started by Segwin, 05-07-2018, 02:15 PM
                    10 responses
                    1,770 views
                    0 likes
                    Last Post Leafcutter  
                    Started by Rapine Heihei, 04-23-2024, 07:51 PM
                    2 responses
                    31 views
                    0 likes
                    Last Post Max238
                    by Max238
                     
                    Started by Shansen, 08-30-2019, 10:18 PM
                    24 responses
                    944 views
                    0 likes
                    Last Post spwizard  
                    Started by Max238, Today, 01:28 AM
                    0 responses
                    11 views
                    0 likes
                    Last Post Max238
                    by Max238
                     
                    Working...
                    X