StopLoss and StopGain order won't trigger.

 

Hello everyone! How are you guys doing?

So, I've been programming my expert for some time, and now I've ran into an issue I can't figure out.
My Expert has been programmed using the template that the wizard generates. I've programmed my signal and the expert.

The code seems to be working just fine, except for one little detail. Both the stop loss and take aren't being triggered. The order gets executed, stops get set, but when the price reaches them they aren't executed. No exceptions gets throwed, no errors, nothing. Here's the video:



I've searched on google and couldn't find anything related to this. The expert entry points are correct. Also, when it receives a signal to close the position it correctly closes it. Just the stops that aren't working. Help....


Here's the expert code:
//+------------------------------------------------------------------+
//|                                                    LucasSeno.mq5 |
//|                                                       Lucas Reis |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Lucas Reis"
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Include                                                          |
//+------------------------------------------------------------------+
#include <Expert\Expert.mqh>
//--- available signals
#include <Expert\MySignals\SinalIndice2Medias.mqh>
//--- available trailing
#include <Expert\Trailing\TrailingNone.mqh>
//--- available money management
#include <Expert\Money\MoneyNone.mqh>

//+------------------------------------------------------------------+
//| Inputs                                                           |
//+------------------------------------------------------------------+
//--- inputs for expert
input string Expert_Title            ="Indice2Medias"; // Document name
input ulong  Expert_MagicNumber      =8273;        // Expert Magic Number
bool         Expert_EveryTick        =false;       //
//--- inputs for main signal
input int    Signal_ThresholdOpen    =10;          // Signal threshold value to open [0...100]
input int    Signal_ThresholdClose   =2;           // Signal threshold value to close [0...100]
input double Signal_PriceLevel       =0.0;         // Price level to execute a deal
input double Signal_StopLevel        =170;         // Stop Loss level (in points)
input double Signal_TakeLevel        =300;         // Take Profit level (in points)
input bool   Usar_Relacao_Stop       =false;       // Usar relacao stop take/loss
input double RelacaoStop             =2;           // Relação stop take/loss 
input int    Signal_Expiration       =4;           // Expiration of pending orders (in bars)
input int    HorarioInicio           =915;         // Horario de início das operacoes
input int    HorarioFim              =1730;        // Horario de fim das operacoes
input int    PeriodFMA               =24;          // Periodo EMA1
input int    PeriodSMA               =30;          // Periodo EMA2
input bool   UseBoAvgs               =false;
input int    PeriodBoShort           =34;          // EMA BoWilliams Curta
input int    PeriodBoMedium          =144;         // EMA BoWilliams Média
input int    PeriodBoLong            =614;         // EMA BoWilliams Longa
input float  Hipotenusa              =2000;        // Valor da hipotenusa
input int    TempoEspera             =6;           // Delay de entrada
input int    TempoEspera2            =12;          // Delay de entrada da média 2
input double ValorSenCompra          =0.05;        // Valor de compra;
input double ValorSenVenda           =-0.03;       // Valor de venda;
input int    PeriodoRSI              =21;           // Período do IFR
input double RSICompra               =56;          // Valor de compra do IFR
input double RSIVenda                =43;          // Valor de venda do IFR
input int    PeriodoEstoc            =8;          // Período do estocástico
input double EstocCompra             =100;          // Valor de compra do estocástico
input double EstocVenda              =32;          // Valor de venda do estocástico
input double Weight                  =1.0;         // Weight [0...1.0]
//+------------------------------------------------------------------+
//| Global expert object                                             |
//+------------------------------------------------------------------+
CExpert ExtExpert;
CSignalSeno2 *filter0;
bool encontraCruzamentoFlag = false;
//+------------------------------------------------------------------+
//| Initialization function of the expert                            |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Initializing expert
   if(!ExtExpert.Init(Symbol(),Period(),Expert_EveryTick,Expert_MagicNumber))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing expert");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Creating signal
   CExpertSignal *signal=new CExpertSignal;
   if(signal==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating signal");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//---
   ExtExpert.InitSignal(signal);
   signal.ThresholdOpen(Signal_ThresholdOpen);
   signal.ThresholdClose(Signal_ThresholdClose);
   signal.PriceLevel(Signal_PriceLevel);
   signal.StopLevel(Signal_StopLevel);
   signal.TakeLevel(Signal_TakeLevel);       
   signal.Expiration(Signal_Expiration);
   
   if(Usar_Relacao_Stop) {
      signal.StopLevel(Signal_TakeLevel / RelacaoStop);
   }
   
//--- Creating filter CSignalSeno
   filter0=new CSignalSeno2;
   if(filter0==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating filter0");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
   signal.AddFilter(filter0);
//--- Set filter parameters
   filter0.HorarioInicio(HorarioInicio);
   filter0.HorarioFim(HorarioFim);
   filter0.PeriodFMA(PeriodFMA);   
   filter0.PeriodSMA(PeriodSMA);
   filter0.UseBoAvgs(UseBoAvgs);
   filter0.PeriodBoShort(PeriodBoShort);
   filter0.PeriodBoMedium(PeriodBoMedium);
   filter0.PeriodBoLong(PeriodBoLong);   
   filter0.TempoEspera(TempoEspera);
   filter0.TempoEspera2(TempoEspera2);
   filter0.ValorCompra(ValorSenCompra);
   filter0.ValorVenda(ValorSenVenda);
   filter0.HipFMA(Hipotenusa);
   filter0.RSIPeriodo(PeriodoRSI);
   filter0.RSICompra(RSICompra);
   filter0.RSIVenda(RSIVenda);
   filter0.EstocPeriodo(PeriodoEstoc);
   filter0.EstocCompra(EstocCompra);
   filter0.EstocVenda(EstocVenda);
   filter0.Weight(Weight);
   
//--- Creation of trailing object
   CTrailingNone *trailing=new CTrailingNone;
   if(trailing==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating trailing");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Add trailing to expert (will be deleted automatically))
   if(!ExtExpert.InitTrailing(trailing))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing trailing");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Set trailing parameters
//--- Creation of money object
   CMoneyNone *money=new CMoneyNone;
   if(money==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating money");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Add money to expert (will be deleted automatically))
   if(!ExtExpert.InitMoney(money))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing money");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Set money parameters
//--- Check all trading objects parameters
   if(!ExtExpert.ValidationSettings())
     {
      //--- failed
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Tuning of all necessary indicators
   if(!ExtExpert.InitIndicators())
     {
      //--- failed
      printf(__FUNCTION__+": error initializing indicators");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
   //filter0.EncontrarCruzamento();     
//--- ok   
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Deinitialization function of the expert                          |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ExtExpert.Deinit();   
  }
//+------------------------------------------------------------------+
//| "Chart" event handler function                                    |
//+------------------------------------------------------------------+
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
  {
     
  }
//+------------------------------------------------------------------+
//| "Tick" event handler function                                    |
//+------------------------------------------------------------------+
void OnTick()
  {
   ExtExpert.OnTick();
   if(!encontraCruzamentoFlag) {
      filter0.EncontrarCruzamento();
      encontraCruzamentoFlag = true;
   }     
  }
//+------------------------------------------------------------------+
//| "Trade" event handler function                                   |
//+------------------------------------------------------------------+
void OnTrade()
  {
   ExtExpert.OnTrade();
  }
//+------------------------------------------------------------------+
//| "Timer" event handler function                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
   ExtExpert.OnTimer();
  }
//+------------------------------------------------------------------+
Basic Principles - Trading Operations - MetaTrader 5 Help
Basic Principles - Trading Operations - MetaTrader 5 Help
  • www.metatrader5.com
Before you proceed to study the trade functions of the platform, you must have a clear understanding of the basic terms: order, deal and position...
 
So, apparently messages can't exceed 64000 chars, so I'm attaching the signal code in here:
Files:
signal_code.mqh  27 kb
 
Lucas Pevidor :
So, apparently messages can't exceed 64000 chars, so I'm attaching the signal code in here:***

Files are transferred using the button  Attach file.

 
Vladimir Karputov:

Files are transferred using the button  .

Oh, my bad. Missed that button