Skip to content

Commit

Permalink
feat: Updated plotchar
Browse files Browse the repository at this point in the history
  • Loading branch information
sibvic committed Sep 5, 2024
1 parent 205a236 commit f8c1aee
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions snippets/PlotChar.mqh
Original file line number Diff line number Diff line change
@@ -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))
Expand All @@ -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);
}
};

0 comments on commit f8c1aee

Please sign in to comment.