Stop Loss nao e executado

 

Boa tarde

Alguem poderia me ajudar?

No meu codigo abaixo, o meu stoploss nao e executado quando o preco atinge a linha so stoploss. Teria algum erro no codigo?

Grato por qualquer ajuda.

//+------------------------------------------------------------------+
//|   INPUTS DE ENTRADA                                              |
//+------------------------------------------------------------------+

input int Quantidade=1;

//+------------------------------------------------------------------+
//|     INDICADORES                                                  |
//+------------------------------------------------------------------+

MqlRates candle[];
MqlTick tick;

double Loss;//Perda Máxima(R$)
CTrade trade;
double stop;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   EventSetTimer(1);
   ArraySetAsSeries(candle,true);
   trade.SetAsyncMode(false);
   CopyRates(_Symbol,_Period,0,1000,candle);
   Print("EA Inicializado");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   EventKillTimer();
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   

   
   CopyRates(_Symbol,_Period,0,1000,candle);
   
//---------Descobrir que estao pedindo-----------------------------+

double Ask;
Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
//Print("Ask: ",Ask);
double Bid;
Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
//Print("Bid: ",Bid);


//+------------------------------------------------------------------+
//|        COMPRA                                                |
//+------------------------------------------------------------------+

   static bool done=false;
   
   if(
      candle[1].high > candle[2].high &&
      candle[1].close > candle[2].close &&
      candle[1].low > candle[2].low &&
      candle[1].close > candle[1].open &&
      candle[2].close > candle[2].open &&
      !done)
     {
      //---enviar ordem de compra

      done=true;
            
      stop=candle[2].low - 2;
     
      
      trade.Buy(Quantidade,_Symbol,0,stop,0,"Compra a mercado");
      
   
   
 
     
   
      //---
      ResetLastError();
      //---

      if(trade.ResultRetcode()==10008 || trade.ResultRetcode()==10009)
        {
         Print("Ordem corretamente executada");
         int magic=123456;
        }
      else
        {
         Print("Erro ao executar ordem. Erro: ",GetLastError());
         ExpertRemove();
        } // fechamento else
} //fechamento if
} //fechamento ontick


 
danilokramer:

Boa tarde

Alguem poderia me ajudar?

No meu codigo abaixo, o meu stoploss nao e executado quando o preco atinge a linha so stoploss. Teria algum erro no codigo?

Grato por qualquer ajuda.

You are posting in the English section, so please write in English. Alternatively you can post in the Portuguese forum.

As for your question, the problem is probably the following:

stop=candle[2].low - 2;

You are not adjusting the value to the number of Points or something similar in scaling. If this were for EUR/USD for example, your stop-loss would be at a negative price, eg. 1.2134 - 2 = -0.7866 which is impossible.

There are probably other problems but that was the first one I noticed.

Reason: