essentially it is just enabling basic trading principles like exponential risk scaling, strategy trading hours, strategy equity monitoring etc
It is to be used with strategies that employ scaling entries and exits.
My problem is that it wont backtest just a basic entry and exit signal, I was hoping someone could tell me why.
I uploaded the exported file, incase copy pasting code here is not the right way to do it.
TIA
#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 templatekjm : Strategy { private bool HomeRunStatus; private int RiskAdjustedPositionSize; private bool ProfitableStrategy; private bool Pretradechecklistpassorfail; private bool MondayToFriday; private bool Tradetimeok; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Strategy Template"; Name = "templatekjm"; Calculate = Calculate.OnEachTick; EntriesPerDirection = 1; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = true; ExitOnSessionCloseSeconds = 500; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.Standard; Slippage = 0; StartBehavior = StartBehavior.WaitUntilFlat; TimeInForce = TimeInForce.Day; TraceOrders = true; 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; StopLoss = 12; TakeProfit = 12; StartingCapital = 1000; RiskScale = 500; ExponetialRiskLimit = 0.5; StartTime = DateTime.Parse("10:00", System.Globalization.CultureInfo.InvariantCulture) ; EndTIme = DateTime.Parse("06:00", System.Globalization.CultureInfo.InvariantCulture) ; HomeRunStatus = false; RiskAdjustedPositionSize = StartingCapital / RiskScale; ProfitableStrategy = true; Pretradechecklistpassorfail = true; MondayToFriday = true; Tradetimeok = true; } else if (State == State.Configure) { } } protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 1) return; { if (BarsInProgress != 0) return; // Set 1 if (SystemPerformance.AllTrades.TradesPerformance.Cur rency.CumProfit + StartingCapital >= StartingCapital) { ProfitableStrategy = true; } // Set 2 if ( // nottradingdays ((DayOfWeek.Saturday == DayOfWeek.Saturday) || (DayOfWeek.Sunday == DayOfWeek.Sunday))) { MondayToFriday = false; } if (CurrentBars[0] < 0) return; // Set 3 if ((Times[0][0].TimeOfDay >= StartTime.TimeOfDay) && (Times[0][0].TimeOfDay < EndTIme.TimeOfDay)) { Tradetimeok = true; } // Set 4 if ((MondayToFriday == false) && (Tradetimeok == true) && (ProfitableStrategy == true)) { Pretradechecklistpassorfail = true; } { if (BarsInProgress != 0) return; if (CurrentBars[0] < 1) return; // entry1 if (CrossAbove(Close, High, 1) && (Tradetimeok = true) &&(ProfitableStrategy == true) &&(Pretradechecklistpassorfail = true)) { EnterLong(Convert.ToInt32(RiskAdjustedPositionSize ), @"enterlong"); } // exit1 if ((GetCurrentBid(0) > Position.AveragePrice) && (CrossBelow(Close, Low, 1))) { ExitLong(Convert.ToInt32(Position.Quantity), @"exitlong", @"enterlong"); } } } } #region Properties [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="StopLoss", Description="Ticks of stop loss", Order=1, GroupName="Parameters")] public int StopLoss { get; set; } [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="TakeProfit", Description="Ticks of take profit", Order=2, GroupName="Parameters")] public int TakeProfit { get; set; } [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="StartingCapital", Order=3, GroupName="Parameters")] public int StartingCapital { get; set; } [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="RiskScale", Order=4, GroupName="Parameters")] public int RiskScale { get; set; } [NinjaScriptProperty] [Range(0.5, double.MaxValue)] [Display(Name="ExponetialRiskLimit", Description="% of risk per trade on equity", Order=5, GroupName="Parameters")] public double ExponetialRiskLimit { get; set; } [NinjaScriptProperty] [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")] [Display(Name="StartTime", Order=6, GroupName="Parameters")] public DateTime StartTime { get; set; } [NinjaScriptProperty] [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")] [Display(Name="EndTIme", Order=7, GroupName="Parameters")] public DateTime EndTIme { get; set; } #endregion } }
Comment