简体   繁体   English

如何以编程方式获取手动绘制的矩形的上限值和下限值

[英]How can I programmatically get the upper and lower values of a manually drawn rectangle

I am using the code below to write a message if blue or red rectangle is drawn manually on a chart. 如果在图表上手动绘制了蓝色或红色矩形,我正在使用下面的代码编写消息。 I tried getting the one of the rectangle values using OBJPROP_PRICE1 but it didn't work. 我尝试使用OBJPROP_PRICE1获取矩形值之一,但是没有用。 How can I get the upper and lower values of a manually drawn rectangle? 如何获得手动绘制的矩形的上限值和下限值? Also the way I setup 2 bools, one for each rectangle print condition, makes it only possible for one rectangle of each color to be recognized. 同样,我设置2个布尔值的方式,每个矩形打印条件一个,则只能识别每种颜色的一个矩形。 What would be an appropriate way for me to get the print condition working regardless of the number of blue or red rectangles? 无论蓝色或红色矩形的数量如何,对我来说使打印条件正常工作的合适方法是什么?

bool hasFoundDemandRect = false;
bool hasFoundSupplyRect = false;

void OnTick()   {
for (int i=ObjectsTotal(); i>=0; i--)  {
         string name = ObjectName(i);

         if (ObjectType(name) == OBJ_RECTANGLE) {
            color rectColor = color(ObjectGetInteger(0,name,OBJPROP_COLOR));
            double price1 = ObjectGetDouble(0,name,OBJPROP_PRICE1);
            if (hasFoundDemandRect == false) {
               if (rectColor == clrBlue)  {
                  Print("a BUY rect has to be created");

                  hasFoundDemandRect = true;
               }
            }
            if (hasFoundSupplyRect == false) {
               if (rectColor == clrRed)  {
                  Print("a SELL rect has to be created");
                  hasFoundSupplyRect = true;
               }
            }
         }
}

Q : How can I get the upper and lower values of a manually drawn rectangle? 如何获取手动绘制的矩形的上限值和下限值?

#define MainWINDOW 0

for ( int i = ObjectsTotal(); i >= 0; i-- )  {

      string name = ObjectName( i );

      if ( ObjectType( name ) == OBJ_RECTANGLE ) {
           double price1 =        ObjectGetDouble(  MainWINDOW, name, OBJPROP_PRICE1 );
           double price2 =        ObjectGetDouble(  MainWINDOW, name, OBJPROP_PRICE2 );
           color  rColor = color( ObjectGetInteger( MainWINDOW, name, OBJPROP_COLOR ) );

           if ( rColor == clrBlue )  {
                Print( "BUY rect was found -----------------------------------" );
                Print( "Obj( ", name, " ): Lower edge is: ", MathMin( price1, price2 ) );
                Print( "Obj( ", name, " ): Upper edge is: ", MathMax( price1, price2 ) );
                continue;
           }

           if ( rColor == clrRed )  {
                Print( "SELL rect was found ----------------------------------" );
                Print( "Obj( ", name, " ): Lower edge is: ", MathMin( price1, price2 ) );
                Print( "Obj( ", name, " ): Upper edge is: ", MathMax( price1, price2 ) );
                continue;
           }
      }
}

Q : What would be an appropriate way for me to get the print condition working regardless of the number of blue or red rectangles? 无论蓝色或红色矩形的数量如何,对我而言,使打印条件正常工作的合适方法是什么?

Solution for this requires you to implement some sort of object-inventory. 解决方案要求您实施某种对象清单。 Your current code just blindly re-iterates per tick over all of the ObjectsTotal() number of GUI-objects. 您的当前代码只是在所有ObjectsTotal()个GUI对象的每个刻度上盲目地重复。

Having worked with a DMA-alike object-repository, I feel confident to confirm, this may work very fast for more than a few hundreds thousands GUI-objects, so the solution is doable. 我曾与DMA类似的对象存储库一起工作过,对此我很有信心确认,这对于数十万个GUI对象而言可能非常快,因此该解决方案是可行的。

MQL4 language may use either the native array-based DMA-alike object-repository, or may get support from a model, using external node(s) via ZeroMQ-messaging custom-defined API, where remote DB-engines may manage GUI-objects repository and DMA-alike calls for this problem at scales well above million of GUI-objects and scale beyond the MQL4 -node's Array/Memory-limits. MQL4语言可以使用基于本地数组的类似于DMA的对象存储库,也可以通过ZeroMQ消息自定义的API使用外部节点从模型获得支持,远程DB引擎可以在其中进行管理GUI对象存储库和类似DMA的问题使此问题的规模大大超过了百万个GUI对象,并且超出了MQL4节点的数组/内存限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM