インジケーターに関する雑多な質問 - ページ 11

 
コメント#99に ある私のコード例をご覧いただけますでしょうか。
 

ああ、そのコードでOKです。

ObjectCreate() はチャートIDも 必要です。

bool  ObjectCreate(
   long         chart_id,      // chart identifier
   string       name,          // object name
   ENUM_OBJECT  type,          // object type
   sub_window   nwin,          // window index
   datetime     time1,         // time of the first anchor point
   double       price1,        // price of the first anchor point
   ...
   datetime     timeN=0,       // time of the N-th anchor point
   double       priceN=0,      // price of the N-th anchor point
   ...
   datetime     time30=0,      // time of the 30th anchor point
   double       price30=0      // price of the 30th anchor point
   );

を最初のパラメータとして必要とします。

int OnInit()
  {
   Print("Outside");

   ObjectCreate("Object Outside",OBJ_LABEL,0,0,0);
   ObjectSetInteger(0,"Object Outside",OBJPROP_XDISTANCE,20);
   ObjectSetInteger(0,"Object Outside",OBJPROP_YDISTANCE,20);
   ObjectSetString(0,"Object Outside",OBJPROP_TEXT,"Outside");

   if(DayOfWeek()==5)
     {
      Print("Inside");

      ObjectCreate("Object Inside",OBJ_LABEL,0,0,0);
      ObjectSetInteger(0,"Object Inside",OBJPROP_XDISTANCE,20);
      ObjectSetInteger(0,"Object Inside",OBJPROP_YDISTANCE,40);
      ObjectSetString(0,"Object Inside",OBJPROP_TEXT,"Inside");
     }
  }

しかし、オブジェクト名から始めるのです。

また、ベースコーナー/アンカーポイントを指定することができます。

https://www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_label を参照してください。

//+------------------------------------------------------------------+
//| Create a text label                                              |
//+------------------------------------------------------------------+
bool LabelCreate(const long              chart_ID=0,               // chart's ID
                 const string            name="Label",             // label name
                 const int               sub_window=0,             // subwindow index
                 const int               x=0,                      // X coordinate
                 const int               y=0,                      // Y coordinate
                 const ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER, // chart corner for anchoring
                 const string            text="Label",             // text
                 const string            font="Arial",             // font
                 const int               font_size=10,             // font size
                 const color             clr=clrRed,               // color
                 const double            angle=0.0,                // text slope
                 const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // anchor type
                 const bool              back=false,               // in the background
                 const bool              selection=false,          // highlight to move
                 const bool              hidden=true,              // hidden in the object list
                 const long              z_order=0)                // priority for mouse click
  {
//--- reset the error value
   ResetLastError();
//--- create a text label
   if(!ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0))
     {
      Print(__FUNCTION__,
            ": failed to create text label! Error code = ",GetLastError());
      return(false);
     }
//--- set label coordinates
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//--- set the chart's corner, relative to which point coordinates are defined
   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//--- set the text
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
//--- set text font
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
//--- set font size
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
//--- set the slope angle of the text
   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
//--- set anchor type
   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
//--- set color
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- display in the foreground (false) or background (true)
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving the label by mouse
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- hide (true) or display (false) graphical object name in the object list
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chart
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful execution
   return(true);
  }
//+------------------------------------------------------------------+

Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_LABEL
Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_LABEL
  • www.mql5.com
Standard Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_LABEL - Reference on algorithmic/automated trading language for MetaTrader 5
 

私はちょうど私が私の問題を説明することができなかったことを心配している、私はあなたがそれを試してみました、お願いします?そうすれば、そのコードの何が問題なのかが分かると思います。

1.サンプルファイルをチャートに追加し、MT4を閉じます。2.2. MT4を開くと、私のインサイド・ラベル・オブジェクトが 見えません。

これが私の問題に対する解決策を見つける方法です。


たぶん、私は月曜日に確実になります。

( これが簡単だと思うと、その簡単なことのために多くの時間を費やし、これが難しいと思うと、簡単にやってしまう... - 私がやりたいことのほとんどは、まずドキュメントを読もうとする....)

 

試してみたところ、2つのオブジェクトが表示されました。

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
      Print("Outside");

   ObjectCreate(0,"Object Outside",OBJ_LABEL,0,0,0);
   ObjectSetInteger(0,"Object Outside",OBJPROP_XDISTANCE,20);
   ObjectSetInteger(0,"Object Outside",OBJPROP_YDISTANCE,20);
   ObjectSetString(0,"Object Outside",OBJPROP_TEXT,"Outside");

   if(DayOfWeek()==5)
     {
      Print("Inside");

      ObjectCreate(0,"Object Inside",OBJ_LABEL,0,0,0);
      ObjectSetInteger(0,"Object Inside",OBJPROP_XDISTANCE,20);
      ObjectSetInteger(0,"Object Inside",OBJPROP_YDISTANCE,40);
      ObjectSetString(0,"Object Inside",OBJPROP_TEXT,"Inside");
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+


 

かっこいい!

私のスクリーンショットを見てください。

訳あり

お時間をいただきありがとうございます。

 

コードの一部がインジケータで異なる結果を与えることは気にしません。
私のインジケーターファイルでその部分を試してみました。

( インジケータ・ファイルにコードを書くことにして、トレード・パネル・ファイルには書かないことにしました。)


2回目の編集

すでにあなたの方法を使用していますが、何の問題もなく動作しています。

ありがとうございます、Marcoさん。


#月曜日ではありません - 終了
 

#リフレッシュ - オープン

この問題が解決すると、私のインジケータはメインのMT4プラットフォームではうまく機能するのですが、2番目のMT4プラットフォームを使用しているため、MT4プラットフォームを起動するとインジケータがリフレッシュされる必要があります。
この問題がどこから来るのか見当がつきません...それについて何か正確にお聞きしたいのです。

Q: どなたか、この奇妙な状況について何か教えていただけませんか?

よろしくお願いします。

 

2つのプラットフォームで異なる挙動を目撃したということですか?

同じビルドなのでしょうか?

 
Marco vd Heijden:

2つのプラットフォームで異なる挙動を目撃したということですか?

同じビルドですか?

そうです、全く異なる挙動です。

また、はい、両方とも1065ビルドです。

 

もしかしたら、これらの奇妙な問題の原因がわかったかもしれない...。

ロードテンプレートの秘密は何ですか?
私はすでに自分のEAやインジケーターのために膨大なことをしてきましたが、今までのように多くの時間を費やしたことはありません。

どうやって?簡単です。

EAのファイルにスクリプトを入れないと決めてから、SEOで解決できないようなマイナーな問題に直面することが多くなったのです。(SEOで簡単に解決できることもあるのですが、これはマイナーな問題です。)

---

この簡単なコードは、私のインジケータファイルのサンプルとして置いてあります。

int OnInit()
{
  Print( "This Year", Year() );
  return(INIT_SUCCEEDED);
}

このサンプルファイルをチャートにロードしようとしたとき。TimeFrameを変更するまで正しく動作しません。
( それは私が今日すでに疲れている可能性があります )
( また、私はOnCalculate(...) - しかし、私はちょうどOnInit()でそのコードを置く必要がある場合、私はこの問題を解決できることを知っている)

どうか、この問題についてもっと明確な説明が必要です。というのも、私のインジケータには同じような無関係な問題がいくつかあるからです。(これをEAのファイルに入れれば正しく動作するということです)

ありがとうございました。
良い週末をお過ごしください。

理由: