Arrow object appears only once in visual mode in MQL4

Arrow object appears only once in visual mode in MQL4

Manage alerts

Loading saved threads...

migdal menora · External communityPost link
External question — Stack Overflow Stack Exchange Author: migdal menora Original post: https://stackoverflow.com/questions/72449760 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I'm an MQL4 newbie and would like to draw an arrow each time a simple trigger is made. I don't understand why in the attached code below the arrow appears only once while the comment is displayed every time the trigger is made. How can I solve this issue? #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"); } }
Quote
Report
tomgny · External communityPost link
External answer — Stack Overflow Stack Exchange Author: tomgny Original post: https://stackoverflow.com/a/72461718 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. The object_name (second parameter in ObjectCreate function) param must by unique for each object. In your code, the object_name is always equal "Arrow" , and this is the reason why the arrow appears only once. For example, you can create a global counter and iterate it on every arrow create trigger. 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
Quote
Report

Post Reply

Checking account access…