How create static trendline object on chart by MQL4?
How create static trendline object on chart by MQL4?
Loading saved threads...
user18173771 · External communityPost link
External question — Stack Overflow Stack Exchange
Author: user18173771
Original post: https://stackoverflow.com/questions/71749594
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 want a down trend line whenever the highest candle in the previous 500 bars is higher than latest 5 candles highest bar. However the trend line is created the first time but does not update.
int highestCandle=iHighest(Symbol(),0,MODE_HIGH,500,0);
if(High[highestCandle]>High[5])
{
ObjectCreate(0,"HT",OBJ_TREND,0,Time[highestCandle],High[highestCandle],Time[0],High[0]);
ObjectSetInteger(0,"HT",OBJPROP_COLOR,clrBlue); ObjectSetInteger(0,"HT",OBJPROP_STYLE,STYLE_SOLID); ObjectSetInteger(0,"HT",OBJPROP_RAY,true);
}
I do not want to delete this object and recreate on every new tick, I would just like it to be updated on the chart.
Quote
Report
PaulB · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: PaulB
Original post: https://stackoverflow.com/a/71750603
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
Because you have already created your object, trying to create it again will not move the coordinates. You need to use
ObjectMove
. Try the following code:
int highestCandle=iHighest(Symbol(),0,MODE_HIGH,500,0);
if(High[highestCandle]>High[5])
{
ObjectCreate(0,"HT",OBJ_TREND,0,Time[highestCandle],High[highestCandle],Time[0],High[0]);
ObjectSetInteger(0,"HT",OBJPROP_COLOR,clrBlue);
ObjectSetInteger(0,"HT",OBJPROP_STYLE,STYLE_SOLID);
ObjectSetInteger(0,"HT",OBJPROP_RAY,true);
ObjectMove("HT",0,Time[highestCandle],High[highestCandle]);
ObjectMove("HT",1,Time[0],High[0]);
}
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: PaulB Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/a/71750603 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Because you have already created your object, trying to create it again will not move the coordinates. You need to use ObjectMove . Try the following code: int highestCandle=iHighest(Symbol(),0,MODE_HIGH,500,0); if(High[highestCandle]>High[5]) { ObjectCreate(0,"HT",OBJ_TREND,0,Time[highestCandle],High[highestCandle],Time[0],High[0]); ObjectSetInteger(0,"HT",OBJPROP_COLOR,clrBlue); ObjectSetInteger(0,"HT",OBJPROP_STYLE,STYLE_SOLID); ObjectSetInteger(0,"HT",OBJPROP_RAY,true); ObjectMove("HT",0,Time[highestCandle],High[highestCandle]); ObjectMove("HT",1,Time[0],High[0]); }
Checking account access…