Announcement

Collapse
No announcement yet.

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

    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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      574 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      332 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      553 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      551 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X