Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to add cumulative delta as an indicator to the chart directly from the strategy?

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

    How to add cumulative delta as an indicator to the chart directly from the strategy?

    Hello,

    I am trying to use OrderFlowCumulativeDelta in a strategy I am experimenting with, I also want to add the delta as an indicator directly from the strategy. "AddChartIndicator" does not seem to do the trick, below is a sample of the code I will mostly use this strategy in a 2000 tick chart.

    Code:
            private OrderFlowCumulativeDelta cumulativeDelta;
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Provide trade entry signal using multiple order flow indicators";
                    Name                                        = "OrderFlowTrader";
                    Calculate                                    = Calculate.OnEachTick;
                    EntriesPerDirection                            = 1;
                    EntryHandling                                = EntryHandling.AllEntries;
                    IsExitOnSessionCloseStrategy                = true;
                    ExitOnSessionCloseSeconds                    = 300;
                    IsFillLimitOnTouch                            = false;
                    MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                    OrderFillResolution                            = OrderFillResolution.Standard;
                    Slippage                                    = 1;
                    StartBehavior                                = StartBehavior.WaitUntilFlat;
                    TimeInForce                                    = TimeInForce.Day;
                    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;
                }
                else if (State == State.Configure)
                {
                    AddDataSeries(BarsPeriodType.Tick, 1);
                }
                else if (State == State.DataLoaded)
                {
                    cumulativeDelta = OrderFlowCumulativeDelta(CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0);
                    AddChartIndicator(cumulativeDelta);
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (BarsInProgress == 1)
                {
                    cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count - 1, 1);
                    return;
                }
            }​
    Thanks!

    #2
    Hello canonguy,

    As a tip, to export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter a unique name for the file in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.
    http://ninjatrader.com/support/helpG...-us/export.htm


    I've tested and found the cumulative delta is being added to the bottom panel on the chart. Attached is an exported test script for you test as well as a screenshot of how this appears when enabled on a chart.

    [ATTACH]n1226862[/ATTACH]

    Click image for larger version

Name:	2022-12-09_10-59-38.png
Views:	573
Size:	25.9 KB
ID:	1226861
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks! It works for me now. There is no code change, but it just seems like some times depending on the changes made to the script just reloading the script in the chart if not enough, I needed to remove and re-add the indicator.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      56 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      132 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      73 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X