MnQInvestmentDevelopment/MnQInvestment/04_Tutorials/PendingOrderTradeMachine.mq5
super.admin cff55d2704 convert
2025-05-30 15:08:44 +02:00

94 lines
2.7 KiB
MQL5

#include <Trade/Trade.mqh>
input int Trailingpoints = 100;
CTrade trade;
int OnInit()
{
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
}
void OnTick()
{
for(int i = OrdersTotal()-1; i >= 0; i--)
{
ulong orderticket = OrderGetTicket(i);
if (OrderSelect(orderticket) && OrderGetString(ORDER_SYMBOL) == _Symbol)
{
ENUM_ORDER_TYPE ordertype = (ENUM_ORDER_TYPE)OrderGetInteger(ORDER_TYPE);
double OrderPrice = OrderGetDouble(ORDER_PRICE_OPEN);
double orderTP = OrderGetDouble(ORDER_TP);
double orderSL = OrderGetDouble(ORDER_SL);
if(ordertype == ORDER_TYPE_BUY_LIMIT){
double price = SymbolInfoDouble(_Symbol,SYMBOL_ASK) - Trailingpoints * _Point;
if(price > OrderPrice)
{
if(trade.OrderModify(orderticket,price,orderSL,orderTP,ORDER_TIME_GTC,0))
{
Print(__FUNCTION__," > Order#",orderticket," was modified by the pending order trail machine...");
}
}
}
else if(ordertype == ORDER_TYPE_BUY_STOP)
{
double price = SymbolInfoDouble(_Symbol,SYMBOL_ASK) + Trailingpoints * _Point;
if(price < OrderPrice)
{
if(trade.OrderModify(orderticket,price,orderSL,orderTP,ORDER_TIME_GTC,0))
{
Print(__FUNCTION__," > Order#",orderticket," was modified by the pending order trail machine...");
}
}
}
else if(ordertype == ORDER_TYPE_SELL_LIMIT)
{
double price = SymbolInfoDouble(_Symbol,SYMBOL_BID) + Trailingpoints * _Point;
if(price < OrderPrice)
{
if(trade.OrderModify(orderticket,price,orderSL,orderTP,ORDER_TIME_GTC,0))
{
Print(__FUNCTION__," > Order#",orderticket," was modified by the pending order trail machine...");
}
}
}
else if(ordertype == ORDER_TYPE_SELL_STOP)
{
double price = SymbolInfoDouble(_Symbol,SYMBOL_BID) - Trailingpoints * _Point;
if(price > OrderPrice)
{
if(trade.OrderModify(orderticket,price,orderSL,orderTP,ORDER_TIME_GTC,0))
{
Print(__FUNCTION__," > Order#",orderticket," was modified by the pending order trail machine...");
}
}
}
}
}
}