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

Alert when price is near old support price

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

    Alert when price is near old support price

    Hi All

    I was just after a bit of help.. I've made a custom indicator that finds a certain type of support and resistance line. It works fine.. But.. Now I wanted to advance it a little by maybe getting it to alert me when the current price is approaching the area of the old support line.

    Is it possible to get a indicator to remember the last say 20 support lines and then alert me when price is near any one of these. I wanted to use the market analyser to list the last 20 support closes and then turn green when current price is approaching that support line

    My custom indicator produces an oscillator, and when changes from falling to rising it draws a line on the close of that bar to produce the support line.

    Would this be possible??

    #2
    Hello Wells0414,

    Thank you for your note.

    This would be possible but will require you to store the values in a list of some format so that you can then can compare the price to these Support/Resistance lines.

    Below is an example of how to add a list to your script -
    Code:
    #region Using declarations
    using System;
    using System.Windows.Forms;
    using System.Collections;
    [B]using System.Collections.Generic;[/B]
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    using System.Linq;
    using System.Reflection;
    
    #endregion
    
    namespace NinjaTrader.Indicator
    {
        [Description("")]
        public class Test1 : Indicator
        {
    		[B]private List<double> myList = new List<double>();[/B]
    		
    		protected override void Initialize()
    		{
    		}
    
    		protected override void OnBarUpdate()
    		{
                            // If new session, then add in resistance lines to myList
    			if(Bars.FirstBarOfSession && FirstTickOfBar)
    				myList.Add(ResistanceLine);
    			
                            // Check that myList has 20 values
                            if(myList.Count >= 20)
                            {	
                                // Check if the Close price is less than or equal to myList 20 values ago
    			    if(Close[0] <= myList[20])
    			    {
    				 // Do something here
    			    }
                            }
    		}
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Hi Cal

      Thanks for the response..

      Just so I can get my head around this :

      myList.Add(ResistanceLine);

      on this line I remove resistanceline and add my indictor name??

      Comment


        #4
        Ok so this is my indicator...

        Ive inserted in what you have given me but im not totally sure at what im doing (this is my first indicator)

        As you can see in the code I get it to draw lines when the indicator is at a high point greater then 10,000 and at a low point less then -10,000...

        Its draws a horizontal line on the close of that bar, its those lines I want the record in the list, and then when price returns back to a price area where the line is drawn, it then produces an output.






        Code:
         
         #region Using declarations
         using System;
         using System.Windows.Forms;
         using System.Collections;
         using System.Collections.Generic;
         using System.ComponentModel;
         using System.Diagnostics;
         using System.Drawing;
         using System.Drawing.Drawing2D;
         using System.Xml.Serialization;
         using NinjaTrader.Cbi;
         using NinjaTrader.Data;
         using NinjaTrader.Gui.Chart;
         using System.Linq;
         using System.Reflection;
         #endregion
         // This namespace holds all indicators and is required. Do not change it.
         namespace NinjaTrader.Indicator
         {
         /// <summary>
         /// Enter the description of your new custom indicator here
         /// </summary>
         [Description("Enter the description of your new custom indicator here")]
         public class CocoaLines : Indicator
         {
         #region Variables
         private int highValue = 10000; // Default setting for HighValue
         private int lowValue = -10000; // Default setting for LowValue
         private DataSeries Diff;
         private DataSeries Spread;
         private List<double> myList = new List<double>();
         
         
         // 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.SlateBlue), PlotStyle.Line, "Plotline"));
         Add(new Line(Color.FromKnownColor(KnownColor.DarkOliveGreen), highValue, "High"));
         Add(new Line(Color.FromKnownColor(KnownColor.Red), lowValue, "Low"));
         Overlay = false;
         
         Diff = new DataSeries(this);
         Spread = new DataSeries(this);
         MaxPlot = new DataSeries(this);
         
         
         
         }
         /// <summary>
         /// Called on each bar update event (incoming tick)
         /// </summary>
         protected override void OnBarUpdate()
         {
         // Use this method for calculating your indicator values. Assign a value to each
         // plot below by replacing 'Close[0]' with your own formula.
         if (BarsInProgress != 0) return;
         if (CurrentBar<100) return;
         
         
         
         
         Diff.Set(((SMA(20))[0] - (Coral(55)[0])) * ((BollingerHMA(0.25, 21).Upper[0] - BollingerHMA(0.25, 21).Lower[0])));
         Spread.Set(((IchiCloud3(9).SenkouSpanA[0] - IchiCloud3(9).SenkouSpanB[0])+1) * (IchiCloud3(9).SenkouSpanA[0] - Close[0])+.1);
         Plotline.Set((((Diff[0])/((Range()[0])+1))/(Spread[0]))*1000000);
         
         
         if (MIN(Plotline, 14)[1] == Plotline[1]
         && Plotline[0] > MIN(Plotline, 14)[0]
         && Plotline[1] < lowValue)
         {
         DrawHorizontalLine("My horizontal line" + CurrentBar, Close[1], Color.Red);
         
         }
         if (MAX(Plotline, 14)[1] == Plotline[1]
         && Plotline[0] < MAX(Plotline, 14)[0]
         && Plotline[1] > highValue)
         {
         DrawHorizontalLine("My horizontal line" + CurrentBar, Close[1], Color.Green);
         
         }
         {
         // If new session, then add in resistance lines to myList
         if(Bars.FirstBarOfSession && FirstTickOfBar)
         myList.Add((double) Plotline[0]);
         
         // Check that myList has 20 values
         if(myList.Count >= 20)
         { 
         // Check if the Close price is less than or equal to myList 20 values ago
         if(Close[0] > myList[20])
         {
         BarColor = Color.OrangeRed;
         }
         }
         }
         
         
         
         
         }

        Comment


          #5
          Wells0414,

          No, the ResistanceLine is going to be a double value as we used a type safe list List<double>

          The goal here is that you would calculate out what you want to input for your resistance lines values and then add that value to the list so that you can reference that value from the code for comparing to the close price.
          Cal H.NinjaTrader Customer Service

          Comment


            #6
            Ok so I need to get my indicator to produce a double value better.
            I understand the theory better now Thankyou

            Just need to figure how to produce the double now
            So the double value has to reflect when the lines is drawn not the actual oscillator itself

            Comment


              #7
              Hi Cal

              One last question
              My indicator currently draws a horizontal line which is a pain when I back test cos I'm unsure if the line has been produced in the past or future.

              What would I change the draw horizontal line code too, so it only draws to right of the close bar. ??

              Comment


                #8
                Wells,

                You would want to use a DrawLine() instead.

                The horizontal line will continue in either direction on the chart. The DrawLine() will allow you to limit where it is showing.
                http://www.ninjatrader.com/support/h...l?drawline.htm
                Cal H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by techgetgame, Yesterday, 11:42 PM
                0 responses
                8 views
                0 likes
                Last Post techgetgame  
                Started by sephichapdson, Yesterday, 11:36 PM
                0 responses
                2 views
                0 likes
                Last Post sephichapdson  
                Started by bortz, 11-06-2023, 08:04 AM
                47 responses
                1,613 views
                0 likes
                Last Post aligator  
                Started by jaybedreamin, Yesterday, 05:56 PM
                0 responses
                10 views
                0 likes
                Last Post jaybedreamin  
                Started by DJ888, 04-16-2024, 06:09 PM
                6 responses
                20 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Working...
                X