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

Error on trying to load additional data

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

    #16
    Hello

    You actually have this condition so you are alredy executing on the primary series:

    Code:
    if (BarsInProgress != 0)
    return;
    Please try using the following instead:



    Code:
    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] < 1
    || CurrentBars[1] < 0)
    return;
    
    if(BarsInProgress == 0)
    {
    // Set 1
    if (
    // Condition group 1
    && (DM1.ADXPlot[0] > DM1.ADXPlot[1])
    && (DM1.DiPlus[0] > DM1.DiMinus[0])
    && (DM1.ADXPlot[0] >= Adxl)
    && (DM2.ADXPlot[0] >= Adx4))
    
    {
    
    }
    
    
    if(BarsInProgress == 1) { DM2 = DM(14); }
    }
    If that is still not correct could you attach the script so that I can run what you have? Also how are you comparing the corectness here? Are you using AddChartIndicator or are you manually adding indicators to the chart to compare?

    JesseNinjaTrader Customer Service

    Comment


      #17
      Hi Jesse,

      That didn't work. It ended up creating way too many entries.
      I manually added the indicators to the chart. But I didn't do an add indicator for the other timeframe. Maybe that's the problem?

      I have entered my code here:
      #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 Stopcodef4 : Strategy
      {
      private bool CanEnterLong;
      private bool CanEnterShort;
      private bool Canstop;

      private bwAO bwAO1;
      private DM DM1;
      private DM DM2;

      private ADX ADX1;

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Strategy here.";
      Name = "Stopcodef4";
      Calculate = Calculate.OnBarClose;
      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.AllEntries;
      IsExitOnSessionCloseStrategy = true;
      ExitOnSessionCloseSeconds = 30;
      IsFillLimitOnTouch = true;
      MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
      OrderFillResolution = OrderFillResolution.Standard;
      Slippage = 0;
      StartBehavior = StartBehavior.WaitUntilFlat;
      TimeInForce = TimeInForce.Gtc;
      TraceOrders = false;
      RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
      StopTargetHandling = StopTargetHandling.PerEntryExecution;
      BarsRequiredToTrade = 200;
      // Disable this property for performance gains in Strategy Analyzer optimizations
      // See the Help Guide for additional information
      IsInstantiatedOnEachOptimizationIteration = true;
      Gain = 70;
      Stop = 20;
      Adxth = 25;
      Adjstop = 30;
      Adjprof = 1;
      Adxl = 15;
      Adx4 = 25;
      CanEnterLong = false;
      CanEnterShort = false;
      Canstop = false;
      }
      else if (State == State.Configure)
      {
      AddDataSeries(new BarsPeriod {
      BarsPeriodType =(BarsPeriodType)2018,
      BarsPeriodTypeName = "UniRenko",
      BaseBarsPeriodValue = 1,
      Value = 2,
      Value2 = 4
      });
      }
      else if (State == State.DataLoaded)
      {
      bwAO1 = bwAO(Close);
      DM1 = DM(Close, 14);
      DM2 = DM(Closes[1], 14);
      ADX1 = ADX(Close, 14);
      SetProfitTarget("", CalculationMode.Ticks, Gain);
      SetStopLoss("", CalculationMode.Ticks, Stop, false);
      }
      }

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

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

      // Set 3
      if (
      // Condition group 1
      ((bwAO1.AOBarPlot[0] > bwAO1.AOBarPlot[1])
      && (DM1.ADXPlot[0] > DM1.ADXPlot[1])
      && (DM1.DiPlus[0] > DM1.DiMinus[0])
      && (DM1.ADXPlot[0] >= Adxth)
      && (Close[0] > Close[1]))
      // && (Times[0][0].TimeOfDay > new TimeSpan(7, 30, 0))
      // && (Times[0][0].TimeOfDay <= new TimeSpan(9, 30, 0))
      )
      {
      EnterLong(Convert.ToInt32(DefaultQuantity), "");
      PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\Alert4.wav");
      Canstop = false;
      CanEnterLong = false;
      }

      // Set 4
      if (
      // Condition group 2
      ((bwAO1.AOBarPlot[0] < bwAO1.AOBarPlot[1])
      && (DM1.ADXPlot[0] > DM1.ADXPlot[1])
      && (DM1.DiPlus[0] < DM1.DiMinus[0])
      && (DM1.ADXPlot[0] <= Adxth)
      && (Close[0] < Close[1]))
      // && (Times[0][0].TimeOfDay > new TimeSpan(7, 30, 0))
      // && (Times[0][0].TimeOfDay <= new TimeSpan(9, 30, 0))
      )
      {
      EnterShort(Convert.ToInt32(DefaultQuantity), "");
      PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\Alert4.wav");
      Canstop = false;
      CanEnterShort = false;
      }

      // Set 5
      if (
      // Condition group 1
      ((bwAO1.AOBarPlot[0] > bwAO1.AOBarPlot[1])
      && (DM1.ADXPlot[0] > DM1.ADXPlot[1])
      && (DM1.DiPlus[0] > DM1.DiMinus[0])
      && (DM1.ADXPlot[0] >= Adxl)
      && (Close[0] > Close[1])
      && (DM2.ADXPlot[0] >= Adx4))
      // && (Times[0][0].TimeOfDay > new TimeSpan(7, 30, 0))
      // && (Times[0][0].TimeOfDay <= new TimeSpan(9, 30, 0))
      )
      {

      if(BarsInProgress == 1) { DM2 = DM(14); }

      }
      {
      EnterLong(Convert.ToInt32(DefaultQuantity), "");
      PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\Alert4.wav");
      Canstop = false;
      CanEnterLong = false;
      // Print (DM2.ADXPlot[0]);
      }

      // Set 6
      if (
      // Condition group 2
      ((bwAO1.AOBarPlot[0] < bwAO1.AOBarPlot[1])
      && (DM1.ADXPlot[0] > DM1.ADXPlot[1])
      && (DM1.DiPlus[0] < DM1.DiMinus[0])
      && (DM1.ADXPlot[0] >= Adxl)
      && (Close[0] < Close[1])
      && (DM2.ADXPlot[0] >= Adx4)))
      // && (Times[0][0].TimeOfDay > new TimeSpan(7, 30, 0))
      // && (Times[0][0].TimeOfDay <= new TimeSpan(9, 30, 0))

      {

      if(BarsInProgress == 1) { DM2 = DM(14); }

      }
      {
      EnterShort(Convert.ToInt32(DefaultQuantity), "");
      PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\Alert4.wav");
      Canstop = false;
      CanEnterShort = false;
      // Print (DM2.ADXPlot[0]);
      }

      // Set 7
      if ((ADX1[0] < ADX1[1])
      && (bwAO1.AOBarPlot[0] < bwAO1.AOBarPlot[1])
      && (DM1.DiPlus[0] < DM1.DiPlus[1])
      && (DM1.DiMinus[0] > DM1.DiMinus[1]))
      {
      ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
      }

      // Set 8
      if ((ADX1[0] > ADX1[1])
      && (bwAO1.AOBarPlot[0] > bwAO1.AOBarPlot[1])
      && (DM1.DiPlus[0] > DM1.DiPlus[1])
      && (DM1.DiMinus[0] < DM1.DiMinus[1]))
      {
      ExitShort(Convert.ToInt32(DefaultQuantity), "", "");
      }

      }

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

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

      [NinjaScriptProperty]
      [Range(5, int.MaxValue)]
      [Display(Name="Adxth", Order=3, GroupName="Parameters")]
      public int Adxth
      { get; set; }

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

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

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

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

      }
      }

      Comment


        #18
        Hello Kal1221,

        Thanks for the additional details.

        Yes you would not want to try and compare manually added indicators because that could have used a different amount of data or different settings. Using AddChartIndicator would be suggested to see what the specific instance the strategy is using is seeing.

        I would suggest to try the comparison again after using AddChartIndicator for the indicators, if there is a difference we could look further into it at that point.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by sidlercom80, 10-28-2023, 08:49 AM
        167 responses
        2,260 views
        0 likes
        Last Post jeronymite  
        Started by warreng86, 11-10-2020, 02:04 PM
        7 responses
        1,361 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by Perr0Grande, Today, 08:16 PM
        0 responses
        5 views
        0 likes
        Last Post Perr0Grande  
        Started by elderan, Today, 08:03 PM
        0 responses
        9 views
        0 likes
        Last Post elderan
        by elderan
         
        Started by algospoke, Today, 06:40 PM
        0 responses
        10 views
        0 likes
        Last Post algospoke  
        Working...
        X