MQL5のオブジェクト関数を完全網羅。ObjectCreate・ObjectDelete・ObjectSetIntegerなど、EA開発で使うすべてのグラフィカルオブジェクト操作をコード付きで解説します。トレンドライン、水平線、矩形、テキスト、ボタン、情報パネルまで、実践的な描画パターンを豊富に紹介。MQL4との違いも併記しています。
目次
MQL5オブジェクト操作の基礎知識
MQL5のグラフィカルオブジェクトを使うと、チャート上にライン、テキスト、ボタンなどの視覚要素を描画できます。EA開発では、取引レベルの表示、情報パネルの作成、ゾーンの描画などに使用します。
MQL4とMQL5のオブジェクト操作の違い
| 項目 | MQL4 | MQL5 |
|---|---|---|
| ObjectCreate | 戻り値bool、chart_id不要 | 第1引数にchart_id |
| プロパティ設定 | ObjectSet()にENUM指定 | ObjectSetInteger/Double/String |
| OBJ_LABEL座標 | ピクセル座標 | ピクセル座標(同じ) |
| OBJ_EDIT | 対応(ビルド600+) | 対応(テキスト入力フィールド) |
| OBJ_BUTTON | 対応(ビルド600+) | 対応(クリック可能なボタン) |
| OBJ_BITMAP_LABEL | 対応 | 対応 |
| アンカーポイント | 限定的 | OBJPROP_ANCHORで細かく指定可能 |
| ObjectGetTimeByValue | 対応 | 対応 |
| ObjectGetValueByTime | 対応 | 対応 |
ObjectCreate — オブジェクトの作成
bool ObjectCreate(
long chart_id, // チャートID(0=現在)
string name, // オブジェクト名(一意)
ENUM_OBJECT type, // オブジェクトタイプ
int sub_window, // サブウィンドウ(0=メイン)
datetime time1, // 第1アンカーポイントの時間
double price1, // 第1アンカーポイントの価格
datetime time2 = 0, // 第2アンカーポイント(任意)
double price2 = 0,
datetime time3 = 0, // 第3アンカーポイント(任意)
double price3 = 0
);主要なオブジェクトタイプ
| タイプ | 説明 | アンカーポイント数 |
|---|---|---|
| OBJ_VLINE | 垂直線 | 1(時間のみ) |
| OBJ_HLINE | 水平線 | 1(価格のみ) |
| OBJ_TREND | トレンドライン | 2 |
| OBJ_RECTANGLE | 矩形 | 2(対角) |
| OBJ_LABEL | テキストラベル(ピクセル座標) | 0(XY座標指定) |
| OBJ_TEXT | テキスト(チャート座標) | 1 |
| OBJ_BUTTON | ボタン(クリック可能) | 0(XY座標指定) |
| OBJ_EDIT | テキスト入力フィールド | 0(XY座標指定) |
| OBJ_BITMAP_LABEL | ビットマップ画像 | 0(XY座標指定) |
| OBJ_ARROW | 矢印マーク | 1 |
| OBJ_ARROW_BUY | 買い矢印 | 1 |
| OBJ_ARROW_SELL | 売り矢印 | 1 |
| OBJ_CHANNEL | 平行チャネル | 3 |
| OBJ_FIBO | フィボナッチリトレースメント | 2 |
ObjectDelete / ObjectsDeleteAll — オブジェクトの削除
bool ObjectDelete(
long chart_id, // チャートID
string name // オブジェクト名
);
int ObjectsDeleteAll(
long chart_id, // チャートID
int sub_window = -1, // サブウィンドウ(-1=全部)
int type = -1 // オブジェクトタイプ(-1=全部)
);
// プレフィックス指定で一括削除
int ObjectsDeleteAll(
long chart_id,
const string prefix, // 名前のプレフィックス
int sub_window = -1,
int type = -1
);
// 単一オブジェクトの削除
ObjectDelete(0, "myLine_SL");
// EA固有のオブジェクトだけを削除(プレフィックスで管理)
string PREFIX = "MyEA_";
ObjectsDeleteAll(0, PREFIX); // "MyEA_"で始まるオブジェクトを全削除
// 水平線だけを削除
ObjectsDeleteAll(0, -1, OBJ_HLINE);
// OnDeinitでクリーンアップ
void OnDeinit(const int reason)
{
ObjectsDeleteAll(0, PREFIX); // EA固有のオブジェクトを全削除
ChartRedraw(0);
}EA固有のオブジェクトには必ずプレフィックスを付けてください(例: "MyEA_")。OnDeinit()でObjectsDeleteAll(0, PREFIX)を呼べば、他のEAやインジケーターのオブジェクトに影響を与えず、自分のオブジェクトだけを確実に削除できます。
ObjectSetInteger / ObjectSetDouble / ObjectSetString — プロパティの設定
bool ObjectSetInteger(long chart_id, string name, ENUM_OBJECT_PROPERTY_INTEGER prop_id, long value);
bool ObjectSetDouble(long chart_id, string name, ENUM_OBJECT_PROPERTY_DOUBLE prop_id, double value);
bool ObjectSetString(long chart_id, string name, ENUM_OBJECT_PROPERTY_STRING prop_id, string value);
// 主要なプロパティ
// OBJPROP_COLOR - 色
// OBJPROP_STYLE - 線種(STYLE_SOLID, STYLE_DASH, STYLE_DOT...)
// OBJPROP_WIDTH - 線幅
// OBJPROP_BACK - 背景に表示
// OBJPROP_SELECTABLE - ユーザーが選択可能か
// OBJPROP_SELECTED - 選択状態
// OBJPROP_HIDDEN - オブジェクト一覧に非表示
// OBJPROP_RAY_RIGHT - 右方向に延長
// OBJPROP_RAY_LEFT - 左方向に延長
// OBJPROP_FILL - 塗りつぶし(矩形等)
// OBJPROP_TOOLTIP - ツールチップ
// OBJPROP_XDISTANCE - X座標(ラベル用)
// OBJPROP_YDISTANCE - Y座標(ラベル用)
// OBJPROP_XSIZE - 幅(ボタン/エディット用)
// OBJPROP_YSIZE - 高さ
// OBJPROP_CORNER - 基準コーナー
// OBJPROP_ANCHOR - アンカーポイント
// OBJPROP_FONTSIZE - フォントサイズ
// OBJPROP_FONT - フォント名
// OBJPROP_TEXT - テキスト内容水平線(OBJ_HLINE)の描画
string PREFIX = "MyEA_";
// 水平線を描画するヘルパー関数
void DrawHLine(string name, double price, color clr, int style = STYLE_SOLID, int width = 1)
{
string objName = PREFIX + name;
if(ObjectFind(0, objName) < 0)
{
ObjectCreate(0, objName, OBJ_HLINE, 0, 0, price);
}
else
{
ObjectSetDouble(0, objName, OBJPROP_PRICE, price);
}
ObjectSetInteger(0, objName, OBJPROP_COLOR, clr);
ObjectSetInteger(0, objName, OBJPROP_STYLE, style);
ObjectSetInteger(0, objName, OBJPROP_WIDTH, width);
ObjectSetInteger(0, objName, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, objName, OBJPROP_HIDDEN, true);
}
// SL/TPの可視化
void VisualizeTradeLevel(double entry, double sl, double tp)
{
DrawHLine("Entry", entry, clrWhite, STYLE_SOLID, 2);
DrawHLine("SL", sl, clrRed, STYLE_DASH, 1);
DrawHLine("TP", tp, clrLime, STYLE_DASH, 1);
ChartRedraw(0);
}
// レベルのクリア
void ClearTradeLevels()
{
ObjectDelete(0, PREFIX + "Entry");
ObjectDelete(0, PREFIX + "SL");
ObjectDelete(0, PREFIX + "TP");
ChartRedraw(0);
}垂直線(OBJ_VLINE)の描画
void DrawVLine(string name, datetime time, color clr, int style = STYLE_DOT)
{
string objName = PREFIX + name;
if(ObjectFind(0, objName) < 0)
ObjectCreate(0, objName, OBJ_VLINE, 0, time, 0);
else
ObjectSetInteger(0, objName, OBJPROP_TIME, time);
ObjectSetInteger(0, objName, OBJPROP_COLOR, clr);
ObjectSetInteger(0, objName, OBJPROP_STYLE, style);
ObjectSetInteger(0, objName, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, objName, OBJPROP_HIDDEN, true);
}
// 取引時刻のマーキング
void MarkTradeTime(datetime entryTime, datetime exitTime)
{
DrawVLine("EntryTime", entryTime, clrDodgerBlue);
DrawVLine("ExitTime", exitTime, clrOrangeRed);
ChartRedraw(0);
}トレンドライン(OBJ_TREND)の描画
void DrawTrendLine(string name, datetime time1, double price1,
datetime time2, double price2, color clr,
bool rayRight = true, int width = 1)
{
string objName = PREFIX + name;
if(ObjectFind(0, objName) < 0)
ObjectCreate(0, objName, OBJ_TREND, 0, time1, price1, time2, price2);
else
{
ObjectSetInteger(0, objName, OBJPROP_TIME, 0, time1);
ObjectSetDouble(0, objName, OBJPROP_PRICE, 0, price1);
ObjectSetInteger(0, objName, OBJPROP_TIME, 1, time2);
ObjectSetDouble(0, objName, OBJPROP_PRICE, 1, price2);
}
ObjectSetInteger(0, objName, OBJPROP_COLOR, clr);
ObjectSetInteger(0, objName, OBJPROP_WIDTH, width);
ObjectSetInteger(0, objName, OBJPROP_RAY_RIGHT, rayRight);
ObjectSetInteger(0, objName, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, objName, OBJPROP_HIDDEN, true);
}
// 移動平均の傾きをトレンドラインで可視化
void DrawMASlope(int maHandle)
{
double ma[];
ArraySetAsSeries(ma, true);
if(CopyBuffer(maHandle, 0, 0, 20, ma) < 20) return;
datetime time1 = iTime(_Symbol, PERIOD_CURRENT, 19);
datetime time2 = iTime(_Symbol, PERIOD_CURRENT, 0);
color clr = ma[0] > ma[19] ? clrLime : clrRed;
DrawTrendLine("MA_Slope", time1, ma[19], time2, ma[0], clr, true, 2);
ChartRedraw(0);
}矩形(OBJ_RECTANGLE)の描画
void DrawRectangle(string name, datetime time1, double price1,
datetime time2, double price2, color clr,
bool fill = true)
{
string objName = PREFIX + name;
if(ObjectFind(0, objName) < 0)
ObjectCreate(0, objName, OBJ_RECTANGLE, 0, time1, price1, time2, price2);
else
{
ObjectSetInteger(0, objName, OBJPROP_TIME, 0, time1);
ObjectSetDouble(0, objName, OBJPROP_PRICE, 0, price1);
ObjectSetInteger(0, objName, OBJPROP_TIME, 1, time2);
ObjectSetDouble(0, objName, OBJPROP_PRICE, 1, price2);
}
ObjectSetInteger(0, objName, OBJPROP_COLOR, clr);
ObjectSetInteger(0, objName, OBJPROP_FILL, fill);
ObjectSetInteger(0, objName, OBJPROP_BACK, true); // 背景に描画
ObjectSetInteger(0, objName, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, objName, OBJPROP_HIDDEN, true);
}
// サポート/レジスタンスゾーンの描画
void DrawSRZone(string name, double upperPrice, double lowerPrice,
color clr, int barsBack = 100)
{
datetime timeFrom = iTime(_Symbol, PERIOD_CURRENT, barsBack);
datetime timeTo = iTime(_Symbol, PERIOD_CURRENT, 0) + PeriodSeconds() * 20;
DrawRectangle(name, timeFrom, upperPrice, timeTo, lowerPrice, clr, true);
}
// 使用例: レジスタンスとサポートゾーン
DrawSRZone("Resistance", 151.500, 151.400, clrLightCoral);
DrawSRZone("Support", 149.800, 149.700, clrLightGreen);
ChartRedraw(0);テキストラベル(OBJ_LABEL)の描画
OBJ_LABELはピクセル座標で配置するテキストです。チャートをスクロールしても位置が固定されるため、情報パネルの作成に適しています。
void DrawLabel(string name, int x, int y, string text,
color clr = clrWhite, int fontSize = 10,
string font = "Arial", ENUM_ANCHOR_POINT anchor = ANCHOR_LEFT_UPPER,
ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER)
{
string objName = PREFIX + name;
if(ObjectFind(0, objName) < 0)
ObjectCreate(0, objName, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, objName, OBJPROP_XDISTANCE, x);
ObjectSetInteger(0, objName, OBJPROP_YDISTANCE, y);
ObjectSetInteger(0, objName, OBJPROP_CORNER, corner);
ObjectSetInteger(0, objName, OBJPROP_ANCHOR, anchor);
ObjectSetString(0, objName, OBJPROP_TEXT, text);
ObjectSetInteger(0, objName, OBJPROP_COLOR, clr);
ObjectSetInteger(0, objName, OBJPROP_FONTSIZE, fontSize);
ObjectSetString(0, objName, OBJPROP_FONT, font);
ObjectSetInteger(0, objName, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, objName, OBJPROP_HIDDEN, true);
}チャートテキスト(OBJ_TEXT)の描画
// OBJ_TEXTはチャート座標(時間・価格)に紐づく
void DrawText(string name, datetime time, double price, string text,
color clr = clrWhite, int fontSize = 8,
ENUM_ANCHOR_POINT anchor = ANCHOR_LEFT)
{
string objName = PREFIX + name;
if(ObjectFind(0, objName) < 0)
ObjectCreate(0, objName, OBJ_TEXT, 0, time, price);
else
{
ObjectSetInteger(0, objName, OBJPROP_TIME, time);
ObjectSetDouble(0, objName, OBJPROP_PRICE, price);
}
ObjectSetString(0, objName, OBJPROP_TEXT, text);
ObjectSetInteger(0, objName, OBJPROP_COLOR, clr);
ObjectSetInteger(0, objName, OBJPROP_FONTSIZE, fontSize);
ObjectSetInteger(0, objName, OBJPROP_ANCHOR, anchor);
ObjectSetInteger(0, objName, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, objName, OBJPROP_HIDDEN, true);
}
// 取引の損益をチャート上に表示
void MarkProfit(datetime time, double price, double profit)
{
string name = "PL_" + IntegerToString((int)time);
string text = (profit >= 0 ? "+" : "") + DoubleToString(profit, 2);
color clr = profit >= 0 ? clrLime : clrRed;
DrawText(name, time, price, text, clr, 9);
}ボタン(OBJ_BUTTON)の描画
void DrawButton(string name, int x, int y, int width, int height,
string text, color bgColor = clrDimGray,
color textColor = clrWhite,
ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER)
{
string objName = PREFIX + name;
if(ObjectFind(0, objName) < 0)
ObjectCreate(0, objName, OBJ_BUTTON, 0, 0, 0);
ObjectSetInteger(0, objName, OBJPROP_XDISTANCE, x);
ObjectSetInteger(0, objName, OBJPROP_YDISTANCE, y);
ObjectSetInteger(0, objName, OBJPROP_XSIZE, width);
ObjectSetInteger(0, objName, OBJPROP_YSIZE, height);
ObjectSetInteger(0, objName, OBJPROP_CORNER, corner);
ObjectSetString(0, objName, OBJPROP_TEXT, text);
ObjectSetInteger(0, objName, OBJPROP_COLOR, textColor);
ObjectSetInteger(0, objName, OBJPROP_BGCOLOR, bgColor);
ObjectSetInteger(0, objName, OBJPROP_FONTSIZE, 10);
ObjectSetInteger(0, objName, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, objName, OBJPROP_HIDDEN, true);
}
// ボタンクリックの処理
void OnChartEvent(const int id, const long &lparam,
const double &dparam, const string &sparam)
{
if(id == CHARTEVENT_OBJECT_CLICK)
{
if(sparam == PREFIX + "BuyButton")
{
Print("Buy ボタンがクリックされました");
// ボタンの押下状態をリセット
ObjectSetInteger(0, PREFIX + "BuyButton", OBJPROP_STATE, false);
ChartRedraw(0);
}
else if(sparam == PREFIX + "SellButton")
{
Print("Sell ボタンがクリックされました");
ObjectSetInteger(0, PREFIX + "SellButton", OBJPROP_STATE, false);
ChartRedraw(0);
}
else if(sparam == PREFIX + "CloseAllButton")
{
Print("CloseAll ボタンがクリックされました");
ObjectSetInteger(0, PREFIX + "CloseAllButton", OBJPROP_STATE, false);
ChartRedraw(0);
}
}
}
// ボタンパネルの作成
void CreateTradingPanel()
{
DrawButton("BuyButton", 10, 30, 100, 30, "BUY", clrForestGreen, clrWhite);
DrawButton("SellButton", 120, 30, 100, 30, "SELL", clrCrimson, clrWhite);
DrawButton("CloseAllButton", 10, 70, 210, 30, "CLOSE ALL", clrDimGray, clrWhite);
ChartRedraw(0);
}ObjectFind / ObjectsTotal / ObjectName — オブジェクトの検索と列挙
int ObjectFind(
long chart_id,
string name // オブジェクト名
);
// 戻り値: サブウィンドウ番号(見つからない場合 -1)
int ObjectsTotal(
long chart_id,
int sub_window = -1, // -1=全ウィンドウ
int type = -1 // -1=全タイプ
);
string ObjectName(
long chart_id,
int pos, // インデックス
int sub_window = -1,
int type = -1
);
// チャート上のすべてのオブジェクトを列挙
void ListAllObjects()
{
int total = ObjectsTotal(0);
for(int i = 0; i < total; i++)
{
string name = ObjectName(0, i);
long type = ObjectGetInteger(0, name, OBJPROP_TYPE);
Print(i, ": ", name, " Type=", EnumToString((ENUM_OBJECT)type));
}
}
// 安全なオブジェクト作成(存在確認付き)
void SafeCreateObject(string name, ENUM_OBJECT type,
datetime time1, double price1,
datetime time2 = 0, double price2 = 0)
{
if(ObjectFind(0, name) >= 0)
ObjectDelete(0, name); // 既存を削除
ObjectCreate(0, name, type, 0, time1, price1, time2, price2);
}ObjectMove / ObjectGetTimeByValue / ObjectGetValueByTime
bool ObjectMove(
long chart_id,
string name,
int point_index, // アンカーポイント番号(0, 1, 2...)
datetime time,
double price
);
datetime ObjectGetTimeByValue(
long chart_id,
string name,
double value, // 価格
int line_id = 0
);
double ObjectGetValueByTime(
long chart_id,
string name,
datetime time,
int line_id = 0
);
// トレンドライン上の特定時刻の価格を取得
void CheckTrendLinePrice(string lineName)
{
datetime now = TimeCurrent();
double priceOnLine = ObjectGetValueByTime(0, lineName, now);
double currentBid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
if(currentBid > priceOnLine)
Print("現在価格はトレンドラインの上");
else
Print("現在価格はトレンドラインの下");
}
// 動的にオブジェクトを移動(リアルタイムSL追跡)
void UpdateTrailingSLLine(double newSL)
{
string objName = PREFIX + "TrailingSL";
if(ObjectFind(0, objName) < 0)
{
ObjectCreate(0, objName, OBJ_HLINE, 0, 0, newSL);
ObjectSetInteger(0, objName, OBJPROP_COLOR, clrOrange);
ObjectSetInteger(0, objName, OBJPROP_STYLE, STYLE_DASHDOT);
}
else
ObjectSetDouble(0, objName, OBJPROP_PRICE, newSL);
}実践パターン:EA開発でのオブジェクト活用
パターン1:取引情報パネル
class CInfoPanel
{
private:
string m_prefix;
int m_x, m_y;
int m_lineHeight;
int m_fontSize;
int m_lineCount;
public:
CInfoPanel(string prefix, int x = 10, int y = 20,
int fontSize = 9, int lineHeight = 18)
: m_prefix(prefix), m_x(x), m_y(y),
m_fontSize(fontSize), m_lineHeight(lineHeight), m_lineCount(0) {}
void Clear()
{
ObjectsDeleteAll(0, m_prefix + "info_");
m_lineCount = 0;
}
void AddLine(string text, color clr = clrWhite)
{
string name = m_prefix + "info_" + IntegerToString(m_lineCount);
int yPos = m_y + m_lineCount * m_lineHeight;
if(ObjectFind(0, name) < 0)
ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, name, OBJPROP_XDISTANCE, m_x);
ObjectSetInteger(0, name, OBJPROP_YDISTANCE, yPos);
ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_UPPER);
ObjectSetString(0, name, OBJPROP_TEXT, text);
ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
ObjectSetInteger(0, name, OBJPROP_FONTSIZE, m_fontSize);
ObjectSetString(0, name, OBJPROP_FONT, "Consolas");
ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
m_lineCount++;
}
void Destroy()
{
ObjectsDeleteAll(0, m_prefix + "info_");
}
};
// 使用例
CInfoPanel *panel;
int OnInit()
{
panel = new CInfoPanel("MyEA_", 10, 30);
return INIT_SUCCEEDED;
}
void OnTick()
{
panel.Clear();
panel.AddLine("=== MyEA v2.0 ===", clrGold);
panel.AddLine(StringFormat("Symbol: %s %s", _Symbol, EnumToString(Period())));
panel.AddLine(StringFormat("Spread: %d pt",
(int)SymbolInfoInteger(_Symbol, SYMBOL_SPREAD)));
panel.AddLine(StringFormat("Bid: %.5f", SymbolInfoDouble(_Symbol, SYMBOL_BID)));
panel.AddLine(StringFormat("Ask: %.5f", SymbolInfoDouble(_Symbol, SYMBOL_ASK)));
// ポジション情報
double profit = 0;
int positions = 0;
for(int i = 0; i < PositionsTotal(); i++)
{
ulong ticket = PositionGetTicket(i);
if(PositionGetString(POSITION_SYMBOL) == _Symbol)
{
positions++;
profit += PositionGetDouble(POSITION_PROFIT) + PositionGetDouble(POSITION_SWAP);
}
}
panel.AddLine("---");
panel.AddLine(StringFormat("Positions: %d", positions));
color plColor = profit >= 0 ? clrLime : clrRed;
panel.AddLine(StringFormat("P/L: %.2f %s", profit,
AccountInfoString(ACCOUNT_CURRENCY)), plColor);
ChartRedraw(0);
}
void OnDeinit(const int reason)
{
panel.Destroy();
delete panel;
}パターン2:取引レベルの自動可視化
// ポジションのエントリー・SL・TPラインを自動表示
void VisualizePendingOrder(double entry, double sl, double tp, bool isBuy)
{
color entryColor = isBuy ? clrDodgerBlue : clrOrangeRed;
string dirStr = isBuy ? "Buy" : "Sell";
// エントリーライン
DrawHLine("OrderEntry", entry, entryColor, STYLE_SOLID, 2);
// SLライン + ラベル
if(sl > 0)
{
double slPips = MathAbs(entry - sl) / _Point;
DrawHLine("OrderSL", sl, clrRed, STYLE_DASH, 1);
DrawLabel("SLLabel", 10, 30, StringFormat("SL: %.1f pt", slPips), clrRed, 8);
}
// TPライン + ラベル
if(tp > 0)
{
double tpPips = MathAbs(tp - entry) / _Point;
DrawHLine("OrderTP", tp, clrLime, STYLE_DASH, 1);
DrawLabel("TPLabel", 10, 50, StringFormat("TP: %.1f pt", tpPips), clrLime, 8);
}
// リスクリワードレシオの表示
if(sl > 0 && tp > 0)
{
double rr = MathAbs(tp - entry) / MathAbs(entry - sl);
DrawLabel("RRLabel", 10, 70, StringFormat("R:R = 1:%.1f", rr), clrYellow, 9);
}
ChartRedraw(0);
}
// 矢印マークの描画(エントリー/エグジットマーカー)
void DrawArrow(string name, datetime time, double price,
int arrowCode, color clr, int size = 2)
{
string objName = PREFIX + name;
if(ObjectFind(0, objName) < 0)
ObjectCreate(0, objName, OBJ_ARROW, 0, time, price);
else
{
ObjectSetInteger(0, objName, OBJPROP_TIME, time);
ObjectSetDouble(0, objName, OBJPROP_PRICE, price);
}
ObjectSetInteger(0, objName, OBJPROP_ARROWCODE, arrowCode);
ObjectSetInteger(0, objName, OBJPROP_COLOR, clr);
ObjectSetInteger(0, objName, OBJPROP_WIDTH, size);
ObjectSetInteger(0, objName, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, objName, OBJPROP_HIDDEN, true);
}
// 矢印コード: 233=上矢印, 234=下矢印, 159=チェック, 251=×
void MarkBuyEntry(datetime time, double price)
{ DrawArrow("BuyEntry_" + IntegerToString((int)time), time, price, 233, clrDodgerBlue); }
void MarkSellEntry(datetime time, double price)
{ DrawArrow("SellEntry_" + IntegerToString((int)time), time, price, 234, clrOrangeRed); }オブジェクト関数一覧リファレンス
| 関数 | 機能 | 主な用途 |
|---|---|---|
| ObjectCreate | オブジェクトの作成 | ライン・テキスト・ボタン等の描画 |
| ObjectDelete | オブジェクトの削除 | 単一オブジェクトの除去 |
| ObjectsDeleteAll | 一括削除 | プレフィックス指定でEA固有オブジェクトを一括除去 |
| ObjectFind | オブジェクトの検索 | 存在確認 |
| ObjectSetInteger/Double/String | プロパティ設定 | 色・位置・スタイル等の変更 |
| ObjectGetInteger/Double/String | プロパティ取得 | 現在の設定値の読み取り |
| ObjectGetTimeByValue | 価格→時間変換 | トレンドラインの交差時刻 |
| ObjectGetValueByTime | 時間→価格変換 | 特定時刻のライン上価格 |
| ObjectsTotal | オブジェクト数 | 列挙の準備 |
| ObjectName | 名前の取得 | インデックスからの名前参照 |
| ObjectMove | アンカーポイント移動 | リアルタイムのオブジェクト更新 |
- オブジェクト名にプレフィックスを付けてOnDeinit()で一括削除
- OBJ_LABELはピクセル座標固定、OBJ_TEXTはチャート座標に紐づく
- OBJ_BUTTON+OnChartEventでインタラクティブなGUIを構築可能
- 矩形はOBJPROP_FILL=true、OBJPROP_BACK=trueでゾーン表示に最適
- オブジェクト変更後はChartRedraw()で即時反映
プロが開発したEAをお探しの方は → シストレ.COM EA一覧





