Invalid Volume Error

 

Hi, i recently started coding using mql5, and i'm making my first steps. I was developing this expert advisor. It was nothing serious (i didn't even finish it), it was just an attempt to understend how simple "buy" methods work. Anyway, i keep getting stuck when i actually have to send the order, because if i try it on graphic ( i tried it on the COCACOLA one and on the EURUSD) it gives me back an error of "Invalid Volume", and i can't figure out why it does. Can someone please help me? This is the code. I wrote it mostly in italian, so if you need some translation ask me. Tnks.


//+------------------------------------------------------------------+
//|                                                  Strategy1.0.mq5 |
//|                                                      TurboTrader |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "TurboTrader"
#property link      "https://www.mql5.com"
#property version   "1.00"

#include <Trade\trade.mqh>
CTrade trade;

bool OnGoingTrade=false;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
  
  double varx=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);
  double varn=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
  
  Print("Volume max: "+DoubleToString(varx));
  Print("Volume min: "+DoubleToString(varn));
  Print(IntegerToString(GetLastError()));
  
   // Salvo i valori attuali della media mobile a 50 e a 200 periodi.

   int handle_50,handle_200;
   double SMA50[],SMA200[];

   handle_50=iMA(Symbol(),0,50,0,MODE_SMA,PRICE_CLOSE);
   handle_200=iMA(Symbol(),0,200,0,MODE_SMA,PRICE_CLOSE);

   CopyBuffer(handle_50,0,0,1,SMA50);
   CopyBuffer(handle_200,0,0,1,SMA200);

// Decido se il trend è positivo o negativo. Nel primo caso, la
// variabile booleana "trend" sarà true, nel secondo sarà false.
// Se i valori coincidono "trend" varrà NULL.

   bool trend=NULL;

   if(SMA50[0]>SMA200[0])
      trend=true;
   if(SMA50[0]<SMA200[0])
      trend=false;
      
// Salvo il valore attuale dell'RSI a 4 periodi.

   int handle_RSI;
   double RSI[];

   handle_RSI=iRSI(NULL,0,4,PRICE_CLOSE);

   CopyBuffer(handle_RSI,0,0,1,RSI);

// Decido se la posizione è long o short.

   bool position=NULL;

   if(RSI[0]<30)
      position=true;
   if(RSI[0]>70)
      position=false;

//Apro la posizione. La posizione sarà long se "trend"=true
// e se "position"=true. Viceversa la posizione sarà short.

   string Strumento=Symbol();
   double Prezzo_apertura=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
   double Size=500*Prezzo_apertura*Point();
   double SL,TP;

   if(trend==true && position==true && OnGoingTrade==false)
     {
      SL=Size-5000*Point();
      TP=Size+2500*Point();
      trade.Buy(Size,Symbol(),Prezzo_apertura,SL,TP);
      OnGoingTrade=true;
     }
   if(trend==false && position==false && OnGoingTrade==false)
     {
      SL=Size+50;
      TP=Size-25;
      trade.Sell(Size,Symbol(),Prezzo_apertura,SL,TP);
      OnGoingTrade=true;
     }
   return(INIT_SUCCEEDED);
  }
 
You may find this topic useful: https://www.mql5.com/en/forum/473812
Invalid volume error, On Market product validation ONLY - I keep getting the same error when I submit my program to the market?
Invalid volume error, On Market product validation ONLY - I keep getting the same error when I submit my program to the market?
  • 2024.09.27
  • Omega J Msigwa
  • www.mql5.com
Error however, this time when i submit it the program to the market, the validation fails due to invalid volume. Thanks, your suggestion and code works locally but, when i submit the program again i get the exact same error. I keep on getting the same error, still