Working an a strategy i was wondering if someone could give me the statement to get the value of the cumulative delta total (bid/ask imbalance) of the last bar and bar previous to it? basically i want to have a statement in my strategy where if the past two closed bars delta where both above 20 (or below -20 for short) it will continue on
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Cumulative Delta check
Collapse
X
-
Cumulative Delta check
Hey Team,
Working an a strategy i was wondering if someone could give me the statement to get the value of the cumulative delta total (bid/ask imbalance) of the last bar and bar previous to it? basically i want to have a statement in my strategy where if the past two closed bars delta where both above 20 (or below -20 for short) it will continue onTags: None
-
I was looking at something like this with shortcdvalue set to -20 but wasnt getting the expected result
if ((OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Bar, 0).DeltaClose[1] <= ShortCDValue)
&& (OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Bar, 0).DeltaClose[2] <= ShortCDValue))
could someone help me please?
-
I attempted to use a session instead of bar approach like yours without sucess it appears i am unable to access the data of 3 bars ago
also when running the indicator i get a blank slot, demo code below7/04/2021 8:10:47 am Default Strategy 'CDv2': Error on calling 'OnBarUpdate' method on bar 1: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
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 CDv2 : Strategy { protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Strategy here."; Name = "CDv2"; Calculate = Calculate.OnBarClose; EntriesPerDirection = 1; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = true; ExitOnSessionCloseSeconds = 30; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.Standard; Slippage = 0; 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; ShortCDValue = -20; LongCDValue = 20; ProfitTake = 3; StopLoss = 12; Contracts = 1; } else if (State == State.Configure) { AddDataSeries(Data.BarsPeriodType.Tick, 1); SetStopLoss("", CalculationMode.Ticks, StopLoss, false); SetProfitTarget("", CalculationMode.Ticks, ProfitTake); } } protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 1) return; // Set 1 if ((OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaClose[1] <= ShortCDValue) && (OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaClose[2] <= ShortCDValue)) { EnterShort(Convert.ToInt32(Contracts), ""); } // Set 2 if ((OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaClose[1] >= LongCDValue) && (OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaClose[2] >= LongCDValue)) { EnterLong(Convert.ToInt32(Contracts), ""); } } #region Properties [NinjaScriptProperty] [Range(-50, double.MaxValue)] [Display(Name="ShortCDValue", Order=1, GroupName="Parameters")] public double ShortCDValue { get; set; } [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="LongCDValue", Order=2, GroupName="Parameters")] public int LongCDValue { get; set; } [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="ProfitTake", Order=3, GroupName="Parameters")] public int ProfitTake { get; set; } [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="StopLoss", Order=4, GroupName="Parameters")] public int StopLoss { get; set; } [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="Contracts", Order=5, GroupName="Parameters")] public int Contracts { get; set; } #endregion } }
Comment
-
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
50 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
126 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
69 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment