|
double 分类单据利润(int type,int magicX,string comm)
{
double 利润=0;
for(int i=0;i<OrdersTotal();i++)
if(OrderSelect(i,SELECT_BY_POS))
if(OrderSymbol()==Symbol())
if(OrderMagicNumber()==magicX || magicX==-1)
if(StringFind(OrderComment(),comm,0)!=-1 || comm=="")
if(
(OrderType()==type || type==-100)
|| (OrderType()<2 && type==-200)
|| (OrderType()>=2 && type==-300)
)
利润+=OrderProfit()+OrderSwap()+OrderCommission();
return(利润);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double 总交易量(int type,int magicX,string comm)
{
double js=0;
for(int i=0;i<OrdersTotal();i++)
if(OrderSelect(i,SELECT_BY_POS))
if(OrderSymbol()==Symbol())
if(OrderMagicNumber()==magicX || magicX==-1)
if(StringFind(OrderComment(),comm,0)!=-1 || comm=="")
if(OrderType()==type || (type==-100 && OrderType()<2))
js+=OrderLots();
return(NormalizeDouble(js,2));
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void 固定位置标签(string 名称,string 内容,int XX,int YX,color C,int 字体大小,int 固定角内)
{
if(内容==EMPTY)
return;
if(ObjectFind(名称)==-1)
{
ObjectDelete(名称);
ObjectCreate(名称,OBJ_LABEL,0,0,0);
}
ObjectSet(名称,OBJPROP_XDISTANCE,XX);
ObjectSet(名称,OBJPROP_YDISTANCE,YX);
ObjectSetText(名称,内容,字体大小,"宋体",C);
ObjectSet(名称,OBJPROP_CORNER,固定角内);
ObjectSetInteger(0,名称,OBJPROP_ANCHOR,ANCHOR_LEFT);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int 建立单据(string 货币对,int 类型,double 单量内,double 价位,double 间隔,double 止损内,double 止盈内,string 备注内,int magicX,color 颜色标记)
{
备注内=备注内+"-"+Period()+"-"+magicX;
if(MarketInfo(货币对,MODE_LOTSTEP)<10)int 单量小数保留内=0;
if(MarketInfo(货币对,MODE_LOTSTEP)<1)单量小数保留内=1;
if(MarketInfo(货币对,MODE_LOTSTEP)<0.1)单量小数保留内=2;
单量内=NormalizeDouble(单量内,单量小数保留内);
if(单量内<MarketInfo(货币对,MODE_MINLOT))
{
laber("低于最低单量",Yellow,0);
return(-1);
}
if(单量内>MarketInfo(货币对,MODE_MAXLOT))
单量内=MarketInfo(货币对,MODE_MAXLOT);
int t;
double POINT=MarketInfo(货币对,MODE_POINT)*系数(货币对);
int DIGITS=MarketInfo(货币对,MODE_DIGITS);
int 滑点内=滑点*系数(货币对);
if(类型==OP_BUY || 类型==OP_SELL)
if(AccountFreeMargin()<单量内*MarketInfo(货币对,MODE_MARGINREQUIRED))
{
Print("保证金不足");
return(-1);
}
if(类型==OP_BUY)
{
t=-1;
for(int ix2=0;ix2<1;ix2++)
if(t==-1)
{
RefreshRates();
t=OrderSend(货币对,OP_BUY,单量内,MarketInfo(货币对,MODE_ASK),滑点内,0,0,备注内,magicX,0,颜色标记);
报错组件("");
if(OrderSelect(t,SELECT_BY_TICKET))
{
if(止损内!=0 && 止盈内!=0)
for(int ix=0;ix<3;ix++)
if(OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-止损内 *POINT,DIGITS),NormalizeDouble(OrderOpenPrice()+止盈内 *POINT,DIGITS),0))
break;
if(止损内==0 && 止盈内!=0)
for(ix=0;ix<3;ix++)
if(OrderModify(OrderTicket(),OrderOpenPrice(),0,NormalizeDouble(OrderOpenPrice()+止盈内 *POINT,DIGITS),0))
break;
if(止损内!=0 && 止盈内==0)
for(ix=0;ix<3;ix++)
if(OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-止损内 *POINT,DIGITS),0,0))
break;
报错组件("");
}
}
}
if(类型==OP_SELL)
{
t=-1;
for(ix2=0;ix2<1;ix2++)
if(t==-1)
{
RefreshRates();
t=OrderSend(货币对,OP_SELL,单量内,MarketInfo(货币对,MODE_BID),滑点内,0,0,备注内,magicX,0,颜色标记);
报错组件("");
if(OrderSelect(t,SELECT_BY_TICKET))
{
if(止损内!=0 && 止盈内!=0)
for(ix=0;ix<3;ix++)
if(OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+止损内 *POINT,DIGITS),NormalizeDouble(OrderOpenPrice()-止盈内 *POINT,DIGITS),0))
break;
if(止损内==0 && 止盈内!=0)
for(ix=0;ix<3;ix++)
if(OrderModify(OrderTicket(),OrderOpenPrice(),0,NormalizeDouble(OrderOpenPrice()-止盈内 *POINT,DIGITS),0))
break;
if(止损内!=0 && 止盈内==0)
for(ix=0;ix<3;ix++)
if(OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+止损内 *POINT,DIGITS),0,0))
break;
}
报错组件("");
}
}
if(类型==OP_BUYLIMIT || 类型==OP_BUYSTOP)
{
t=-1;
for(ix2=0;ix2<1;ix2++)
if(t==-1)
{
if(价位==0)
{
RefreshRates();
价位=MarketInfo(货币对,MODE_ASK);
}
if(类型==OP_BUYLIMIT)
{
if(止损内!=0 && 止盈内!=0)
t=OrderSend(货币对,OP_BUYLIMIT,单量内,NormalizeDouble(价位-间隔*POINT,DIGITS),滑点内,NormalizeDouble(价位-间隔*POINT-止损内 *POINT,DIGITS),NormalizeDouble(价位-间隔*POINT+止盈内 *POINT,DIGITS),备注内,magicX,0,颜色标记);
if(止损内==0 && 止盈内!=0)
t=OrderSend(货币对,OP_BUYLIMIT,单量内,NormalizeDouble(价位-间隔*POINT,DIGITS),滑点内,0,NormalizeDouble(价位-间隔*POINT+止盈内 *POINT,DIGITS),备注内,magicX,0,颜色标记);
if(止损内!=0 && 止盈内==0)
t=OrderSend(货币对,OP_BUYLIMIT,单量内,NormalizeDouble(价位-间隔*POINT,DIGITS),滑点内,NormalizeDouble(价位-间隔*POINT-止损内 *POINT,DIGITS),0,备注内,magicX,0,颜色标记);
if(止损内==0 && 止盈内==0)
t=OrderSend(货币对,OP_BUYLIMIT,单量内,NormalizeDouble(价位-间隔*POINT,DIGITS),滑点内,0,0,备注内,magicX,0,颜色标记);
}
if(类型==OP_BUYSTOP)
{
if(止损内!=0 && 止盈内!=0)
t=OrderSend(货币对,OP_BUYSTOP,单量内,NormalizeDouble(价位+间隔*POINT,DIGITS),滑点内,NormalizeDouble(价位+间隔*POINT-止损内 *POINT,DIGITS),NormalizeDouble(价位+间隔*POINT+止盈内 *POINT,DIGITS),备注内,magicX,0,颜色标记);
if(止损内==0 && 止盈内!=0)
t=OrderSend(货币对,OP_BUYSTOP,单量内,NormalizeDouble(价位+间隔*POINT,DIGITS),滑点内,0,NormalizeDouble(价位+间隔*POINT+止盈内 *POINT,DIGITS),备注内,magicX,0,颜色标记);
if(止损内!=0 && 止盈内==0)
t=OrderSend(货币对,OP_BUYSTOP,单量内,NormalizeDouble(价位+间隔*POINT,DIGITS),滑点内,NormalizeDouble(价位+间隔*POINT-止损内 *POINT,DIGITS),0,备注内,magicX,0,颜色标记);
if(止损内==0 && 止盈内==0)
t=OrderSend(货币对,OP_BUYSTOP,单量内,NormalizeDouble(价位+间隔*POINT,DIGITS),滑点内,0,0,备注内,magicX,0,颜色标记);
}
报错组件("");
}
}
if(类型==OP_SELLLIMIT || 类型==OP_SELLSTOP)
{
t=-1;
for(ix2=0;ix2<1;ix2++)
if(t==-1)
{
if(价位==0)
{
RefreshRates();
价位=MarketInfo(货币对,MODE_BID);
}
if(类型==OP_SELLSTOP)
{
if(止损内!=0 && 止盈内!=0)
t=OrderSend(货币对,OP_SELLSTOP,单量内,NormalizeDouble(价位-间隔*POINT,DIGITS),滑点内,NormalizeDouble(价位-间隔*POINT+止损内 *POINT,DIGITS),NormalizeDouble(价位-间隔*POINT-止盈内 *POINT,DIGITS),备注内,magicX,0,颜色标记);
if(止损内==0 && 止盈内!=0)
t=OrderSend(货币对,OP_SELLSTOP,单量内,NormalizeDouble(价位-间隔*POINT,DIGITS),滑点内,0,NormalizeDouble(价位-间隔*POINT-止盈内 *POINT,DIGITS),备注内,magicX,0,颜色标记);
if(止损内!=0 && 止盈内==0)
t=OrderSend(货币对,OP_SELLSTOP,单量内,NormalizeDouble(价位-间隔*POINT,DIGITS),滑点内,NormalizeDouble(价位-间隔*POINT+止损内 *POINT,DIGITS),0,备注内,magicX,0,颜色标记);
if(止损内==0 && 止盈内==0)
t=OrderSend(货币对,OP_SELLSTOP,单量内,NormalizeDouble(价位-间隔*POINT,DIGITS),滑点内,0,0,备注内,magicX,0,颜色标记);
}
if(类型==OP_SELLLIMIT)
{
if(止损内!=0 && 止盈内!=0)
t=OrderSend(货币对,OP_SELLLIMIT,单量内,NormalizeDouble(价位+间隔*POINT,DIGITS),滑点内,NormalizeDouble(价位+间隔*POINT+止损内 *POINT,DIGITS),NormalizeDouble(价位+间隔*POINT-止盈内 *POINT,DIGITS),备注内,magicX,0,颜色标记);
if(止损内==0 && 止盈内!=0)
t=OrderSend(货币对,OP_SELLLIMIT,单量内,NormalizeDouble(价位+间隔*POINT,DIGITS),滑点内,0,NormalizeDouble(价位+间隔*POINT-止盈内 *POINT,DIGITS),备注内,magicX,0,颜色标记);
if(止损内!=0 && 止盈内==0)
t=OrderSend(货币对,OP_SELLLIMIT,单量内,NormalizeDouble(价位+间隔*POINT,DIGITS),滑点内,NormalizeDouble(价位+间隔*POINT+止损内 *POINT,DIGITS),0,备注内,magicX,0,颜色标记);
if(止损内==0 && 止盈内==0)
t=OrderSend(货币对,OP_SELLLIMIT,单量内,NormalizeDouble(价位+间隔*POINT,DIGITS),滑点内,0,0,备注内,magicX,0,颜色标记);
}
报错组件("");
}
}
return(t);
}
double 滑点=30;
input bool 是否显示文字标签=true;
input bool 国际点差自适应=true;
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
double 系数(string symbol)
{
int 系数=1;
if(
MarketInfo(symbol,MODE_DIGITS)==3
|| MarketInfo(symbol,MODE_DIGITS)==5
|| (StringFind(symbol,"XAU",0)==0 && MarketInfo(symbol,MODE_DIGITS)==2)
||(StringFind(symbol,"GOLD",0)==0&&MarketInfo(symbol,MODE_DIGITS)==2)
||(StringFind(symbol,"Gold",0)==0&&MarketInfo(symbol,MODE_DIGITS)==2)
|| (StringFind(symbol,"USD_GLD",0)==0 && MarketInfo(symbol,MODE_DIGITS)==2)
)系数=10;
if(StringFind(symbol,"XAU",0)==0 && MarketInfo(symbol,MODE_DIGITS)==3)系数=100;
if(StringFind(symbol,"GOLD",0)==0 && MarketInfo(symbol,MODE_DIGITS)==3)系数=100;
if(StringFind(symbol,"Gold",0)==0 && MarketInfo(symbol,MODE_DIGITS)==3)系数=100;
if(StringFind(symbol,"USD_GLD",0)==0 && MarketInfo(symbol,MODE_DIGITS)==3)系数=100;
if(国际点差自适应==false)
return(1);
return(系数);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void laber(string a,color b,int jl)
{
Print(a);
if(IsOptimization())
return;
if(是否显示文字标签==true)
{
int pp=WindowBarsPerChart();
double hh=High[iHighest(Symbol(),0,MODE_HIGH,pp,0)];
double ll=Low[iLowest(Symbol(),0,MODE_LOW,pp,0)];
double 文字小距离=(hh-ll)*0.03;
ObjectDelete("箭头"+TimeToStr(Time[0],TIME_DATE|TIME_MINUTES)+a);
ObjectCreate("箭头"+TimeToStr(Time[0],TIME_DATE|TIME_MINUTES)+a,OBJ_TEXT,0,Time[0],Low[0]-jl*文字小距离);
ObjectSetText("箭头"+TimeToStr(Time[0],TIME_DATE|TIME_MINUTES)+a,a,8,"Times New Roman",b);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void 报错组件(string a)
{
RefreshRates();
if(IsOptimization())
return;
int t=GetLastError();
string 报警;
if(t!=0)
switch(t)
{
//case 0:报警="错误代码:"+(string)0+"没有错误返回";break;
//case 1:报警="错误代码:"+(string)1+"没有错误返回但结果不明";break;
//case 2:报警="错误代码:"+(string)2+"一般错误";break;
//case 3:报警="错误代码:"+(string)3+"无效交易参量";break;
case 4:报警="错误代码:"+(string)4+"交易服务器繁忙";break;
case 5:报警="错误代码:"+(string)5+"客户终端旧版本";break;
case 6:报警="错误代码:"+(string)6+"没有连接服务器";break;
case 7:报警="错误代码:"+(string)7+"没有权限";break;
//case 8:报警="错误代码:"+(string)8+"请求过于频繁";break;
case 9:报警="错误代码:"+(string)9+"交易运行故障";break;
case 64:报警="错误代码:"+(string)64+"账户禁止";break;
case 65:报警="错误代码:"+(string)65+"无效账户";break;
// case 128:报警="错误代码:"+(string)128+"交易超时";break;
//case 129:报警="错误代码:"+(string)129+"无效价格";break;
case 130:报警="错误代码:"+(string)130+"无效停止";break;
//case 131:报警="错误代码:"+(string)131+"无效交易量";break;
case 132:报警="错误代码:"+(string)132+"市场关闭";break;
case 133:报警="错误代码:"+(string)133+"交易被禁止";break;
case 134:报警="错误代码:"+(string)134+"资金不足";break;
case 135:报警="错误代码:"+(string)135+"价格改变";break;
//case 136:报警="错误代码:"+(string)136+"开价";break;
case 137:报警="错误代码:"+(string)137+"经纪繁忙";break;
//case 138:报警="错误代码:"+(string)138+"重新开价";break;
case 139:报警="错误代码:"+(string)139+"定单被锁定";break;
case 140:报警="错误代码:"+(string)140+"只允许看涨仓位";break;
//case 141:报警="错误代码:"+(string)141+"过多请求";break;
//case 145:报警="错误代码:"+(string)145+"因为过于接近市场,修改否定";break;
//case 146:报警="错误代码:"+(string)146+"交易文本已满";break;
case 147:报警="错误代码:"+(string)147+"时间周期被经纪否定";break;
case 148:报警="错误代码:"+(string)148+"开单和挂单总数已被经纪限定";break;
case 149:报警="错误代码:"+(string)149+"当对冲备拒绝时,打开相对于现有的一个单置";break;
case 150:报警="错误代码:"+(string)150+"把为反FIFO规定的单子平掉";break;
case 4000:报警="错误代码:"+(string)4000+"没有错误";break;
case 4001:报警="错误代码:"+(string)4001+"错误函数指示";break;
case 4002:报警="错误代码:"+(string)4002+"数组索引超出范围";break;
case 4003:报警="错误代码:"+(string)4003+"对于调用堆栈储存器函数没有足够内存";break;
case 4004:报警="错误代码:"+(string)4004+"循环堆栈储存器溢出";break;
case 4005:报警="错误代码:"+(string)4005+"对于堆栈储存器参量没有内存";break;
case 4006:报警="错误代码:"+(string)4006+"对于字行参量没有足够内存";break;
case 4007:报警="错误代码:"+(string)4007+"对于字行没有足够内存";break;
//case 4008:报警="错误代码:"+(string)4008+"没有初始字行";break;
case 4009:报警="错误代码:"+(string)4009+"在数组中没有初始字串符";break;
case 4010:报警="错误代码:"+(string)4010+"对于数组没有内存";break;
case 4011:报警="错误代码:"+(string)4011+"字行过长";break;
case 4012:报警="错误代码:"+(string)4012+"余数划分为零";break;
case 4013:报警="错误代码:"+(string)4013+"零划分";break;
case 4014:报警="错误代码:"+(string)4014+"不明命令";break;
case 4015:报警="错误代码:"+(string)4015+"错误转换(没有常规错误)";break;
case 4016:报警="错误代码:"+(string)4016+"没有初始数组";break;
case 4017:报警="错误代码:"+(string)4017+"禁止调用DLL ";break;
case 4018:报警="错误代码:"+(string)4018+"数据库不能下载";break;
case 4019:报警="错误代码:"+(string)4019+"不能调用函数";break;
case 4020:报警="错误代码:"+(string)4020+"禁止调用智能交易函数";break;
case 4021:报警="错误代码:"+(string)4021+"对于来自函数的字行没有足够内存";break;
case 4022:报警="错误代码:"+(string)4022+"系统繁忙 (没有常规错误)";break;
case 4050:报警="错误代码:"+(string)4050+"无效计数参量函数";break;
case 4051:报警="错误代码:"+(string)4051+"无效参量值函数";break;
case 4052:报警="错误代码:"+(string)4052+"字行函数内部错误";break;
case 4053:报警="错误代码:"+(string)4053+"一些数组错误";break;
case 4054:报警="错误代码:"+(string)4054+"应用不正确数组";break;
case 4055:报警="错误代码:"+(string)4055+"自定义指标错误";break;
case 4056:报警="错误代码:"+(string)4056+"不协调数组";break;
case 4057:报警="错误代码:"+(string)4057+"整体变量过程错误";break;
case 4058:报警="错误代码:"+(string)4058+"整体变量未找到";break;
case 4059:报警="错误代码:"+(string)4059+"测试模式函数禁止";break;
case 4060:报警="错误代码:"+(string)4060+"没有确认函数";break;
case 4061:报警="错误代码:"+(string)4061+"发送邮件错误";break;
case 4062:报警="错误代码:"+(string)4062+"字行预计参量";break;
case 4063:报警="错误代码:"+(string)4063+"整数预计参量";break;
case 4064:报警="错误代码:"+(string)4064+"双预计参量";break;
case 4065:报警="错误代码:"+(string)4065+"数组作为预计参量";break;
case 4066:报警="错误代码:"+(string)4066+"刷新状态请求历史数据";break;
case 4067:报警="错误代码:"+(string)4067+"交易函数错误";break;
case 4099:报警="错误代码:"+(string)4099+"文件结束";break;
case 4100:报警="错误代码:"+(string)4100+"一些文件错误";break;
case 4101:报警="错误代码:"+(string)4101+"错误文件名称";break;
case 4102:报警="错误代码:"+(string)4102+"打开文件过多";break;
case 4103:报警="错误代码:"+(string)4103+"不能打开文件";break;
case 4104:报警="错误代码:"+(string)4104+"不协调文件";break;
case 4105:报警="错误代码:"+(string)4105+"没有选择定单";break;
case 4106:报警="错误代码:"+(string)4106+"不明货币对";break;
case 4107:报警="错误代码:"+(string)4107+"无效价格";break;
case 4108:报警="错误代码:"+(string)4108+"无效定单编码";break;
case 4109:报警="错误代码:"+(string)4109+"不允许交易";break;
case 4110:报警="错误代码:"+(string)4110+"不允许长期";break;
case 4111:报警="错误代码:"+(string)4111+"不允许短期";break;
case 4200:报警="错误代码:"+(string)4200+"定单已经存在";break;
case 4201:报警="错误代码:"+(string)4201+"不明定单属性";break;
//case 4202:报警="错误代码:"+(string)4202+"定单不存在";break;
case 4203:报警="错误代码:"+(string)4203+"不明定单类型";break;
case 4204:报警="错误代码:"+(string)4204+"没有定单名称";break;
case 4205:报警="错误代码:"+(string)4205+"定单坐标错误";break;
case 4206:报警="错误代码:"+(string)4206+"没有指定子窗口";break;
case 4207:报警="错误代码:"+(string)4207+"定单一些函数错误";break;
case 4250:报警="错误代码:"+(string)4250+"错误设定发送通知到队列中";break;
case 4251:报警="错误代码:"+(string)4251+"无效参量- 空字符串传递到SendNotification()函数";break;
case 4252:报警="错误代码:"+(string)4252+"无效设置发送通知(未指定ID或未启用通知)";break;
case 4253:报警="错误代码:"+(string)4253+"通知发送过于频繁";break;
}
if(t!=0)
{
while(IsTradeContextBusy())
Sleep(300);
Print(a+报警);
laber(a+报警,Yellow,0);
}
}
string JLA[999];
double JLB[999];
datetime JLC[999];
string JLD[999];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+(接下一楼) |
|