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

Divergence

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

    Divergence

    Code:
    #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.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators.BobC
    {
    public class CDDivergenceUDT : Indicator
    {NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Arial", 10) { Size = 10, Bold = false };
    private OrderFlowCumulativeDelta OrderFlowCumulativeDelta1;
    private Brush divergeCandle = Brushes.Purple; // Color body for Divergence Candle
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"A Line is drawn from the specified Open.";
    Name = "CDDivergenceUDT";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = false;
    DrawOnPricePanel = true;
    PaintPriceMarkers = false;
    IsSuspendedWhileInactive = true;
    IsAutoScale = false;
    }
    else if (State == State.Configure)
    {
    // OrderFlowCumulativeDelta1 = OrderFlowCumulativeDelta(Close, NinjaTrader.NinjaScript.Indicators.CumulativeDelta Type.BidAsk, NinjaTrader.NinjaScript.Indicators.CumulativeDelta Period.Session, 0);
    OrderFlowCumulativeDelta1 = OrderFlowCumulativeDelta(Close, NinjaTrader.NinjaScript.Indicators.CumulativeDelta Type.UpDownTick, NinjaTrader.NinjaScript.Indicators.CumulativeDelta Period.Session, 0);
    }
    else if (State == State.DataLoaded)
    {
    }
    }
    
    protected override void OnBarUpdate()
    {
    if (CurrentBars[0]<BarsRequiredToPlot)
    {return;}
    
    #region Transition Candles
    if(OrderFlowCumulativeDelta1.DeltaClose[0] > OrderFlowCumulativeDelta1.DeltaOpen[0] && Close[0] < Open[0]) //added Transition Yellow Outline
    {
    BarBrushes[0]=divergeCandle;
    Draw.Line(this, @"", false, 0, 0, 0, 0, Brushes.CornflowerBlue, DashStyleHelper.Solid, 2);
    }
    if(OrderFlowCumulativeDelta1.DeltaClose[0] < OrderFlowCumulativeDelta1.DeltaOpen[0] && Close[0] > Open[0])
    {
    BarBrushes[0]=divergeCandle;
    Draw.Line(this, @"", false, 0, 0, 0, 0, Brushes.CornflowerBlue, DashStyleHelper.Solid, 2);
    }
    #endregion
    
    }
    
    // In order to trim the indicator's label we need to override the ToString() method.
    public override string DisplayName
    {
    get { return Name ;}
    }
    
    
    #region Properties
    [XmlIgnore]
    [Display(Name="DivergenceCandle", Description="Divergence Candle Body Color", Order=4, GroupName="Visual")]
    public Brush DivergeCandle
    {
    get { return divergeCandle;}
    set { divergeCandle = value;}
    }
    
    [Browsable(false)]
    public string DivergeCandleSerializable
    {
    get { return Serialize.BrushToString(divergeCandle); }
    set { divergeCandle = Serialize.StringToBrush(value); }
    }
    
    #endregion
    
    }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private BobC.CDDivergenceUDT[] cacheCDDivergenceUDT;
    public BobC.CDDivergenceUDT CDDivergenceUDT()
    {
    return CDDivergenceUDT(Input);
    }
    
    public BobC.CDDivergenceUDT CDDivergenceUDT(ISeries<double> input)
    {
    if (cacheCDDivergenceUDT != null)
    for (int idx = 0; idx < cacheCDDivergenceUDT.Length; idx++)
    if (cacheCDDivergenceUDT[idx] != null && cacheCDDivergenceUDT[idx].EqualsInput(input))
    return cacheCDDivergenceUDT[idx];
    return CacheIndicator<BobC.CDDivergenceUDT>(new BobC.CDDivergenceUDT(), input, ref cacheCDDivergenceUDT);
    }
    }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.BobC.CDDivergenceUDT CDDivergenceUDT()
    {
    return indicator.CDDivergenceUDT(Input);
    }
    
    public Indicators.BobC.CDDivergenceUDT CDDivergenceUDT(ISeries<double> input )
    {
    return indicator.CDDivergenceUDT(input);
    }
    }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.BobC.CDDivergenceUDT CDDivergenceUDT()
    {
    return indicator.CDDivergenceUDT(Input);
    }
    
    public Indicators.BobC.CDDivergenceUDT CDDivergenceUDT(ISeries<double> input )
    {
    return indicator.CDDivergenceUDT(input);
    }
    }
    }
    
    #endregion
    I'm trying to use this dude's code to make my own divergence indicator.
    However I cant figure out how to turn the Divergence Candle bar location into an integer so I can insert it into my Draw.Line code?
    Any help? thanks

    #2
    Hello ezrollin,

    I'm not seeing a Divergence Candle bar location in this code. These appear to be drawing lines on the current bar (0 bars ago).

    Which line and which variable are you referring to?

    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
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Bhavika, Yesterday, 09:03 PM
    1 response
    4 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by slimcactus, Today, 10:26 AM
    1 response
    13 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by Monares, Today, 10:49 AM
    3 responses
    17 views
    0 likes
    Last Post NinjaTrader_JustinD  
    Started by d122y, Today, 10:20 AM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_ChrisL  
    Started by trader3000a, Today, 06:41 AM
    1 response
    15 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X