a inicialização global falhou!!!!!!! - página 4

 
deysmacro:

Você não coloca nenhuma função de procura de objetos para verificar se o objeto já existe ou não. A partir daí, você cria o objeto de acordo.


Estou ajudando você, agora mesmo.


Agora, essa é uma boa dica, para fazer uma limpeza no OnInit(), obrigado.

Não que isso realmente resolva qualquer um dos problemas acima, você sabe.

As etiquetas ainda não se fixam na posição.

Depois de todas as coisas que fiz, é melhor, mas ainda não é perfeito.

Acho que a questão é muito mais profunda e tem a ver com dados que não estão sendo limpos.

Como se de alguma forma o MT4 tivesse recuperado alguns dados antigos de alguns registros não limpos.

 

Desculpe-me se eu apenas lhe dou dicas, porque a última palavra em codificação é aquele que realmente faz a codificação.

Infelizmente, muitos não entendem/apoiam a dica dada.

 
qjol:



1. As etiquetas estão saindo da linha, como se a XDISTÂNCIA e a YDISTÂNCIA não fossem obedecidas.

Eles só voltam à linha depois de trocar os Tf's para frente e para trás.

Depois de trocar as janelas do gráfico ou mudar os parâmetros de entrada, eles saem da linha.

isso significa que você pode corrigi-lo em seu código

Eu tenho feito muito, nada ajuda.

Fica melhor, mas mesmo assim, ou seja, depois de trocar o smth em parametrs, não o X,Y, a etiqueta fica muito fora de linha!

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

#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);
}

Alguma coisa errada com o código?



 
Dadas:


Algum problema com o código?


já lhe foi dito, esqueça

int start()  

começar a usar os novos 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[])
  {

diasmacro já escrito acima

i dont see 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:

já lhe foi dito, esqueça

começar a usar os novos métodos

diasmacro já escrito acima

i dont see ObjectFind()



Então, eu fiz:

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

#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);
}

Ainda assim, o mesmo efeito. Isto não mudou nada no que diz respeito ao posicionamento das etiquetas.

ObjectFind() está em OnInit() verificando se o objeto está lá e eliminando-o se estiver.

A etiqueta na inicialização indi é onde ele deve estar.

Depois de alterar algum parâmetro, ele desaparece para a direita.

Salta de volta ao lugar somente após a mudança de Tf.

 
Na verdade, você só precisa de algo como um primeiro conjunto de objetos no primeiro carregamento e depois um segundo conjunto de objetos após o carregamento (a poeira assenta). Eu também tenho o mesmo problema onde fazer como eu disse para resolver o problema. É mais como uma solução de trabalho, mas tudo é bom o suficiente para mim.
 
deysmacro:
Na verdade, você só precisa de algo parecido com um primeiro objeto definido no primeiro carregamento e depois um segundo objeto definido após o carregamento (a poeira assenta). Eu também tenho o mesmo problema onde fazer como eu disse para resolver o problema. É mais como uma solução de trabalho, mas tudo é bom o suficiente para mim.

Então, eu fiz assim, mesmo checando novamente os acordes X,Y para testar a etiqueta caso os acordes sejam diferentes.

Sem suco, nada muda, ele se comporta exatamente como acima.

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

#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.

	          
 
Então, isso já está feito?
 

E, o engraçado é que, usando Comentário(), os acordes nunca mudam, mesmo quando a etiqueta vai bem.

Assim, o problema permanece, não é feito.

 
Comentário() não afeta o gráfico, a maior parte do tempo.
Razão: