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

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:	258
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 sgordet, Today, 11:48 AM
      0 responses
      1 view
      0 likes
      Last Post sgordet
      by sgordet
       
      Started by Trader146, Today, 11:41 AM
      0 responses
      2 views
      0 likes
      Last Post Trader146  
      Started by jpapa, 04-23-2024, 07:22 AM
      2 responses
      16 views
      0 likes
      Last Post rene69851  
      Started by funk10101, Today, 11:35 AM
      0 responses
      1 view
      0 likes
      Last Post funk10101  
      Started by samish18, Today, 11:26 AM
      0 responses
      1 view
      0 likes
      Last Post samish18  
      Working...
      X