Code producing errors is attached, As well as the chart with orders shown.
I didn't have this issue before and should not even be able to have this issue because I have an Int that is set to the current bar number whenever an order is submitted. These orders also accumulate until the bar is closed & all of these scenarios are triggered on the OnPriceChange() event.
I'm very confused how this can occur considering I check if the current bar has already been traded before submitting any orders & then set it to the current bar if a trade is made.
Relevant code is "2-2D" and "2-2U"
P.S I know there is a lot of redundant code and return statements, I've been trying to get this kink out for hours.
#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 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; namespace NinjaTrader.NinjaScript.Strategies { public class TheStrat : Strategy { private Boolean FTFC = false; private int tradeSize = 1; private Boolean inPositionLong = false; private int tradedBar = 0; private int tradedBarGoThree = 0; private ATR atr; private double defaultTp = 0.75; private Boolean inLongonetwo = false; private Boolean inLongtwotwo = false; private Boolean inLongthree = false; private Boolean inLongthreetwo = false; private Boolean inShortonetwo = false; private Boolean inShorttwotwo = false; private Boolean inShortthree = false; private Boolean inShortthreetwo = false; private VOLMA volumeMa; /*####################################*/ private Boolean oneTwoSetup = false; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = "Multi-timeframe analysis with actionable signals automatically traded."; Name = "TheStrat"; Calculate = Calculate.OnPriceChange; // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information } else if (State == State.Configure) { AddDataSeries(Data.BarsPeriodType.Minute,15); AddDataSeries(Data.BarsPeriodType.Minute,60); AddDataSeries(Data.BarsPeriodType.Day, 1); //AddDataSeries(Data.BarsPeriodType.Week,1); } else if (State == State.DataLoaded) { tradedBar = 0; volumeMa = VOLMA(14); AddChartIndicator(volumeMa); } } public Boolean isInside(int bar) { if(High[bar] <= High[bar+1]) { if(Low[bar] >= Low[bar+1]) { return true; } } return false; } public Boolean twoDown(int bar) { if(High[bar] < High[bar+1]) { if(Low[bar] < Low[bar+1]) { return true; } return false; } return false; } public Boolean twoUp(int bar) { if(High[bar] > High[bar+1]) { if(Low[bar] > Low[bar+1]) { return true; } return false; } return false; } public Boolean threeDown(int bar) { if(High[bar] > High[bar+1]) { if(Low[bar] < Low[bar+1]) { if(Open[bar] > Close[bar]) { return true; } } } return false; } public Boolean threeUp(int bar) { if(High[bar] > High[bar+1]) { if(Low[bar] < Low[bar+1]) { if(Open[bar] < Close[bar]) { return true; } } } return false; } public Boolean volumeCheck() { if(volumeMa[1] >= 15000) { return true; } return false; } public Boolean ftfcUp() { return false; } public Boolean ftfcDown() { return true; } protected override void OnBarUpdate() { if (CurrentBar < BarsRequiredToTrade) { return; } if(!volumeCheck()) { if(inLongonetwo) { ExitLong("1-2U"); inLongonetwo = false; } if(inLongtwotwo) { ExitLong("2-2U"); inLongtwotwo = false; } if(inLongthree) { ExitLong("3U"); inLongthree = false; } if(inLongthreetwo) { ExitLong("3-2U"); inLongthreetwo = false; } if(inShortonetwo) { ExitShort("1-2D"); inShortonetwo = false; } if(inShorttwotwo) { ExitShort("2-2D"); inShorttwotwo = false; } if(inShortthree) { ExitShort("3D"); inShortthree = false; } if(inShortthreetwo) { ExitShort("3-2D"); inShortthreetwo = false; } return; } /*Long Trades*/ if(isInside(1)) { if(High[0] > High[1]) { if(Low[0] > Low[1]) { if(tradedBar != CurrentBar) { tradedBar = CurrentBar; EnterLong(tradeSize, "1-2U"); inLongonetwo = true; } } } } if(twoDown(1)) { if(twoUp(0)) { if(tradedBar != CurrentBar) { tradedBar = CurrentBar; EnterLong(tradeSize, "2-2U"); inLongtwotwo = true; } } } if(threeUp(0)) { if(tradedBarGoThree != CurrentBar) { tradedBarGoThree = CurrentBar; tradedBar = CurrentBar; EnterLong(tradeSize, "3U"); inLongthree = true; } } if(threeUp(1)) { if(twoUp(0)) { if(tradedBar != CurrentBar) { tradedBar = CurrentBar; EnterLong(tradeSize, "3-2U"); inLongthreetwo = true; } } } /*Short Trades*/ if(isInside(1)) { if(twoDown(0)) { if(High[0] > High[1]) { return;} if(tradedBar != CurrentBar) { tradedBar = CurrentBar; EnterShort(tradeSize, "1-2D"); inShortonetwo = true; } } } if(twoUp(1)) { if(twoDown(0)) { if(tradedBar != CurrentBar) { tradedBar = CurrentBar; EnterShort(tradeSize, "2-2D"); inShorttwotwo = true; } } } if(threeDown(0)) { if(tradedBarGoThree != CurrentBar) { tradedBarGoThree = CurrentBar; tradedBar = CurrentBar; if(inShortthree == true) { return; } EnterShort(tradeSize, "3D"); inShortthree = true; } } if(threeDown(1)) { if(twoDown(0)) { if(tradedBar != CurrentBar) { tradedBar = CurrentBar; EnterShort(tradeSize, "3-2D"); inShortthreetwo = true; } } } if(IsFirstTickOfBar) { } } } }
Comment