グローバル初期化に失敗した!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - ページ 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() の中でオブジェクトがあるかどうかをチェックし、あればそれを削除しています。

インディ初期化時のラベルは、あるべき位置にある。

パラメータを変更すると、右側に消える。

Tfシフト後に元の位置にジャンプする。

 
実際には、最初のロード時に最初のオブジェクトを設定し、ロード後(塵も積もれば山となる)に2番目のオブジェクトを設定するようなことが必要です。私も同じ問題に直面しましたが、私が言ったようにすることで問題が解決しました。これは回避策に近いものですが、私にとっては十分なものです。
 
deysmacro:
実は、最初のロード時に最初のオブジェクトをセットし、ロード後(塵も積もれば山となる)に2番目のオブジェクトをセットするようなことが必要なのです。私も同じ問題が発生しましたが、私が言ったようにすることで問題が解決しました。これは回避策に近いものですが、私にとっては十分なものです。

そこで、このように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()は、ほとんどの場合、チャートに影響を与えません。