Watch how to download trading robots for free
Find us on Telegram!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Libraries

PriceChannel - library for MetaTrader 5

Views:
4021
Rating:
(19)
Published:
2019.02.07 08:48
\MQL5\Include\fxsaber\PriceChannel\
Pricest.mqh (5.67 KB) view
Highest.mqh (0.33 KB) view
Lowest.mqh (0.34 KB) view
\MQL5\Experts\fxsaber\
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

PriceChannel the highest and the lowest price over the period selected.


This cross-platform library allows computing the PriceChannel without attributing it to standard bars, i.e., by ticks.

Accordingly, PriceChannel can be computed on any timeframe, including the one-second one. It can also work as a channel on ticks.


Example.

// PriceChannel library operation sample

input int inPeriod = 1;            // Channel period
sinput bool inPriceChannel = true; // Enable/disable calculating the PriceChannel via the library

#define PRICECHANNEL_LOW_PRICE bid  // bid/ask/last for the bar Low
#include <fxsaber\PriceChannel\PriceChannel.mqh> // https://www.mql5.com/en/code/23418

// The highest price over the last iPeriod bars
double GetHigh( const int iPeriod )
{
  static double Highs[];

  CopyHigh(_Symbol, PERIOD_CURRENT, 0, iPeriod, Highs);

  return(Highs[ArrayMaximum(Highs)]);
}

// The lowest price over the last iPeriod bars
double GetLow( const int iPeriod )
{
  static double Lows[];

  CopyLow(_Symbol, PERIOD_CURRENT, 0, iPeriod, Lows);

  return(Lows[ArrayMinimum(Lows)]);
}

double Sum = 0;

void OnTick()
{
  static const int BarInterval = PeriodSeconds(PERIOD_CURRENT);
  static PRICECHANNEL PriceChannel(inPeriod); // Created a PriceChannel object with a predefined period

  static int CountBars = 0;
  static datetime PrevTime = 0;

  if (inPriceChannel)
    PriceChannel.NewTick(); // Considered the new tick

  if (TimeCurrent() / BarInterval != PrevTime / BarInterval) // New bar
    CountBars++;

  if (CountBars > MAX_BARS) // Start calculating when the relevant history has accumulated
    Sum += inPriceChannel ? PriceChannel.GetHigh() - PriceChannel.GetLow() // Calculate the PriceChannel via the library
                          :   GetHigh(inPeriod) - GetLow(inPeriod);        // Calculate the PriceChannel by standard method

  PrevTime = TimeCurrent();
}

double OnTester()
{
  return(Sum);
}

This EA will show in Tester the identical results: The standard one and that via the library.


Performance.


Standard calculations

optimization finished, total passes 200
optimization done in 6 minutes 55 seconds
shortest pass 0:00:01.061, longest pass 0:00:03.432, average pass 0:00:02.066


Via the library

optimization finished, total passes 200
optimization done in 2 minutes 57 seconds
shortest pass 0:00:00.764, longest pass 0:00:01.982, average pass 0:00:00.862


Features.

  • Calculations on every tick.
  • You can set any duration for the bar.
  • No binding to standard bars.
  • The largest default value (can be specified) is calculated by Bid, the smallest one by Ask.
  • The performance does not practically depend on the period.

Translated from Russian by MetaQuotes Ltd.
Original code: https://www.mql5.com/ru/code/23418

Stochastic_RSI Stochastic_RSI

Indicator Stochastic RSI

MTF_LRMA MTF_LRMA

Indicator Multi Timeframe Linear Regression MA with signal line

MTF_Stochastic_RSI MTF_Stochastic_RSI

Indicator Multi timeframes Stochastic RSI

ZigZag_Oscillator ZigZag_Oscillator

Indicator ZigZag Oscillator