Se necesita ayuda

 

Estoy tratando de codificar un EA basado en mi propia estrategia, con la ayuda del código de algunos otros EAs y indis. pero ahora atascado en una cosa.

(user defined lot sizes for each trade)

extern string LotsProgression="0.1;0.1;0.2;0.3;0.4;0.6;0.8;1.1;1.5;2.0;2.7;3.6;4.7;6.2;8.0;10.2;13.0;16.5;20.8;26.3;33.1;41.6;52.2;65.5;82.5;103.9;130.9;165;207.9;262;330.1;416;524.7;661.1";

extern bool RestartNewCycle = true;

(and the code)

int init()

{

int i,j,k;

string ls;

while (true) {

        j=StringFind(LotsProgression,";",i);

        if (j>0) {

                ls=StringSubstr(LotsProgression,i,j-i);

                i=j+1;

                k++;

                ArrayResize(lots,k);

                lots[k-1]=StrToDouble(ls);

        } else {

                ls=StringSubstr(LotsProgression,i);

                k++;

                ArrayResize(lots,k);

                lots[k-1]=StrToDouble(ls);

                break;

        }

}



plen=ArraySize(lots);

}

No soy capaz de entender esta lógica o lo que realmente es.

PD: A un amigo le gustó mi estrategia y creó este EA. Pero perdí ambos (el EA y el contacto de ese amigo codificador) así que ahora estoy tratando de probar mis conocimientos muy básicos de codificación, ya que realmente quiero que esta Estrategia sea codificada de nuevo.

 
qgmql:

Estoy tratando de codificar un EA basado en mi propia estrategia, con la ayuda de código de algunos otros EAs e indis. Pero ahora atascado en una cosa.

<suprimido>


Porfavor, utilice el botón SRC para publicar el código.. .
 
qgmql: No soy capaz de entender esta lógica o lo que realmente es.

extern string LotsProgression="0.1;0.1;0.2;0.3 ...

double lots[];     // [0]=0.1 [1]=0.1 [2]=0.2 [3]=0.3 [34]=661.1
int    plen;       // 35
int init(){ ... }

Divide la cadena en los puntos y comas, convierte las subcadenas en dobles y almacena los valores en el array dinámico.
 

Lo que mencionas está bien. El problema está en el resto del código. Me salen dos errores (sólo en el nuevo metaeditor).

'init' - function can be declared only in the global scope

and

'init' - function already defined and has body
 
qgmql:

Lo que mencionas está bien. El problema está en el resto del código. Me salen dos errores (sólo en el nuevo metaeditor).

Parece que has declarado init() dentro de otra función y luego la has definido por segunda vez....
 

Sí, lo he entendido y corregido. Ahora se produce un error en el código del marco temporal.

   //--- EA PARAMETERS
extern int      EA_TF=240;
extern bool     Forced_TF=True;


bool   TF;

     if(Forced_TF != True) TF = EA_TF;     //These two lines i think, have error.
     else TF = Period();                   //New metaeditor is not accepting "TF = EA_TF;" from above line.

Si Forced_TF es verdadero, entonces el EA debe operar y debe obtener señales del marco de tiempo mencionado solamente, incluso si el gráfico activo (en el que coloco el EA) se abre en un marco de tiempo diferente. Si el valor es falso, entonces debería funcionar en cualquier marco de tiempo.

 
qgmql:

Sí, lo he entendido y corregido. Ahora se produce un error en el código de marco de tiempo.

Si Forced_TF es verdadero, entonces el EA debe operar y debe obtener señales del marco de tiempo mencionado solamente, incluso si el gráfico activo (en el que coloco el EA) se abre en un marco de tiempo diferente. Si el valor es falso, entonces debería funcionar en cualquier marco de tiempo.

Usted tiene TF como un bool . .. pero está tratando de establecerlo como un int... intente esto ...

   //--- EA PARAMETERS
extern int      EA_TF=240;
extern bool     Forced_TF=True;


int   TF;

     if(!Forced_TF) TF = EA_TF;     //These two lines i think, have error. 
     else TF = Period();            //New metaeditor is not accepting "TF = EA_TF;" from above line.
 
Publica TODO el código o al menos indica el truncamiento. Ese IF/ELSE debe estar dentro de una función.
 

@RaptorUK Te tengo. y de nuevo todo bien con el viejo editor, pero el nuevo editor sigue dando una advertencia, citado en el código después de la línea de error,

//+------------------------------------------------------------------+
//|                                                   01Multi_EA.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
#property version   "1.00"
#property strict

//--- input parameters
input int      EA_TF=60;
input bool     Forced_TF=True;
input int      MagicNumber=12345;
input int      FastMA_Period=5;
input int      FastMA_Shift=0;
input int      FastMA_Method=1;
input int      FastMA_Price=0;
input int      SlowMA_Period=34;
input int      SlowMA_Shift=0;
input int      SlowMA_Method=1;
input int      SlowMA_Price=0;
input string   LotsProgression="0.01;0.02;0.03;0.04;0.05;0.06;0.07;0.08;0.09;0.10;0.11;0.12;0.13;0.14;0.15;0.16;0.17;0.18;0.19;0.20";
input bool     NewCycle=True;
input int      Limit_TP=50;
input bool     Use_TP=False;
input int      Limit_SL=50;
input bool     Use_SL=False;
input int      MaxSlippage=3;
input int      OrderTries=10;

int      TF, Plen;
double   TP, SL, pips2dbl, pips2point, pipValue, Slippage, Lots[];
         
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//----
 if(Forced_TF != True) TF = EA_TF;
      else TF = Period();
   int i,j,k;
   string ls;
   while (true) {
        j=StringFind(LotsProgression,";",i);
        if(j>0) {
                ls=StringSubstr(LotsProgression,i,j-i);    // <<<<<"possible use of uninitialized variable 'i'	01Multi_EA.mq4	46	38">>>>>

                i=j+1;
                k++;
                ArrayResize(Lots,k);
                Lots[k-1]=StrToDouble(ls);
        } else {
                ls=StringSubstr(LotsProgression,i);
                k++;
                ArrayResize(Lots,k);
                Lots[k-1]=StrToDouble(ls);
                break;
        }
   }


   Comment("Copyright © 2004, MetaQuotes Software Corp.");
   
   if (Digits == 5 || Digits == 3)
   {            
      pips2dbl = Point*10; pips2point = 10; pipValue = (MarketInfo(Symbol(),MODE_TICKVALUE))*10;
   } 
   else 
   {    
      pips2dbl = Point;   pips2point = 1; pipValue = (MarketInfo(Symbol(),MODE_TICKVALUE))*1;
   }
   
   Slippage = pips2dbl*MaxSlippage;
   TP = pips2dbl*Limit_TP;
   SL = pips2dbl*Limit_SL;
   
//----
   return(INIT_SUCCEEDED);
  }

@WHRoeder Pegado todo el código.

 
qgmql:

@RaptorUK Te tengo. y de nuevo todo bien con el viejo editor, pero el nuevo editor sigue dando una advertencia, citado en el código después de la línea de error,

@WHRoeder Pegado todo el código.

No es un error, es una advertencia... para deshacerse de la advertencia inicialice la variable en lugar de declararla. En mql4 cuando declarabas una variable también se inicializaba, ahora con mql4.5 tienes que inicializar explícitamente la variable si quieres. . .

int i = 0, j, k;   //  i initialised to 0
 
pipValue = (MarketInfo(Symbol(),MODE_TICKVALUE))*10;
No utilice el tickvalue por sí mismo https://www.mql5.com/en/forum/133792/page3#512466