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

Writing an indicator but don't know what I did wrong

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

    Writing an indicator but don't know what I did wrong

    I'm trying to write an indicator that draws rectangles between High[2] and Low[0] when an if condition is triggered. Can someone tell what I need to fix to make it work? This was modified from NT7 indicator so I can start using NT8 but can't seem to find a way to work.


    public class Gaps : Indicator
    {
    #region Variables
    // Wizard generated variables


    private int linewidth = 2;
    private int _intCalculationIndex = 1;
    private int _intStartBar = 0;
    private Brush hiddenGapdown=Brushes.Magenta;
    private Brush hiddenGapup=Brushes.Cyan;
    private int opaque = 5;

    #endregion

    /// <summary>
    /// </summary>
    protected override void OnStateChange()
    {
    IsAutoScale = false;
    IsOverlay = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>

    protected override void OnBarUpdate()
    {
    this._intCalculationIndex = 1;
    if (CurrentBar < 5)
    return;
    {
    //Gap Up++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++Up+++++++ ++++++++++++
    if (Low[0] > High[2] )

    {
    Draw.Rectangle(this, CurrentBar.ToString(), false, 2, High[2] , 0, Low[0], hiddenGapup, hiddenGapup, Opacity);
    }


    //Gap Down ---------------------------------------------------------------------------Down--------------------------------------------
    if (High[0] < Low[2] //Gap from Current Candle to Candle before

    )
    {
    Draw.Rectangle(this, CurrentBar.ToString(), false, 2, Low[2], 0, High[0] , hiddenGapdown,hiddenGapdown,Opacity);
    }

    }
    }
    // In order to trim the indicator's label we need to override the ToString() method.
    public override string ToString()
    {
    return Name ;
    // return "" ;
    }


    // In order to trim the indicator's label we need to override the ToString() method.
    public override string ToString()
    {
    return Name ;
    // return "" ;
    }

    #region Properties
    #region Gap Down Color
    [XmlIgnore()]
    [Category("\t\t\t\tTrigger Colors")]

    public Brush GapDownColor
    {
    get { return hiddenGapdown; }
    set { hiddenGapdown = value; }
    }
    [Browsable(false)]
    public string GapDownColorSerialize
    {
    get { return Serialize.BrushToString(hiddenGapdown); }
    set {hiddenGapdown = Serialize.StringToBrush(value); }
    }
    #endregion

    #region Gap Up Color
    [XmlIgnore()]
    [Category("\t\t\t\tTrigger Colors")]

    public Brush GapUpColor
    {
    get { return hiddenGapup; }
    set { hiddenGapup = value; }
    }
    [Browsable(false)]
    public string GapUpColorSerialize
    {
    get { return Serialize.BrushToString(hiddenGapup); }
    set {hiddenGapup = Serialize.StringToBrush(value); }
    }
    #endregion

    #region Gap Fill Opacity
    [XmlIgnore()]
    [Category("\t\t\t\tTrigger Colors")]

    public int Opacity
    {
    get { return opaque; }
    set { opaque = value; }
    }
    #endregion

    #2
    Hi jheo0270, thanks for your note.

    Could you extrapolate on what exactly is not working? One thing I notice right away is your OnStateChanged method is not filtering the various states. See the SMA indicator for an example on this. I attached an example that will compile, but have not tested.

    I look forward to hearing from you.
    Attached Files
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      I added the onstatechanged method from your code and it's working perfectly now thank you!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by cmtjoancolmenero, Yesterday, 03:58 PM
      2 responses
      19 views
      0 likes
      Last Post cmtjoancolmenero  
      Started by Stanfillirenfro, Today, 07:23 AM
      0 responses
      2 views
      0 likes
      Last Post Stanfillirenfro  
      Started by olisav57, Yesterday, 07:39 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by cocoescala, 10-12-2018, 11:02 PM
      7 responses
      942 views
      0 likes
      Last Post Jquiroz1975  
      Started by oviejo, Today, 12:28 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X