Download MetaTrader 5

[Invalid Volume] error!!!

To add comments, please log in or register
gdhami
145
gdhami  

Hey guys,

 

I'm trying to run this very simple EA (written in mql5), but for some reason I always get this error: 

2016.04.15 02:00:00.573 2012.10.05 07:17:59   CTrade::OrderSend: instant buy 0.01 NZDCAD at 0.80842 tp: 0.81842 [invalid volume

 

EA is really very simple, I googled a lot (in vain) , any idea what could be the error?

#property copyright "Test EA"

#define      EA_NAME        "Test EA"

input double Lots           = 0.01;
input double TP_absolute    = 0.0100;          // Take Profits (absolute price)


#include <Trade\Trade.mqh>



// ===================================================================
//| expert initialization function                                   |
// ===================================================================
int init()
{
   return(0);
}

// ===================================================================
//| expert deinitialization function                                 |
// ===================================================================
int deinit()
{
   return(0);
}

// ===================================================================
//| New bar event handler for the expert advisor                     |
// ===================================================================
void OnTick()
{
   if (PositionsTotal() != 0)
      return;

   CTrade *TradeCls = new CTrade;

   TradeCls.SetDeviationInPoints(1000);

   if (!TradeCls.PositionOpen(_Symbol, ORDER_TYPE_BUY, Lots, Ask(), 0, Ask() + TP_absolute, EA_NAME + " (Buy)"))
   {
      TradeCls.Result(result);
      Print("Buy Failed. Result Comment = ", TradeCls.ResultComment());
   }
}
// ===================================================================
double Ask()
{
   // Used for [ BUY ]

   MqlTick last_tick;
   SymbolInfoTick(_Symbol,last_tick);

   if (last_tick.ask != 0)
      return(last_tick.ask);
   else
   {
      // Most likely it's weekend
      double price[1];
      int    spread[1];

      CopyOpen  (_Symbol, PERIOD_M1, TimeCurrent(), 1, price);
      CopySpread(_Symbol, PERIOD_M1, TimeCurrent(), 1, spread);

      double ask = price[0] + spread[0] * _Point;

      return(ask);
   }
}
// ====================================================================
double Bid()
{
   // Used for [ SELL ]

   MqlTick last_tick;
   SymbolInfoTick(_Symbol,last_tick);

   if (last_tick.bid != 0)
      return(last_tick.bid);
   else
   {
      // Most likely it's weekend
      double price[1];
      int    spread[1];

      CopyOpen  (_Symbol, PERIOD_M1, TimeCurrent(), 1, price);
      CopySpread(_Symbol, PERIOD_M1, TimeCurrent(), 1, spread);

      double bid = price[0] + spread[0] * _Point;

      return(bid);
   }
}

 

Thanks! 

gdhami
145
gdhami  

I forgot to mention:

1. Not even a single order is executed (so it's not like I don't have enough margin, for example)

2. Test run with a virtual balance of 10,000 USD

Daniela Bluemel
761
Daniela Bluemel  
Is it the same with Lot of 0.1?
Alain Verleyen
Moderator
35055
Alain Verleyen  
Top-SecreT:
Is it the same with Lot of 0.1?
Yes, you need to check the minimum volume for this symbol on this broker.
gdhami
145
gdhami  
Thank you guys, indeed the min. volume for this pair is 0.1 lot, good catch!
To add comments, please log in or register