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

trigger order on /MES with indicator based on /ES

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

    trigger order on /MES with indicator based on /ES

    Need help in triggering orders with indicator based on /ES. I have a crossover strategy built in strategy builder on tick chart. It works fine in demo, now I want to test it live, so first would want to test it on /MES. How do I trigger buy order for /MES with strategy based on /ES? Thanks in advance.

    #2
    Hello dkbyond,

    Thanks for your first post and welcome to the NinjaTrader forums!

    It would somewhat depend on how you have created the strategy.

    If you created the strategy and do not have any added data series then when you apply the strategy it would use the data of the instrument you have applied it to. So when you apply it to ES then it would use ES data and submit orders to ES. When you apply the strategy to MES then the strategy would use the data of MES and apply the orders to MES.

    If you created the strategy with ES as an Added data series and have referenced that data when creating your conditions, then when you apply the strategy to MES it would use the ES data for your conditions and would only submit orders to the MES.

    If you are not familiar with adding and accessing additional data series, I previously created a short video on the process of adding (in this case higher time frames but the process is identical) and then accessing the added data series in the conditions. In your case you would be specifying the current contract of the ES. https://paul-ninjatrader.tinytake.co...MF8xMTY0NTQyMw
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul,

      Thanks for welcoming me and your reply.

      From your video and explanation, got to know how to use the /ES data as primary series. Now my /ES chart is 500 ticks and Heinken Ashi bars, in strategy builder in additional data section I get to choose TYPE as TICK and Value as 500 ticks for /ES, but where do I select Heinken Ashi bars. My strategy is based on if /ES Heiken Ashi bar closes above EMA10 then buy triggers.

      I noticed a indicator as HeinkenAshi8, this is what I should select? Thanks.

      Comment


        #4
        Hello dkbyond,

        Thanks for your reply.

        Heiken-ashi bar types are not available as an added data series in the strategy builder.

        Yes, you can use the HeikenAshi8 indicator to accomplish the same thing. In this case you would be adding standard 500 ticks bars. In the conditions window you would select the HeikenAshi8 indicator and make sure to set the input series as the added tick bars, Note the indicator provides 4 values (HAClose, HAOpen, HAHigh, HAClose) that represent the candle Open, High, Low and Close, make sure that you select the HiekenAshi8 "Value plot" to use each time you select the indicator in the conditions. I've attached a screenshot of a simple condition of the close > open using the HeikenAshi8 indicator and using an added 500 tick ES bars.

        Click image for larger version

Name:	dkbyond-1.PNG
Views:	608
Size:	54.4 KB
ID:	1078514
        Paul H.NinjaTrader Customer Service

        Comment


          #5

          I got the first part where HeinkenAshi8(ES 12-19(500 Tick)).HAClose[0] >. Now for the second part, where it should be EMA10, this ema is based on HeinkenAshi8 of /ES 500 tick chart. How do I get this, I tried a number of times but there is buy and exit buy order discrepancies on the chart as attached.


          Click image for larger version

Name:	chart discrepancies.JPG
Views:	396
Size:	83.9 KB
ID:	1078564




          Comment


            #6
            Hello dkbyond,

            Thanks for your reply.

            There would be 3 items, the EMA indicator, the HeikenAshi8 indicator and the added data series.

            On the right side you would select the EMA indicator and set the period to 10, you would change the input series to be the HeikenAshi8 indicator (make sure to use the HAClose for plot) and the input series for the HeikenAshi8 indicator would be then the ES 500 tick bars.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hi Paul,

              The discrepancy is coming because the HeinkenAshi8 indicator and the built in HeinkenAshi bar are different. Is there a way to code it, can a script get the HeinkenAshi bar value. Thanks.

              Comment


                #8
                Hello dkbyond,

                Thanks for your reply.

                Please double check your conditions to ensure you have select the correct "value plot" for the HeikenAshi8 indicator. IE: selecting "HAClose" when you want the close value of the bar.

                I would expect the HeikenAshi8 indicator bars to be the same as the Heiken Ashi bars. I would suggest adding a print statement, in a set without conditions, to print the values of the HeikenAshi8 indicator from the added data series. Here is a short video on how to create a print statement in the strategy builder: https://paul-ninjatrader.tinytake.co...NV8xMDk5MDc5Nw

                Can you reconfirm what you are working with? My understanding was a chart of 500 tick MES Heiken ashi bars and the strategy is using an Added series of 500 tick bars feed into the HeikenAshi8 indicator.


                To directly answer your question of "Is there a way to code it, can a script get the HeinkenAshi bar value", Yes, you can create a Ninjascript strategy that adds and uses the native Heiken Ashi Bars





                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Please find the differences in both the plots as attached.The left one is ES 500 tick chart with regular HiekenAshi and the right one is ES 500 tick with the indicator HeikenAshi8. The left chart shows a green bar crossing above the EMA10 while the right chart shows the next bar crossing above EMA10. This is visible, I'll do the print statements later when I get time. And if you increase the tick size the more the discrepancy.

                  I want to trigger auto order on /ES when the HeinkenAshi bar closes above the EMA10 and exit for if the opposite. I Have done this on Demo account and it fairs well. Now i want to do it live, but to make sure one last time, I want to apply the same strategy in MES as its much smaller and so lesser the risk when i'm testing it. But ES and MES have different ticks and their tick based charts are not the same, so I want to trigger orders on MES based on my ES strategy of HeikenAshi bar crossing above EMA10.

                  Also I have double checked that "HAClose" is selected as the value of the bar, I can make a small video of how i'm doing it and can send you here.

                  My opinion is that scripting it will be more accurate, If you could guide me in this regard, would appreciate it. Thanks.


                  Click image for larger version

Name:	discrepancy.JPG
Views:	424
Size:	161.4 KB
ID:	1078655

                  Comment


                    #10
                    Hello dkbyond,

                    Thanks for your reply.

                    In your screenshot, the chart behind is the standard 500 tick bars with the HeikenAshi8 indicator applied as well as the EMA 10. The EMA input series is the 500 tick bars and it should instead be the HeikenAshi8 indicator's HAClose. It's indicator label on the chart should show as EMA(HeikenAshi8(ES 12-19 (500 tick)).HAClose, 10).

                    If you would rather work in Ninjascript that is certainly fine as well. A starting point for you would be to use your existing strategy (do a save as.. to create a copy), then "Unlock the code of the copy and then you can work directly in the script. You would need to replace the AddDataSeries() with AddHeikenAshi(), please see: https://ninjatrader.com/support/help...heikenashi.htm

                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Hope this time I have done the charting right. Still the same discrepancy. Thanks for the guide. Will spend some time on it and hopefully with your help get done with it.


                      Click image for larger version

Name:	discrepancy 2.JPG
Views:	404
Size:	104.7 KB
ID:	1078704

                      Comment


                        #12
                        Hi Paul,

                        Could you please check the below script, it's throwing error at line 66 & 77 (The name Heinken Ashi doesn't exist in the current context and line 79 (caanot convert from "string" to "int". Thanks.


                        #region Using declarations
                        using System;
                        using System.Collections.Generic;
                        using System.ComponentModel;
                        using System.ComponentModel.DataAnnotations;
                        using System.Linq;
                        using System.Text;
                        using System.Threading.Tasks;
                        using System.Windows;
                        using System.Windows.Input;
                        using System.Windows.Media;
                        using System.Xml.Serialization;
                        using NinjaTrader.Cbi;
                        using NinjaTrader.Gui;
                        using NinjaTrader.Gui.Chart;
                        using NinjaTrader.Gui.SuperDom;
                        using NinjaTrader.Gui.Tools;
                        using NinjaTrader.Data;
                        using NinjaTrader.NinjaScript;
                        using NinjaTrader.Core.FloatingPoint;
                        using NinjaTrader.NinjaScript.Indicators;
                        using NinjaTrader.NinjaScript.DrawingTools;
                        #endregion

                        //This namespace holds Strategies in this folder and is required. Do not change it.
                        namespace NinjaTrader.NinjaScript.Strategies
                        {
                        public class ThreeTenBuyScript : Strategy
                        {
                        private EMA EMA1;


                        protected override void OnStateChange()
                        {
                        if (State == State.SetDefaults)
                        {
                        Description = @"Enter the description for your new custom Strategy here.";
                        Name = "ThreeTenBuyScript";
                        Calculate = Calculate.OnBarClose;
                        EntriesPerDirection = 1;
                        EntryHandling = EntryHandling.AllEntries;
                        IsExitOnSessionCloseStrategy = true;
                        ExitOnSessionCloseSeconds = 30;
                        IsFillLimitOnTouch = false;
                        MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
                        OrderFillResolution = OrderFillResolution.Standard;
                        Slippage = 0;
                        StartBehavior = StartBehavior.WaitUntilFlat;
                        TimeInForce = TimeInForce.Gtc;
                        TraceOrders = false;
                        RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
                        StopTargetHandling = StopTargetHandling.PerEntryExecution;
                        BarsRequiredToTrade = 20;
                        // Disable this property for performance gains in Strategy Analyzer optimizations
                        // See the Help Guide for additional information
                        IsInstantiatedOnEachOptimizationIteration = true;
                        }
                        else if (State == State.Configure)
                        {
                        AddHeikenAshi("ES 12-19", Data.BarsPeriodType.Tick, 500, Data.MarketDataType.Last);
                        }
                        else if (State == State.DataLoaded)
                        {

                        EMA1 = EMA(HeikenAshi().HAClose[1], 10);

                        }
                        }

                        protected override void OnBarUpdate()
                        {

                        if (BarsInProgress == 1)


                        { //Set 1
                        if (CrossAbove(HeikenAshi().HAClose[1], EMA1, 1))
                        {
                        EnterLong(Convert.ToInt32(DefaultQuantity), "", "");
                        }
                        //Set 2
                        if (CrossBelow(HeikenAshi().HAClose[1], EMA1, 1))
                        {
                        EnterShort(Convert.ToInt32(DefaultQuantity), "", "");
                        }

                        }
                        }
                        }
                        }

                        Comment


                          #13
                          Hi Paul,

                          Got it with the code below. Just checking if everything is right. Thanks.



                          #region Using declarations
                          using System;
                          using System.Collections.Generic;
                          using System.ComponentModel;
                          using System.ComponentModel.DataAnnotations;
                          using System.Linq;
                          using System.Text;
                          using System.Threading.Tasks;
                          using System.Windows;
                          using System.Windows.Input;
                          using System.Windows.Media;
                          using System.Xml.Serialization;
                          using NinjaTrader.Cbi;
                          using NinjaTrader.Gui;
                          using NinjaTrader.Gui.Chart;
                          using NinjaTrader.Gui.SuperDom;
                          using NinjaTrader.Gui.Tools;
                          using NinjaTrader.Data;
                          using NinjaTrader.NinjaScript;
                          using NinjaTrader.Core.FloatingPoint;
                          using NinjaTrader.NinjaScript.Indicators;
                          using NinjaTrader.NinjaScript.DrawingTools;
                          #endregion

                          //This namespace holds Strategies in this folder and is required. Do not change it.
                          namespace NinjaTrader.NinjaScript.Strategies
                          {
                          public class ThreeTenBuyScript1 : Strategy
                          {

                          private EMA EMA1;

                          protected override void OnStateChange()
                          {
                          if (State == State.SetDefaults)
                          {
                          Description = @"Enter the description for your new custom Strategy here.";
                          Name = "ThreeTenBuyScript1";
                          Calculate = Calculate.OnBarClose;
                          EntriesPerDirection = 1;
                          EntryHandling = EntryHandling.AllEntries;
                          IsExitOnSessionCloseStrategy = true;
                          ExitOnSessionCloseSeconds = 30;
                          IsFillLimitOnTouch = false;
                          MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
                          OrderFillResolution = OrderFillResolution.Standard;
                          Slippage = 0;
                          StartBehavior = StartBehavior.WaitUntilFlat;
                          TimeInForce = TimeInForce.Gtc;
                          TraceOrders = false;
                          RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
                          StopTargetHandling = StopTargetHandling.PerEntryExecution;
                          BarsRequiredToTrade = 20;
                          // Disable this property for performance gains in Strategy Analyzer optimizations
                          // See the Help Guide for additional information
                          IsInstantiatedOnEachOptimizationIteration = true;
                          }
                          else if (State == State.Configure)
                          {
                          AddHeikenAshi("ES 12-19", Data.BarsPeriodType.Tick, 500, Data.MarketDataType.Last);
                          }
                          else if (State == State.DataLoaded)
                          {
                          EMA1 = EMA(Closes[1], 10);
                          }
                          }

                          protected override void OnBarUpdate()
                          {
                          if (BarsInProgress != 0)
                          return;

                          if (CurrentBars[0] < 1
                          || CurrentBars[1] < 1)
                          return;

                          // Set 1
                          if (CrossAbove(Closes[1], EMA1, 1))
                          {
                          EnterLong(Convert.ToInt32(DefaultQuantity), "");
                          }

                          // Set 2
                          if (CrossBelow(Closes[1], EMA1, 1))
                          {
                          EnterShort(Convert.ToInt32(DefaultQuantity), "");
                          }

                          }
                          }
                          }

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Gerik, Today, 09:40 AM
                          1 response
                          6 views
                          0 likes
                          Last Post NinjaTrader_Gaby  
                          Started by RookieTrader, Today, 09:37 AM
                          1 response
                          10 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by alifarahani, Today, 09:40 AM
                          0 responses
                          5 views
                          0 likes
                          Last Post alifarahani  
                          Started by KennyK, 05-29-2017, 02:02 AM
                          3 responses
                          1,284 views
                          0 likes
                          Last Post NinjaTrader_Clayton  
                          Started by AttiM, 02-14-2024, 05:20 PM
                          11 responses
                          185 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Working...
                          X