图表中间放置物件的示范

//---- external parameters ------------------------------------------+
extern int    Window_Index = 0;      // index of window: 0 = main chart
extern string TxtMessage   = "This is text at center of chart";
extern int    FontSize     = 10;
extern string FontName     = "Arial";
extern color  TextColor    = Snow;

//---- global variables ---------------------------------------------+
static string Txt_objname  = "Example object";

//-------------------------------------------------------------------+
//---- initialization of expert -------------------------------------+
//-------------------------------------------------------------------+
int init()
  {
   return(0);
  }

//-------------------------------------------------------------------+
//---- deinitialization of expert -----------------------------------+
//-------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete(Txt_objname);
   return(0);
  }

//-------------------------------------------------------------------+
//---- main programm cycle ------------------------------------------+
//-------------------------------------------------------------------+
int start()
  {
   int window_index = ObjectFind(Txt_objname);
   if(window_index < 0)
     {
      datetime obj_time1 = Time[WindowFirstVisibleBar() - WindowBarsPerChart() / 2];
      double obj_price1 = NormalizeDouble((WindowPriceMax(Window_Index) + WindowPriceMin(Window_Index)) / 2,Digits);
      ObjectCreate(Txt_objname,OBJ_TEXT,Window_Index,obj_time1,obj_price1);
      ObjectSetText(Txt_objname,TxtMessage,FontSize,FontName,TextColor);
     }
   else
     {
      obj_time1 = Time[WindowFirstVisibleBar() - WindowBarsPerChart() / 2];
      obj_price1 = NormalizeDouble((WindowPriceMax(window_index) + WindowPriceMin(window_index)) / 2,Digits);
      if(obj_time1  != ObjectGet(Txt_objname,OBJPROP_TIME1) || 
         obj_price1 != NormalizeDouble(ObjectGet(Txt_objname,OBJPROP_PRICE1),Digits)) ObjectMove(Txt_objname,0,obj_time1,obj_price1);
     }
   return(0);
  }
本博客所有文章如无特别注明均为原创。作者:天泓评测
分享到:更多

相关推荐

发表评论

路人甲 表情
Ctrl+Enter快速提交

网友评论(0)