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!
See more
See less

Partner 728x90

Collapse

Cumulative Delta check

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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 on

    #2
    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?

    Comment


      #3
      Hi RookieKiwi, thanks for your post.

      My test script is printing out previous bars' cumulative delta. Could you test this on your end? The file goes within Documents\NinjaTrader 8\bin\Custom\Indicators

      Best regards,
      -ChrisL
      Attached Files
      Chris L.NinjaTrader Customer Service

      Comment


        #4
        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
        7/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.
        also when running the indicator i get a blank slot, demo code below

        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


          #5
          Hello, thanks for your reply.

          The strategy is only checking for one bar one the chart before it starts running. Add this instead:

          if (CurrentBars[0] < 2) return;

          Best regards,
          -ChrisL
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            You sir are a gentleman and a scholar thank you for your help

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by jclose, Today, 09:37 PM
            0 responses
            4 views
            0 likes
            Last Post jclose
            by jclose
             
            Started by WeyldFalcon, 08-07-2020, 06:13 AM
            10 responses
            1,413 views
            0 likes
            Last Post Traderontheroad  
            Started by firefoxforum12, Today, 08:53 PM
            0 responses
            10 views
            0 likes
            Last Post firefoxforum12  
            Started by stafe, Today, 08:34 PM
            0 responses
            10 views
            0 likes
            Last Post stafe
            by stafe
             
            Started by sastrades, 01-31-2024, 10:19 PM
            11 responses
            169 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Working...
            X