SL/TP Strategy Tester not executing

 

Hello everyone,

I am cracking my head here. My code simply does not execute the SL or TP orders. They appear on the testing graph, but they are not executed. Can anybody help, please? Thanks.

//IMPORTAÇÃO
#include<Trade\Trade.mqh>

//cria instância chamada "trade"
CTrade trade;

input int lote    =12;
input int StopLoss    =530;
input int StopGain    =180;



void OnTick()
  {
  
  

  
  //EMAS//
      //cria o array das médias
      double EMASlow[], EMAFast[];
      
      //define as propriedades das médias
      int EMAFastDefinition = iMA (_Symbol,_Period,14,0,MODE_EMA,PRICE_CLOSE);
      int EMASlowDefinition = iMA (_Symbol,_Period,35,0,MODE_EMA,PRICE_CLOSE);
      
      //contar regressivamente a partir do último candle
      ArraySetAsSeries(EMAFast,true);
      ArraySetAsSeries(EMASlow,true);
      
      //definição das propriedades, uma linha, candle corrente, 3 candles passados, guardar resultado
      CopyBuffer(EMAFastDefinition,0,0,3,EMAFast);
      CopyBuffer(EMASlowDefinition,0,0,3,EMASlow);
      
   //MACD//
      //cria o array do indicador
      double MACD[];
      
      //defines as propriedades do MACD
      int MACDDefinition = iMACD (_Symbol,_Period,12,35,9,PRICE_CLOSE);
      
      //contar regressivamente a partir do último candle
      ArraySetAsSeries(MACD,true);
      
      //definição das propriedades, uma linha, candle corrente, 3 candles passados, guardar resultado
      CopyBuffer(MACDDefinition,0,0,3,MACD);
      
      //obter valor do MACD para o candle
      float MACDValue = (MACD[0]);
      
   //VALORES DE PREÇO
      //pede o preço corrente
      double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
      double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
      
      //cria array para os preços
      MqlRates PriceInfo[];
      
      //contar regressivamente a partir do último candle
      ArraySetAsSeries(PriceInfo,true);
      
      //copia os valores do mercado para o array
      int PriceData = CopyRates(_Symbol,_Period,0,3,PriceInfo);
      
      
      
      
      
      
   //ORDENS      
      //condição de compra
      if(
      (EMAFast[0]>EMASlow[0])
      && (EMAFast[1]<EMASlow[1])
      && (MACD[0]>0)
      && (PositionsTotal() == 0)
         )
        {
          Comment ("Buy");
          trade.Buy(
                     lote,
                     NULL,
                     Ask,
                     Bid-StopLoss*_Point,
                     Bid+StopGain*_Point,
                     NULL
                     ); // se for usar mais de um advisor no mesmo gráfico
        }


        
      //condição de venda
      if(
      (EMAFast[0]<EMASlow[0])
      && (EMAFast[1]>EMASlow[1])
      && (MACD[0]<0)
         )
        {
          Comment ("Sell");
        }
            
   
  }
 

"are not executed" by itself is not very helpful.

Did you get any error messages?

 
WindmillMQL:

"are not executed" by itself is not very helpful.

Did you get any error messages?

Thx for you reply. I could figure it out, it was the allowed TP/SL values for the currency pair.

But anyway, thank you for taking your time!

 
void OnTick(){
      
      //define as propriedades das médias
      int EMAFastDefinition = iMA (_Symbol,_Period,14,0,MODE_EMA,PRICE_CLOSE);
      int EMASlowDefinition = iMA (_Symbol,_Period,35,0,MODE_EMA,PRICE_CLOSE);
⋮
      CopyBuffer(EMAFastDefinition,0,0,3,EMAFast);
      CopyBuffer(EMASlowDefinition,0,0,3,EMASlow);
Perhaps you should read the manual, especially the examples. They all (including iCustom) return a handle (an int.) You get that in OnInit. In OnTick (after the indicator has updated its buffers,) you use the handle, shift and count to get the data.
          Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
          Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08
          How to call indicators in MQL5 - MQL5 Articles 12 March 2010

Also see my example for encapsulating calls
          Detailed explanation of iCustom - MQL4 programming forum 2017.05.23

Reason: