mql4写一个输入框开单的时候将 输入框的值加上货币对名称写入订单备注中。再写一个根据输入框的前缀关闭的按钮。
以下是一个使用MQL4编写的示例代码,实现了一个带有输入框和按钮的简单界面。在开单时,会将输入框的值加上货币对名称写入订单备注中。同时,通过点击按钮可以根据输入框的前缀关闭。
//+------------------------------------------------------------------+
//| InputBoxDemo.mq4 |
//| Copyright 2022, MetaQuotes Software Corp. |
//| https://mql4.com |
//+------------------------------------------------------------------+
#property strict
input string PairName = "EURUSD";
input string Prefix = "CLOSE";
string inputText = "";
bool buttonClicked = false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// 创建输入框
int inputBox = InputBox("输入框", "请输入值", inputText, 100, 0, 0);
if (inputBox == 2) {
// 点击取消按钮,终止脚本
return INIT_FAILED;
}
// 创建按钮
int button = ButtonCreate("关闭订单", 0, 0);
return INIT_SUCCEEDED;
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
void OnTick()
{
if (buttonClicked) {
CloseOrdersByPrefix();
buttonClicked = false;
}
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// 删除按钮
ButtonDelete(0);
}
//+------------------------------------------------------------------+
//| Event handler function for button click |
//+------------------------------------------------------------------+
void OnButtonClick(const int button)
{
if (button == 0) {
buttonClicked = true;
}
}
//+------------------------------------------------------------------+
//| Close orders by prefix |
//+------------------------------------------------------------------+
void CloseOrdersByPrefix()
{
int total = OrdersTotal();
for (int i = total - 1; i >= 0; i--) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
string orderSymbol = OrderSymbol();
if (StringFind(orderSymbol, Prefix, 0) == 0) {
OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 3, CLR_NONE);
}
}
}
}
//+------------------------------------------------------------------+
//| Create a button |
//+------------------------------------------------------------------+
int ButtonCreate(string text, int x, int y)
{
int button = EventChartCustom(EVENT_OBJECT_CREATE, 0, 0, 0, 0);
if (button > 0) {
EventChartCustom(EVENT_OBJECT_TYPE, button, OBJ_BUTTON, 0, 0);
EventChartCustom(EVENT_OBJECT_XPOSITION, button, x, 0, 0);
EventChartCustom(EVENT_OBJECT_YPOSITION, button, y, 0, 0);
EventChartCustom(EVENT_OBJECT_CLICK, button, 1, 0, 0);
EventChartCustom(EVENT_OBJECT_TOOLTIP, button, 1, 0, 0);
EventChartCustom(EVENT_OBJECT_TEXT, button, 0, 0, text);
}
return button;
}
//+------------------------------------------------------------------+
//| Delete a button |
//+------------------------------------------------------------------+
void ButtonDelete(int button)
{
EventChartCustom(EVENT_OBJECT_DELETE, button, 0, 0, 0);
}
//+------------------------------------------------------------------+
//| Create an input box |
//+------------------------------------------------------------------+
int InputBox(string caption, string prompt, string& value, int x, int y, int flags)
{
EventChartCustom(EVENT_OBJECT_CREATE, 0, 0, 0, 0);
EventChartCustom(EVENT_OBJECT_TYPE, OBJ_EDIT, OBJ_EDIT, 0, 0);
EventChartCustom(EVENT_OBJECT_XPOSITION, 0, x, 0, 0);
EventChartCustom(EVENT_OBJECT_YPOSITION, 0, y, 0, 0);
EventChartCustom(EVENT_OBJECT_XSIZE, 0, 150, 0, 0);
EventChartCustom(EVENT_OBJECT_YSIZE, 0, 20, 0, 0);
EventChartCustom(EVENT_OBJECT_TOOLTIP, 0, 1, 0, 0);
EventChartCustom(EVENT_OBJECT_TEXT, 0, 0, 0, caption);
EventChartCustom(EVENT_OBJECT_PROP, 0, 0, 0, flags);
EventChartCustom(EVENT_OBJECT_PROP, 0, 1, 0, prompt);
EventChartCustom(EVENT_OBJECT_PROP, 0, 2, 0, value);
return EventChartCustom(EVENT_OBJECT_VALUE, 0, 0, 0, 0);
}
请注意,以上代码是一个简化的示例,可能需要根据您的实际需求进行修改和扩展
原文地址: http://www.cveoy.top/t/topic/iJHM 著作权归作者所有。请勿转载和采集!