amrismail2000: i want to know is this indicator function that i use is right or wrong.so if wrong what is the right ?
- When you post code please use the SRC button! Please edit your post.
General rules and best pratices of the Forum. - General - MQL5 programming forum -
Why did you post your MT4 question in the
Root /
MT5 EA section
instead of the
MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. - Don't post code that doesn't compile.
bool Stochastics(){ : return EMPTY_VALUE;
You can only return true or false from a bool function. What do you think you return there? You might think about returning an int (OP_BUY, OP_SELL, or EMPTY,) or an enumeration instead.
Do as whoerder says, there is nothing more frustrating than trying to make sense of poorly formatted code. That being said your code is riddled full of various errors. Here are just a few I fixed but there are many more...
#property strict enum SIGNAL { LONG, SHORT, NEUTRAL, ERROR }; SIGNAL Ma() { double ma5 = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE, 0); double ma10 = iMA(NULL, 0, 10, 0, MODE_EMA, PRICE_CLOSE, 0); double ma20 = iMA(NULL, 0, 20, 0, MODE_EMA, PRICE_CLOSE, 0); if(ma5 >= ma20 && ma10 >= ma20) return LONG; if(ma5 <= ma20 && ma10 <= ma20) return SHORT; return NEUTRAL; } SIGNAL Rsi() { double r0 = iRSI(NULL, 0, 14, PRICE_CLOSE, 0); double r1 = iRSI(NULL, 0, 14, PRICE_CLOSE, 1); if(r1 < 30 && r0 >= 30) return LONG; if(r1 > 70 && r0 <= 70) return SHORT; return NEUTRAL; } SIGNAL Macd() { bool macd1, macd2, macd3, macd4; double macdmaincurr = iMACD(NULL, 0, 12, 26, 9, 0, MODE_MAIN, 0); double macdmainprev = iMACD(NULL, 0, 12, 26, 9, 0, MODE_MAIN, 1); double macdsigcurr = iMACD(NULL, 0, 12, 26, 9, 0, MODE_SIGNAL, 0); double macdsigprev = iMACD(NULL, 0, 12, 26, 9, 0, MODE_SIGNAL, 1); macd1 = iMACD(NULL, 0, 12, 26, 9, 0, MODE_MAIN, 1) < 0 && iMACD(NULL, 0, 12, 26, 9, 0, MODE_MAIN, 0) >= 0; macd2 = iMACD(NULL, 0, 12, 26, 9, 0, MODE_MAIN, 1) > 0 && iMACD(NULL, 0, 12, 26, 9, 0, MODE_MAIN, 0) <= 0; macd3 = iMACD(NULL, 0, 12, 26, 9, 0, MODE_MAIN, 1) < iMACD(NULL, 0, 12, 26, 9, 0, MODE_SIGNAL, 1) && iMACD(NULL, 0, 12, 26, 9, 0, MODE_MAIN, 0) >= iMACD(NULL, 0, 12, 26, 9, 0, MODE_SIGNAL, 0); macd4 = iMACD(NULL, 0, 12, 26, 9, 0, MODE_MAIN, 1) > iMACD(NULL, 0, 12, 26, 9, 0, MODE_SIGNAL, 1) && iMACD(NULL, 0, 12, 26, 9, 0, MODE_MAIN, 0) <= iMACD(NULL, 0, 12, 26, 9, 0, MODE_SIGNAL, 0); if(macd1 && macd3) return LONG; if(macd2 && macd4) return SHORT return NEUTRAL; }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
this is my first EA to do
i want to know is this indicator function that i use is right or wrong.so if wrong what is the right ?
//MA
bool MA()
{
double ma5= iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,0);
double ma10=iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,0);
double ma20=iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,0);
if(ma5 && ma10 >= ma20)
return (true);
else if (ma5 && ma10 <= ma20)
return (false);
else
return (EMPTY_VALUE);
}
// RSI
bool rsi()
{
double r0,r1;
r0=iRSI(NULL,0,14,PRICE_CLOSE,0);
r1=iRSI(NULL,0,14,PRICE_CLOSE,1);
if (r1 < 30 && r0 >= 30 )
return (true);
else if (r1 > 70 && r0 <= 70)
return (false);
else
return (EMPTY_VALUE);
}
// MACD
bool macd()
{
double macd1,macd2,macd3,macd4;
double macdmaincurr=iMACD(NULL,0,12,26,9,0,MODE_MAIN,0);
double macdmainprev=iMACD(NULL,0,12,26,9,0,MODE_MAIN,1);
double macdsigcurr=iMACD(NULL,0,12,26,9,0,MODE_SIGNAL,0);
double macdsigprev=iMACD(NULL,0,12,26,9,0,MODE_SIGNAL,1);
macd1 = iMACD(NULL,0,12,26,9,0,MODE_MAIN,1) < 0 && iMACD(NULL,0,12,26,9,0,MODE_MAIN,0) >= 0;
macd2 = iMACD(NULL,0,12,26,9,0,MODE_MAIN,1) > 0 && iMACD(NULL,0,12,26,9,0,MODE_MAIN,0) <= 0;
macd3 = iMACD(NULL,0,12,26,9,0,MODE_MAIN,1) < iMACD(NULL,0,12,26,9,0,MODE_SIGNAL,1)
&& iMACD(NULL,0,12,26,9,0,MODE_MAIN,0) >= iMACD(NULL,0,12,26,9,0,MODE_SIGNAL,0);
macd4 = iMACD(NULL,0,12,26,9,0,MODE_MAIN,1) > iMACD(NULL,0,12,26,9,0,MODE_SIGNAL,1)
&& iMACD(NULL,0,12,26,9,0,MODE_MAIN,0) <= iMACD(NULL,0,12,26,9,0,MODE_SIGNAL,0);
if (macd1 > 0 && macd3 == true)
return (true);
else if ( macd2 < 0 && macd4 == true)
return (false);
else
return (EMPTY_VALUE);
}
//SAR
bool SAR()
{
double sar1,sar2;
sar1 = iSAR(NULL,0,0.02,0.2,1) > iClose(NULL,0,1) && iSAR(NULL,0,0.02,0.2,0) <= iClose(NULL,0,0);
sar2 = iSAR(NULL,0,0.02,0.2,1) < iClose(NULL,0,1) && iSAR(NULL,0,0.02,0.2,0) >= iClose(NULL,0,0);
if(Ask < sar1)
return (true);
else if (Ask > sar2)
return (false);
else
return (EMPTY_VALUE);
}
//ADX
bool ADX()
{
double PosDLine =iADX(NULL,0,14,PRICE_CLOSE,MODE_PLUSDI,0);
double NegDLine =iADX(NULL,0,14,PRICE_CLOSE,MODE_MINUSDI,0);
double ADXCurrent =iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,0);
double ADXPrevious =iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,1);
if (PosDLine > NegDLine && ADXCurrent >= 25 && ADXCurrent > ADXPrevious)
return (true);
else if (NegDLine > PosDLine && ADXCurrent >= 25 && ADXCurrent > ADXPrevious)
return (false);
else
return (EMPTY_VALUE);
}
//CCI
bool cci()
{
double CCCurrent = iCCI(NULL,0,14,PRICE_TYPICAL,0);
double CCPrevious = iCCI(NULL,0,14,PRICE_TYPICAL,1);
int CCCrossLinePos = 100;
int CCCrossLineNeg =-100;
if ((CCPrevious<CCCrossLinePos && CCCurrent >= CCCrossLinePos) || (CCPrevious <=CCCrossLineNeg&& CCCurrent>=CCCrossLineNeg) )
return (true);
else if ((CCPrevious>CCCrossLinePos && CCCurrent <= CCCrossLinePos)||(CCPrevious >=CCCrossLineNeg&& CCCurrent<=CCCrossLineNeg) )
return (false);
else
return (EMPTY_VALUE);
}
//Stochastics Occilator usig signal line
bool Stochastics()
{
double stomaincurr=iStochastic(NULL,0,14,3,3,1,0,MODE_MAIN,0);
double stomainprev=iStochastic(NULL,0,14,3,3,1,0,MODE_MAIN,1);
double stosignalcurr=iStochastic(NULL,0,14,3,3,1,0,MODE_SIGNAL,0);
double stosignalprev=iStochastic(NULL,0,14,3,3,1,0,MODE_SIGNAL,1);
if (stomainprev < stosignalprev && stomaincurr >= stosignalcurr)
return (true);
else if (stomainprev > stosignalprev && stomaincurr <= stosignalcurr)
return (false);
else
return (EMPTY_VALUE);
Thanks