HELP:AFIRMA x MOVING AVERAGE.

 

Hi,

i´m triyng to build an expert crossing one moving average with the indicator AFIRMA, but  the backtest doesn´t work and pop up the message:   

cannot load custom indicator '2' [4801].

this phrase indicates to line101!

thank you very much for help!


//+------------------------------------------------------------------+

//|                                                         new1.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

#include<trade/Symbolinfo.mqh>

#include <Trade/Trade.mqh>   //biblioteca padrão ctrade







//| Declaration of enumerations                  |
//+----------------------------------------------+
enum ENUM_WINDOWS   // Type of constant
  {
   Rectangular = 1, // Rectangular window
   Hanning1,        // Hanning window 1
   Hanning2,        // Hanning window 2
   Blackman,        // Blackman window
   Blackman_Harris  // Blackman-Harris window
  };
  
  
 
 
string BoolToString(bool b)
{
   if (b) return("true");
   else return("false");
}

// * Média móvel
input ENUM_TIMEFRAMES      period=PERIOD_CURRENT;        // timeframe
input int                  ma_period=10;                 // Média móvel
input int                  ma_shift=0;                   // deslocamento
input ENUM_MA_METHOD       ma_method=MODE_SMA;           // tipo de média
input ENUM_APPLIED_PRICE   applied_price=PRICE_CLOSE;    // aplicar a
//Afirma                                                    
input double                  Period = 2;                // LF transmission width 1/(2*Periods)
input int                  Taps    = 21;                 // Number of delay units in the filter
input   ENUM_WINDOWS       Window=Blackman;              // Window index
input int                  Shift=0;                      // Horizontal shift of the indicator in bars
                                                      
// Entrada                                               // Tipo de Operação
extern bool  OPERARSell=false;                           // Operar vendido
extern bool  OPERARBuy=false;                            // Operar comprado
extern bool  OPERARSelleBuy=true;                        // Operar comprado e vendido
input double                  lote=0.01;                 // Quantidade de Contratos
input int                  stoploss=150;                 // Stop loss
input int                  takeprofit=300;               // Takeprofit
input int                  EA_magic=12345;               // EA magic number
                                                          



//+------------------------------------------------------------------+
//--- manipuladores dos indicadores de média móvel
int mediamovelHandle = INVALID_HANDLE;
int AfirmaHandle = INVALID_HANDLE;


//* vetores de dados dos indicadores
double Afirma[];
double mediamovel[];









CTrade trade;

int OnInit()
  {
//---
int ind_c=iCustom (_Symbol,_Period,"afirma",2,21,Blackman,0);

ChartIndicatorAdd(0,0,ind_c);




ArraySetAsSeries(Afirma,true);
ArraySetAsSeries(mediamovel,true);


int Afirmahandle =iCustom(0,0,2,21,Blackman,0);
int mediamovelhandle =iMA(0,0,7,2,MODE_EMA,PRICE_CLOSE);


   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

      if(isNewBar())
     {
      // execute a lógica operacional do robô
      
      //+------------------------------------------------------------------+
      //| OBTENÇÃO DOS DADOS                                               |
      //+------------------------------------------------------------------+
      int copied1 = CopyBuffer(mediamovelHandle,0,0,3,mediamovel);
      int copied2 = CopyBuffer(AfirmaHandle,0,0,3,Afirma);
      //---
      bool sinalCompra = false;
      bool sinalVenda = false;
      //--- se os dados tiverem sido copiados corretamente
      if(copied1==3 && copied2==3)
        {
         //--- sinal de compra
         if( Afirma[1]>mediamovel[1] && Afirma[2]<mediamovel[2] )
           {
            sinalCompra = true;
           }
         //--- sinal de venda
         if( Afirma[1]<mediamovel[1] && Afirma[2]>mediamovel[2] )
           {
            sinalVenda = true;
           }
   
  }
  
  //+------------------------------------------------------------------+
      //| VERIFICAR SE ESTOU POSICIONADO                                   |
      //+------------------------------------------------------------------+
      bool comprado = false;
      bool vendido = false;
      if(PositionSelect(_Symbol))
        {
         //--- se a posição for comprada
         if( PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY )
           {
            comprado = true;
           }
         //--- se a posição for vendida
         if( PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL )
           {
            vendido = true;
           }
        }
      
  
  
  //+------------------------------------------------------------------+
      //| LÓGICA DE ROTEAMENTO                                             |
      //+------------------------------------------------------------------+
      //--- ZERADO
      if( !comprado && !vendido )
        {
         //--- sinal de compra
         if( sinalCompra )
           {
            trade.Buy(lote,_Symbol,0,0,0,"Compra a mercado");
           }
         //--- sinal de venda
         if( sinalVenda )
           {
            trade.Sell(lote,_Symbol,0,0,0,"Venda a mercado");
           }
        }
      else
        {
         //--- estou comprado
         if( comprado )
           {
            if( sinalVenda )
              {
               trade.Sell(lote*2,_Symbol,0,0,0,"Virada de mão (compra->venda)");
              }
           }
         //--- estou vendido
         else if( vendido )
           {
            if( sinalCompra )
              {
               trade.Buy(lote*2,_Symbol,0,0,0,"Virada de mão (venda->compra)");
              }
           }
        }
      
      
     }
  }
//+------------------------------------------------------------------+

bool isNewBar()
  {
//--- memorize the time of opening of the last bar in the static variable
   static datetime last_time=0;
//--- current time
   datetime lastbar_time=(datetime)SeriesInfoInteger(Symbol(),Period(),SERIES_LASTBAR_DATE);

//--- if it is the first call of the function
   if(last_time==0)
     {
      //--- set the time and exit
      last_time=lastbar_time;
      return(false);
     }

//--- if the time differs
   if(last_time!=lastbar_time)
     {
      //--- memorize the time and return true
      last_time=lastbar_time;
      return(true);
    }
//--- if we passed to this line, then the bar is not new; return false
   return(false);
}
Descubra novos recursos para o MetaTrader 5 com a comunidade e os serviços MQL5
Descubra novos recursos para o MetaTrader 5 com a comunidade e os serviços MQL5
  • 2021.05.03
  • www.mql5.com
MQL5: linguagem de estratégias de negociação inseridas no Terminal do Cliente MetaTrader 5. A linguagem permite escrever seus próprios sistemas automáticos de negócios, indicadores técnicos, scripts e bibliotecas de funções
 
Please edit your post and use the code button (Alt+S) when pasting code.
EDIT your original post, please do not just post the code correctly in a new post.