MQL5: Validation :-( I've already racked my brain to find out what it is and how it's solved. - page 4

 
The code was removed.
 
Andrey Minaev:
I read what checks to pass. Why are you writing this to everyone. I have a volume question, what's wrong.

Reading and doing are two big differences.

The treatment method: in addition to reading, do what is written. Repeat until you understand the error.


Added: To study codeIntersection 2 iMA Choosing Strategies, functions OpenBuy, OpenSell, LotCheck.

Intersection 2 iMA Choosing Strategies
Intersection 2 iMA Choosing Strategies
  • www.mql5.com
На баре может быть только одна сделка 'вход в рынок' (это внутренний параметр, он не вынесен во входные параметры и это не имеет отношения к параметру ' Only one positions'). При работе в режиме 'внутри бара' ('Search signals, in seconds' больше или равно '10') текущий бар - бар #0, при работе в режиме 'только в момент рождения нового бара'...
 

How do I understand you, I ask about lots, you advise me to look at price normalisation.

I've already spent a lot of time, I can't understand what's wrong. I have done what they write. It turns out here too do not know how to help.

What to do?

 
Andrey Minaev:

How do I understand you, I ask about lots, you advise me to look at price normalisation.

I have already spent a lot of time, I can't understand what this is all about. I have done what they write. It turns out here too do not know how to help.

What to do?

Forum on trading, automated trading systems and strategy testing

MQL5: Validation :-( I have already searched my head in depth what it is and how it is solved.

Vladimir Karputov, 2020.03.10 18:36

You have read and executed - are two big differences.

Your method of treatment: Do what you read, but also read what is written. Repeat until you understand the error.


Added: to study codeIntersection 2 iMA Choosing Strategies, functions OpenBuy, OpenSell, LotCheck.

I put in the price normalisation by mistake - sorry about that.
 

I inserted your LotCheck function.

Here is the result

 

Can anyone help? I've already tried everything.

 
Andrey Minaev:

Can anyone help? I've tried everything.

Where's the code? Paste the code using theCode button

 
//+-----------------------------------------------------------------------------------------------+
//| Функция открывает позицию Sell                                                                |
//+-----------------------------------------------------------------------------------------------+
void OpenSell(void)
{
   double volume=CalculateVolume(ORDER_TYPE_SELL);
   //volume=CheckVolumeValue(volume);
   //volume=NormalizeDouble(volume,DigitsLots());
   volume=LotCheck(volume,symb);
   if(!CheckMoneyForTrade(volume,ORDER_TYPE_BUY))
   {
      sell.allowOpen=false;
      return;
   }
   if(volume==0)
   {
      sell.allowOpen=false;
      return;
   }
   if(trd.Sell(volume,symb.Name(),symb.Bid(),0,0,inpComment))
//+-----------------------------------------------------------------------------------------------+
//| Функция рассчитывает объем позиции                                                            |
//+-----------------------------------------------------------------------------------------------+
double CalculateVolume(ENUM_ORDER_TYPE type)
{
   double volume=0;
   
   double size=cndl.high-cndl.low;
   
   if(symb.Point()==0)
      return 0;
   
   double sl=(size*inpStopLoss*0.01)/symb.Point();
   double risk=AccountInfoDouble(ACCOUNT_BALANCE)*inpRisk*0.01;
   
   volume=(risk/sl)/symb.TickValue();
   
   if(sl==0 || symb.TickValue()==0)
      return 0;
   
   if(inpMaxVolume>0 && inpMaxVolume<volume)
   {
      volume=inpMaxVolume;
      //Print(STR_TIME,"Установлен максимальный объем установленный в настройках");
      //Print(STR_TIME,"The maximum volume set in the settings is set");
   }
   return volume;
}
double LotCheck(double lots,CSymbolInfo &symbol)
  {
//--- calculate maximum volume
   double volume=NormalizeDouble(lots,2);
   double stepvol=symbol.LotsStep();
   if(stepvol>0.0)
      volume=stepvol*MathFloor(volume/stepvol);
//---
   double minvol=symbol.LotsMin();
   if(volume<minvol)
      volume=0.0;
//---
   double maxvol=symbol.LotsMax();
   if(volume>maxvol)
      volume=maxvol;
   return(volume);
  }
 
bool CheckMoneyForTrade(double lots,ENUM_ORDER_TYPE type)
  {
//--- получим цену открытия
   MqlTick mqltick;
   SymbolInfoTick(symb.Name(),mqltick);
   double price=mqltick.ask;
   if(type==ORDER_TYPE_SELL)
      price=mqltick.bid;
//--- значения необходимой и свободной маржи
   double margin,free_margin=AccountInfoDouble(ACCOUNT_MARGIN_FREE);
   //--- вызовем функцию проверки
   if(!OrderCalcMargin(type,symb.Name(),lots,price,margin))
     {
      //--- что-то пошло не так, сообщим и вернем false
      Print("Error in ",__FUNCTION__," code=",GetLastError());
      return(false);
     }
   //--- если не хватает средств на проведение операции
   if(margin>free_margin)
     {
      //--- сообщим об ошибке и вернем false
      Print("Not enough money for ",EnumToString(type)," ",lots," ",symb.Name()," Error code=",GetLastError());
      return(false);
     }
//--- проверка прошла успешно
   return(true);
  }
 
Andrey Minaev:

Can anyone help? I've already tried everything.

How do you close positions?