编辑的MT5下单面板,勾了算法交易,能看见不能用为什么?
mt5吧
全部回复
仅看楼主
level 1
龙客衣柜 楼主
编辑的MT5下单面板能看见,允许算法交易也打勾了就是不能用,点击下单,没反应,按下去也不会弹,再点击一下才能弹起来,好像没有下单的指令似得,谁懂回复一下。
//+------------------------------------------------------------------+
//| Simple Order Panel |
//| Copyright 2023, Your Name |
//| https://www.yourwebsite.com |
//+------------------------------------------------------------------+
#property strict
#include <Trade/Trade.mqh> // 引入交易库
// 定义全局变量
input double LotSize = 1; // 默认手数
input int Slippage = 3; // 滑点
input int MagicNumber = 123456; // 魔术号
// 定义按钮和标签
int btnBuy, btnSell, btnClose;
int lblLotSize;
// 创建交易对象
CTrade trade;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// 创建按钮和标签
btnBuy = CreateButton("买入", 4, 20, 60, 30, clrRed, clrWhite);
btnSell = CreateButton("卖出", 64, 20, 60, 30, clrGreen, clrWhite);
btnClose = CreateButton("平 仓", 4, 50, 120, 30, clrGray, clrWhite);
lblLotSize = CreateLabel("Lot Size: " + DoubleToString(LotSize, 2), 10, 10, 200, 20, clrBlack);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// 删除按钮和标签
ObjectDelete(0, "btnBuy");
ObjectDelete(0, "btnSell");
ObjectDelete(0, "btnClose");
ObjectDelete(0, "lblLotSize");
}
//+------------------------------------------------------------------+
//| Expert chart event function |
//+------------------------------------------------------------------+
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
{
// 处理按钮点击事件
if(id == CHARTEVENT_OBJECT_CLICK)
{
if(sparam == "btnBuy")
{
OpenOrder(ORDER_TYPE_BUY);
}
else if(sparam == "btnSell")
{
OpenOrder(ORDER_TYPE_SELL);
}
else if(sparam == "btnClose")
{
CloseAllOrders();
}
}
}
//+------------------------------------------------------------------+
//| 创建按钮函数 |
//+------------------------------------------------------------------+
int CreateButton(string name, int x, int y, int width, int height, color bgColor, color textColor)
{
ObjectCreate(0, name, OBJ_BUTTON, 0, 0, 0);
ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x);
ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y);
ObjectSetInteger(0, name, OBJPROP_XSIZE, width);
ObjectSetInteger(0, name, OBJPROP_YSIZE, height);
ObjectSetInteger(0, name, OBJPROP_BGCOLOR, bgColor);
ObjectSetInteger(0, name, OBJPROP_COLOR, textColor);
ObjectSetString(0, name, OBJPROP_TEXT, name);
return 0;
}
//+------------------------------------------------------------------+
//| 创建标签函数 |
//+------------------------------------------------------------------+
int CreateLabel(string text, int x, int y, int width, int height, color textColor)
{
ObjectCreate(0, text, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, text, OBJPROP_XDISTANCE, x);
ObjectSetInteger(0, text, OBJPROP_YDISTANCE, y);
ObjectSetInteger(0, text, OBJPROP_XSIZE, width);
ObjectSetInteger(0, text, OBJPROP_YSIZE, height);
ObjectSetInteger(0, text, OBJPROP_COLOR, textColor);
ObjectSetString(0, text, OBJPROP_TEXT, text);
return 0;
}
//+------------------------------------------------------------------+
//| 开单函数 |
//+------------------------------------------------------------------+
void OpenOrder(int orderType)
{
double price = (orderType == ORDER_TYPE_BUY) ? SymbolInfoDouble(_Symbol, SYMBOL_ASK) : SymbolInfoDouble(_Symbol, SYMBOL_BID);
trade.Buy(LotSize, _Symbol, price, 0, 0, "Buy Order");
}
//+------------------------------------------------------------------+
//| 平仓所有订单函数 |
//+------------------------------------------------------------------+
void CloseAllOrders()
{
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
ulong ticket = PositionGetTicket(i);
trade.PositionClose(ticket);
}
}
//+------------------------------------------------------------------+
2025年02月20日 12点02分 1
1