Please help me test this code

 

Hello friends,

I am testing this EA at the moment. This will only allow one trade at anytime and will close the current order if you switch to a different chart. The EX4 file shouldn't allow you to use it on a real account, if it is attached to a real account it will not start and EA ends straight away.


<ex4 file deleted - please only attach mq4>

 

This isn't the same as the deleted EX4. Try it if you wish.

#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
long chartid,Chart_ID;
extern  ENUM_TIMEFRAMES    TIME_FRAME=PERIOD_H1;
extern double              TRAILING_STOP  = 50;  
extern ENUM_CHART_MODE     CHART_MODES    = 1;
extern int                 DELAY          = 1000;
extern long                CHARTS_SIZE    = 4;     
extern double              LOT            = 0.20;
extern bool                OHLC           = true;  
extern bool                CHART_PERIOD   = false;
extern bool                GRID           = false; 
extern bool                SCROLL_ON      = true;
string Pairs[]={"EURAUD","AUDUSD","EURUSD","GBPUSD","USDJPY","USDCAD","USDCHF"},DemoAccount,charts;
double Profit=0,Y,X,MA_0_1,MA_1_1,MA_1,MA_2,MA_3,MA_0,OrderPrice;
int Sell_condition=0,Buy_condition=0,Sell_prev=0,Buy_prev=0,frame=0,counter=0,Trade,shift=0,SPREAD,x,y,z,i,pos,total,order_type;
bool sell=false,buy=false;

int OnInit()  {
   bool T=ChartSetSymbolPeriod(Chart_ID,Symbol(),TIME_FRAME);
   ChartSetInteger(Chart_ID,CHART_SHOW_PERIOD_SEP,CHART_PERIOD);
   ChartSetInteger(Chart_ID,CHART_SHIFT,4); 
   ChartSetInteger(Chart_ID,CHART_COLOR_CANDLE_BEAR,clrCoral); 
   ChartSetInteger(Chart_ID,CHART_SHOW_GRID,GRID);
   ChartSetInteger(Chart_ID,CHART_COLOR_CANDLE_BULL,clrBlue); 
   ChartSetInteger(Chart_ID,CHART_SHOW_OHLC,OHLC);   
   ChartSetInteger(Chart_ID,CHART_COLOR_CHART_DOWN,clrCoral); 
   ChartSetInteger(Chart_ID,CHART_SCALE,CHARTS_SIZE);
   ChartSetInteger(Chart_ID,CHART_COLOR_CHART_UP,clrBlue); 
   ChartSetInteger(Chart_ID,CHART_COLOR_ASK,clrBlue);
   ChartSetInteger(Chart_ID,CHART_COLOR_BACKGROUND,clrBlack);
   ChartSetInteger(Chart_ID,CHART_COLOR_BID,clrBlack);
   ChartSetInteger(Chart_ID,CHART_AUTOSCROLL,SCROLL_ON); 
   ChartSetInteger(Chart_ID,CHART_SHOW_ASK_LINE,true);
   ChartSetInteger(Chart_ID,CHART_COLOR_BID,clrBlue); 
   ChartSetInteger(Chart_ID,CHART_MODE,CHART_MODES);
   ChartSetInteger(Chart_ID,CHART_COLOR_FOREGROUND,clrWhite);
   if(IsDemo()) DemoAccount="DEMO ACCOUNT";
   else ExpertRemove();
   return(INIT_SUCCEEDED); }
 void OnTick() 
 {   Comment("\n Server Date Time : ",(string)Day()," ",(string)Month()," ",(string)Year()," ",TimeToString(TimeCurrent(),TIME_MINUTES),
           "\n User               :  ",AccountName(),
           "\n Account          :  ",(string)DemoAccount," ",(string)AccountNumber(),
           "\n Broker            :  ",TerminalCompany(),
           "\n Balance          :  ",DoubleToString(AccountBalance(), 2),
           "\n Equity           :  ",DoubleToString(AccountEquity(),  2),
           "\n Credit           :  ",DoubleToString(AccountCredit(),  2),
           "\n Profit           :  ",DoubleToString(AccountProfit(),  2),
           "\n Total Orders     :  ",DoubleToString(OrdersTotal(),    0));
   if(OrderSelect(0, SELECT_BY_POS)==true) 
    { 
   OrderPrice =OrderOpenPrice();
   Profit= OrderProfit(); 
   if (Profit >= 100){Close_position();} 
       MA_0 =iMA(Pairs[0],TIME_FRAME,5,0,MODE_SMA,PRICE_CLOSE,1);
       MA_1 =iMA(Pairs[0],TIME_FRAME,26,0,MODE_SMA,PRICE_CLOSE,1);
  if ( MA_0 >= MA_1)  {Pre_Buy_conditions();}
  if ( MA_0 <= MA_1)  {Pre_Sell_conditions();}
  }
 }
//+------------------------------------------------------------------+
//                                                                   |
//+------------------------------------------------------------------+
void Pre_Sell_conditions()
  {
   total=OrdersTotal();
   if(total<=0)
      Sell();
   for(pos=0;pos<total;pos++)
     {
      if(OrderSelect(pos,SELECT_BY_POS)==true)
         order_type=OrderType();
      if(order_type!=1)
         Close_position();
      else
         continue;
      Sell();
   RefreshRates();
     }     
  }
//+------------------------------------------------------------------+
//                                                                   |
//+------------------------------------------------------------------+
void Pre_Buy_conditions()
  {
   total=OrdersTotal();
   if(total<=0)
      Buy();
   for(pos=0;pos<total;pos++)
     {
      if(OrderSelect(pos,SELECT_BY_POS)==true)
         order_type=OrderType();
      if(order_type!=0)
         Close_position();
      else
         continue;
      Buy();
      RefreshRates();
     }
  }
//+------------------------------------------------------------------+
//                                                                   |
//+------------------------------------------------------------------+
int Buy()
  {
  Alert("Buy");
      int  slippage=int((Ask-Bid)/_Point);
      int OPbuy=OrderSend(Pairs[0],OP_BUY,LOT,Ask,0,0,0,"buy 1",OrderTicket(),0,clrNONE);
      if(OPbuy<0)
        {Operation();}
        {Buy_prev=Buy_condition;
         buy=true;}
   return(Buy_prev);
  }
//+------------------------------------------------------------------+
//                                                                   |
//+------------------------------------------------------------------+
int Sell()
  {
  Alert("Sell");
      int  slippage=int((Ask-Bid)/_Point);
      int OPsell=OrderSend(Pairs[0],OP_SELL,LOT,Bid,0,0,0,"sell 1",OrderTicket(),0,clrNONE);
      if(OPsell<0)
        {Operation();}
        {Sell_prev=Sell_condition;
         sell=true;}
   return (Sell_prev);
  }
//+------------------------------------------------------------------+
void Close_position()
  {
   RefreshRates();
   if(OrderSelect(0,SELECT_BY_POS)==true)
      bool Order_Closing=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,clrNONE);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Operation()
  {
   switch(GetLastError()){
      case 0: Comment("\n Order Placed Sussesfully :"); return;
      case 1: Comment("\n No error returned, but the result is unknown :");break;
      case 2: Comment("\n Common error :");break;
      case 3: Comment("\n Invalid trade parameters :"); break;
      case 6: Comment("\n No connection :");break;
      case 65: Comment("\n Invalid Account :");break;
      case 129: Comment("\n Invalid price :");break;
      case 130: Comment("\n Invalid stops :");break;
      case 131: LOT=MarketInfo(Symbol(),MODE_MINLOT);break;
      case 132: //ExpertRemove();
      case 133:// ExpertRemove();
      case 134: Comment("\n Selected Account doesn't have enough money :", (string)AccountNumber());break;
      case 145: Comment("\n Modification denied because order is too close to market :");break;
      case 148: Comment("\n Reached the limit set by the broker :");break;
      case 4105: Comment("\n No order selected. ");break;
      case 4108: Comment("\n Invalid ticket. ");break;
      case 4109: Comment("\n check box: ( Allow Live Trading ) must be checked. ");break;
      case 4110: Comment("\n Check the EA properties;  Only SHORT's are allowed. ");break;
      case 4111: Comment("\n Check the EA properties:  Only LONG's are allowed.  ");break;
      default: break;
     }
  }
//+------------------------------------------------------------------+
 
Reason: