From f8c1aee24b324095041df065593cbaaa0e58459f Mon Sep 17 00:00:00 2001 From: Victor Tereschenko Date: Thu, 5 Sep 2024 09:57:42 +0600 Subject: [PATCH] feat: Updated plotchar --- snippets/PlotChar.mqh | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/snippets/PlotChar.mqh b/snippets/PlotChar.mqh index bc4050d..363ba34 100644 --- a/snippets/PlotChar.mqh +++ b/snippets/PlotChar.mqh @@ -1,27 +1,29 @@ // Implementation of PineScript's plotchar -// v1.0 +// v1.2 class PlotChar { string _char; string _id; + string _location; public: - PlotChar(string ch, string id) + PlotChar(string ch, string id, string location) { _char = ch; _id = id; + _location = location; } - void set(int pos, bool toTrue) + void Set(int pos, bool toTrue, color clr = Blue) { datetime time = iTime(_Symbol, _Period, pos); string id = _id + TimeToString(time); if (!toTrue) { - ObjectDelete(id); + ObjectDelete(0, id); return; } ResetLastError(); - double price = iHigh(_Symbol, _Period, pos); + double price = GetPrice(pos); if (ObjectFind(0, id) == -1) { if (!ObjectCreate(0, id, OBJ_TEXT, 0, time, price)) @@ -31,11 +33,36 @@ public: } ObjectSetString(0, id, OBJPROP_FONT, "Arial"); ObjectSetInteger(0, id, OBJPROP_FONTSIZE, 12); - ObjectSetInteger(0, id, OBJPROP_COLOR, Blue); - ObjectSetInteger(0, id, OBJPROP_ANCHOR, ANCHOR_LOWER); + ObjectSetInteger(0, id, OBJPROP_COLOR, clr); + ObjectSetInteger(0, id, OBJPROP_ANCHOR, GetAnchor()); } ObjectSetInteger(0, id, OBJPROP_TIME, time); - ObjectSetDouble(0, id, OBJPROP_PRICE1, price); + ObjectSetDouble(0, id, OBJPROP_PRICE, 1, price); ObjectSetString(0, id, OBJPROP_TEXT, _char); } +private: + int GetAnchor() + { + if (_location == "abovebar") + { + return ANCHOR_LOWER; + } + if (_location == "belowbar") + { + return ANCHOR_UPPER; + } + return ANCHOR_CENTER; + } + double GetPrice(int pos) + { + if (_location == "abovebar") + { + return iHigh(_Symbol, _Period, pos); + } + if (_location == "belowbar") + { + return iLow(_Symbol, _Period, pos); + } + return iClose(_Symbol, _Period, pos); + } }; \ No newline at end of file