• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

place a midpoint line on an autoscaled indicator

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

    #16
    Hello GeorgeW,

    Thank you for your response.

    Use GetValueByY to compare the plot value and the line's value: http://ninjatrader.com/support/helpG...etvaluebyy.htm

    Please let me know if you have any questions.
    Patrick H.NinjaTrader Customer Service

    Comment


      #17
      Hello PatrickH,
      I have tried using GetValueByY both with a normal double variable and a double series. With the normal double I get Draw.Arrow signals, but they are all in the wrong place, as they only use the initial value of the variable set in "State == State.SetDefaults". When I use the double series I get no arrow signals. The output screen only show values for the first day of 15 I have loaded on the chart, and all for 23:05:10 even though the scale values are different. How do I get values for all the days loaded on the chart?

      Below is the main parts of the code concerned, and I have attached an image of the output window.

      Thank you.

      Code:
      protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
      		{
      			
      			/*The 2 floats below already restricts the line to what is on the screen, so you should not use below to restrict it, or else problems:
      			if (ChartBars != null) { for (int barIndex = ChartBars.FromIndex; ChartBars.FromIndex <= ChartBars.ToIndex; barIndex++) { }*/ 
      			float startX = chartControl.GetXByBarIndex(ChartBars, ChartBars.FromIndex); 
      			float endX = chartControl.GetXByBarIndex(ChartBars, ChartBars.ToIndex);
      			
      //			float chartScaleYValue = chartScale.GetYByValue(ChartPanel.MinValue + ((ChartPanel.MaxValue - ChartPanel.MinValue)/2));
      			float chartScaleYValue = chartScale.GetYByValue((chartScale.MaxMinusMin)/2); //WH added 27/05/2917 - this works, original above does it off the visible chart
      			
      			SharpDX.Vector2 startPoint = new SharpDX.Vector2(startX, chartScaleYValue);
              	SharpDX.Vector2 endPoint = new SharpDX.Vector2(endX, chartScaleYValue);	
      			
      			using (SharpDX.Direct2D1.SolidColorBrush dxBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.DarkOrange))
      			{
      				RenderTarget.DrawLine(startPoint, endPoint, dxBrush, 2.0f);
      			}
      			/*GetValueByY: Returns the series value on the chart scale determined by a y pixel coordinate on the chart. A double value representing 
      			a series value on the chart scale.  This is normally a price value, but can represent indicator plot values as well.
      			This changes the pixel value of chartScaleYValue to the left scale value so that I can calculate when there is a cross of it.*/
      			midScale[0] = chartScale.GetValueByY(chartScaleYValue);
      			Print(Time[0].ToString()+" " + "midScale =" + midScale[0]);
      
      			base.OnRender(chartControl, chartScale);			
      		}
      
      
      		protected override void OnBarUpdate()
      		{
      //Bull Signal
      			if (low1 < BMTCollectiveMA1.Plot0[1] &&
      				Values[1][1] > midScale[0] && Values[1][0] < midScale[0] && Values[0][1] < 1 && Values[0][0] > Values[0][1])
      			{
      			Alert("myAlertStochasticsK", Priority.High, "OB falls below midScale = UB", [email protected]"\sounds\Alert1.wav", 10, 
      			Brushes.Green, Brushes.Black);
      			ArrowUp myArrowUpA = Draw.ArrowUp(this, "My2PeriodsSignalsStrategy Arrow up_1" + CurrentBar, false, 0, Low[0] - 2*TickSize, Brushes.DarkGreen); 
      			myArrowUpA.OutlineBrush = Brushes.Black;	
      			}
      			
      			//Bear Signal
      			if (high1 > BMTCollectiveMA1.Plot0[1] &&
      				Values[0][1] > midScale[0] && Values[0][0] < midScale[0] && Values[1][1] < 1 && Values[1][0] > Values[1][1])
      			{
      			Alert("myAlertStochasticsK", Priority.High, "OS falls below midScale = US", [email protected]"\sounds\Alert1.wav", 10, 
      			Brushes.Red, Brushes.Black);
      			ArrowDown myArrowDownA = Draw.ArrowDown(this, "My2PeriodsSignalsStrategy Arrow down_1" + CurrentBar, false, 0, High[0] + 3*TickSize, Brushes.Red);
      			myArrowDownA.OutlineBrush = Brushes.Black;	
      			}
      		}
      Attached Files

      Comment


        #18
        Hello GeorgeW,

        Thank you for your patience.

        The OnRender would only call on the chart after historical data processed. We would not see the values of this across the historical collection when it loads. We would only see the cross occur in real-time.

        For example run the attached indicator in Market Replay with a SMA(14) on your chart and the Output window open. You should only see Print()s when the SMA crosses the middle line as the Playback connection plays forward.
        Attached Files
        Patrick H.NinjaTrader Customer Service

        Comment


          #19
          Thanks for that, PatrickH.

          I having incorporated parts of your code into mine, and I can now get a Draw.ArrowUp signal when a bar closes above that midline. However, writing the reverse code for when a bar closes below, I am getting no arrows. Is there something peculiar to the line so that the closing below code needs to be written differently? My arrow codes are below:

          Code:
          if ((close0 > open0 || ((open0 == close0) &&((Math.Abs(high0 - open0) < Math.Abs(low0 - open0)))))
          				&& (close0 > midScale[0] || close0 > midScale[1]))
          			{
          			ArrowUp myArrowUpA = Draw.ArrowUp(this, "MyAboveMidScaleAU", false, 0, Low[0] - 2*TickSize, Brushes.DarkBlue); 
          			myArrowUpA.OutlineBrush = Brushes.Black;	
          			}
          if ((close0 < open0 || ((open0 == close0) &&((Math.Abs(high0 - open0) > Math.Abs(low0 - open0)))))
          				&& (close0 < midScale[0] || close0 < midScale[1]))
          			{
          			ArrowDown myArrowDownA = Draw.ArrowDown(this, "MyBelowMidScaleAD", false, 0, High[0] + 2*TickSize, Brushes.Orange);
          			myArrowDownA.OutlineBrush = Brushes.Black;	
          			}

          Comment


            #20
            Hello PatrickH,
            I have tried your script on a live chart but I am not getting prints to the output window. Also, I have tried your Cross code with my arrow signals, but I am getting nothing there.

            Code:
            if (midLine != double.MinValue && CrossBelow(Values[1], midLine, 1))
            			{
            			ArrowUp myArrowUpB = Draw.ArrowUp(this, "MyAboveMidScaleAU" + CurrentBar, false, 0, Low[0] - 2*TickSize, Brushes.DarkBlue); 
            			myArrowUpB.OutlineBrush = Brushes.Black;
            			Print("");
            			Print(Time[0]);
            			Print("OBCross");
            //			Print(Time[0].ToString()+" " + "OBCross" + " " + "midLine =" + midLine);
            			}

            Comment


              #21
              Hello PatrickH,

              After some playing around I have got it to work in playback.

              Thank you.

              Comment


                #22
                Thank you for the update, GeorgeW.

                Please let me know if I may be of further assistance.
                Patrick H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by williamzz, Today, 03:10 PM
                1 response
                3 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by cabum, 09-25-2018, 06:46 AM
                8 responses
                226 views
                0 likes
                Last Post koganam
                by koganam
                 
                Started by saeed, Today, 02:07 PM
                5 responses
                11 views
                0 likes
                Last Post saeed
                by saeed
                 
                Started by 7robert, Today, 01:40 PM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_ChrisL  
                Started by bortz, Today, 12:57 PM
                3 responses
                17 views
                0 likes
                Last Post NinjaTrader_PatrickH  
                Working...
                X