Measuring Device

I am looking for a measuring tool / formula that can be used to:

  • Measure between 2 points on a chart (Dates or positions) (any direction)
  • To have the day count measured, the bar count measured
  • Then to have the exact same distant (date / bar No.) again proposed or extended in the direction I choose (i.e. if I start a point then move mouse to the left then the extension continues to the left)

Is there something in existence that I am not locating correctly or has someone already programmed something and I am not using the correct search words??

Regards,

Dan

Draw a trendline between 2 bars, then pause the mouse on it and wait for the popup window

3 Likes

Hi,

Thanks for the suggestion. I do realize that this is a possibility to get
the data I’m after. But I am looking for something a little more detailed
so I can use it in analysis, thus the data I’m wanting exposed from the
ruler measurement is to be in an exposed text format on the chart next to
the selected point placement.

Regards.

You could get the starting and ending X and Y coordinates of the line using this code, then just calculate what you need yourself and output it to the chart using PlotText.

Hi Alan,

Thanks for the info and suggestion mate. I have attempted your direction yet I don't seem to have the skillset to manipulate any of the code to make it suit to what I am chasing. Maybe I am not been clear, but more likely I am not understanding you and your directions.... :I think you are definitely accurate is the assistance for myself but I'm not capable of 'getting it'.

To help clear this up, have a look at the pictures below, they are snapshots of other charting packages that have this ability I am trying to get in amibroker ~ In the pictures you can see the horizontal lines (that have been drawn in) with a text number between 2 points (X&Y) points): the text is either in (1) bars or days (I'd like both if possible) and on another platform just the number of bars.

This is all I am wanting to produce. Then for every 1 length that I have drawn, I can redraw the same again for future plotting of price movements OR if there is an ability to have this same length extended again 'mirroring' the originally drawn length then that would be a bonus!

​Appreciate your time again mate.​

Cheers,

Dan

Untitled 3

Untitled 2

1 Like

Hello Dan,

Here is a First draft for the measuring tool bar counter.

//Measuring tool modification
//under development

if (ParamToggle("Enabled", "No|Yes", 1))
{
  EnableTextOutput(False);
  
  what = ParamList("Object", "Bar count", 0);
  mColor = ParamColor("Color", colorRed);
  mStyle = ParamStyle("Style", styleLine | styleDashed, styleDashed | styleThick);
  mbgColor = ParamColor("Label Bg Color", colorWhite);
  showInTitle = ParamToggle("Show in title", "No|Yes", 1);
  
  SelectedBar = SelectedValue(BarIndex());
  StartRangeBar = BeginValue(BarIndex());
  FinishRangeBar = EndValue(BarIndex());
  
  // determine start & end of range
  if (StartRangeBar > 0 AND FinishRangeBar < BarCount - 1) // range defined by markers
  {
    start = StartRangeBar;
    end = FinishRangeBar;
  }
  else
  {
    if (StartRangeBar > 0) // range defined by start marker & selection
    {
      start = StartRangeBar;
      end = SelectedBar;
    }
    else // range defined by selected bar and end
    {
      start = SelectedBar;
      end = FinishRangeBar;
    }
  }
  if (start > end) { tmp = start; start = end; end = tmp; }
  
  // measuring
  switch (what)
  {
    // bar count
    case "Bar count":
      Value = end - start;
      Label = WriteVal(Value, 1.0);
      if (showInTitle) 
      Title = "\n" + EncodeColor(mColor) + "Measuring bars: " + WriteVal(Value, 1.0);
      break;
      }
    
 
  
  if (start != end)
  {
    // get highest visible value
    Hh = -1e8;
    for (i = Status("firstvisiblebarindex"); i < Status("lastvisiblebarindex") AND i < BarCount; i++)
        
      if (High[i] > Hh) Hh = High[i];
      {
    
    VGrid = (Status("axismaxy") - Status("axisminy")) * 0.01;
    VH = Hh;
    }
    Plot(LineArray(start, VH, end, VH), "", mColor, mStyle | styleNoLabel);
    plotText(Label , start + (end - start) / 2 - 2, VH + VGrid, mColor, mbgColor);
    
   // Plot vertical lines forward and back 
    bi=BarIndex();
    x=start;
    y=end;
        
    conditionback = bi==(x - value);
    conditionforward = bi==(y + value);  
    
    line_style=ParamStyle("Style",styleDashed|stylethick );
    line_color=ParamColor("Vert_Color", colorblack);
    
    Plot(conditionback,"",line_color,stylehistogram|Line_style|styleOwnScale| styleNoLabel);
    Plot(conditionforward,"",line_color,styleHistogram|Line_style|styleOwnScale| styleNoLabel);
    
    
    
    Plot(LineArray(start-value, VH, end+value, VH), "", mColor, mStyle | styleNoLabel);
        PlotText(Label , start - value / 2 - 2, VH + VGrid, mColor, mbgColor);
        PlotText(Label , end + value / 2 - 2, VH + VGrid, mColor, mbgColor);
        
  }
 EnableTextOutput(True);
 }
 
Plot(C,"Close",colorBlack,stylebar);

Anthony

1 Like

Hi Anthony,

Thanks for the effort in development! & Please excuse this ignorance that
may be apart of this question. The Code works as it does provide a count on
the chart.

Whatever I am doing results with this: The starting point is the latest bar
(as in today’s bar) on the chart and then when you click the mouse pointer
on a certain number of bars/days previous the code then shows the number of
bars and then also the mirror extension of the exact same number of bars
further back.

The presentation of the text and the verticals are good!

Q’s:

  • Is the default X placement always to be the latest bar on the chart?
  • Can this be changed so that the first click I place on the chart (at
    whatever date/day I choose) can be the beginning or the X position, and
    then the next mouse click I do become the Y position (either forward or
    backwards)

Does this make sense?

Cheers

: I activate it using the [RE] for Study ID.

  • The count starts back And simply hit the chart once with the mouse
    pointer to place the X position, then again for a Y position.
  • The But I am not sure how

Cheers,

*Dan *

Hello Dan,

Sorry for not mentioning the following. You can anchor the study by using Range markers. If you are not familar with the RANGE MARKERS just type in Range Markers in the help / search . You will be presented with a nice visual and scroll down to the following.

Marking range

To show range marker just double click the chart at the beginning of the range and double click again at the end of the range. You can also use F12 key in conjunction with “select” mode (described above). Just select quote and press F12 for begin and SHIFT+F12 for the range end. You can switch off the range marker by pressing CTRL+F12 key or double clicking in the same place twice.

Several more improvements coming.

Anthony

Hi Anthony,

Thanks mate. I’ll take a look. Having a Mac will make the pressing of F12 button difficult, so I’ll have to rely on the mouse activation.

Appreciate the update and info!

Cheers

hello Dan
i think this is what you are looking for.

But Donot forget to check Fibonacci Time Extention also

_SECTION_BEGIN("BAR COUNTING RULER Ver 2");

/**  BAR COUNTING RULER Version_2 	01/11/2017
Measuring Device:, let’s call the Formula BAR/DAY COUNTING RULER
  @link http://forum.amibroker.com/t/measuring-device/2696
 
* you MUST TYPE  "m1", or  "M2" for the second line.
 
* Also right click to open the parameters window 
*/  
  

SetChartOptions(0,chartShowArrows|chartShowDates ) ; 
Plot( C, "Price", colorDefault, stylebar );

GfxSetOverlayMode( 1 ); 
GfxSetCoordsMode( 1 ); // bar/price mode (instead of pixel)

function  BarCountingRuler( StudyID, Color )
{
	trendline = Study(StudyID, GetChartID() );
	bi =BarIndex();
	
	X0= StartX = LastValue( ValueWhen( ExRem( trendline, 0 ), BarIndex() ) );
	X1= EndX = LastValue( ValueWhen( trendline, BarIndex()) );			// printf("X0 StartX  = %g,\n X1 EndX = %g\n", StartX, EndX );
	Y0= StartY = LastValue( ValueWhen( ExRem( trendline, 0 ), trendline ) );
	Y1= EndY = LastValue( ValueWhen( trendline, trendline ) );		// printf("Y0 StartY  = %g,\nY1  EndY = %g\n", StartY, EndY );

	GfxSelectPen( Color );
	Bars=  bi[x1]-bi[x0];
	if( ParamToggle( "Measuring Extend Line ", "No|Yes" )) ext= Bars; else ext= 0;
	GfxMoveTo( X0, y1 );	GfxLineTo( X1+ext, y1 );   // 0% 
	GfxMoveTo( X0, y0 );	GfxLineTo( X1, y0 );   // 100%
	
	adjustment =5;  x2= x0+Bars*2; x3= x0+Bars*3;  printf("x2  = %g,\t  x3 = %g\n", x2, x3 );
	
	// Plot Vetrical lines 
	if( ParamToggle( "Plot Vetrical Lines ", "No|Yes" ))
	{
		visH=HighestVisibleValue(h); VisL= LowestVisibleValue(l);
		GfxMoveTo( X0, visH );	GfxLineTo( x0, VisL ); 
		GfxMoveTo( X1, visH );	GfxLineTo( x1, VisL );
		GfxMoveTo( X2, visH );	GfxLineTo( x2, VisL );
		GfxMoveTo( X3, visH );	GfxLineTo( x3, VisL );
	}
	GfxsetBkMode( colorDefault );
	GfxSetTextColor( ParamColor("Text Color", colorOrange ));
		
	if( ParamToggle( "Bars between X & Y ", "No|Yes" ))  GfxTextOut( "Bars: "+Bars  , X0+adjustment, Y1 );

		BarsToGo2= bars-(BarCount -1 -X1 ); 
	if (BarsToGo2 < bars)
	if (BarsToGo2>0) GfxTextOut( "Bars to Go: "+BarsToGo2  , X1+adjustment, Y1 );
	
		BarsToGo3= bars-(BarCount -1 -X2 );
	if (BarsToGo3 < bars)
	if (BarsToGo3>0) GfxTextOut( "Bars to Go: "+BarsToGo3  , X1+bars+adjustment, Y1 );

	PlotShapes(IIf(x1==bi,shapeDigit1,shapeNone ),colorWhite,0,Y1 ,10  );
	PlotShapes(IIf(x2==bi,shapeDigit2,shapeNone ),colorWhite,0,Y1 ,10  );
	PlotShapes(IIf(x3==bi,shapeDigit3,shapeNone ),colorWhite,0,Y1 ,10  );

}
BarCountingRuler("M1",colorGreen ) ;
BarCountingRuler("M2",colorBlueGrey ) ;

_SECTION_END();

measuringTool

1 Like

dji%20zaman%20analizi%20%C3%A7%C3%B6z
hello
I could not
how can we do this way

tr

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));

Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

_SECTION_END();

_SECTION_BEGIN("BAR COUNTING RULER Ver 2");

GfxSetOverlayMode( 1 ); 
GfxSetCoordsMode( 1 ); // bar/price mode (instead of pixel)

function  BarCountingRuler( StudyID, Color )
{
	trendline = Study(StudyID, GetChartID() );
	bi =BarIndex();
	
	X0= StartX = LastValue( ValueWhen( ExRem( trendline, 0 ), BarIndex() ) );
	X1= EndX = LastValue( ValueWhen( trendline, BarIndex()) );			// printf("X0 StartX  = %g,\n X1 EndX = %g\n", StartX, EndX );
	Y0= StartY = LastValue( ValueWhen( ExRem( trendline, 0 ), trendline ) );
	Y1= EndY = LastValue( ValueWhen( trendline, trendline ) );		// printf("Y0 StartY  = %g,\nY1  EndY = %g\n", StartY, EndY );
    Y2=((Y1-Y0)*0.382)+Y0;
    Y3=((Y1-Y0)*1.618)+Y0;
    Y4=((Y1-Y0)*2.618)+Y0;
    y6=y0-((Y1-Y0)*1.618);
    y7=y0-((Y1-Y0)*2.618);
    
	GfxSelectPen( Color );
	Bars=  bi[x1]-bi[x0];
	ext= Bars;  
	GfxMoveTo( X0, y1 );	GfxLineTo( X1+(ext*2), y1 );   // 0% 
	GfxMoveTo( X0, y0 );	GfxLineTo( X1, y0 );   // 100%
	GfxMoveTo( X0, Y2 );	GfxLineTo( X1+(ext), y2 ); 
    GfxMoveTo( X0, Y3 );	GfxLineTo( X1+(ext*2), y3 ); 
    GfxMoveTo( X0, Y4 );	GfxLineTo( X1+(ext*2), y4 ); 
   
    GfxMoveTo( X0, Y6 );	GfxLineTo( X1+(ext*2), y6 ); 
    GfxMoveTo( X0, Y7 );	GfxLineTo( X1+(ext*2), y7 ); 
    
	adjustment =-5;  x2= x0+Bars*0.618; x3= x0+Bars*1.618; x4= x0+Bars*2; x5= x0+Bars*2.618; x6= x0+Bars*3;  //printf("x2  = %g,\t  x3 = %g\n", x2, x3 );
	
	// Plot Vetrical lines 
	
		visH=HighestVisibleValue(h); VisL= LowestVisibleValue(l);
		
		GfxMoveTo( X0, visH );	GfxLineTo( x0, VisL ); 
		GfxMoveTo( X1, visH );	GfxLineTo( x1, VisL );
		GfxMoveTo( X2, visH );	GfxLineTo( x2, VisL );
		GfxMoveTo( X3, visH );	GfxLineTo( x3, VisL );
		GfxMoveTo( X4, visH );	GfxLineTo( x4, VisL );
		GfxMoveTo( X5, visH );	GfxLineTo( x5, VisL );
		GfxMoveTo( X6, visH );	GfxLineTo( x6, VisL );
	
	GfxsetBkMode( colorDefault );
	GfxSetTextColor( ParamColor("Text Color", colorWhite ));
		
   GfxTextOut( "BAR: "+Bars , X0+adjustment, VISH );

	PlotShapes(IIf(x1==bi,shapeDigit1,shapeNone ),colorBlack,0,Y1 ,10  );
	PlotShapes(IIf(x6==bi,shapeDigit3,shapeNone ),colorBlue,0,Y1 ,10  );
	PlotShapes(IIf(x4==bi,shapeDigit2,shapeNone ),colorRed,0,Y1 ,10  );
}
BarCountingRuler("M1",colorGreen ) ;
BarCountingRuler("M2",colorBlueGrey ) ;

_SECTION_END();
1 Like

hello
i did a little