Ayuda a la codificación - página 726

 

Hola Mladen,

Estoy intentando codificar esto en MT5, pero creo que no estoy usando la implementación correcta,

mi idea es usar más indicadores, por favor dame una luz... ;-)

I need help to make this modular, because I will work with more indicators (6 to 8), 
this is a sample to understand I'm trying to do..

in this sample:
I put only 3 indicadors.

//global variables
bool m_buy = true;
bool m_sell = true;
enum Signal{
   IN_OUT=0,  //in & out
   IN=1,      //in
   OUT=2,     //out
};

I have a EA with indicators that I want to mix and optimize it in BackTest.

//some sample data for signal for In/Out states only for exemplification
iT_InOut = IN_OUT;  //Itrend usage => In & Out
RSI_InOut = IN_;     //RSI usage =>only IN 
MFI_InOut = OUT_;     //MFI usage =>only OUT
//

//this is the complete sequence IF I USE all signals in+out
//only to show the completly sequence (I will not use it)
m_buy=(m_it00[0]>m_it10[0] && m_it00[0]>m_it01[0] && m_rsi0[0]>m_rsi1[0] && m_mfi0[0]>m_mfi1[0]);
// The green is growing and more than red, RSI is growing, MFI is growing
m_sell=(m_it00[0]<m_it10[0] && m_it00[0]<m_it01[0] && m_rsi0[0]<m_rsi1[0] && m_mfi0[0]<m_mfi1[0]);
// The green falls and less than red, RSI falls, MFI falls


//now the skeleton that I'm trying to make work (in future I will use much more indicators)
               
              if(!PositionSelect(Symbol()))   ///No opened it's first entrance
                 {              
                 
                 if (!iT_InOut==OUT_) //Itrend (only options with IN)
                     {
                     m_buy= (m_buy  && m_it00[0]>m_it10[0] && m_it00[0]>m_it01[0]);
                     m_sell=(m_sell && m_it00[0]<m_it10[0] && m_it00[0]<m_it01[0]);
                     }
                  
                 if (!RSI_InOut==OUT_) //RSI (only options with IN)
                     {
                     m_buy =(m_buy  && m_rsi0[0]>m_rsi1[0]);
                     m_sell=(m_sell && m_rsi0[0]<m_rsi1[0]);
                     }                
                
                 if (!MFI_InOut==OUT_) //MFI (only options with IN)
                     {
                     m_buy =(m_buy  && m_mfi0[0]>m_mfi1[0]);
                     m_sell=(m_sell && m_mfi0[0]<m_mfi1[0]);
                     }                 
                  }
                 
                 ///We have opened order it's EXIT
                 else
                 {
                 //Itrend (only options with EXIT)
                 if (!iT_InOut==IN_)
                     {
                     m_buy =(m_buy  && m_it00[0]>m_it10[0] && m_it00[0]>m_it01[0]);
                     m_sell=(m_sell && m_it00[0]<m_it10[0] && m_it00[0]<m_it01[0]);
                     }
                 //RSI (only options with EXIT)
                 if (!RSI_InOut==IN_)
                     {
                     m_buy =(m_buy  && m_rsi0[0]>m_rsi1[0]);
                     m_sell=(m_sell && m_rsi0[0]<m_rsi1[0]);
                     }                     
                 //MFI (only options with EXIT)
                 if (!MFI_InOut==IN_)
                     {
                     m_buy =(m_buy  && m_mfi0[0]>m_mfi1[0]);
                     m_sell=(m_sell && m_mfi0[0]<m_mfi1[0]);
                     }
                 }
 
baraozemo:

Hola Mladen,

Estoy intentando codificar esto en MT5, pero creo que no estoy usando la implementación correcta,

mi idea es usar más indicadores, por favor dame una luz... ;-)

I need help to make this modular, because I will work with more indicators (6 to 8), 
this is a sample to understand I'm trying to do..

in this sample:
I put only 3 indicadors.

//global variables
bool m_buy = true;
bool m_sell = true;
enum Signal{
   IN_OUT=0,  //in & out
   IN=1,      //in
   OUT=2,     //out
};

I have a EA with indicators that I want to mix and optimize it in BackTest.

//some sample data for signal for In/Out states only for exemplification
iT_InOut = IN_OUT;  //Itrend usage => In & Out
RSI_InOut = IN_;     //RSI usage =>only IN 
MFI_InOut = OUT_;     //MFI usage =>only OUT
//

//this is the complete sequence IF I USE all signals in+out
//only to show the completly sequence (I will not use it)
m_buy=(m_it00[0]>m_it10[0] && m_it00[0]>m_it01[0] && m_rsi0[0]>m_rsi1[0] && m_mfi0[0]>m_mfi1[0]);
// The green is growing and more than red, RSI is growing, MFI is growing
m_sell=(m_it00[0]<m_it10[0] && m_it00[0]<m_it01[0] && m_rsi0[0]<m_rsi1[0] && m_mfi0[0]<m_mfi1[0]);
// The green falls and less than red, RSI falls, MFI falls


//now the skeleton that I'm trying to make work (in future I will use much more indicators)
               
              if(!PositionSelect(Symbol()))   ///No opened it's first entrance
                 {              
                 
                 if (!iT_InOut==OUT_) //Itrend (only options with IN)
                     {
                     m_buy= (m_buy  && m_it00[0]>m_it10[0] && m_it00[0]>m_it01[0]);
                     m_sell=(m_sell && m_it00[0]<m_it10[0] && m_it00[0]<m_it01[0]);
                     }
                  
                 if (!RSI_InOut==OUT_) //RSI (only options with IN)
                     {
                     m_buy =(m_buy  && m_rsi0[0]>m_rsi1[0]);
                     m_sell=(m_sell && m_rsi0[0]<m_rsi1[0]);
                     }                
                
                 if (!MFI_InOut==OUT_) //MFI (only options with IN)
                     {
                     m_buy =(m_buy  && m_mfi0[0]>m_mfi1[0]);
                     m_sell=(m_sell && m_mfi0[0]<m_mfi1[0]);
                     }                 
                  }
                 
                 ///We have opened order it's EXIT
                 else
                 {
                 //Itrend (only options with EXIT)
                 if (!iT_InOut==IN_)
                     {
                     m_buy =(m_buy  && m_it00[0]>m_it10[0] && m_it00[0]>m_it01[0]);
                     m_sell=(m_sell && m_it00[0]<m_it10[0] && m_it00[0]<m_it01[0]);
                     }
                 //RSI (only options with EXIT)
                 if (!RSI_InOut==IN_)
                     {
                     m_buy =(m_buy  && m_rsi0[0]>m_rsi1[0]);
                     m_sell=(m_sell && m_rsi0[0]<m_rsi1[0]);
                     }                     
                 //MFI (only options with EXIT)
                 if (!MFI_InOut==IN_)
                     {
                     m_buy =(m_buy  && m_mfi0[0]>m_mfi1[0]);
                     m_sell=(m_sell && m_mfi0[0]<m_mfi1[0]);
                     }
                 }
En ese código no veo para nada el uso del indicador (y cómo se copian los valores a los arrays correspondientes)
 

Hola chicos,

Realmente necesito ayuda, estoy construyendo un experto con el indicador waddah attar scalping, la lógica está funcionando, todo está bien.

Excepto una cosa, como se ve en la captura de pantalla backtest, en cada barra verde el experto abre una compra, lo mismo para las barras rojas. Quiero sólo 1 operación por cambio de color.

Lo que quiero es :

EL INDICADOR SE PONE VERDE ---> abre una compra ---> la compra se cierra ---> EL INDICADOR SE PONE ROJO ---> abre una venta ---> la venta se cierra ---> repite

Quiero sólo 1 operación por cambio de color.

Este es mi código: (lo mismo para los cortos)

//Trading decision.
   bool SendLong = false, SendShort = false;
  
    double clnowsell = iCustom(Symbol(),WAScalpingTimeFrame,"Waddah_Attar_Scalping",IPeriod,P1,P2,1,clbar);
    double clpresell = iCustom(Symbol(),WAScalpingTimeFrame,"Waddah_Attar_Scalping",IPeriod,P1,P2,1,clbar+1);
  
    double clnowbuy = iCustom(Symbol(),WAScalpingTimeFrame,"Waddah_Attar_Scalping",IPeriod,P1,P2,0,clbar);
    double clprebuy = iCustom(Symbol(),WAScalpingTimeFrame,"Waddah_Attar_Scalping",IPeriod,P1,P2,0,clbar+1);

   //Long trade
  
   //Specific system filters
   //if (some condition) SendLong = true;
  
   if (clnowbuy > 0) SendLong = true;

Puede alguien por favor venir con una solución simple, mira la línea 1265, la lógica viene aquí.

Muchas gracias.

 
LittleCaro:

Hola chicos,

Realmente necesito ayuda, estoy construyendo un experto con el indicador waddah attar scalping, la lógica está funcionando, todo está bien.

Excepto una cosa, como se ve en la captura de pantalla backtest, en cada barra verde el experto abre una compra, lo mismo para las barras rojas. Quiero sólo 1 operación por cambio de color.

Lo que quiero es :

EL INDICADOR SE PONE VERDE ---> abre una compra ---> la compra se cierra ---> EL INDICADOR SE PONE ROJO ---> abre una venta ---> la venta se cierra ---> repite

Quiero sólo 1 operación por cambio de color.

Este es mi código: (lo mismo para los cortos)

//Trading decision.
   bool SendLong = false, SendShort = false;
  
    double clnowsell = iCustom(Symbol(),WAScalpingTimeFrame,"Waddah_Attar_Scalping",IPeriod,P1,P2,1,clbar);
    double clpresell = iCustom(Symbol(),WAScalpingTimeFrame,"Waddah_Attar_Scalping",IPeriod,P1,P2,1,clbar+1);
  
    double clnowbuy = iCustom(Symbol(),WAScalpingTimeFrame,"Waddah_Attar_Scalping",IPeriod,P1,P2,0,clbar);
    double clprebuy = iCustom(Symbol(),WAScalpingTimeFrame,"Waddah_Attar_Scalping",IPeriod,P1,P2,0,clbar+1);

   //Long trade
  
   //Specific system filters
   //if (some condition) SendLong = true;
  
   if (clnowbuy > 0) SendLong = true;

Puede alguien por favor venir con una solución simple, mira la línea 1265, la lógica viene aquí.

Muchas gracias.

Cambia la condición a

  if (clnowbuy > 0 && clprebuy == 0) SendLong = true;

Lo mismo para los cortos

 

¡Gracias Mladen !

A veces nos atascamos y necesitamos una nueva mirada a nuestro trabajo.

Gracias de nuevo.

 
LittleCaro:

¡Gracias Mladen !

A veces nos atascamos y necesitamos una nueva mirada a nuestro trabajo.

Gracias de nuevo.

Bonjour,

Ravi de voir une Française, tiens moi au courant des tes résultats avec waddah attar ;)

Pips verdes

 

Hola chicos estoy tratando de editar un indicador ema-rsi que puede mostrar una flecha hacia arriba o hacia abajo cuando 4 ema cruz ocurre y rsi es > o < 50.

Mi problema es que estas flechas no se actualizan porcada tick una vez que aparecen, tengo que cambiar el marco de tiempo si quiero comprobar si las condiciones siguen siendo buenas para mostrar la flecha. ¿Me pueden decir dónde está el problema? He publicado el código.

Gracias

#property indicator_chart_window
#property indicator_buffers 2
#property  indicator_color1 Green
#property  indicator_color2 Red

#property  indicator_width1 4
#property  indicator_width2 4

double CrossUp[];
double CrossDown[];
extern int FasterEMA1     = 6;
extern int SlowerEMA1     = 12;
extern int FasterEMA2     = 7;
extern int SlowerEMA2     = 14;
extern int RSInowPeriod   = 6;
extern int barsBack       = 2000;
extern bool AlertsMessage = true;
extern bool AlertsSound   = true;
extern bool debug         = false;
extern double K           = 1.0 ;

bool EMACrossedUp = false;
bool RSICrossedUp = false;
bool EMACrossedDown = false;
bool RSICrossedDown = false;
int SignalLabeled = 0// 0: initial state; 1: up; 2: down.
int upalert=false,downalert=false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0DRAW_ARROWEMPTY);
   SetIndexArrow(0241);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1DRAW_ARROWEMPTY);
   SetIndexArrow(1242);
   SetIndexBuffer(1, CrossDown);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int limit, i, counter;
   double fasterEMA1now, slowerEMA1now, fasterEMA1previous, slowerEMA1previous, fasterEMA2now, slowerEMA2now, fasterEMA2previous, slowerEMA2previous;
   double RSInow;
   double Range, AvgRange;

   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=MathMin(Bars-counted_bars,barsBack);
   
   for(i = limit; i>=0; i--) {
       
      counter=i;
      Range=0;
      AvgRange=0;
      for (counter=i ;counter<=i+9;counter++)
      {
        AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }
      Range=AvgRange/10;

      fasterEMA1now = iMA(NULL0, FasterEMA1, 0MODE_EMAPRICE_CLOSE, i);
      fasterEMA1previous = iMA(NULL0, FasterEMA1, 0MODE_EMAPRICE_CLOSE, i+1);
      
      fasterEMA2now = iMA(NULL0, FasterEMA2, 0MODE_EMAPRICE_CLOSE, i);
      fasterEMA2previous = iMA(NULL0, FasterEMA2, 0MODE_EMAPRICE_CLOSE, i+1);
      
      slowerEMA1now = iMA(NULL0, SlowerEMA1, 0MODE_EMAPRICE_CLOSE, i);
      slowerEMA1previous = iMA(NULL0, SlowerEMA1, 0MODE_EMAPRICE_CLOSE, i+1);
      
      slowerEMA2now = iMA(NULL0, SlowerEMA2, 0MODE_EMAPRICE_CLOSE, i);
      slowerEMA2previous = iMA(NULL0, SlowerEMA2, 0MODE_EMAPRICE_CLOSE, i+1);
      
      RSInow=iRSI(NULL,0,RSInowPeriod,PRICE_CLOSE,i);
      
      if (RSInow > 50) {
         if (debug)Print(TimeToStr(Time[i],TIME_DATE)+TimeToStr(Time[i],TIME_SECONDS)+" RSI UP ");
         RSICrossedUp = true;
         RSICrossedDown = false;
      }
      
      if (RSInow < 50) {
         if (debug)Print(TimeToStr(Time[i],TIME_DATE)+TimeToStr(Time[i],TIME_SECONDS)+" RSI DOWN ");
         RSICrossedUp = false;
         RSICrossedDown = true;
      }
      
      if ((fasterEMA1now >= slowerEMA1now) && (fasterEMA1previous < slowerEMA1previous) && (fasterEMA2now >= slowerEMA2now) && (fasterEMA2previous < slowerEMA2previous) ) {
         if (debug)Print(TimeToStr(Time[i],TIME_DATE)+TimeToStr(Time[i],TIME_SECONDS)+" EMA UP ");
         EMACrossedUp = true;
         EMACrossedDown = false;
      }

      if ((fasterEMA1now <= slowerEMA1now) && (fasterEMA1previous > slowerEMA1previous) && (fasterEMA2now <= slowerEMA2now) && (fasterEMA2previous > slowerEMA2previous)) {
         if (debug)Print(TimeToStr(Time[i],TIME_DATE)+TimeToStr(Time[i],TIME_SECONDS)+" EMA DOWN ");
         EMACrossedUp = false;
         EMACrossedDown = true;
      }

      if ((EMACrossedUp == true) && (RSICrossedUp == true) && (SignalLabeled != 1)) {
         CrossUp[i] = Low[i] - K*Range;
         if (debug)Print(TimeToStr(Time[i],TIME_DATE)+TimeToStr(Time[i],TIME_SECONDS)+" SIGNAL UP ");
         if(i<=2 && AlertsMessage && !upalert)
           {
            Alert (Symbol()," ",Period(),"M  BUY SIGNAL ");
            //SendMail("EMA Cross Up on "+Symbol(),"");
            upalert=true;
            downalert=false;
           }           
         if(i<=2 && AlertsSound && !upalert)
           {
            PlaySound("alert.wav");
            upalert=true;
            downalert=false;
           }
         SignalLabeled = 1;
      }

      else if ((EMACrossedDown == true) && (RSICrossedDown == true) && (SignalLabeled != 2)) {
         CrossDown[i] = High[i] + K*Range;
         if (debug)Print(TimeToStr(Time[i],TIME_DATE)+TimeToStr(Time[i],TIME_SECONDS)+" SIGNAL DOWN ");
         if(i<=2 && AlertsMessage && !downalert)
           {
            Alert (Symbol()," ",Period(),"M  SELL SIGNAL ");
            //SendMail("EMA Cross Down on "+Symbol(),"");
            downalert=true;
            upalert=false;
           }
         if(i<=2 && AlertsSound && !downalert)
           {
            PlaySound("alert.wav");
            downalert=true;
            upalert=false;
           }
         SignalLabeled = 2;
      }
   }
   return(0);
}
//end
 
mladen:
En ese código no veo para nada el uso de los indicadores (y cómo se copian los valores a los arrays correspondientes)

Hola Mladen,

Aquí está el "sample-ea-modular.mq5" con algo de código dentro... y con la interfaz que tiene la idea que quiero.

Estoy tratando de hacerlo modular , la idea es optimizar por separado la entrada/salida de cada indicador..

Si consigo hacer esto con el "sample-ea-modular.mq5" cambiaré el EA real.

la base real es el Ea-sample.mq5. (lo pongo solo para que veas todos los indicadores)

Archivos adjuntos:
 
oguz:

Estimado @mladen,

Si eres capaz de resolver el error que se menciona a continuación, por favor, muy contentos.

Gracias...

"Pregunta: Hay una advertencia cuando attched a la carta y el uso de auto gmt offset.


La advertencia es la siguiente: Advertencia, utilizar manual GMToffsets sólo en backtest.

El cálculo automático del offset GMT sólo funciona en operaciones en vivo/demo
y debe establecerse como FALSO para backtests - pruebas de estrategia.

¿Es esto normal? ¿O debería poner la compensación automática de GMT en falso?

Respuesta : He desactivado el AutoGMTOffset y he establecido el offset GMT manualmente. No hay más mensajes de advertencia y parece que funciona bien en la demo. Imagínate. Tal vez sea un error. Oh sí, definitivamente es un error.

He mirado el código y una operación "else" está omitida o mal colocada. El mensaje sólo debería ser emitido si UseAutoGMTOffset se establece en FALSE.

Así que ignora este mensaje y sé feliz. Todo está funcionando como (ejem) fue diseñado".

oguz

Como siempre (ya lo sabes) no comento el código descompilado, pero veo que vas por buen camino : si funciona (la opción), úsala. Si no lo hace entonces no lo hagas. Por lo que veo eso es sólo un mensaje (no un error) así que ...

 

Estimado @mladen,

Si eres capaz de resolver el error que se menciona a continuación, por favor, muy contentos.

Gracias...

"Pregunta: Hay una advertencia cuando attched al gráfico y el uso de auto gmt offset.


La advertencia es la siguiente: Advertencia, utilizar manual GMToffsets sólo en backtest.

El cálculo automático del offset GMT sólo funciona en operaciones en vivo/demo
y debe establecerse como FALSO para backtests - pruebas de estrategia.

¿Es esto normal? ¿O debería poner la compensación automática de GMT en falso?

Respuesta : He desactivado el AutoGMTOffset y he establecido el offset GMT manualmente. No hay más mensajes de advertencia y parece que funciona bien en la demo. Imagínate. Tal vez sea un error. Oh sí, definitivamente es un error.

He mirado el código y una operación "else" está omitida o mal colocada. El mensaje sólo debería ser emitido si UseAutoGMTOffset se establece en FALSE.

Así que ignora este mensaje y sé feliz. Todo está funcionando como (ejem) fue diseñado".
Razón de la queja: