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

Add "Drawdot"

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

    Add "Drawdot"

    Hi,

    Im trying to change a line of code in my indicator, so that it draws a dot and not an arrow... Can you help me with the code please, it is coming up with an error when I add my line... (CS1501).

    My Code is as follows....

    Code:
    [Description("Doji bar with arrow")]
        public class DojiBar : Indicator
        {
            #region Variables
            // Wizard generated variables
            private double wick = 3;
    		private double tail = 3;
    		private double body = 1;
    		private Color barColorUp =   Color.Orange;
    		bool both = false;
            // 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()
            {
          
                CalculateOnBarClose	= true;
                Overlay				= true;
                PriceTypeSupported	= true;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
    			if (CurrentBar < 1) return;
                // Use this method for calculating your indicator values. Assign a value to each
                // plot below by replacing 'Close[0]' with your own formula.
    			double body0 = Instrument.MasterInstrument.Round2TickSize(Math.Abs(Open[0] - Close[0]))/TickSize;
    			double wick0 = Instrument.MasterInstrument.Round2TickSize(Math.Abs(High[0] - Open[0]))/TickSize;
    			double tail0 = Instrument.MasterInstrument.Round2TickSize(Math.Abs(Close[0] - Low[0]))/TickSize;
    	//		Print(CurrentBar +"  body0  "+body0+ " wick0 " + wick0 + "  tail0   "+tail0);
    			
                  	if(body0 <= body) 
    					  if (both)
    					{
    					  if (wick0 >= wick && tail0 >= tail )
    				    	DrawArrowDown("MyArrowDown"+Curre[CODE]
    ntBar, 0, High[0]+2* TickSize, barColorUp);
    PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\S & P.wav");
    }
    else
    if (wick0 >= wick || tail0 >= tail )
    DrawArrowDown("MyArrowDown"+CurrentBar, 0, High[0]+2* TickSize, barColorUp);
    PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\S & P.wav");[/CODE]

    Im trying to change the line

    Code:
    DrawArrowDown("MyArrowDown"+CurrentBar, 0, High[0]+2* TickSize, barColorUp);
    to
    Code:
    DrawDot("MyDot", true, 0, Low[0] - TickSize, Color.Red);

    #2
    Hello ScottieDog,

    What is the error message you are getting?

    What line does the error message indicate the error is on?

    What characters does the error message show where there is an issue?

    If you double click the error message where does it take you in the code?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Sorry, my bad, its not throwing the error now, I just tried it again... Not sure why that was happening, must have had something wrong somewhere else.

      Another question though, I am trying to add a sound alert to the original code, I am adding

      Code:
      PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\S & P.wav");
      and the sound is playing on every new bar.... the arrows are plotting correctly at close of the bar only, id like the sound to alert only when the arrow plots at the end of a bar.

      Comment


        #4
        Hello ScottieDog,

        You have explicity written into your code to trigger the sound if both is true even if wick0 is not less than wick and tail0 is greater than tail.

        Your usage of brackets { } is incorrect if you want the if to also apply to the PlaySound.

        Current code:
        if (both)
        {
        if (wick0 >= wick && tail0 >= tail )
        DrawArrowDown("MyArrowDown"+CurrentBar, 0, High[0]+2* TickSize, barColorUp);
        PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\S & P.wav");
        }

        When you use an if without brackets, only the next line is affected by the if. (Otherwise how would it know how many lines to include?)

        Change your code to:
        if (both && wick0 >= wick && tail0 >= tail)
        {
        DrawArrowDown("MyArrowDown"+CurrentBar, 0, High[0]+2* TickSize, barColorUp);
        PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\S & P.wav");
        }

        Everything between the opening and closing curly braces will trigger when the if is true.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I want to revisit this as I am trying to do the same again, and I am getting the same error code... Ill give more details in this reply.

          I have the indicator working fine, it draws an arrow down at the correct time, and it plays a sound correctly.. I want to change the "arrow down" to a simple "dot".

          This is the code I'm using that works fine...

          Code:
          if (both && wick0 >= wick && tail0 >= tail)
          						{
          						DrawArrowDown("MyArrowDown"+CurrentBar, 0, High[0]+2* TickSize, barColorUp);
          						PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\beeplow.wav");
          						}
          					
          						else
          					 if (wick0 >= wick || tail0 >= tail )
          						{
          				    	DrawArrowDown("MyArrowDown"+CurrentBar, 0, High[0]+2* TickSize, barColorUp);
          						PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\beeplow.wav");				
          						}
          I am simply trying to change the one line where it says "DrawArrowDown".

          Code:
          DrawArrowDown("MyArrowDown"+CurrentBar, 0, High[0]+2* TickSize, barColorUp);
          I am changing the line to "DrawDot" instead,

          Code:
          DrawDot("MyArrowDown"+CurrentBar, 0, High[0]+2* TickSize, barColorUp);
          but then I get a CS1501 error when compiling. The error is on the line I am changing. The error quotes "no overload for method "DrawDot" takes "4" arguments. What else do I have to change?

          Comment


            #6
            I had this same issue some time ago.

            You second overload needs to be a boolean (true or false) which "determines if the draw object will be included in the y-axis scale".

            So the line will look something like this:

            Code:
            DrawDot("tag"+CurrentBar, [B][COLOR="Purple"]true[/COLOR][/B], 0, High[0]+2* TickSize, barColorUp);

            Comment


              #7
              Thank-You.

              That sorted it.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by rdtdale, Today, 01:02 PM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by alifarahani, Today, 09:40 AM
              3 responses
              16 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by RookieTrader, Today, 09:37 AM
              4 responses
              19 views
              0 likes
              Last Post RookieTrader  
              Started by PaulMohn, Today, 12:36 PM
              0 responses
              10 views
              0 likes
              Last Post PaulMohn  
              Started by love2code2trade, 04-17-2024, 01:45 PM
              4 responses
              41 views
              0 likes
              Last Post love2code2trade  
              Working...
              X