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
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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 briansaul, Today, 05:31 AM
|
0 responses
2 views
0 likes
|
Last Post
by briansaul
Today, 05:31 AM
|
||
Started by fwendolynlpxz, Today, 05:19 AM
|
0 responses
4 views
0 likes
|
Last Post Today, 05:19 AM | ||
Started by traderqz, Yesterday, 12:06 AM
|
11 responses
28 views
0 likes
|
Last Post Today, 05:11 AM | ||
Started by PaulMohn, Today, 03:49 AM
|
0 responses
8 views
0 likes
|
Last Post
by PaulMohn
Today, 03:49 AM
|
||
Started by inanazsocial, Today, 01:15 AM
|
1 response
10 views
0 likes
|
Last Post Today, 02:18 AM |
Comment