From 3c339ecb56840b80299161c46d486a9116e48346 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Sat, 13 Jan 2024 06:16:18 -0800 Subject: [PATCH] Add the ability to configure price range high / low levels --- strategies/CaptainBacktestModel.cs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/strategies/CaptainBacktestModel.cs b/strategies/CaptainBacktestModel.cs index 457b7d6..6f19ab8 100644 --- a/strategies/CaptainBacktestModel.cs +++ b/strategies/CaptainBacktestModel.cs @@ -94,6 +94,9 @@ namespace NinjaTrader.NinjaScript.Strategies UseFixedRiskReward = true; Risk = 25.0; Reward = 75.0; + + PriceRangeHigh = new Stroke(Brushes.LimeGreen, DashStyleHelper.Solid, 3); + PriceRangeLow = new Stroke(Brushes.Red, DashStyleHelper.Solid, 3); } else if (State == State.Configure) { @@ -304,13 +307,17 @@ namespace NinjaTrader.NinjaScript.Strategies int startX = chartControl.GetXByTime(priceRange.Key + rangeStartTime); int endX = chartControl.GetXByTime(priceRange.Key + rangeEndTime); + SharpDX.Direct2D1.Brush priceRangeHighBrush = PriceRangeHigh.Brush.ToDxBrush(RenderTarget); int highY = chartScale.GetYByValue(priceRange.Value.High); - RenderTarget.DrawLine(new SharpDX.Vector2(startX, highY), new SharpDX.Vector2(endX, highY), - Brushes.LimeGreen.ToDxBrush(RenderTarget), 3); + RenderTarget.DrawLine(new SharpDX.Vector2(startX, highY), new SharpDX.Vector2(endX, highY), + priceRangeHighBrush, PriceRangeHigh.Width, PriceRangeHigh.StrokeStyle); + priceRangeHighBrush.Dispose(); + SharpDX.Direct2D1.Brush priceRangeLowBrush = PriceRangeLow.Brush.ToDxBrush(RenderTarget); int lowY = chartScale.GetYByValue(priceRange.Value.Low); - RenderTarget.DrawLine(new SharpDX.Vector2(startX, lowY), new SharpDX.Vector2(endX, lowY), - Brushes.Red.ToDxBrush(RenderTarget), 3); + RenderTarget.DrawLine(new SharpDX.Vector2(startX, lowY), new SharpDX.Vector2(endX, lowY), + priceRangeLowBrush, PriceRangeLow.Width, PriceRangeLow.StrokeStyle); + priceRangeLowBrush.Dispose(); } } @@ -398,6 +405,16 @@ namespace NinjaTrader.NinjaScript.Strategies public double Reward { get; set; } + [NinjaScriptProperty] + [Display(Name = "Range High", GroupName = "Price Range Window", Order = 1)] + public Stroke PriceRangeHigh + { get; set; } + + [NinjaScriptProperty] + [Display(Name = "Range Low", GroupName = "Price Range Window", Order = 2)] + public Stroke PriceRangeLow + { get; set; } + #endregion } }