¡¡¡¡¡¡¡inicialización global fallida!!!!!!! - página 4

 
deysmacro:

No se pone ninguna función de búsqueda de objetos para comprobar si el objeto ya existe o no. A partir de ahí, entonces creas el objeto en consecuencia.


Te estoy ayudando, ahora mismo.


Ahora, eso es una buena pista, para hacer la limpieza OnInit(), gracias.

No es que realmente resuelva ninguno de los problemas anteriores.

Las etiquetas siguen sin fijarse en su posición.

Después de todo lo que he hecho, es mejor, pero todavía no es perfecto.

Creo que el problema es mucho más profundo y tiene algo que ver con los datos que no se limpian.

Como si de alguna manera MT4 recuperó algunos datos antiguos de algunos registros sin limpiar.

 

Lo siento si sólo te doy consejos porque lo último en codificación es el que realmente hace la codificación.

Desafortunadamente, muchos no entienden/captan la pista dada.

 
qjol:



1. Las etiquetas se salen de la línea, como si no se cumplieran las XDISTANCE e YDISTANCE.

Se vuelven a alinear sólo después de cambiar Tf's de un lado a otro.

Después de cambiar las ventanas del gráfico o de cambiar los parámetros de entrada, se desalinean.

eso significa que puedes arreglarlo en tu código

He hecho mucho, nada ayuda.

¡Se mejora, pero aún así, es decir, después de cambiar algo en los parámetros, no el X, Y, la etiqueta se sale de la línea!

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window

extern double StopLoss    = 30;
extern double RiskPercent = 3;
extern int Corner = 3;
extern int Font_Size = 13;
extern string Font_Type = "Berlin Sans FB";
extern color Font_Color = clrSnow;
extern color Warning_Color = clrRed;
extern int XDistance = 9;
extern int YDistance = 27;
string  comment;
int X,Y;


int OnInit()   {   
 X = XDistance;
 Y = YDistance;
if(ObjectFind("Lot_Size_Label")==0)
 {
 ObjectDelete("Lot_Size_Label");
 }
ObjectCreate("Lot_Size_Label", OBJ_LABEL, 0, 0,0); return(0); 
  }

//-------------------------------------------------------------+
  
int OnDeinit(int reason) 
  {
  ObjectDelete("Lot_Size_Label"); 
  return(0); 
  }

//-------------------------------------------------------------+
int start()  
{
      string AcctCurrency = AccountCurrency();
       
      if (AcctCurrency == "")
          return(0);
 X = XDistance;
 Y = YDistance;
           
   double pipValue = MarketInfo(Symbol(),MODE_TICKVALUE); 
   if (Digits==3 || Digits==5) pipValue *= 10;
   double step     = MarketInfo(Symbol(),MODE_LOTSTEP);
      int norm     = 0;
            if (step==1)    norm = 0;
            if (step==0.1)  norm = 1;
            if (step==0.01) norm = 2;
   double minLot = MarketInfo(Symbol(),MODE_MINLOT);
   double maxLot = MarketInfo(Symbol(),MODE_MAXLOT);
   if(pipValue!=0)
    {
   double lots   = AccountBalance()*(RiskPercent/100.0)/(StopLoss*pipValue);
    }
         lots   = NormalizeDouble(lots,norm);
          
         comment = "SL("+DoubleToStr(RiskPercent,2)+"%): "+DoubleToStr(StopLoss,0)+" Pts  Vol: "+DoubleToStr(lots,norm)+" Lot";
          
          double actualRisk,maxRiskSL; 
          if (lots<minLot)
            {
               actualRisk = (100*minLot*StopLoss*pipValue)/AccountBalance();
               if(RiskPercent<=0) RiskPercent=1;
               maxRiskSL = StopLoss/(actualRisk/RiskPercent);
               comment = "SL("+DoubleToStr(actualRisk,2)+"%): "+DoubleToStr(StopLoss,0)+" Pts  Vol: "+DoubleToStr(minLot,norm)+" Lot"+"  SL("+IntegerToString(RiskPercent,0)+"%): "+IntegerToString(maxRiskSL,0)+" Pts";
               Font_Color=Warning_Color;
            }
  ObjectSet    ("Lot_Size_Label",OBJPROP_CORNER,Corner);

  ObjectSet    ("Lot_Size_Label",OBJPROP_XDISTANCE,X);
  ObjectSet    ("Lot_Size_Label",OBJPROP_YDISTANCE,Y);
  ObjectSetText("Lot_Size_Label",comment,Font_Size,Font_Type,Font_Color);
  ObjectSet    ("Lot_Size_Label",OBJPROP_SELECTABLE,false); 
 
   return(0);
}

¿Algún problema con el código?



 
Dadas:


¿Hay algún problema con el código?


ya te lo han dicho, olvídate de

int start()  

empieza a usar los nuevos métodos

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {

daysmacro ya está escrito arriba

no veo ObjectFind()

if (ObjectFind(....) == xxx, or != yyy ...)
   {
   ObjectSet    ("Lot_Size_Label",OBJPROP_CORNER,Corner);
   
   ObjectSet    ("Lot_Size_Label",OBJPROP_XDISTANCE,X);
   ObjectSet    ("Lot_Size_Label",OBJPROP_YDISTANCE,Y);
   ObjectSetText("Lot_Size_Label",comment,Font_Size,Font_Type,Font_Color);
   ObjectSet    ("Lot_Size_Label",OBJPROP_SELECTABLE,false); 
   }
else
   {
   do something maybe GetLastError() ??
   }
 
qjol:

ya te lo han dicho, olvídate de

empezar a utilizar los nuevos métodos

daysmacro ya escrito arriba

no veo ObjectFind()



Así que lo hice:

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window

extern double StopLoss    = 30;
extern double RiskPercent = 3;
extern int Corner = 3;
extern int Font_Size = 13;
extern string Font_Type = "Berlin Sans FB";
extern color Font_Color = clrSnow;
extern color Warning_Color = clrRed;
extern int XDistance = 9;
extern int YDistance = 27;
string  comment;
int X,Y;
//
//
//
//
//

int OnInit()   {   
 X = XDistance;
 Y = YDistance;
if(ObjectFind("Lot_Size_Label")==0)
 {
 ObjectDelete("Lot_Size_Label");
 }
ObjectCreate("Lot_Size_Label", OBJ_LABEL, 0, 0,0); 

  return(INIT_SUCCEEDED); 
  }
  
void OnDeinit(const int reason) 
  {
  ObjectDelete("Lot_Size_Label"); 
  }

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
 {                
      string AcctCurrency = AccountCurrency();
       
      if (AcctCurrency == "")
          return(rates_total);
          
 X = XDistance;
 Y = YDistance;
           
   double pipValue = MarketInfo(Symbol(),MODE_TICKVALUE); 
   if (Digits==3 || Digits==5) pipValue *= 10;
   double step     = MarketInfo(Symbol(),MODE_LOTSTEP);
      int norm     = 0;
            if (step==1)    norm = 0;
            if (step==0.1)  norm = 1;
            if (step==0.01) norm = 2;
   double minLot = MarketInfo(Symbol(),MODE_MINLOT);
   double maxLot = MarketInfo(Symbol(),MODE_MAXLOT);
   if(pipValue!=0)
    {
   double lots   = AccountBalance()*(RiskPercent/100.0)/(StopLoss*pipValue);
    }
         lots   = NormalizeDouble(lots,norm);
          
          //
          //
          //
          //
          //
          comment = "SL("+DoubleToStr(RiskPercent,2)+"%): "+DoubleToStr(StopLoss,0)+" Pts  Vol: "+DoubleToStr(lots,norm)+" Lot";
          
          double actualRisk,maxRiskSL; 
          if (lots<minLot)
            {
               actualRisk = (100*minLot*StopLoss*pipValue)/AccountBalance();
               if(RiskPercent<=0) RiskPercent=1;
               maxRiskSL = StopLoss/(actualRisk/RiskPercent);
               comment = "SL("+DoubleToStr(actualRisk,2)+"%): "+DoubleToStr(StopLoss,0)+" Pts  Vol: "+DoubleToStr(minLot,norm)+" Lot"+"  SL("+IntegerToString(RiskPercent,0)+"%): "+IntegerToString(maxRiskSL,0)+" Pts";
               Font_Color=Warning_Color;
            }
  ObjectSet    ("Lot_Size_Label",OBJPROP_CORNER,Corner);

  ObjectSet    ("Lot_Size_Label",OBJPROP_XDISTANCE,X);
  ObjectSet    ("Lot_Size_Label",OBJPROP_YDISTANCE,Y);
  ObjectSetText("Lot_Size_Label",comment,Font_Size,Font_Type,Font_Color);
  ObjectSet    ("Lot_Size_Label",OBJPROP_SELECTABLE,false);  
   return(rates_total);
}

Aún así, el mismo efecto. Esto no ha cambiado nada en cuanto al posicionamiento de la etiqueta.

ObjectFind() está en OnInit() comprobando si el objeto está ahí y borrándolo si lo está.

La etiqueta en la incialización de indi está donde se supone que debe estar.

Después de cambiar algún parámetro, desaparece a la derecha.

Vuelve a su sitio sólo tras el cambio de Tf.

 
En realidad solo necesitas algo como un primer conjunto de objetos al cargar por primera vez y luego un segundo conjunto de objetos después de cargar (el polvo se asienta). Yo también tengo el mismo problema, pero haciendo lo que he dicho se soluciona el problema. Es más bien una solución, pero para mí es suficiente.
 
deysmacro:
En realidad solo se necesita algo así como un primer conjunto de objetos al cargar por primera vez y un segundo conjunto de objetos después de cargar (el polvo se asienta). Yo también tengo el mismo problema donde al hacer lo que he dicho se soluciona el problema. Es más bien una solución, pero para mí es suficiente.

Entonces, hice así, incluso volviendo a comprobar las coordenadas X,Y para volver a probar la etiqueta en caso de que las coordenadas sean diferentes.

No hay zumo, no cambia nada en absoluto, se comporta igual que el anterior.

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window

extern double StopLoss    = 30;
extern double RiskPercent = 3;
extern int Corner = 3;
extern int Font_Size = 13;
extern string Font_Type = "Berlin Sans FB";
extern color Font_Color = clrSnow;
extern color Warning_Color = clrRed;
extern int XDistance = 9;
extern int YDistance = 27;
string  comment;
int X,Y;
//
//
//
//
//

int OnInit()   {   
 X = XDistance;
 Y = YDistance;
if(ObjectFind("Lot_Size_Label")==0)
 {
 ObjectDelete("Lot_Size_Label");
 }
  ObjectCreate("Lot_Size_Label", OBJ_LABEL, 0, 0,0); 
  ObjectSet    ("Lot_Size_Label",OBJPROP_CORNER,Corner);
  ObjectSet    ("Lot_Size_Label",OBJPROP_XDISTANCE,X);
  ObjectSet    ("Lot_Size_Label",OBJPROP_YDISTANCE,Y);
  ObjectSet    ("Lot_Size_Label",OBJPROP_SELECTABLE,false);    
  
  return(INIT_SUCCEEDED); 
  }
  
void OnDeinit(const int reason) 
  {
  ObjectDelete("Lot_Size_Label"); 
  }

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
 {                
      string AcctCurrency = AccountCurrency();
       
      if (AcctCurrency == "")
          return(rates_total);
          
 X = XDistance;
 Y = YDistance;
           
   double pipValue = MarketInfo(Symbol(),MODE_TICKVALUE); 
   if (Digits==3 || Digits==5) pipValue *= 10;
   double step     = MarketInfo(Symbol(),MODE_LOTSTEP);
      int norm     = 0;
            if (step==1)    norm = 0;
            if (step==0.1)  norm = 1;
            if (step==0.01) norm = 2;
   double minLot = MarketInfo(Symbol(),MODE_MINLOT);
   double maxLot = MarketInfo(Symbol(),MODE_MAXLOT);
   if(pipValue!=0)
    {
   double lots   = AccountBalance()*(RiskPercent/100.0)/(StopLoss*pipValue);
    }
         lots   = NormalizeDouble(lots,norm);
          
          //
          //
          //
          //
          //
          comment = "SL("+DoubleToStr(RiskPercent,2)+"%): "+DoubleToStr(StopLoss,0)+" Pts  Vol: "+DoubleToStr(lots,norm)+" Lot";
          
          double actualRisk,maxRiskSL; 
          if (lots<minLot)
            {
               actualRisk = (100*minLot*StopLoss*pipValue)/AccountBalance();
               if(RiskPercent<=0) RiskPercent=1;
               maxRiskSL = StopLoss/(actualRisk/RiskPercent);
               comment = "SL("+DoubleToStr(actualRisk,2)+"%): "+DoubleToStr(StopLoss,0)+" Pts  Vol: "+DoubleToStr(minLot,norm)+" Lot"+"  SL("+IntegerToString(RiskPercent,0)+"%): "+IntegerToString(maxRiskSL,0)+" Pts";
               Font_Color=Warning_Color;
            }
            
  if(ObjectFind("Lot_Size_Label")==0)
   {         
  int x_check=ObjectGet("Lot_Size_Label",OBJPROP_XDISTANCE);
  int y_check=ObjectGet("Lot_Size_Label",OBJPROP_YDISTANCE);  
   }  

  if(X!=x_check||Y!=y_check)
   {            
  ObjectSet    ("Lot_Size_Label",OBJPROP_CORNER,Corner);
  ObjectSet    ("Lot_Size_Label",OBJPROP_XDISTANCE,X);
  ObjectSet    ("Lot_Size_Label",OBJPROP_YDISTANCE,Y);
  ObjectSetText("Lot_Size_Label",comment,Font_Size,Font_Type,Font_Color);
  ObjectSet    ("Lot_Size_Label",OBJPROP_SELECTABLE,false);  
   }
   return(rates_total);
}
PS. this didn't happen in B625, only started with B646 update.

	          
 
Entonces, ¿ya está hecho?
 

Y, lo curioso es que, usando Comment(), las coords nunca cambian, incluso cuando la etiqueta va a la derecha.

Por lo tanto, el problema sigue siendo, no se hace.

 
Comment() no afecta al gráfico, la mayoría de las veces.
Razón de la queja: