Hi my friend
Please send all code
You can use the following commands:
for call function
and exit function :
Hi
Thanks.
It's all of the code! It's the beginning of an E.A. I'll complete this code after that problem is solved! (I'll add RSI & ADX indicators and then Volume and Bid/Ask analysis and ...)
Releasing Stochastic handle in OnDeinit() function didn't help me!
I think the amount space occupied by indicator buffer becomes very great (Large) and leads to the program termination. I don't know any tools to check Indicator buffer of resizing or cleaning it! Do you know? I just know CopyBuffer() function for reading Indicator buffer!
please help me! :(
- www.mql5.com
please help me! :(
Ok
Here you are, with some changes....
Note: The E.A must check approximately 1,000 symbols of the many markets!
///**************************** Global Variables **********************************/// int Stoch_Handle; //********************************** My Functions *********************************// int StochasticSignal() { double kline[3], dline[3]; bool Stoch_crossedup, Stoch_crosseddown; for(int j=0; j< SymbolsTotal(true); j++) { if(Bars(SymbolName(j, true),PERIOD_D1)>=60) { Stoch_crossedup= false; Stoch_crosseddown= false; ArrayInitialize(kline,true); ArrayInitialize(dline,true); Stoch_Handle=iStochastic(SymbolName(j, true),PERIOD_D1,5,3,3,MODE_SMA,STO_LOWHIGH); if(Stoch_Handle<0) Print("The iStochastic object is not created: Error",GetLastError()); else for(int i = 0;i < 3;i++) {CopyBuffer(Stoch_Handle,0,0,3,kline);CopyBuffer(Stoch_Handle,1,0,3,dline);} if ((kline[1] < dline[1]) && (kline[0] > dline[0])) Stoch_crosseddown = true; else if ((kline[1] > dline[1]) && (kline[0] < dline[0])) Stoch_crossedup = true; if (Stoch_crossedup && (kline[1] <= 20.0)) Alert(" Buy Signal generated ", " " , SymbolName(j, true)); //Go Long /*if (Stoch_crosseddown && (kline[1] >= 80.0)) Go short */ } } return 0; } //********************************** End Of My Functions *********************************// //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { StochasticSignal(); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { IndicatorRelease(Stoch_Handle); }
Ok
Here you are, with some changes....
Note: The E.A must check approximately 1,000 symbols of the many markets!
I can run this code without problem, but only with 12 symbols in Market Watch. So your issue comes from some symbols...
In this snippet of code :
for(int i = 0;i < 3;i++) {CopyBuffer(Stoch_Handle,0,0,3,kline);CopyBuffer(Stoch_Handle,1,0,3,dline);}
Why are you using a loop ?
You have to check the returned value of CopyBuffer(), it may be 0 and then you have an error.
- www.mql5.com
I can run this code without problem, but only with 12 symbols in Market Watch. So your issue comes from some symbols...
In this snippet of code :
Why are you using a loop ?
You have to check the returned value of CopyBuffer(), it may be 0 and then you have an error.
You are right! Silly loop makes system busy! MQL4 syntax has remained in my mind and conflicts with MQL5 syntax. With the following correction the problem solved! :))
Thanks so.
///**************************** Global Variables **********************************/// int Stoch_Handle; //********************************** My Functions *********************************// int StochasticSignal() { double kline[3], dline[3]; bool Stoch_crossedup, Stoch_crosseddown; for(int j=200; j< SymbolsTotal(true); j++) { if(Bars(SymbolName(j, true),PERIOD_D1)>=60) { Stoch_crossedup= false; Stoch_crosseddown= false; ArrayInitialize(kline,true); ArrayInitialize(dline,true); Stoch_Handle=iStochastic(SymbolName(j, true),PERIOD_D1,5,3,3,MODE_SMA,STO_LOWHIGH); if(Stoch_Handle<0) { Print("The iStochastic object is not created: Error",GetLastError()); } else { if(CopyBuffer(Stoch_Handle,0,0,3,kline)>0 && CopyBuffer(Stoch_Handle,1,0,3,dline)>0) { Alert(SymbolName(j, true)); if ((kline[1] < dline[1]) && (kline[0] > dline[0])) Stoch_crosseddown = true; else if ((kline[1] > dline[1]) && (kline[0] < dline[0])) Stoch_crossedup = true; if (Stoch_crossedup && (kline[1] <= 20.0)) Alert(" Buy Signal generated ", " " , SymbolName(j, true)); //Go Long /*if (Stoch_crosseddown && (kline[1] >= 80.0)) Go short */ } else { Print("The CopyBuffer function failed! Symbol: ",SymbolName(j, true)); } } } } return 0; } //********************************** End Of My Functions *********************************// //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { StochasticSignal(); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { IndicatorRelease(Stoch_Handle); }
Because OnStart() gets never called on MT5.
Because OnStart() gets never called on MT5.
A note!
When i transferred main calling functions commands, from OnInit() to OnStart(), The performance increased extraordinary!!! But why? I don't know :(
Do you know?
Are you coding an EA or Script ? Program Running
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello
As you can see in the two attached images, from my Desktop, when I run a simple EA on my Metatrader 5 the program goes hanging and terminate!
Do you know whats the problem?
Thanks in advanced
That simple code is as follow:
//************************************** My Function ***********************************************
int StochasticSignal(string SymbolForCheck)
{
double kline[3], dline[3];
bool Stoch_crossedup= false, Stoch_crosseddown= false;
int Stoch_Handle;
ArrayInitialize(kline,true);
ArrayInitialize(dline,true);
Stoch_Handle=iStochastic(SymbolForCheck,PERIOD_D1,5,3,3,MODE_SMA,STO_LOWHIGH);
if(Stoch_Handle<0)
{
Print("The iStochastic object is not created: Error",GetLastError());
IndicatorRelease(Stoch_Handle);
return(-1);
}
else
{
for(int i = 0;i < 3;i++)
{
CopyBuffer(Stoch_Handle,0,0,3,kline);
CopyBuffer(Stoch_Handle,1,0,3,dline);
}
if ((kline[1] < dline[1]) && (kline[0] > dline[0]))
Stoch_crosseddown = true;
else if ((kline[1] > dline[1]) && (kline[0] < dline[0]))
Stoch_crossedup = true;
else
{
//there is no sell or buy signal!
IndicatorRelease(Stoch_Handle);
return 0;
}
if (Stoch_crossedup && (kline[1] <= 20.0))
{
//GoLong();
Alert(" Buy Signal generated ", " " , SymbolForCheck);
IndicatorRelease(Stoch_Handle);
return 1;
}
if (Stoch_crosseddown && (kline[1] >= 80.0))
{
//GoShort();
//Alert(" Sell Signal generated ", " " , SymbolForCheck);
IndicatorRelease(Stoch_Handle);
return -1;
}
}
IndicatorRelease(Stoch_Handle);
return 0;
}
//********************************** My Function *********************************//
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//Alert("Symbols= ",DoubleToString(NoOfSymbols));
for(int i=0; i< SymbolsTotal(true); i++)
if(Bars(SymbolName(i, true),PERIOD_D1)>=60)
StochasticSignal(SymbolName(i, true));
return(INIT_SUCCEEDED);
}