130 lines
No EOL
12 KiB
Text
130 lines
No EOL
12 KiB
Text
int OnInit()
|
|
if (!IsTesting()) CenterSymbol();
|
|
|
|
void OnTick()
|
|
if (!IsTesting()) CenterSymbol();
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| チャートの中央にシンボルを描画する |
|
|
//+------------------------------------------------------------------+
|
|
void CenterSymbol()
|
|
{
|
|
string TEXT1 = StringSubstr(Symbol(), 0, 6);
|
|
string TEXT2 = (Period() == 1? "M1": Period() == 5? "M5": Period() == 15? "M15": Period() == 30? "M30":
|
|
Period() == 60? "H1": Period() == 240? "H4": Period() == 1440? "D1": Period() == 10080? "W1": "MN1")
|
|
+ "/" + DoubleToStr(MarketInfo(Symbol(),MODE_SPREAD) / 10, 1);
|
|
int FontSize = 36;
|
|
|
|
int chartWidth = (int)ChartGetInteger(0, CHART_WIDTH_IN_PIXELS);
|
|
int chartHeight = (int)ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS);
|
|
int textWidth = StringLen(TEXT1) * FontSize / 2; // テキストの幅の計算
|
|
int textHeight = FontSize; // テキストの高さ
|
|
|
|
// テキストの中心からの座標を計算
|
|
int x = (chartWidth - textWidth) / 2 + textWidth / 2;
|
|
int y = (chartHeight - textHeight) / 2 + textHeight / 2;
|
|
|
|
DrawTextInCenter("Symbol1", TEXT1, x, y - FontSize, FontSize, C'60, 60, 60');
|
|
DrawTextInCenter("Symbol2", TEXT2, x, y + FontSize, FontSize, C'60, 60, 60');
|
|
}
|
|
void DrawTextInCenter(string Symbolname, string label_text, int pos_x, int pos_y, int s, color clr= clrBlack)
|
|
{
|
|
ObjectCreate(Symbolname, OBJ_LABEL, 0, 0, 0);
|
|
ObjectSetString(0, Symbolname, OBJPROP_TEXT, label_text);
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_FONTSIZE, s);
|
|
ObjectSetString(0, Symbolname, OBJPROP_FONT, "Segoe UI");
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_XDISTANCE, pos_x);
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_YDISTANCE, pos_y);
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_COLOR, clr);
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_BACK, true);
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_SELECTABLE, false);
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_ANCHOR, ANCHOR_CENTER);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
|
|
|
|
|
// 以下バリエーション
|
|
//+------------------------------------------------------------------+
|
|
//| チャートの中央にシンボルを描画する(単色) |
|
|
//+------------------------------------------------------------------+
|
|
void CenterSymbol()
|
|
{
|
|
string TEXT1 = StringSubstr(Symbol(), 0, 6) + " / " +
|
|
(Period() == 1? "M1": Period() == 5? "M5": Period() == 15? "M15": Period() == 30? "M30":
|
|
Period() == 60? "H1": Period() == 240? "H4": Period() == 1440? "D1": Period() == 10080? "W1": "MN1");
|
|
int FontSize = 36;
|
|
|
|
int chartWidth = (int)ChartGetInteger(0, CHART_WIDTH_IN_PIXELS);
|
|
int chartHeight = (int)ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS);
|
|
int textWidth = StringLen(TEXT1) * FontSize / 2; // テキストの幅の計算
|
|
int textHeight = FontSize; // テキストの高さ
|
|
|
|
// テキストの中心からの座標を計算
|
|
int x = (chartWidth - textWidth) / 2 + textWidth / 2;
|
|
int y = (chartHeight - textHeight) / 2 + textHeight / 2;
|
|
|
|
DrawTextInCenter("Symbol1", TEXT1, x, y, FontSize, C'60, 60, 60');
|
|
}
|
|
void DrawTextInCenter(string Symbolname, string label_text, int pos_x, int pos_y, int s, color clr= clrBlack)
|
|
{
|
|
ObjectCreate(Symbolname, OBJ_LABEL, 0, 0, 0);
|
|
ObjectSetString(0, Symbolname, OBJPROP_TEXT, label_text);
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_FONTSIZE, s);
|
|
ObjectSetString(0, Symbolname, OBJPROP_FONT, "Segoe UI");
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_XDISTANCE, pos_x);
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_YDISTANCE, pos_y);
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_COLOR, clr);
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_BACK, true);
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_SELECTABLE, false);
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_ANCHOR, ANCHOR_CENTER);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
|
|
// トレード中色変化バージョン
|
|
void CenterSymbol()
|
|
{
|
|
string TEXT1 = StringSubstr(Symbol(), 0, 6) + " / " +
|
|
(Period() == 1? "M1": Period() == 5? "M5": Period() == 15? "M15": Period() == 30? "M30":
|
|
Period() == 60? "H1": Period() == 240? "H4": Period() == 1440? "D1": Period() == 10080? "W1": "MN1");
|
|
int FontSize = 36;
|
|
|
|
int OrderTipe = 2;
|
|
double profit = 0;
|
|
bool res;
|
|
|
|
int chartWidth = (int)ChartGetInteger(0, CHART_WIDTH_IN_PIXELS);
|
|
int chartHeight = (int)ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS);
|
|
int textWidth = StringLen(TEXT1) * FontSize / 2; // テキストの幅の計算
|
|
int textHeight = FontSize; // テキストの高さ
|
|
|
|
// テキストの左上隅からの座標を計算
|
|
int x = (chartWidth - textWidth) / 2 + textWidth / 2;
|
|
int y = (chartHeight - textHeight) / 2 + textHeight / 2;
|
|
|
|
for (int i = OrdersTotal() - 1; i >= 0; i--)
|
|
{
|
|
res = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
|
|
if (OrderSymbol() != Symbol() || OrderType() > 1 || OrderType() >= 2 || (OrderMagicNumber() != MagicNumber))// && OrderMagicNumber() != MagicNumber2))
|
|
continue;
|
|
OrderTipe = OrderType();
|
|
profit = OrderProfit();
|
|
}
|
|
|
|
DrawTextInCenter("Symbol1", TEXT1, x, y, FontSize,
|
|
OrderTipe < 2 && profit < 0? clrCrimson: OrderTipe < 2 && profit >= 0? clrLimeGreen: C'60, 60, 60');
|
|
}
|
|
void DrawTextInCenter(string Symbolname, string label_text, int pos_x, int pos_y, int s, color clr= clrBlack)
|
|
{
|
|
ObjectCreate(Symbolname, OBJ_LABEL, 0, 0, 0);
|
|
ObjectSetString(0, Symbolname, OBJPROP_TEXT, label_text);
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_FONTSIZE, s);
|
|
ObjectSetString(0, Symbolname, OBJPROP_FONT, "Segoe UI");
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_XDISTANCE, pos_x);
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_YDISTANCE, pos_y);
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_COLOR, clr);
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_BACK, true);
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_SELECTABLE, false);
|
|
ObjectSetInteger(0, Symbolname, OBJPROP_ANCHOR, ANCHOR_CENTER);
|
|
} |