帖子
作者
回复/查看
最后发表
2022-09-06 01:52
2022-08-12 08:41
2022-08-11 08:32
2022-07-24 13:26
2022-07-20 14:13
2022-05-10 14:06
//+------------------------------------------------------------------+
//| OrderSetStop.mq4 |
//| Copyright 2019, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
extern double PriceHigh = 0.0; //过滤订单_上限
extern double PriceLow = 0.0; //过滤订单_下限
extern double BuyStopPrice = 0.0; //多单止损价格
extern double BuyTakePrice = 0.0; //多单止盈价格
extern double SellStopPrice = 0.0; //空单止损价格
extern double SellTakePrice = 0.0; //空单止盈价格
extern bool executeFlag = false;
extern int sleep_ms = 100; //每操作一个单结束休眠多少毫秒
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
int successNumber = 0;
int failedNumber = 0;
int ignoreNumber = 0;
double stopPrice = 0.0;
double takePrice = 0.0;
bool result;
if(executeFlag == true) {
for(int i=OrdersTotal(); i>=0; i--) {
if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
continue;
}
if( (PriceLow > 0.1 && OrderOpenPrice() < PriceLow) || (PriceHigh > 0.1 && OrderOpenPrice() > PriceHigh) ) {
ignoreNumber = ignoreNumber + 1;
}
else if(OrderSymbol() == Symbol() && OrderType() == OP_BUY ) {
if(BuyStopPrice > 0.1) {
stopPrice = BuyStopPrice;
}
else {
stopPrice = OrderStopLoss();
}
if(BuyTakePrice > 0) {
takePrice = BuyTakePrice;
}
else {
takePrice = OrderTakeProfit();
}
result = OrderModify(OrderTicket(), OrderOpenPrice(), stopPrice, takePrice, 0);
if(result == true) {
successNumber = successNumber + 1;
}
else {
failedNumber = failedNumber + 1;
Alert("Order", OrderTicket(), " failed to set long order. Error:", GetLastError());
Sleep(1000);
}
}
else if(OrderSymbol() == Symbol() && OrderType() == OP_SELL ) {
if(SellStopPrice > 0.1) {
stopPrice = SellStopPrice;
}
else {
stopPrice = OrderStopLoss();
}
if(SellTakePrice > 0) {
takePrice = SellTakePrice;
}
else {
takePrice = OrderTakeProfit();
}
result = OrderModify(OrderTicket(), OrderOpenPrice(), stopPrice, takePrice, 0);
if(result == true) {
successNumber = successNumber + 1;
}
else {
failedNumber = failedNumber + 1;
Alert("Order", OrderTicket(), " failed to set short order. Error:", GetLastError());
Sleep(1000);
}
}
else {
ignoreNumber = ignoreNumber + 1;
}
Sleep(sleep_ms);
RefreshRates();
}// end for
executeFlag = false;
Alert("设置止损OK. 成功:", successNumber, ", 失败:", failedNumber, ", 忽略:", ignoreNumber);
}
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
}
//+------------------------------------------------------------------+
2022-05-10 14:04
2022-04-10 00:43
2022-03-28 15:54