Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help o CrossAbove/below with arrows indicator

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

    Help o CrossAbove/below with arrows indicator

    Hi

    Can you please help me to put this code working it gave me a lot of errors. In english what I want to do is an indicator that paints a Red arrowdown on crossabove close x EMA bar and paints a blue arrowup on crossbelow close x EMA bar


    CODE:

    #region Variables
    // Wizard generated variables
    private int period = 14; // Default setting for Period
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Dot, "CrosseAbove"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Dot, "CrosseBelow"));
    CalculateOnBarClose = false;
    Overlay = false;
    PriceTypeSupported = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {

    // Paints a blue down arrown on cross bar
    if (Close[0] > Open[0] && CrossAbove(Close[0], EMA(10), 1)))
    DrawArrowDown(CurrentBar.ToString(), true, 0, High[0] + TickSize, Color.Blue);

    }

    // Paints a Red down arrown on cross bar
    if (Close[0] < Open[0] && CrossBelow(Close[0], EMA(20), 1)))
    DrawArrowDown(CurrentBar.ToString(), true, 0, High[0] + TickSize, Color.Blue);

    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    CrosseAbove.Set(Close[0] > Open[0] && CrossAbove(EMA(10), EMA(20), 5)) );
    CrosseBelow.Set(Close[0] < Open[0] && CrossBelow(EMA(10), EMA(20), 5)) );
    }


    #region Properties
    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries CrosseAbove
    {
    get { return Values[0]; }
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries CrosseBelow
    {
    get { return Values[1]; }
    }

    [Description("SMA Period")]
    [Category("Parameters")]
    public int Period
    {
    get { return period; }
    set { period = Math.Max(1, value); }
    }
    #endregion

    #2
    Hello,

    First, if I understand correctly, you don't need to use Add to add a plot because objects (arrows) are not plots. I suggest reviewing this sample:

    And this link:


    The basic form that you need is something like this:

    OnBarUpdate()
    {

    if(...your condition here....)
    {
    DrawArrowUp("tag1", true, 0, Low[0], Color.Red);
    }

    //then a similar one for the down arrows
    }
    DenNinjaTrader Customer Service

    Comment


      #3
      Draw a rectangle with other time-frame references

      Hi Ben

      Thanks very much your post. I already did what I wanted.

      Now I need to draw a rectangle with reference of other time frame.

      I want to draw a rectangle (as you have on example of the indicator SampleDrawObject) on a 8 ticks rangebar chart with the references of a 16ticks rangebar chart (references I mean for example open, High or low from other time frame chart). For example the rectangle base line is the Low [0] from 16ticks chart and the rectangle top line is the High [0] from 16ticks chart. How can I reference this?

      Do you have any post with an example similar of this?

      Best

      Rita

      Comment


        #4
        Hello,

        I suggest downloading NT7 and looking at the multiple timeframe sample strategy:


        Or you can try to do read about it here:


        Basically you will need to add the interval, create a global variable you can use in all areas of your system that will hold the values you want to use for your rectangle, call the values (see the link for examples), store the values in the global variables you created, and at the bottom of your OnBarUpdate block plot your triangle.

        Give it a try and if you get stuck on a certain part, post a code snippet of the part you are not understanding.
        DenNinjaTrader Customer Service

        Comment


          #5
          Change Draw arrowup by Draw Horizontal line

          Thanks Ben

          I'll have a look.

          But now I try to change a Draw Arrowup for a Draw Horizontal line and I can not see the line.

          On the code as you can see, I changed

          DrawArrowUp("Up Arrow" + CurrentBar, 0, Low[0] - TickSize, Color.Blue);

          by

          DrawHorizontalLine("tag1", false, High [0], Color.Cyan, DashStyle.Solid, 2);

          I put "tag1" because I want it change every new signal (plot only the current signal/last signal). Is it right? High [0] because I want it on the high bar, is it right? do I need to add new variables for this case? 2 is for line tickness... How can I have line style as solid and hash?

          Best


          PART OF CODE:


          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          // When the close of the bar crosses above the HMA, draw a blue diamond
          if (CrossAbove(Close, HMA(period), 1))
          {
          /* Adding the 'CurrentBar' to the string creates unique draw objects because they will all have unique IDs
          Having unique ID strings may cause performance issues if many objects are drawn */
          DrawHorizontalLine("tag1", false, High [0], Color.Cyan, DashStyle.Solid, 2);
          }

          Comment


            #6
            Multi frame reference crosseabove/below indicator

            Hi Ben

            I've a look at the multiple timeframe sample strategy on NT7 and tried to adapt to my job (I'm still on NT 6.5 ) I tried to have on 8ticks range bar chart the crosseabove and below of 15ticks range bar with draw arrowup and arrow down and the rectangle (on 8ticks chart) as you have on yours indicator SampleDrawObject.

            I change the word Minutes by Range (because my chart is rangebar not min chart) as you can see on the code (Add(PeriodType.Range, 15); ) is it correct?

            I have a lot of errors againg can you please have a look on it? Thanks a lot

            Best

            CODE:

            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            /// </summary>
            protected override void Initialize()
            {

            // Add a 15 Range Bars object to the indicator
            Add(PeriodType.Range, 15);

            // Note: Bars are added to the BarsArray and can be accessed via an index value
            // E.G. BarsArray[1] ---> Accesses the 15 range Bars object added above

            // Add hull moving averages to the chart for display
            // This only displays the HMA's for the primary Bars object on the chart
            Add(HMA(period));


            CalculateOnBarClose = true;
            Overlay = true;
            }

            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {

            // OnBarUpdate() will be called on incoming tick events on all Bars objects added to the indicator
            // We only want to process events on our primary Bars object (index = 0) which is set when adding
            // the indicator to a chart
            if (BarsInProgress != 0)
            return;

            // When the close of the bar crosses above the HMA(14)on the 15 range bar chart, draw a blue diamond on this chart
            if (CrossAbove(Close, HMA(BarsArray[1], 15)[0], 1))
            {
            /* Adding the 'CurrentBar' to the string creates unique draw objects because they will all have unique IDs
            Having unique ID strings may cause performance issues if many objects are drawn */
            DrawArrowUp("Up Arrow" + CurrentBar, 0, Low[0] + TickSize, Color.Blue);
            }

            // But when the close crosses below the SMA(20), draw a magenta diamond
            else if (CrossBelow(Close, HMA(BarsArray[1], 15)[0], 1))
            {
            /* Adding the 'CurrentBar' to the string creates unique draw objects because they will all have unique IDs
            Having unique ID strings may cause performance issues if many objects are drawn */
            DrawArrowDown("Down Arrow" + CurrentBar, 0, High[0] + TickSize, Color.Orange);
            }

            // Draw a blue-violet rectangle representing the latest uptrend based on the SMA(20)
            if (Close[0] >= HMA(BarsArray[1], 15)[0])
            {
            /* Because the ID string is not unique for every rectangle, the latest draw object will replace the
            old draw object. The rectangle's starting bar is determined by the uptrend counter. */
            DrawRectangle("Rectangle", rectWidth, Close[rectWidth], 0, Close[0], Color.Blue, Color.BlueViolet, 2);

            // Counter that keeps track of the uptrend by incrementing
            rectWidth++;
            }

            // Reset the uptrend counter when trend has ended
            if (Close[0] < HMA(BarsArray[1], 15)[0])
            rectWidth = 0;
            }
            #region Properties
            #endregion

            Comment


              #7
              Hello,

              I am sorry, we don't really get into debugging systems for people. If you have a specific question on a specifice method I am happy to help you. Here is a link that will help you with debugging:


              Two tips though:
              1- You should try not to mix NT7 code with NT6.5 code. Most of it transfers but not all of it. This is true for the multiple timeframe stuff.

              2- I think you have some code outside of the OnBarUpdate block that should be in it. The part just after the OnBarUpdate block.
              DenNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              596 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              343 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              556 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              554 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X