pasken:
//| Copyright 2014, MetaQuotes Software Corp. |
//| https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link "https://www.mql4.com"
#property version "1.00"
#property strict
extern string 说明 = "设置锁单";
int start() {
string note = "网格EA" ;
double lotdif ;
int ticketId ;
int EaMagic = 123456;
// if (OrderSymbol() == Symbol() )
// {
double buylot = Balance("buy","lot"); //多单的手数
double sellot = Balance("sell","lot"); //空单的手数
if (buylot>sellot)
{ lotdif = buylot - sellot;
double slot =NormalizeDouble(lotdif,2); //如何保留两位小数???
//脚本不成功invalid lots amount for ordersend function
ticketId = OrderSend(Symbol(), OP_SELL, slot, Bid, 3, 0, 0, note, EaMagic, 0, Blue);
if (ticketId>0)
Alert("锁单成功!");
else
Alert("锁单失败!");
}
else
{ lotdif = sellot - buylot;
double blot =NormalizeDouble(lotdif,2);
ticketId = OrderSend(Symbol(), OP_BUY, blot, Ask, 3, 0, 0, note, EaMagic, 0, Blue);
if (ticketId>0)
Alert("锁单成功!");
else
Alert("锁单失败!");
}
// }
return (0);
}
//账户资金管理函数
//double Balance(buy,banlance) 获取多单盈亏
//double Balance(buy,lot) 获取多单的手数
//double Balance(sell,banlance) 获取空单盈亏
//double Balance(sell,lot) 获取空单的手数
double Balance(string as_0, string as_8)
{
double ld_ret_16 = 0; //声明一个变量,用于接受返回值
//遍历订单,
for (int l_pos_24 = OrdersTotal() - 1; l_pos_24 >= 0; l_pos_24--)
{
if( OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES))
{
//symbol()当前货币
if (OrderSymbol() == Symbol() )
{
//多单
if (as_0 == "buy")
{
if (OrderType() == OP_BUY)
// if (as_8 == "Balance") //多单的盈亏
// ld_ret_16 = ld_ret_16 + OrderProfit() - OrderSwap() - OrderCommission();
if (as_8 == "Lot") //多单的手数
ld_ret_16 += OrderLots();
}
}
//空单
if (as_0 == "sell")
{
if (OrderType() == OP_SELL)
{
// if (as_8 == "Balance") //空单的盈亏
// ld_ret_16 = ld_ret_16 + OrderProfit() - OrderSwap() - OrderCommission() ;
if (as_8 == "Lot") //空单的手数
ld_ret_16 += OrderLots();
}
}
}
}
return (ld_ret_16);
}
有两处明显输入错误:if (as_8 == "Lot"),"Lot"改为"lot"。
程序代码如下,请各位帮帮忙
目前功能非常简陋,所有订单的止损止盈函数未添加
//+------------------------------------------------------------------+
//| 锁单脚本.mq4 |//| Copyright 2014, MetaQuotes Software Corp. |
//| https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link "https://www.mql4.com"
#property version "1.00"
#property strict
extern string 说明 = "设置锁单";
int start() {
string note = "网格EA" ;
double lotdif ;
int ticketId ;
int EaMagic = 123456;
// if (OrderSymbol() == Symbol() )
// {
double buylot = Balance("buy","lot"); //多单的手数
double sellot = Balance("sell","lot"); //空单的手数
if (buylot>sellot)
{ lotdif = buylot - sellot;
double slot =NormalizeDouble(lotdif,2); //如何保留两位小数???
//脚本不成功invalid lots amount for ordersend function
ticketId = OrderSend(Symbol(), OP_SELL, slot, Bid, 3, 0, 0, note, EaMagic, 0, Blue);
if (ticketId>0)
Alert("锁单成功!");
else
Alert("锁单失败!");
}
else
{ lotdif = sellot - buylot;
double blot =NormalizeDouble(lotdif,2);
ticketId = OrderSend(Symbol(), OP_BUY, blot, Ask, 3, 0, 0, note, EaMagic, 0, Blue);
if (ticketId>0)
Alert("锁单成功!");
else
Alert("锁单失败!");
}
// }
return (0);
}
//账户资金管理函数
//double Balance(buy,banlance) 获取多单盈亏
//double Balance(buy,lot) 获取多单的手数
//double Balance(sell,banlance) 获取空单盈亏
//double Balance(sell,lot) 获取空单的手数
double Balance(string as_0, string as_8)
{
double ld_ret_16 = 0; //声明一个变量,用于接受返回值
//遍历订单,
for (int l_pos_24 = OrdersTotal() - 1; l_pos_24 >= 0; l_pos_24--)
{
if( OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES))
{
//symbol()当前货币
if (OrderSymbol() == Symbol() )
{
//多单
if (as_0 == "buy")
{
if (OrderType() == OP_BUY)
// if (as_8 == "Balance") //多单的盈亏
// ld_ret_16 = ld_ret_16 + OrderProfit() - OrderSwap() - OrderCommission();
if (as_8 == "Lot") //多单的手数
ld_ret_16 += OrderLots();
}
}
//空单
if (as_0 == "sell")
{
if (OrderType() == OP_SELL)
{
// if (as_8 == "Balance") //空单的盈亏
// ld_ret_16 = ld_ret_16 + OrderProfit() - OrderSwap() - OrderCommission() ;
if (as_8 == "Lot") //空单的手数
ld_ret_16 += OrderLots();
}
}
}
}
return (ld_ret_16);
}
程序代码如下,请各位帮帮忙
目前功能非常简陋,所有订单的止损止盈函数未添加
//+------------------------------------------------------------------+
//| 锁单脚本.mq4 |//| Copyright 2014, MetaQuotes Software Corp. |
//| https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link "https://www.mql4.com"
#property version "1.00"
#property strict
extern string 说明 = "设置锁单";
int start() {
string note = "网格EA" ;
double lotdif ;
int ticketId ;
int EaMagic = 123456;
// if (OrderSymbol() == Symbol() )
// {
double buylot = Balance("buy","lot"); //多单的手数
double sellot = Balance("sell","lot"); //空单的手数
if (buylot>sellot)
{ lotdif = buylot - sellot;
double slot =NormalizeDouble(lotdif,2); //如何保留两位小数???
//脚本不成功invalid lots amount for ordersend function
ticketId = OrderSend(Symbol(), OP_SELL, slot, Bid, 3, 0, 0, note, EaMagic, 0, Blue);
if (ticketId>0)
Alert("锁单成功!");
else
Alert("锁单失败!");
}
else
{ lotdif = sellot - buylot;
double blot =NormalizeDouble(lotdif,2);
ticketId = OrderSend(Symbol(), OP_BUY, blot, Ask, 3, 0, 0, note, EaMagic, 0, Blue);
if (ticketId>0)
Alert("锁单成功!");
else
Alert("锁单失败!");
}
// }
return (0);
}
//账户资金管理函数
//double Balance(buy,banlance) 获取多单盈亏
//double Balance(buy,lot) 获取多单的手数
//double Balance(sell,banlance) 获取空单盈亏
//double Balance(sell,lot) 获取空单的手数
double Balance(string as_0, string as_8)
{
double ld_ret_16 = 0; //声明一个变量,用于接受返回值
//遍历订单,
for (int l_pos_24 = OrdersTotal() - 1; l_pos_24 >= 0; l_pos_24--)
{
if( OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES))
{
//symbol()当前货币
if (OrderSymbol() == Symbol() )
{
//多单
if (as_0 == "buy")
{
if (OrderType() == OP_BUY)
// if (as_8 == "Balance") //多单的盈亏
// ld_ret_16 = ld_ret_16 + OrderProfit() - OrderSwap() - OrderCommission();
if (as_8 == "Lot") //多单的手数
ld_ret_16 += OrderLots();
}
}
//空单
if (as_0 == "sell")
{
if (OrderType() == OP_SELL)
{
// if (as_8 == "Balance") //空单的盈亏
// ld_ret_16 = ld_ret_16 + OrderProfit() - OrderSwap() - OrderCommission() ;
if (as_8 == "Lot") //空单的手数
ld_ret_16 += OrderLots();
}
}
}
}
return (ld_ret_16);
}