Help with EA. opening trades 5 pips away from close

 

Hello, 

i am having trouble with my trades. I dont know if it's the EA or the broker am using that causing me problems. All my trades are opened 4 to 5 pips away from the previous bar's close. I understand there's slippage but 5 pips away from the close is just too much.

the ea reads a decision from a csv and executes the trade 20 seconds away from the bar change.

input double MaximumRisk   =0.012;
//--- parameters for data reading
input string InpFileName="decision1hr.csv"; // file name
input string InpDirectoryName="Data"; // directory name
int BarsCount = 0;
double Lots=1.05;
datetime old_bar = 0;
int Ticket;



int open()
  {
//--- open the file
 
   int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ);
   {
   
      Alert("%s file is available for reading",InpFileName);
      Alert("File path: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH));
      //--- additional variables
      int    str_size;
      int decision;
      //--- read data from the file
      while(!FileIsEnding(file_handle))
        {
         //--- find out how many symbols are used for writing the time
         str_size=FileReadInteger(file_handle,INT_VALUE);
         //--- read the string
         decision=FileReadString(file_handle,str_size);
         //--- print the decision
       Alert(decision);
      
       
       double SL = 100;
       int TP=30000;
       //--- trade conditions
             if(decision==1) 
       {Alert("BUY"); Ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,2,Ask-SL*Point,Ask+TP*Point);}
        else 
        if (decision==2)
        {Alert("SELL"); Ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,2,Bid+SL*Point,Bid-TP*Point);}
       }
       //--- trade conditions
         if(Ticket<0)
       {
      Alert("OrderSend failed with error #",GetLastError());
     }
   else
      Alert("OrderSend placed successfully");
     }
       
      //--- close the file
      FileClose(file_handle);
      Alert("Data is read, %s file is closed ",InpFileName);
     }
 

int close()  
{
    for (int i = OrdersTotal() - 1; i >= 0; i--) 
      {
        if(OrderSelect(i,SELECT_BY_POS) == true) 
        {
          int ticket=OrderTicket();
          if(OrderType()==OP_BUY)          
          OrderClose(ticket,Lots,Bid,3);
          else
          OrderClose(ticket,Lots,Ask,3);

        }
      }
}
 
  
int start()
{
  if (Bars > BarsCount)
{   
close();
Sleep(20000);    // interval
open();
}

  BarsCount = Bars;
}
 

For example in the pic below, the green line is where i were the EA entered the market but it's 5 pips away from the open...and this is on the 1hour chart


pic

 
  1. You buy at the Ask and sell at the Bid. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools -> Options {control-O} -> charts -> Show ask line.)
  2. Your image is useless without the price scale (and the symbol.) We can't know whether you mean 5 pips or 5 points (1/2 pip.)
Reason: