error during EA validation

To add comments, please log in or register
Mohd Hafizuddin Shaharom
113
Mohd Hafizuddin Shaharom  

Hi All,

Need someone help on my EA. i want to upload my EA and it shows error during the validation, the error is not enough money as below;


my code as below;

#property copyright "Copyright © 2017,"
#property version     "1.00"              // Version
#property strict

extern string OptionsEA="DEFAULT SETTINGS";
extern double TakeProfit = 200;
extern double FloatingTakeProfit = 400;
extern int AccountisNormal=0;
extern int mm=0;
extern int risk=3;
extern double Lots = 0.1;

extern double InitialStop = 0;
extern double TrailingStop = 100;
extern double DeviasiEnvelope = 0.07;
extern int MaxTrades=15;
extern int Pips=30;
extern int SecureProfit=3;
extern int AccountProtection=1;
extern int OrderstoProtect=3;
input bool   UseScalp_tp = true;
input int Scalp_tp = 30;

int result1;
double EURUSDPipValue=10;
double GBPUSDPipValue=10;
double USDCHFPipValue=10;
double USDJPYPipValue=9.715;
int MyAccountNumber;
string comment;
int  OpenOrders=0, cnt=0;
int  slippage=5;
double sl=0, tp=0;
double BuyPrice=0, SellPrice=0;
double lotsi=0, mylotsi=0;
int mode=0, myOrderType=0;
bool ContinueOpening=True;
double LastPrice=0;
int  PreviousOpenOrders=0;
double Profit=0;
int LastTicket=0, LastType=0;
double LastClosePrice=0, LastLots=0;
double Pivot=0;
double PipValue=0;
string text="", text2="";
double BUY=0,SELL=0, floatingbuy=0, floatingsell=0; 
int Scalp_tpi;
int floatinglotsi;
int floating=0;
// -----------------------------------------
int start()
  {
//----

   double MACD1min_00 =iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);   
   double MACD1min_01 =iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);               
   double MACD1min_10 =iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);   
   double MACD1min_11 =iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);

   
   //-- if there is not enough money
   if(AccountFreeMargin()<(1000*Lots))
        {
         Print("We have no money. Free Margin = ",AccountFreeMargin());
         return(0);
        }
       
   if (AccountisNormal==1)
   {
      if (mm!=0) { lotsi=MathCeil(AccountBalance()*risk/10000); }
        else { lotsi=Lots; }
   } else {  // then is mini
    if (mm!=0) { lotsi=MathCeil(AccountBalance()*risk/10000)/10; }
        else { lotsi=Lots; }
   }

   if (lotsi>100){ lotsi=100; }
   
   OpenOrders=0;
   for(cnt=0;cnt<OrdersTotal();cnt++)   
   {
     if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      if (OrderSymbol()==Symbol())
      {                
            OpenOrders++;
      }
      
   }     
   
   if (Symbol()=="EURUSD") { PipValue=EURUSDPipValue; }
   if (Symbol()=="GBPUSD") { PipValue=GBPUSDPipValue; }
   if (Symbol()=="USDJPY") { PipValue=USDJPYPipValue; }
   if (Symbol()=="USDCHF") { PipValue=USDCHFPipValue; }
   if (PipValue==0) { PipValue=5; }
   
   if (PreviousOpenOrders>OpenOrders) 
   {      
      for(cnt=OrdersTotal();cnt>=0;cnt--)
      {
         if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
            mode=OrderType();
          if (OrderSymbol()==Symbol()) 
          {
            if (mode==OP_BUY) 
            { result1=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Blue); 
              if(result1!=true)//if it did not close
           Print("error",GetLastError());    

            }
            if (mode==OP_SELL) 
            { result1=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Red); 
              if(result1!=true)//if it did not close
           Print("error",GetLastError()); 

            }
            return(0);
         }
      }
   }

   PreviousOpenOrders=OpenOrders;
   if (OpenOrders>=MaxTrades) 
   {
      ContinueOpening=False;
   } else {
      ContinueOpening=True;
   }

   if (LastPrice==0) 
   {
      for(cnt=0;cnt<OrdersTotal();cnt++)
      {    
        if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
         mode=OrderType();    
         if (OrderSymbol()==Symbol()) 
         {
            LastPrice=OrderOpenPrice();
            if (mode==OP_BUY) { myOrderType=2; }
            if (mode==OP_SELL) { myOrderType=1;    }
         }
      }
   }

   if (OpenOrders<1) 
   {
      myOrderType=3;
      floatingbuy=0;
      floatingsell=0;

//-------------------------------------------BUY CONDITION--------------------------------------------------
       
         
         if (MACD1min_00>MACD1min_10
          ) 
         
         { myOrderType=2;
          comment="BUY ORDER3";
          } //BUY
           
//-------------------------------------------SELL CONDITION--------------------------------------------------           
           
     
       
      if (MACD1min_00<MACD1min_10
         ) 
         { myOrderType=1;
         comment="SELL ORDER3";
          } //SELL
          
   }
   
//-------------------------------------------------MOdify Order-----------------------------------------------------
   for(cnt=OrdersTotal();cnt>=0;cnt--)
   {
     if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      if (OrderSymbol() == Symbol()) 
      {    
            if (OrderType()==OP_SELL) 
            {            
                  if (TrailingStop>0) 
              {
                  if (OrderOpenPrice()-Ask>=TrailingStop*Point + Pips * Point) 
                  {                        
                     if (OrderStopLoss()>(Ask+Point*TrailingStop))
                     {            
                        if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),800,Purple))
                           Print("OrderModify error ",GetLastError());
                           return(0);                          
                       }
                    }
              }
          }
   
            if (OrderType()==OP_BUY)
            {
               if (TrailingStop>0) 
               {
               if (Bid-OrderOpenPrice()>=TrailingStop*Point) 
                {
                    if (OrderStopLoss()<(Bid-Point*TrailingStop)) 
                    {                       
                       if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),800,Yellow))
                  Print("OrderModify error ",GetLastError());
                  return(0);
                    }
                  }
             }
            }
       }
   }
   
   Profit=0;
   LastTicket=0;
   LastType=0;
    LastClosePrice=0;
    LastLots=0;    
    for(cnt=0;cnt<OrdersTotal();cnt++)
    {
      if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      if (OrderSymbol()==Symbol()) 
      {            
             LastTicket=OrderTicket();
            if (OrderType()==OP_BUY) { LastType=OP_BUY; }
            if (OrderType()==OP_SELL) { LastType=OP_SELL; }
            LastClosePrice=OrderClosePrice();
            LastLots=OrderLots();
            if (LastType==OP_BUY) 
            {
                //Profit=Profit+(Ord(cnt,VAL_CLOSEPRICE)-Ord(cnt,VAL_OPENPRICE))*PipValue*Ord(cnt,VAL_LOTS);                
                if (OrderClosePrice()<OrderOpenPrice()) 
                    { Profit=Profit-(OrderOpenPrice()-OrderClosePrice())*OrderLots()/Point; }
                if (OrderClosePrice()>OrderOpenPrice()) 
                    { Profit=Profit+(OrderClosePrice()-OrderOpenPrice())*OrderLots()/Point; }
            }
            if (LastType==OP_SELL) 
            {
                //Profit=Profit+(Ord(cnt,VAL_OPENPRICE)-Ord(cnt,VAL_CLOSEPRICE))*PipValue*Ord(cnt,VAL_LOTS);
                if (OrderClosePrice()>OrderOpenPrice()) 
                    { Profit=Profit-(OrderClosePrice()-OrderOpenPrice())*OrderLots()/Point; }
                if (OrderClosePrice()<OrderOpenPrice()) 
                    { Profit=Profit+(OrderOpenPrice()-OrderClosePrice())*OrderLots()/Point; }
               
            }
      }
   }
    
    Profit=Profit*PipValue;
    text2="Profit: $"+DoubleToStr(Profit,2)+" +/-";
    
   if (OpenOrders>=(MaxTrades-OrderstoProtect) && AccountProtection==1) 
   {        
         //Print(Symbol,":",Profit);
         if (Profit>=SecureProfit) 
         {
            result1=OrderClose(LastTicket,LastLots,LastClosePrice,slippage,Yellow);    
            if(result1!=true)//if it did not close
           {
            Print("error",GetLastError()); 
           }      
            ContinueOpening=False;
            return(0);
         }
   }

      if (!IsTesting()) 
      {
         if (myOrderType==3) { text="No conditions to open trades"; }
         else { text="                         "; }
         Comment("LastPrice=",LastPrice," Previous open orders=",PreviousOpenOrders,"\nContinue opening=",ContinueOpening," OrderType=",myOrderType,"\n",text2,"\nLots=",lotsi,"\n",text);
      }

///////////////////////////////////////////OPEN TRADE SELL///////////////////////////////////////////////////////////////////////////////////////////

      if (myOrderType==1 && ContinueOpening)             
      {    
                           
         if ((Bid-LastPrice)>=Pips*Point || OpenOrders<1) 
             {
             TrailingStop=1;    
            SellPrice=Bid;                
            LastPrice=0;
            if (TakeProfit==0) { tp=0; }
            else { tp=SellPrice-TakeProfit*Point; }    
            if (InitialStop==0) { sl=0; }
            else { sl=SellPrice+InitialStop*Point;  }
                
            if (OpenOrders!=0) 
            {
                  mylotsi=lotsi;            
                  for(cnt=1;cnt<=OpenOrders;cnt++)
                  {
                     if (MaxTrades>12) { mylotsi=NormalizeDouble(mylotsi*2,2); }
                     else { mylotsi=NormalizeDouble(mylotsi*2,2); }
                  }
            } else { mylotsi=lotsi; }
            if (mylotsi>100) { mylotsi=100; }
            
            if(!OrderSend(Symbol(),OP_SELL,mylotsi,SellPrice,slippage,sl,tp,Symbol()+  comment,0,0,Red))
           Print("error",GetLastError());    
            
                    
            return(0);
         }
      }
           
///////////////////////////////////////////OPEN TRADE BUY///////////////////////////////////////////////////////////////////////////////////////////
    
       if (myOrderType==2 && ContinueOpening) 
      {         
         if ((LastPrice-Ask)>=Pips*Point || OpenOrders<1) 
         {    TrailingStop=1;        
            BuyPrice=Ask;
            LastPrice=0;
            if (TakeProfit==0) { tp=0; }
            else { tp=BuyPrice+TakeProfit*Point; }    
            if (InitialStop==0)  { sl=0; }
            else { sl=BuyPrice-InitialStop*Point; }
                        
            if (OpenOrders!=0) {
               mylotsi=lotsi;            
               for(cnt=1;cnt<=OpenOrders;cnt++)
               {
                  if (MaxTrades>12) { mylotsi=NormalizeDouble(mylotsi*2,2); }
                  else { mylotsi=NormalizeDouble(mylotsi*2,2); }
               }
            } else { mylotsi=lotsi; }
            if (mylotsi>100) { mylotsi=100; }

            if(!OrderSend(Symbol(),OP_BUY,mylotsi,BuyPrice,slippage,sl,tp,Symbol()+  comment,0,0,Blue))
            
            return(0);
         }
      }   

      
//----
   return(0);
  }
//+------------------------------------------------------------------+


Keith Watford
Moderator
13921
Keith Watford  

Do not double post.

I have deleted your other post

Vladislav Andruschenko
143480
Vladislav Andruschenko  
Mohd Hafizuddin Shaharom:

Hi All,

Need someone help on my EA. i want to upload my EA and it shows error during the validation, the error is not enough money as below;


my code as below;

The problem is that experts added to the market who do not follow the rules of trade.

To add comments, please log in or register