全局初始化失败!!!!!!! - 页 4

 
deysmacro:

你不需要放任何对象查找函数 来检查对象是否已经存在。从那里,然后你创建相应的对象。


我正在帮助你,现在。


现在,这是个很好的提示,要对OnInit()进行清理,谢谢。

这并不是说它真的解决了上述任何问题,你知道。

标签仍然不能锁定位置。

在我做了这么多事情之后,它已经好了,但仍然不完美。

我认为这个问题更深层次,与数据没有被清理有关。

就像MT4从一些未清理的寄存器中获取了一些旧数据。

 

如果我只是给你提示,我很抱歉,因为编码的终极是真正做编码的人。

不幸的是,许多人不理解/不接受所给的提示。

 
qjol:



1.标签变得不一致了,好像XDISTANCE和YDISTANCE没有被遵守一样。

只有在来回切换Tf后,它们才会回到直线上。

在切换图表窗口或改变参数 输入后,它们会脱线。

这意味着你可以在你的代码中修复它

我已经做了很多,但没有任何帮助。

它变得更好,但仍然是,即在改变参数后,而不是改变X、Y,标签就会变得不一致!这说明什么?

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

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

代码有什么问题吗?



 
Dadas:


代码有什么问题吗?


你已经被告知了,忘了吧

int start()  

开始使用新的方法

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已经写在上面了

我没有看到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:

你已经被告知,忘记

开始使用新的方法

daysmacro已经写在上面

我没有看到ObjectFind()



所以,我做了。

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

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

还是一样的效果。就标签定位而言,这没有改变什么。

ObjectFind()是在OnInit()中检查对象是否在那里,如果是,就删除它。

在Indi初始化时的标签是它应该在的位置。

在改变一些参数后,它就消失在右边。

只有在Tf移位后才跳回原位。

 
事实上,你只需要像第一次加载时的第一个对象集和加载后的第二个对象集(尘埃落定)。我也遇到了同样的问题,像我说的那样做可以解决问题。这更像是一个变通办法,但对我来说已经足够好了。
 
deysmacro:
实际上,你只需要在第一次加载时设置第一个对象,然后在加载后设置第二个对象(尘埃落定)。我也遇到了同样的问题,像我说的那样做可以解决问题。这更像是一个变通办法,但对我来说已经足够好了。

所以,我这样做了,甚至重新检查了X,Y坐标以重新测试标签,以防坐标不同。

没有汁液,没有任何变化,它的行为与上面一样。

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

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

	          
 
那么,它已经完成了吗?
 

而且,有趣的是,使用Comment(),坐标永远不会改变,即使标签向右转。

因此,问题仍然存在,它没有完成。

 
Comment()对图表没有影响,大部分时间都是如此。