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

Reset Order Flow Cumulative Delta to 0

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

    Reset Order Flow Cumulative Delta to 0

    Hi,

    I'm working on a strategy where Cumulative Delta would reset to 0 if a large volume where to occur and the beginning of a session. Would the code below be able to reset the cumulative delta to 0, especially the areas highlighted in red?

    Thanks!

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class Name : Strategy
    {
    private VOL VOL1;

    private double CD;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "Name";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 3;
    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;
    UserDefinedVolume = 10000;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Tick, 1);
    }
    else if (State == State.DataLoaded)
    {
    ClearOutputWindow();
    VOL1 = VOL(Closes[0]);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 10)
    return;

    if (BarsInProgress == 0)
    {
    // Print the close of the cumulative delta bar with a delta type of Bid Ask and with a Session period
    CD = OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaClose[0];
    }

    else if (BarsInProgress == 1)
    {
    // We have to update the secondary series of the cached indicator to make sure the values we get in BarsInProgress == 0 are in sync
    OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).Update(OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).BarsArray[1].Count - 1, 1);
    }


    // Reset the tradeCounter value at the first tick of the first bar of each session.
    if (Bars.IsFirstBarOfSession && IsFirstTickOfBar)
    {
    CD = 0;
    }


    if (VOL1[0]>UserDefinedVolume)
    {
    CD = 0;
    }


    if (ToTime(Times[0][0]) >= StartTradingTime)
    {
    if (CD > UserDefinedVolume)
    EnterLong();

    if (CD < -UserDefinedVolume)
    EnterShort();
    }

    #2
    Hello AgriTrdr,

    The first areas that you marked red are just a requirement of how to use that indicator. The second area where you marked red would be a way to reset your variable to 0. To know if this is working or not you would need to test it and add prints to output the values the script is observing.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Does anyone have a code for a simple Cumulative Delta indicator that they would be willing to share? I don't need anything fancy and would like to be able to reset the indicator to 0 at the beginning of the session and then again when large volume occurs.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by OllieFeraher, 05-09-2024, 11:14 AM
      5 responses
      16 views
      0 likes
      Last Post MisterTee  
      Started by jackiegils, Yesterday, 11:05 PM
      1 response
      10 views
      0 likes
      Last Post marcus2300  
      Started by Skifree, Today, 02:50 PM
      0 responses
      8 views
      0 likes
      Last Post Skifree
      by Skifree
       
      Started by owen5819, Today, 02:24 PM
      1 response
      12 views
      0 likes
      Last Post owen5819  
      Started by Skifree, 05-07-2024, 11:38 PM
      2 responses
      28 views
      1 like
      Last Post Skifree
      by Skifree
       
      Working...
      X