专家顾问 - 杂项问题 - 页 25

 

我尝试在拖动完成后,用下面的代码将OBJPROP_SELECTED 设为 "假",但没有效果。

请问我该如何解决?

if(id==CHARTEVENT_OBJECT_DRAG)
  {
   SL_TPdrags();

   Sleep(1000);
   drag_onoff=false; // OBJPROP_SELECTED
  }

先谢谢你。

 
对不起,我从来不用CHARTEVENT_OBJECT_DRAG
 
Marco vd Heijden:
对不起,我从未使用过CHARTEVENT_OBJECT_DRAG
好的!总之谢谢你!
 

最后,我发现了 "OBJ_RECTANGLE 和OBJ_TEXT",我想我可以用它们来代替 "OBJ_LABEL和OBJ_RECTANGLE_LABEL",因为它们都是一起移动标线的。

问:那么,请问哪些对象对一起移动Bid线非常有用?

我真的很需要有价值的评论。
祝你周末愉快。

 

身份证

描述

OBJ_VLINE

垂直线

OBJ_HLINE

水平线

OBJ_TREND

趋势线

obj_trendbyangle

按角度的趋势线

OBJ_CYCLES

周期线

obj_arrowed_line

箭形线

OBJ_CHANNEL

等距通道

obj_stddevchannel

标准偏差通道

OBJ_REGRESSION

线性回归通道

OBJ_PITCHFORK

安德鲁斯分叉

OBJ_GANNLINE

江恩线

OBJ_GANNFAN

江恩扇

OBJ_GANNGRID

江恩网格

OBJ_FIBO

Fibonacci Retracement

OBJ_FIBOTIMES

斐波那契时间区间

OBJ_FIBOFAN

斐波纳契扇形图

OBJ_FIBOARC

斐波那契弧形图(Fibonacci Arcs

obj_fibochannel

斐波那契通道

OBJ_EXPANSION

斐波那契扩展

obj_elliotwave5

艾略特动机波

obj_elliotwave3

艾略特修正波

OBJ_RECTANGLE

矩形

OBJ_TRIANGLE

三角形

OBJ_ELLIPSE

椭圆

Obj_arrow_thumb_up

拇指向上

Obj_arrow_thumb_down

拇指向下

OBJ_ARROW_UP

箭头向上

OBJ_ARROW_DOWN(向下箭头

箭头向下

OBJ_ARROW_STOP

停止标志

OBJ_ARROW_check

检查标志

Obj_arrow_left_price

左侧价格标签

右边价格

右价格标签

OBJ_ARROW_BUY

购买标志

OBJ_ARROW_SELL

卖出标签

OBJ_ARROW

箭头

OBJ_TEXT

文本

OBJ_LABEL

标签

OBJ_BUTTON

按钮

OBJ_CHART

图表

OBJ_BITMAP

位图

OBJ_bitmap_label

位图标签

OBJ_EDIT

编辑

OBJ_EVENT

与经济日历中的一个事件相对应的 "事件 "对象。

obj_rectangle_label

用于创建和设计自定义图形界面的 "矩形标签 "对象。


你说的一起移动是什么意思?

 
Max Enrik:

我尝试在拖动完成后,用下面的代码将OBJPROP_SELECTED 设为 "假",但没有效果。

请问我该如何解决?

if(id==CHARTEVENT_OBJECT_DRAG)
  {
   SL_TPdrags();

   Sleep(1000);
   drag_onoff=false; // OBJPROP_SELECTED
  }

谢谢。

除非你在进一步测试sparam,否则该代码在 任何 对象被拖动。

我的原始代码。

void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
  {
   if(id==CHARTEVENT_OBJECT_DRAG && sparam=="line") // the chart event of dragging the line
 
@Marco vd Heijden

我已经知道/读过你的一个伟大的例子CrossHair.mq4。
但我在给Label、RectLabel对象提供Bid价格时感到很困难。也就是我想把Label, RectLabel对象和Bid线一起移动。

我只需要类似的图片,请找到附件文件。

祝您一切顺利。

附加的文件:
 

对于固定尺寸的对象。OBJ_BUTTON,OBJ_RECTANGLE_LABEL 和 OBJ_EDIT, 属性 OBJPROP_XDISTANCE 和 OBJPROP_YDISTANCE 设置对象的左上角相对于图表角(OBJPROP_CORNER)的位置,X 和 Y 坐标将从这里开始计算,单位为像素。

//+------------------------------------------------------------------+
//|                                                    rectangle.mq4 |
//|      Copyright 2017, Marco vd Heijden, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, Marco vd Heijden, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(1);
//--- create rectangle
   RectangleCreate(0,"Rectangle",0,0,0);  
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
      
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   RectanglePointChange(0,"Rectangle",0,TimeCurrent(),Ask);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
  
  }
//+------------------------------------------------------------------+
//| Create rectangle by the given coordinates                        |
//+------------------------------------------------------------------+
bool RectangleCreate(const long            chart_ID=0,        // chart's ID
                     const string          name="Rectangle",  // rectangle name
                     const int             sub_window=0,      // subwindow index
                     datetime              time1=0,           // first point time
                     double                price1=0,          // first point price
                     datetime              time2=0,           // second point time
                     double                price2=0,          // second point price
                     const color           clr=clrRed,        // rectangle color
                     const ENUM_LINE_STYLE style=STYLE_SOLID, // style of rectangle lines
                     const int             width=1,           // width of rectangle lines
                     const bool            fill=false,        // filling rectangle with color
                     const bool            back=false,        // in the background
                     const bool            selection=true,    // highlight to move
                     const bool            hidden=true,       // hidden in the object list
                     const long            z_order=0)         // priority for mouse click
  {
//--- set anchor points' coordinates if they are not set
   ChangeRectangleEmptyPoints(time1,price1,time2,price2);
//--- reset the error value
   ResetLastError();
//--- create a rectangle by the given coordinates
   if(!ObjectCreate(chart_ID,name,OBJ_RECTANGLE,sub_window,time1,price1,time2,price2))
     {
      Print(__FUNCTION__,
            ": failed to create a rectangle! Error code = ",GetLastError());
      return(false);
     }
//--- set rectangle color
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set the style of rectangle lines
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- set width of the rectangle lines
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
//--- display in the foreground (false) or background (true)
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of highlighting the rectangle for moving
//--- when creating a graphical object using ObjectCreate function, the object cannot be
//--- highlighted and moved by default. Inside this method, selection parameter
//--- is true by default making it possible to highlight and move the object
   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);
  }
//+------------------------------------------------------------------+
//| Move the rectangle anchor point                                  |
//+------------------------------------------------------------------+
bool RectanglePointChange(const long   chart_ID=0,       // chart's ID
                          const string name="Rectangle", // rectangle name
                          const int    point_index=0,    // anchor point index
                          datetime     time=0,           // anchor point time coordinate
                          double       price=0)          // anchor point price coordinate
  {
//--- if point position is not set, move it to the current bar having Bid price
   if(!time)
      time=TimeCurrent();
   if(!price)
      price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- reset the error value
   ResetLastError();
//--- move the anchor point
   if(!ObjectMove(chart_ID,name,point_index,time,price))
     {
      Print(__FUNCTION__,
            ": failed to move the anchor point! Error code = ",GetLastError());
      return(false);
     }
//--- successful execution
   return(true);
  }
//+------------------------------------------------------------------+
//| Check the values of rectangle's anchor points and set default    |
//| values for empty ones                                            |
//+------------------------------------------------------------------+
void ChangeRectangleEmptyPoints(datetime &time1,double &price1,
                                datetime &time2,double &price2)
  {
//--- if the first point's time is not set, it will be on the current bar
   if(!time1)
      time1=TimeCurrent();
//--- if the first point's price is not set, it will have Bid value
   if(!price1)
      price1=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- if the second point's time is not set, it is located 9 bars left from the second one
   if(!time2)
     {
      //--- array for receiving the open time of the last 10 bars
      datetime temp[10];
      CopyTime(Symbol(),Period(),time1,10,temp);
      //--- set the second point 9 bars left from the first one
      time2=temp[0];
     }
//--- if the second point's price is not set, move it 300 points lower than the first one
   if(!price2)
      price2=price1-300*SymbolInfoDouble(Symbol(),SYMBOL_POINT);
  }
//+------------------------------------------------------------------+
 
honest_knave:

除非你进一步测试sparam,否则该代码会在 任何 对象被拖动。
我的原始代码。

void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
  {
   if(id==CHARTEVENT_OBJECT_DRAG && sparam=="line") // the chart event of dragging the line
我已经试过下面的代码。
if(id==CHARTEVENT_OBJECT_DRAG && sparam=="#"+IntegerToString(OrderTicket())+"-TP")
  {
// here was my functions
  }

这不是对我的回应。

---

但我使用的是下面的代码,我对你的代码做了一点改动--它对我来说完美无缺,是我想要的。到目前为止,我还没有遇到任何问题。
我是否做错了,请问?

if(id==CHARTEVENT_OBJECT_DRAG){}

一切都是最好的。

 

也许这将有所帮助。

把这个添加到图表中,你会看到。

  • 每当该线被移动时都会有一个警报(包括新的价格)。
  • 移动 线和警报之间没有延迟。
  • 当其他东西移动时没有警报。
  • 当线被实际移动时,没有警报。

#property strict
#property indicator_chart_window

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   ObjectCreate(0,"MyLine",OBJ_HLINE,0,0,Bid);
   ObjectSetInteger(0,"MyLine",OBJPROP_SELECTED,true);
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ObjectDelete(0,"MyLine");  
  }

//+------------------------------------------------------------------+
//| OnChartEvent()                                                   |

//+------------------------------------------------------------------+
void
OnChartEvent(const int id,
                  const long& lparam,
                  const double& dparam,
                  const string& sparam)
  {
   if(id==CHARTEVENT_OBJECT_DRAG && sparam=="MyLine")
     {
      double price=ObjectGetDouble(0,"MyLine",OBJPROP_PRICE,0);
      Alert("MyLine moved! New price is " + DoubleToStr(price,_Digits));
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {

   return(rates_total);
  }
原因: