I am trying to read a moving average buffer from a downloaded indicator (AllAverages_v4.9_MT5), and want to read a few values to calculate entry (eg close above MA for a buy).
I'll attach the indi file and paste my EA code.
#include <Trade\Trade.mqh>
enum ENUM_PRICE //copied from indicator
{
close, // Close
open, // Open
high, // High
low, // Low
median, // Median
typical, // Typical
weightedClose, // Weighted Close
medianBody, // Median Body (Open+Close)/2
average, // Average (High+Low+Open+Close)/4
trendBiased, // Trend Biased
trendBiasedExt, // Trend Biased(extreme)
haClose, // Heiken Ashi Close
haOpen, // Heiken Ashi Open
haHigh, // Heiken Ashi High
haLow, // Heiken Ashi Low
haMedian, // Heiken Ashi Median
haTypical, // Heiken Ashi Typical
haWeighted, // Heiken Ashi Weighted Close
haMedianBody, // Heiken Ashi Median Body
haAverage, // Heiken Ashi Average
haTrendBiased, // Heiken Ashi Trend Biased
haTrendBiasedExt // Heiken Ashi Trend Biased(extreme)
};
enum ENUM_MA_MODE //copied from indicator
{
SMA, // Simple Moving Average
EMA, // Exponential Moving Average
Wilder, // Wilder Exponential Moving Average
LWMA, // Linear Weighted Moving Average
SineWMA, // Sine Weighted Moving Average
TriMA, // Triangular Moving Average
LSMA, // Least Square Moving Average (or EPMA, Linear Regression Line)
SMMA, // Smoothed Moving Average
HMA, // Hull Moving Average by Alan Hull
ZeroLagEMA, // Zero-Lag Exponential Moving Average
DEMA, // Double Exponential Moving Average by Patrick Mulloy
T3_basic, // T3 by T.Tillson (original version)
ITrend, // Instantaneous Trendline by J.Ehlers
Median, // Moving Median
GeoMean, // Geometric Mean
REMA, // Regularized EMA by Chris Satchwell
ILRS, // Integral of Linear Regression Slope
IE_2, // Combination of LSMA and ILRS
TriMAgen, // Triangular Moving Average generalized by J.Ehlers
VWMA, // Volume Weighted Moving Average
JSmooth, // Smoothing by Mark Jurik
SMA_eq, // Simplified SMA
ALMA, // Arnaud Legoux Moving Average
TEMA, // Triple Exponential Moving Average by Patrick Mulloy
T3, // T3 by T.Tillson (correct version)
Laguerre, // Laguerre filter by J.Ehlers
MD, // McGinley Dynamic
BF2P, // Two-pole modified Butterworth filter by J.Ehlers
BF3P, // Three-pole modified Butterworth filter by J.Ehlers
SuperSmu, // SuperSmoother by J.Ehlers
Decycler, // Simple Decycler by J.Ehlers
eVWMA, // Modified eVWMA
EWMA, // Exponential Weighted Moving Average
DsEMA, // Double Smoothed EMA
TsEMA, // Triple Smoothed EMA
VEMA // Volume-weighted Exponential Moving Average(V-EMA)
};
input ENUM_MA_MODE ma_mode;
input ENUM_PRICE ma_price;
inputdouble lots;
inputint ma_period;
inputint atr_period;
CTrade trade;
int hCustom;
double mabuf[];
MqlRates ratesbuf[];
bool BuySignal()
{
if (CopyBuffer(hCustom,0,0,3,mabuf)<0) //ERROR HERE. ALWAYS RETURNS -1 !!!!
{PrintFormat("Data copied %i",CopyBuffer(hCustom,0,0,3,mabuf)); returnfalse;}
if (!CopyRates(_Symbol,PERIOD_CURRENT,0,3,ratesbuf)) returnfalse;
if(ratesbuf[2].close<=mabuf[2] && ratesbuf[1].close>mabuf[1]) returntrue;
returnfalse;
}
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
//---if (hCustom = iCustom(_Symbol,PERIOD_CURRENT,"AllAverages_v4.9_MT5",
PERIOD_CURRENT,
ma_price, //price as per above ENUM
ma_period,
0, //indicator shift
ma_mode,
false) == INVALID_HANDLE) //false = solid color, true = color trend
{ Print("iCustom invalid handle");
returnINIT_FAILED;
}
PrintFormat("Indicator handle %i",hCustom); //just checking - this worksArraySetAsSeries(ratesbuf,true);
ArraySetAsSeries(mabuf,true);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
//---
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
staticlong curtime;
bool isNewBar;
MqlRates dt[];
double bid,ask;
ArraySetAsSeries(dt,true);
if (!CopyRates(_Symbol,PERIOD_CURRENT,0,1,dt)) return;
isNewBar=false;
if (dt[0].time != curtime)
{curtime = dt[0].time;
isNewBar=true;
}
if (isNewBar && PositionsTotal()<1 && BuySignal())
{
ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
trade.Buy(lots,_Symbol,ask,0,0,"CST_BUY");
}
}
//+------------------------------------------------------------------+
Pardon the unused variables.
I just cannot get a value from any of the 3 buffers (but it looks to me buffer 0 is the main moving average buffer.)
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hello everyone
I cannot get this thing to work.
I am trying to read a moving average buffer from a downloaded indicator (AllAverages_v4.9_MT5), and want to read a few values to calculate entry (eg close above MA for a buy).
I'll attach the indi file and paste my EA code.
Pardon the unused variables.
I just cannot get a value from any of the 3 buffers (but it looks to me buffer 0 is the main moving average buffer.)
Can anybody help me with this please?