Trading help, book reviews, risk management, and interviews.

Disclaimer

The contents of this blog do not constitute investment advice. Trading CFDs and Forex can be very risky and you can lose much more than your initial deposit. Seek professional advice before making any trades.

MQL4 helper functions for calculating bar sizes

Here are some more MQL4 helper functions for MetaTrader. You can use them in your expert advisors and custom indicators. The three functions will allow you to quickly get the size of the upper and lower wicks of the candle stick, and also the size of the candle stick body. To use them you will also need some of the code I gave you in my simple MetaTrader MQL4 helper functions post.

If you use these functions in your code please give a reference to this blog post.

double UpperWickSize(int bar)
   {
   if (UpBar(bar))
      {
      return (High[bar]-Close[bar]);
      }
   if (DownBar(bar))
      {
      return (High[bar]-Open[bar]);
      }
   return (0);
   }
double LowerWickSize(int bar)
   {
   if (UpBar(bar))
      {
      return (Open[bar]-Low[bar]);
      }
   if (DownBar(bar))
      {
      return (Close[bar]-Low[bar]);
      }
   return (0);
   }
double BarBodySize(int bar)
  {
  if (UpBar(bar))
    {
    return (Close[bar]-Open[bar]);
    }
  if (DownBar(bar))
    {
    return (Open[bar]-Close[bar]);
    }
  return (0);
  }



Reader Feedback

One Response to “MQL4 helper functions for calculating bar sizes”

  1. john says:

    A pathetic half-assed attempt. How about

    double BarBodySize(int bar)
    {
    return MathAbs((Close[bar]-Open[bar]));
    }

Leave a Reply

Do NOT fill this !