Questions from Beginners MQL5 MT5 MetaTrader 5 - page 664

 
Alexey Kozitsyn:
Yes, input parameters cannot be modified. To be honest, I don't understand why you need to change this value according to 3/5 digit quotes? You do set this value in the input parameters. Can't you just write 100 (if 3/5 digits) and not bother?

In fact, I optimise on 5 digits - more history, but trade on 4 and use different settings, including points. I don't want to confuse the settings - that's why this is the solution.

 
-Aleks-:

In fact, I optimise on 5 digits - more history, but trade on 4 and use different settings, including points. I don't want to confuse the settings - that's why this is the solution.

It should work like this

int Sign = 1;

int OnInit() {
// Округлим огрызки - 3 и 5 знак
Sign=(SymbolInfoInteger(_Symbol,SYMBOL_DIGITS)==3 || SymbolInfoInteger(_Symbol,SYMBOL_DIGITS)==5)?10:1;
// Приведем к терминальному количеству знаков
TakeProfit*=Sign;
StopLoss*=Sign;
TrailingShift*=Sign;
TrailingStep*=Sign;
Slippage*=Sign;
}
 
Vitaly Muzichenko:

This should work

int Sign = 1;

int OnInit() {
// Округлим огрызки - 3 и 5 знак
Sign=(SymbolInfoInteger(_Symbol,SYMBOL_DIGITS)==3 || SymbolInfoInteger(_Symbol,SYMBOL_DIGITS)==5)?10:1;
// Приведем к терминальному количеству знаков
TakeProfit*=Sign;
StopLoss*=Sign;
TrailingShift*=Sign;
TrailingStep*=Sign;
Slippage*=Sign;
}


Thanks - I will try it out as soon as I can get the EA up and running...

 

I also get this error - how do I correct it?

'MODE_MAIN' - enumerator identifier already defined initmql4__1.mqh 223 24


 ENUM_STO_PRICE StoFieldMigrate(int field)


  {
   switch(field)
     {
      case 0: return(STO_LOWHIGH);
      case 1: return(STO_CLOSECLOSE);
      default: return(STO_LOWHIGH);
     }
  }

//+------------------------------------------------------------------+
enum ALLIGATOR_MODE  { MODE_GATORJAW=1,   MODE_GATORTEETH, MODE_GATORLIPS };
enum ADX_MODE        { MODE_MAIN,         MODE_PLUSDI, MODE_MINUSDI };
enum UP_LOW_MODE     { MODE_BASE,         MODE_UPPER,      MODE_LOWER };
enum ICHIMOKU_MODE   { MODE_TENKANSEN=1,  MODE_KIJUNSEN, MODE_SENKOUSPANA, MODE_SENKOUSPANB, MODE_CHINKOUSPAN };
enum MAIN_SIGNAL_MODE{ MODE_MAIN,         MODE_SIGNAL };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double CopyBufferMQL4(int handle,int index,int shift)
  {
   double buf[];
   switch(index)
     {
      case 0: if(CopyBuffer(handle,0,shift,1,buf)>0)
         return(buf[0]); break;
      case 1: if(CopyBuffer(handle,1,shift,1,buf)>0)
         return(buf[0]); break;
      case 2: if(CopyBuffer(handle,2,shift,1,buf)>0)
         return(buf[0]); break;
      case 3: if(CopyBuffer(handle,3,shift,1,buf)>0)
         return(buf[0]); break;
      case 4: if(CopyBuffer(handle,4,shift,1,buf)>0)
         return(buf[0]); break;
      default: break;
     }
   return(EMPTY_VALUE);
  }
//+------------------------------------------------------------------+

 
-Aleks-:

Such a situation, I get an error - help me understand why the error occurs - in MQL5 you can't change the value of a variable entered by the user?

You can't!

If you decided to use MQL4_to_MQL5.mqh, I strongly recommend you not to do that. Since it was written for the examples, that are in library description. I.e. it's not universal at all. In particular, there is a very limited version of MarketInfo (to make examples work only). But good solutions are there. Therefore, it is better not to use this mqh itself, but take only useful things from it.

 
-Aleks-:

I also get this error - how do I correct it?

'MODE_MAIN' - enumerator identifier already defined initmql4__1.mqh 223 24


 ENUM_STO_PRICE StoFieldMigrate(int field)


  {
   switch(field)
     {
      case 0: return(STO_LOWHIGH);
      case 1: return(STO_CLOSECLOSE);
      default: return(STO_LOWHIGH);
     }
  }

//+------------------------------------------------------------------+
enum ALLIGATOR_MODE  { MODE_GATORJAW=1,   MODE_GATORTEETH, MODE_GATORLIPS };
enum ADX_MODE        { MODE_MAIN,         MODE_PLUSDI, MODE_MINUSDI };
enum UP_LOW_MODE     { MODE_BASE,         MODE_UPPER,      MODE_LOWER };
enum ICHIMOKU_MODE   { MODE_TENKANSEN=1,  MODE_KIJUNSEN, MODE_SENKOUSPANA, MODE_SENKOUSPANB, MODE_CHINKOUSPAN };
enum MAIN_SIGNAL_MODE{ MODE_MAIN,         MODE_SIGNAL };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double CopyBufferMQL4(int handle,int index,int shift)
  {
   double buf[];
   switch(index)
     {
      case 0: if(CopyBuffer(handle,0,shift,1,buf)>0)
         return(buf[0]); break;
      case 1: if(CopyBuffer(handle,1,shift,1,buf)>0)
         return(buf[0]); break;
      case 2: if(CopyBuffer(handle,2,shift,1,buf)>0)
         return(buf[0]); break;
      case 3: if(CopyBuffer(handle,3,shift,1,buf)>0)
         return(buf[0]); break;
      case 4: if(CopyBuffer(handle,4,shift,1,buf)>0)
         return(buf[0]); break;
      default: break;
     }
   return(EMPTY_VALUE);
  }
//+------------------------------------------------------------------+

Rename. The fields of ALL enumerators must be different. And you have the same fields inenum ADX_MODE andenum MAIN_SIGNAL_MODE.
 
fxsaber:
Renaming. The fields of ALL enumerations should be different. And you have the same fields inenum ADX_MODE andenum MAIN_SIGNAL_MODE.

I've commented it out for now... I don't think it's critical...

However, compiled an EA using two libraries - trading functions and translation of other functions from 4 to 5.

I'm still sick of the tester in 5 - I can't find where indicators can be added in visualization and how to filter the log...

Can't see the open orders yet, eh.

 

How to interpret this:

2016.11.04 20:42:25.224 2016.02.11 14:04:30 When setting pending unforeseen error - 4756
2016.11.04 20:42:25.224 2016.02.11 14:04:30 Magic=49266773 cPoza::setOrder sent a request to set an order. Type: BuyStop lot=1.0 opPrice=68180.0 tp=68200.0 sl=67260.0
2016.11.04 20:42:25.224 2016.02.11 14:04:30 failed buy stop 1.00 RTS-12.16 at 68180 sl: 67260 tp: 68200 [Invalid expiration]
2016.11.04 20:42:25.224 2016.02.11 14:04:30 When setting pending unforeseen error - 4756

 
-Aleks-:

How to interpret this:

2016.11.04 20:42:25.224 2016.02.11 14:04:30 When setting pending unforeseen error - 4756
2016.11.04 20:42:25.224 2016.02.11 14:04:30 Magic=49266773 cPoza::setOrder sent a request to set an order. Type: BuyStop lot=1.0 opPrice=68180.0 tp=68200.0 sl=67260.0
2016.11.04 20:42:25.224 2016.02.11 14:04:30 failed buy stop 1.00 RTS-12.16 at 68180 sl: 67260 tp: 68200 [Invalid expiration]
2016.11.04 20:42:25.224 2016.02.11 14:04:30 When setting pending unforeseen error - 4756

There is something wrong with the expiration setting.
 
-Aleks-:

So far I'm sick of the tester in five - I can't find where the indicators can be added to the visualisation and how to filter the log...

No way to see open orders yet, eh.

I am using an MT4 converted script from 2006 to view the tester's history. It shows everything as conveniently as MT4.