Minimize Spread/Slipping M1

 

Hello my friends!

My SETUP: MT4, EURUSD, M1.

I am making a simple robot and simply using the Hi-Lo indicator. In the posted image, the yellow arrow is a purchase order (OP_BUY) and the blue arrow is the closing of a sales order (OP_SELL). I believe that both arrows (identified with red circle in attachment) should be effective in the range of the respective candle where the indicator tells me the Buy / Sell trend. We note that the trend was obeyed, however, the value of the order / closure was much higher than the values ​​obtained from the sails where I wanted to do the operation. I have read about GAP / Slipping / Spread (is that really thr problem??) but I am not getting an effective way to minimize the losses with these value lags.

My CODE:


         if(OrderType()==OP_BUY)   // Em relação a ordem de compra
           {
            if(Bid>=(OrderOpenPrice()+Alvo*Point))
              {
               ticket=OrderClose(OrderTicket(),OrderLots(),Bid,3,Blue); // Fecha ordem suposto lucro - Suporte
               Qtd_Ordem_COMPRA=0;
              }
            if(Bid<(OrderOpenPrice()-StopLoss*Point)) // Distancia (pip) --> StopLoss
              {
               ticket=OrderClose(OrderTicket(),OrderLots(),Bid,3,Red); // Fecha ordem prejuizo - Resistencia
              }
           }
         else // Venda
           {
            if(Ask<=(OrderOpenPrice()-Alvo*Point)) 
              {
               ticket=OrderClose(OrderTicket(),OrderLots(),Ask,3,Blue); // Fecha ordem lucro - Suporte
              }
            if(Ask>(OrderOpenPrice()+StopLoss*Point)) //--> Distancia (pip) --> StopLoss 
              {
               ticket=OrderClose(OrderTicket(),OrderLots(),Ask,3,Red); // Fecha ordem prejuizo - Resistencia
              }

           }


I am looking for a command or logic not to enter a sale with a certain GAP / Spread / Slipping and an exit in the same conditions.


Can you help me?

[]´s

https://charts.mql5.com/19/838/eurusd-m1-trading-point-of.png

Files:
EURUSDM1.png  24 kb
Reason: