Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

Measuring Tool for Amibroker (AFL)
demon
about 14 years ago
Amibroker (AFL)

Rating:
4 / 5 (Votes 5)
Tags:
amibroker, exploration, measuring

This simple tool allows measuring of a number of parameters between two points (selected as usual by vertical lines or doubleclicks). Possible cases are:

  • bar count
  • difference between close prices
  • difference between high and low of range
  • average volume
  • cumulative volume
  • average market facilitation index (yes, I’ve read Bill Williams’ books once :))

Seems that amibroker lacks such basic measuring capability.

New options easily could be added – just extend ParamList and append new section in switch operator.

At start I wished to select points with mouse clicks and draw a line between clicked points with a label somewhere in the middle, but I could not handle it in a such way. Maybe someone can help?

Screenshots

Similar Indicators / Formulas

General Market Exploration by XeL
Submitted by xel over 12 years ago
miftha indicator
Submitted by coolpace over 14 years ago
Deel - Average Dollar Price Volatility
Submitted by kaiji almost 15 years ago
DIX50,20,10
Submitted by morgen over 14 years ago
Volume Spike Exploration
Submitted by ngocleasing over 14 years ago

Indicator / Formula

Copy & Paste Friendly
_SECTION_BEGIN("Measurer");
if (ParamToggle("Enabled", "No|Yes", 1))
{
  EnableTextOutput(False);
  
  what = ParamList("Object", "Bar count|Price change (close)|Price change (high/low)|Average volume|Total volume|Average BW MFI", 0);
  mColor = ParamColor("Color", colorBlue);
  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;
    // price change (close)
    case "Price change (close)":
      Value = Close[end] - Close[start];
      Label = WriteVal(Value, 1.3);
      if (showInTitle) Title = "\n" + EncodeColor(mColor) + "Measuring price change (close): " + WriteVal(Value, 1.3);
      if (start != end) Plot(LineArray(start, Close[start], end, Close[end]), "", mColor, mStyle | styleNoLabel);
      break;
    // price change (high/low)
    case "Price change (high/low)":
      if (High[end] >= High[start])
        Value = High[end] - Low[start];
      else
        Value = -(High[start] - Low[end]);
      Label = WriteVal(Value, 1.3);
      if (showInTitle) Title = "\n" + EncodeColor(mColor) + "Measuring price change (high/low): " + WriteVal(Value, 1.3);
      if (start != end)
      {
        if (High[end] >= High[start])
          Plot(LineArray(start, Low[start], end, High[end]), "", mColor, mStyle | styleNoLabel);
        else
          Plot(LineArray(start, High[start], end, Low[end]), "", mColor, mStyle | styleNoLabel);
      }
      break;
    // Average volume
    case "Average volume":
      Bars = end - start + 1; // (inclusive)
      Value = 0;
      for (i = start; i <= end AND i < BarCount; i++) Value += Volume[i];
      Value = Value / Bars;
      Label = WriteVal(Value, 1.0);
      if (showInTitle) Title = "\n" + EncodeColor(mColor) + "Measuring average volume: " + WriteVal(Value, 1.0);
      break;
    // Total volume
    case "Total volume":
      Value = 0;
      for (i = start; i <= end AND i < BarCount; i++) Value += Volume[i];
      Value = Value;
      Label = WriteVal(Value, 1.0);
      if (showInTitle) Title = "\n" + EncodeColor(mColor) + "Measuring total volume: " + WriteVal(Value, 1.0);
      break;
    // Average BW MFI
    case "Average BW MFI":
      Bars = end - start + 1; // (inclusive)
      Value = 0;
      for (i = start; i <= end AND i < BarCount; i++) Value += 100000 * (High[i] - Low[i]) / Volume[i];
      Value = Value / Bars;
      fmt = 1;
      if (log10(Value) < 0) fmt += (-floor(log10(Value)) + 2) / 10;
      Label = WriteVal(Value, fmt);
      if (showInTitle) Title = "\n" + EncodeColor(mColor) + "Measuring average BW MFI: " + WriteVal(Value, fmt);
      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);
  }
  EnableTextOutput(True);
}
_SECTION_END();

13 comments

1. rajaswamy

error coming not working check it

2. demon

Whereis error? AMI 5.10.2 works fine (though if you do AFL checking it barks on “Title variable not initialized” – just ignore)

Fixed some issue with scaling.
if (start != end) { VGrid = (Status("axismaxy") - Status("axisminy")) * 0.01; VH = Status("axismaxy") - VGrid * 5; Plot(LineArray(start, VH, end, VH), "", mColor, mStyle | styleNoLabel); PlotText(Label, start + (end - start) / 2 - 2, VH + VGrid, mColor, mbgColor); }

should be replaced with
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); }

3. cnbondre

HI,

Admin, demon, and others,

Pl check the following small correction, it works well after that.
Gives all the values as shown in the picture ( adjust parameter ).

Thanks demon for sharing this excellent afl

CNB

_SECTION_BEGIN("Measuring Tool");

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN ( "CODE" );

// measuring

REMOVE “+” SIGN AFTER “Title” * Title += * SO AFTER THIS CORRECTION WILL LOOK LIKE Title = ++++++++++++CNB

// price change (close )

REMOVE “+” SIGN AFTER “Title” * Title += * SO AFTER THIS CORRECTION WILL LOOK LIKE Title = ++++++++++++CNB

// price change (high/low)

REMOVE “+” SIGN AFTER “Title” * Title += * SO AFTER THIS CORRECTION WILL LOOK LIKE Title = ++++++++++++CNB

// Average volume

REMOVE “+” SIGN AFTER “Title” * Title += * SO AFTER THIS CORRECTION WILL LOOK LIKE Title = ++++++++++++CNB

// Total volume

REMOVE “+” SIGN AFTER “Title” * Title += * SO AFTER THIS CORRECTION WILL LOOK LIKE Title = ++++++++++++CNB

// Average BW MFI

REMOVE “+” SIGN AFTER “Title” * Title += * SO AFTER THIS CORRECTION WILL LOOK LIKE Title = ++++++++++++CNB

_SECTION_END();
4. administrator

Hi cnbondre and demon

I adjusted the formula as per both comments.

5. slamanakbar

GOOD one

I want to add the percentage change between two points? how can i do it ?

Kindly help

6. rajaswamy

not working still

7. filinta

Showing the percentage change between the two points I want to mouse clicks.
Thanks demon for sharing this excellent afl.
Is it possible to show the percentage change of the trend line?

8. demon

As you see this formula works by bar selection, not actual mouse clicks. Percentage change between two points defined by range can be added by new section in switch operator (just as Price change in currency).
For now I’m not able to produce such a tool that selects region with mouse clicks at arbitrary point of a chart. I’ve written that in description and if anyone could assist to explain how I can handle mouse events – this would be nice :) Or someday I’ll dig it by myself. If I’ll do this I just post here my new code. Cheers.

9. demon

By the way – percentage change of a trend line could be seen in a tooltips when you using native amibroker trendlines. This tool I made to examine barcounts of swings and average volumes.

10. filinta

Mr. Demon, thank you for an explanation.

11. xavier

thanks

12. analystbank

can someone explain, how to make it work, this is fabulous afl

13. chunwaihome

Hello,

5.4 Version only show barcount, others cannot show at all.
Good thinking, But I would like to know except use mouse selection. Could I input specified two date parameters to formula show infomration?

Leave Comment

Please login here to leave a comment.

Back