Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Mismatched data type error

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

    Mismatched data type error

    Hi,

    I am using NT8 and building a strategy that looks at a gap above an SMA. e.g.


    private SMA sma;
    sma=SMA(x)

    if ((Close[1] > sma[1]) && (Open + Gap >= Close[1]))

    is throwing the errors. I realize it is a type mismatch but not sure how to correct it.

    Any thoughts??

    Thanks in advance.

    #2
    Hello,
    You will need to specifiy which bar you are wanting to get from the open collection. If you are wanting to get the current bar's open you will use Open[0]. In addition Gap is not an object in NinjaTrader 8. If you have created this as a variable or collection for the strategy please specify how you have defined it for this strategy.
    Cody B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the response. Gap is a variable as well defined as a double. I have used Open with and without the [0] identifier.

      Comment


        #4
        Hello,
        Do you see the condition not compile if you use Open[0]?
        Can you provide a screenshot of the compile error?
        Cody B.NinjaTrader Customer Service

        Comment


          #5
          I seem to have gotten by the compile error somehow but when I add the strategy to a daily chart of the ES ##-## nothing plots. When I backtest from 1/1/2011 until today there are 68 trades.

          Here is the code.

          #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.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 GapUp : Strategy
          {
          private SMA sma;
          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = @"Previous bar closes above SMA and current bar gaps open.";
          Name = "GapUp";
          Calculate = Calculate.OnBarClose;
          EntriesPerDirection = 1;
          EntryHandling = EntryHandling.AllEntries;
          IsExitOnSessionCloseStrategy = false;
          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;
          Gap = 1;
          Ma = 5;
          AddPlot(Brushes.Orange, "MovingAvg");
          }
          else if (State == State.Configure)
          {
          sma=SMA(Ma);
          sma.Plots[0].Brush = Brushes.Orange;
          AddChartIndicator(sma);
          }
          }

          protected override void OnBarUpdate()
          {
          //Add your custom strategy logic here.
          if (CurrentBar < BarsRequiredToTrade)
          return;

          if ((Close[1] >= sma[1]) && (Open[0] >= Close[1] + Gap))
          EnterLong(1, "Long");
          else if (Close[0] < sma[0])
          ExitLong();
          }

          #region Properties
          [Range(1, double.MaxValue)]
          [NinjaScriptProperty]
          [Display(Name="Gap", Order=1, GroupName="Parameters")]
          public double Gap
          { get; set; }

          [Range(1, int.MaxValue)]
          [NinjaScriptProperty]
          [Display(Name="Ma", Order=2, GroupName="Parameters")]
          public int Ma
          { get; set; }

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> MovingAvg
          {
          get { return Values[0]; }
          }
          #endregion

          }
          }

          Comment


            #6
            Hello,
            I have tested the code on my end and I do see the SMA plotting. Can you clarify what you are not seeing plot? Can you provide a screenshot of the chart?
            Please also detail the steps you are taking to reproduce.
            Cody B.NinjaTrader Customer Service

            Comment


              #7
              I am not seeing the SMA or "Long" on the chart. I have attached a pdf of part of the chart and the screen for adding the strategy. I am just adding the strategy to the chart by right clicking and choosing strategy.
              Attached Files

              Comment


                #8
                Hello,
                From the screenshot and pdf it does not appear that the strategy is enabled. Within the strategy parameters check the "Enabled" box and then press OK.
                Cody B.NinjaTrader Customer Service

                Comment


                  #9
                  Big newbie mistake. Thanks for you help and patience!

                  Comment


                    #10
                    One other question. The entry and exit are one day late. Is there a way to have the entry occur on the day of the gap and the exit occur on the day price closes below the SMA?

                    Comment


                      #11
                      Hello,
                      To have the orders fill when the conditions are triggering instead of occuring at the end of the bar,resulting in a trade placed on the next bar, you will need to enable Tick Replay and change the setting for Order Fill Resolution to High.

                      For more information on Tick Replay please see the following link: http://ninjatrader.com/support/helpG...ick_replay.htm

                      For more information on the Order Fill Resolution please see the following link: http://ninjatrader.com/support/helpG...FillResolution

                      I would like to note that this will only work if you have historical tick data from your data provider.
                      Cody B.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      648 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      369 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      109 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      573 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      576 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X