箭头对象在 MQL4 的可视化模式下只出现一次

Arrow object appears only once in visual mode in MQL4

我是 MQL4 新手,每次触发一个简单的触发器时我都想画一个箭头。 我不明白为什么在下面的附加代码中箭头只出现一次,而每次触发时都会显示评论。 我该如何解决这个问题?

#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link      
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   double UpBarPlace1 = Close[1]>Open[1];
   double UpBarPlace2 = Close[2]>Open[2];
   double UpBarPlace3 = Close[3]>Open[3];
   
   double DwBarPlace1 = Close[1]<Open[1];
   double DwBarPlace2 = Close[2]<Open[2];
   double DwBarPlace3 = Close[3]<Open[3];
   
 
   if(UpBarPlace1 == 1)
      {
        Comment ("Sell for 2 range size target ");
        ObjectCreate(_Symbol,"Arrow", OBJ_ARROW,0,TimeCurrent(),Close[1]);       
                
      } else 
      {
        Comment("Ambiguous");  
      }
  }

object_nameObjectCreate 函数中的第二个参数)参数必须 unique 每个对象。 在您的代码中,object_name 始终等于 "Arrow",这就是箭头只出现一次的原因。

例如,您可以创建一个全局计数器并在每个箭头创建触发器上迭代它。

ObjectCreate(_Symbol,"Arrow_" + IntegerToString(arrowIndexingCounter), OBJ_ARROW,0,TimeCurrent(),Close[1]); 
arrowIndexingCounter++;

object_name -> Name of the object. The name must be unique within a chart, including its subwindows.

ObjectCreate function docs