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

OrderFlowCumulativeDelta Indicator

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

  • NinjaTrader_ChelseaB
    replied
    Hello ij001,

    Values[1], Values[2], and Values[3] do not exist. These are invalid indexes.
    Hello, I want to create an indicator that show data in a chart but calculate in other charttime different to the time of the chart where is showed. For example:


    You would need to call AddPlot() 3 more times for these plot series to exist.

    Leave a comment:


  • ij001
    replied
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello ij001,
    Candle body outline OutlineStroke.Brush
    Candle wick WickStroke.Brush
    Color for down bars DownBrush
    Color for up bars UpBrush
    Print(OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DownBrush.ToString());
    Hi Chelsea,

    I have been working on it. First I am trying to get the indicator to display the delta candles before I work on the mirror aspect.

    I seem to get hung up with the "index out of bound error"

    That is: Indicator 'OFCFDeltaCandles': Error on calling 'OnBarUpdate' method on bar 2: Index was outside the bounds of the array.

    I've read the NT guide on CurrentBar but still get the error. What am I missing?


    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.DrawingTools;
    #endregion

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class OFCFDeltaCandles : Indicator
    {
    private OrderFlowCumulativeDelta cumulativeDelta;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    AddPlot(Brushes.Orange, "DeltaClose");

    Name = "OFCFDeltaCandles";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false; // Set to false to use its own plot

    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Tick, 1);
    }
    else if (State == State.DataLoaded)
    {
    cumulativeDelta = OrderFlowCumulativeDelta(CumulativeDeltaType.BidAs k, CumulativeDeltaPeriod.Bar, 0);
    }
    }

    protected override void OnBarUpdate()
    {
    // Ensure that we have enough bars to avoid the index out of bounds error
    if (CurrentBar < 2 || BarsInProgress != 0 || CurrentBars[0] < 2 || CurrentBars[1] < 2)
    return;

    if (BarsInProgress == 0)
    {
    Values[0][0] = cumulativeDelta.DeltaClose[0];
    Values[1][0] = cumulativeDelta.DeltaOpen[0];
    Values[2][0] = cumulativeDelta.DeltaHigh[0];
    Values[3][0] = cumulativeDelta.DeltaLow[0];

    // Determine the color based on deltaClose value
    Brush barColor = cumulativeDelta.DeltaClose[0] > 0 ? Brushes.SpringGreen : Brushes.Red;

    // Drawing the candlestick
    // Note: You will need to implement the DrawCandlestick method to draw the actual candlestick
    DrawCandlestick(Values[1][0], Values[2][0], Values[3][0], Values[0][0], barColor);
    }

    else if (BarsInProgress == 1)
    {
    cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count - 1, 1);
    }

    }

    private void DrawCandlestick(double open, double high, double low, double close, Brush color)
    {
    int barIndex = CurrentBar;
    double bodyTop = Math.Max(open, close);
    double bodyBottom = Math.Min(open, close);
    int barWidth = 1; // Adjust the width as needed

    // Drawing the body of the candlestick
    Draw.Rectangle(this, "body" + barIndex, false, barIndex, bodyTop, barIndex - barWidth, bodyBottom, color, color, 10);

    // Drawing the upper wick
    if (high > bodyTop)
    {
    Draw.Line(this, "upperWick" + barIndex, false, barIndex, high, barIndex, bodyTop, color, DashStyleHelper.Solid, 1);
    }

    // Drawing the lower wick
    if (low < bodyBottom)
    {
    Draw.Line(this, "lowerWick" + barIndex, false, barIndex, bodyBottom, barIndex, low, color, DashStyleHelper.Solid, 1);
    }
    }
    }
    }

    region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private OFCFDeltaCandles[] cacheOFCFDeltaCandles;
    public OFCFDeltaCandles OFCFDeltaCandles()
    {
    return OFCFDeltaCandles(Input);
    }

    public OFCFDeltaCandles OFCFDeltaCandles(ISeries<double> input)
    {
    if (cacheOFCFDeltaCandles != null)
    for (int idx = 0; idx < cacheOFCFDeltaCandles.Length; idx++)
    if (cacheOFCFDeltaCandles[idx] != null && cacheOFCFDeltaCandles[idx].EqualsInput(input))
    return cacheOFCFDeltaCandles[idx];
    return CacheIndicator<OFCFDeltaCandles>(new OFCFDeltaCandles(), input, ref cacheOFCFDeltaCandles);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.OFCFDeltaCandles OFCFDeltaCandles()
    {
    return indicator.OFCFDeltaCandles(Input);
    }

    public Indicators.OFCFDeltaCandles OFCFDeltaCandles(ISeries<double> input )
    {
    return indicator.OFCFDeltaCandles(input);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.OFCFDeltaCandles OFCFDeltaCandles()
    {
    return indicator.OFCFDeltaCandles(Input);
    }

    public Indicators.OFCFDeltaCandles OFCFDeltaCandles(ISeries<double> input )
    {
    return indicator.OFCFDeltaCandles(input);
    }
    }
    }

    #endregion

    ​​
    Attached Files

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello ij001,
    Candle body outline OutlineStroke.Brush
    Candle wick WickStroke.Brush
    Color for down bars DownBrush
    Color for up bars UpBrush

    Print(OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DownBrush.ToString());

    Leave a comment:


  • ij001
    replied
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello Irvin,

    The Order Flow Cumulative Delta does produce DeltaOpen, DeltaHigh, DeltaLow, and DeltaClose values, and these values can be called from another indicator.


    Theoretically it would be possible to do something similar to the mirror bars and multiply the value by -1 and then plot the values in the new script.
    Hi Chelsea_B,

    I am able to plot the various values (DeltaOpen, DeltaHigh, DeltaLow, DeltaClose)

    Any insight on where I can get code for the "Parameters" below?
    Candle body outline Color and line settings for the candle body outline
    Candle wick Color and line settings for the candle wick
    Color for down bars Color for bars that have a close less than the open
    Color for up bars Color for bars that have an open greater than the open


    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello Irvin,

    The Order Flow Cumulative Delta does produce DeltaOpen, DeltaHigh, DeltaLow, and DeltaClose values, and these values can be called from another indicator.


    Theoretically it would be possible to do something similar to the mirror bars and multiply the value by -1 and then plot the values in the new script.

    Leave a comment:


  • ij001
    started a topic OrderFlowCumulativeDelta Indicator

    OrderFlowCumulativeDelta Indicator

    Hi NT,

    I have a lifetime license for NT.

    Occasionally, I use Mirror Charts for visual purposes.

    I'm wondering if there's also a way to also mirror the OFCD (OrderFlowCumulativeDelta) indicator using some code in a new indicator.

    What would you suggest?

    Thanks in advance.
    Irvin

Latest Posts

Collapse

Topics Statistics Last Post
Started by reynoldsn, 05-10-2024, 07:04 PM
6 responses
37 views
0 likes
Last Post reynoldsn  
Started by ETFVoyageur, 05-07-2024, 07:05 PM
22 responses
181 views
0 likes
Last Post NinjaTrader_ChelseaB  
Started by ETFVoyageur, Today, 02:15 AM
5 responses
30 views
0 likes
Last Post NinjaTrader_ChelseaB  
Started by drnoggin, Today, 12:19 PM
1 response
14 views
0 likes
Last Post NinjaTrader_Jesse  
Started by synthhokie, Today, 12:00 PM
1 response
16 views
0 likes
Last Post NinjaTrader_Jesse  
Working...
X