OrderSend Error 134 (No Enough Money)

 

My EA keeps giving me this error OrderSend Error 134 when i backtest it which stands for not enough money as the error description says. I added in the code 

 

 if (((AccountStopoutMode() == 1)
&& (AccountFreeMarginCheck(Symbol(),OP_BUY, BuyVolume) > AccountStopoutLevel()))
|| ((AccountStopoutMode() == 0)
&& (((AccountFreeMarginCheck(Symbol(), OP_BUY, BuyVolume)/AccountEquity()) * 100) > AccountStopoutLevel())))  {

as suggested in 

http://www.earnforex.com/blog/2010/11/ordersend-error-134-no-enough-money/

 it helps a bit but the journal still tells me that there isnt enough money that makes me wonder which part of my code went wrong. And when i check the report, i am making negative gross with my EA, which it isnt suppose to.

below is my full code, anyone know why am i losing money with this EA and ended up not having enough money?

 

//+------------------------------------------------------------------+
//|                                              My RSI strategy.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#include <stderror.mqh> 
#include <stdlib.mqh>  
//All Variables here

extern double UpperBound    =  90;      //set upper bound value
extern double LowerBound    =  5;      //set lower bound value
extern double VarPeriod     =  2;      //number of periods
extern double BuyVolume     = 2;       //set buying volume, preset to 5
extern double SellVolume    = 2;       //set selling volume, preset to 5
extern double StopLoss      = 60;//Set the stop loss level
extern double TakeProfit    = 60;//Set the take profit level


//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   
   double CurrentRSI;                  //Finds out the RSI for now
   double MA200;                       //200 day Moving Average           
   double MA5;                         //5 day Moving Average
   double CurrentAsk;                  //Finds out the Ask price now
   double CurrentBid;                  //Finds out the Bid price now
   int Err;
   
   CurrentAsk = MarketInfo(Symbol(), MODE_ASK);
   CurrentBid = MarketInfo(Symbol(), MODE_BID);
   MA200 = iMA(NULL, 0, 200, 8,MODE_SMA,PRICE_CLOSE, 0);
   MA5 = iMA(NULL, 0, 5, 8,MODE_SMA,PRICE_CLOSE, 0);
   CurrentRSI = iRSI (NULL, 0, VarPeriod,PRICE_CLOSE ,0);
   
   
   
   if (((AccountStopoutMode() == 1)
&& (AccountFreeMarginCheck(Symbol(),OP_BUY, BuyVolume) > AccountStopoutLevel()))
|| ((AccountStopoutMode() == 0)
&& (((AccountFreeMarginCheck(Symbol(), OP_BUY, BuyVolume)/AccountEquity()) * 100) > AccountStopoutLevel())))  {

   
    if (CurrentRSI < LowerBound && MarketInfo(Symbol(), MODE_ASK) > MA200 ) {    //If RSI value is less than lowerbound value and Ask price is 200 units higher than Moving Average
        Err = OrderSend(Symbol(), OP_BUY, BuyVolume, Ask, 3, Bid - ( StopLoss * Point ), Ask + ( TakeProfit * Point ), "Buy888.", 111,0,Yellow)   ;       //execute buy order
   }
   }
  
  
   if (((AccountStopoutMode() == 1)
&& (AccountFreeMarginCheck(Symbol(),OP_SELL, SellVolume) > AccountStopoutLevel()))
|| ((AccountStopoutMode() == 0)
&& (((AccountFreeMarginCheck(Symbol(), OP_SELL, SellVolume)/AccountEquity()) * 100) > AccountStopoutLevel())))  {

  if (CurrentRSI > UpperBound && MarketInfo(Symbol(), MODE_BID) > MA5) {     //If RSI value is more than upperbound and Moving Average is 200 units higher than Bid price 
       Err = OrderSend(Symbol(), OP_SELL, SellVolume, Bid, 3, Ask + ( StopLoss * Point ), Bid - ( TakeProfit * Point ), "Sell888.",000, 0, Yellow)  ;     //execute sell order
   }
   }
    
     Err=GetLastError();
     Print("error(",Err,"): ",ErrorDescription(Err));
     return(0);
    
   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

chan,

If you wish to discover the root of your issue, you may consider reducing multiple order signals to a single signal only. Remove any unnecessary code considered inapplicable to your issue-

(take away all the "fluff-and-puff" and you are left with less "fluff-and-puff" to sort through to isolate your issue).

Maybe these statements were of value to you.

Thank you

 

alright , i placed the error part

 

 Err=GetLastError();
     Print("error(",Err,"): ",ErrorDescription(Err));
     return(0);

 inside the OrderSend Blocks the error 134 went away...

 
--
 

cyxstudio:

Err = OrderSend(Symbol(),    //  ?????????

and

Err=GetLastError();    //?????

 

Why this way......