I had the idea to create a strategy based off of the correlation between a indicator and Close[0]. I wrote up some 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.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 CorrelationAndCausalityGTB : Strategy { private WilliamsR WilliamsR1; private Correlation Correlation1; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"WilliamR causality cross Correlated with price. Vector William R and Correlation confirmation initiates trades. ATR in Ticks dictates Profit Target and Stop Loss. "; Name = "CorrelationAndCausalityGTB"; Calculate = Calculate.OnEachTick; EntriesPerDirection = 1; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = true; ExitOnSessionCloseSeconds = 30; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.High; OrderFillResolutionType = BarsPeriodType.Minute; OrderFillResolutionValue = 1; Slippage = 2; 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; SharedPeriodLength = 2; ATRticksPeriodLength = 2; ProfitTargetMultiplier = 1; ProfitTargetAndStopLossMultiplier = 1; } else if (State == State.Configure) { } else if (State == State.DataLoaded) { WilliamsR1 = WilliamsR(Close, Convert.ToInt32(SharedPeriodLength)); Correlation1 = Correlation(WilliamsR1, Convert.ToInt32(SharedPeriodLength), @"WilliamsRCorrelationWithInstrumentAppliedToo"); SetProfitTarget(@"EnterLongCorrelationCausalityGTB", CalculationMode.Ticks, ((20 * ProfitTargetAndStopLossMultiplier)); SetTrailStop(@"EnterLongCorrelationCausalityGTB", CalculationMode.Ticks, ((20 *ProfitTargetAndStopLossMultiplier), false); SetProfitTarget(@"EnterShortCorrelationCausalityGTB", CalculationMode.Ticks, ((20 *ProfitTargetAndStopLossMultiplier)); SetTrailStop(@"EnterShortCorrelationCausalityGTB", CalculationMode.Ticks, ((20 *ProfitTargetAndStopLossMultiplier), false); } } protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 1) return; // Set 1 if ((WilliamsR1[0] > WilliamsR1[1]) && (Correlation1[0] > Correlation1[1])) { EnterLong(Convert.ToInt32(1000), @"EnterLongCorrelationCausalityGTB"); } // Set 2 if ((WilliamsR1[0] < WilliamsR1[1]) && (Correlation1[0] < Correlation1[1])) { EnterShort(Convert.ToInt32(1000), @"EnterShortCorrelationCausalityGTB"); } } #region Properties [NinjaScriptProperty] [Range(2, int.MaxValue)] [Display(Name="SharedPeriodLength", Description="Shared Period Length (Set 5 to 125)", Order=1, GroupName="Parameters")] public int SharedPeriodLength { get; set; } [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="ProfitTargetAndStopLossMultiplier", Description="Profit Target And Stop Loss Multiplier (Set 1 to 10)", Order=2, GroupName="Parameters")] public int ProfitTargetAndStopLossMultiplier { get; set; } #endregion } }
Is there anything I should know about Correlation that might be causing this issue?
Comment