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:	591
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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      93 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      138 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      123 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      73 views
      0 likes
      Last Post PaulMohn  
      Working...
      X