Download MetaTrader 5

Metatrader Termination

To add comments, please log in or register
ali Mohammadi
76
ali Mohammadi  

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);
  }

MQL5.community - User Memo
MQL5.community - User Memo
  • 2010.02.25
  • MetaQuotes Software Corp.
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
Kourosh Davallou
50796
Kourosh Davallou  

Hi my friend 

Please send all code

 You can use the following commands:

for call function 

int OnInit()
{
.
.
.
 Stoch_Handle=iStochastic(SymbolForCheck,PERIOD_D1,5,3,3,MODE_SMA,STO_LOWHIGH);


}

 and exit function :

void OnDeinit(const int reason)
}
.
.
IndicatorRelease(Stoch_Handle);
}
ali Mohammadi
76
ali Mohammadi  
kourosh1347:

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! :(

Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
  • www.mql5.com
Timeseries and Indicators Access / CopyBuffer - Documentation on MQL5
Simon Gniadkowski
Moderator
18045
Simon Gniadkowski  
alinagoo:


please help me! :(

When you post code please use the SRC button to post code: How to use the SRC button.
ali Mohammadi
76
ali Mohammadi  
RaptorUK:
When you post code please use the SRC button to post code: How to use the SRC button.

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);  
  }
Alain Verleyen
Moderator
33767
Alain Verleyen  
alinagoo:

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.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Symbol Properties - Documentation on MQL5
ali Mohammadi
76
ali Mohammadi  
angevoyageur:

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.

Hello Angevoyageur

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);  
  }
ali Mohammadi
76
ali Mohammadi  

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?



Uwe Goetzke
1649
Uwe Goetzke  

Because OnStart() gets never called on MT5.

Simon Gniadkowski
Moderator
18045
Simon Gniadkowski  
ugo58:

Because OnStart() gets never called on MT5.

Yes it does if you are writing a Script.
Simon Gniadkowski
Moderator
18045
Simon Gniadkowski  
alinagoo:

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

To add comments, please log in or register