[英]Limit Trade On Each Pair Using MQL4
I want to limit the number or trades/orders in MT4 using my EA in MQL4.我想在 MQL4 中使用我的 EA 来限制 MT4 中的数量或交易/订单。 I want the limit on each pair not on all Pairs, like: If the condition / logic match then 2 trades will be executed on Each currency where the EA is attached.
我想要每对的限制而不是所有的对,例如:如果条件/逻辑匹配,那么将在 EA 附加的每种货币上执行 2 笔交易。
This is the code i tried, but it limits the trades on all pairs where EA has been attached.这是我尝试过的代码,但它限制了所有附加了 EA 的货币对的交易。
//+------------------------------------------------------------------+
//| psar.mq4 |
//| MSZ |
//| nill |
//+------------------------------------------------------------------+
#property copyright "MSZ"
#property link "nill"
#property version "1.00"
#property strict
#define MAX_ORDERS 5
input int TP=10;
input int SL=30;
input double lot=1;
void OnTick()
{
//---
double SAR;
static int Ticket=0;
SAR=iSAR(Symbol(),0,0.02,0.2,0);
if(OrdersTotal()<=MAX_ORDERS)
{
if(SAR>Open[0])
{
Ticket=OrderSend(Symbol(),OP_SELL,lot,Bid,10,Ask+SL*Point,Ask-TP*Point,"Done By MSZ.Inc");
if(Ticket<0)
{
Alert("Error In Opening Order");
}
else
{
Alert("Sell Order Executed");
}
//Alert("Its Sell Signal");
}
else if(SAR<Open[0])
{
Ticket=OrderSend(Symbol(),OP_BUY,lot,Ask,10,Bid-SL*Point,Bid+TP*Point,"Done By MSZ.Inc");
if(Ticket<0)
{
Alert("Error In Opening Order");
}
else
{
Alert("Buy Order Executed");
}
}
}
else
{
Alert("Orders Limits reached");
}
}
//+------------------------------------------------------------------+
I want that it will execute 5 orders on Each Chart where the EA is attached.我希望它会在附加了 EA 的每个图表上执行 5 个订单。
**if(OrdersTotal()<=MAX_ORDERS)**
This may send up to 6 trades due to the = sign.由于 = 符号,这可能会发送多达 6 笔交易。 It will also top up trades either buy or sell at any time until the
<=
condition is met.它还会在满足
<=
条件之前随时补足买入或卖出交易。 To clarify, are you meaning to hedge?澄清一下,你的意思是对冲吗? Your
MAX_ORDERS
is defined as a pre-processor directive.您的
MAX_ORDERS
被定义为预处理器指令。 input int MAX_ORDERS =5;
to be able to change this value.能够改变这个值。
#define MAX_ORDERS 5 在 ea 脚本开头输入 this 后是否需要在脚本后面添加 **if(OrdersTotal()<=MAX_ORDERS
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.