索引
1、在屏幕上表明文字标签
void iDisplayInfo(string LableName,string LableDoc,int Corner,int LableX,int LableY,int DocSize,string DocStyle,color DocColor);
2、金额转换手数
double iFundsToHands(string mySymbol,double myFunds);
3、订单净值转换点数
int iOrderEquitToPoint(int myTicket);
4、表明错误信息
tring iGetErrorInfo(int myErrorNum);
5、交易繁忙,程序等候,更新缓存报告
void iWait(int myDelayTime);
6、有效时间段
ool iValidTime(string myStartTime,string myEndTime,bool myServerTime);
7、计算特定条件的订单
int iOrdersSort(int myOrderType,int myOrderSort,int myMaxMin,int myMagicNum);
8、持仓单数量统计
int iOrderStatistics(int myOrderType,int myMagicNum);
9、物件颜色
color iObjectColor(double myInput);
10、持仓单开仓量总计
int iGroupLots(int myOrderType,int myMagicNum);
11、持仓单净值总计
double iGroupEquity(int myOrderType,int myMagicNum);
12、开仓量整形
double iLotsFormat(double myLots);
13、批量清仓
void iBatchClose(int myType,double myLots,int myMagicNum);
14、标注符号和画线、文字
void iDrawSign(string myType,int myBarPos,double myPrice,color myColor,int mySymbol,string myString,int myDocSize);
15、时间周期转换字符
tring iTimeFrameToString(int myTimeFrame);
16、文件操作
void iFileOperation(string myFileName,string myString,int myFileType,int myFileMode);
void iFileOperation(string myFileName,int myFileType,int myFileMode,string myFileString)
{
int myHandle; //文件序列号
if (myFileMode==0 && myFileString=="") //新建文件
{
if (myFileType==0) myHandle=FileOpen(myFileName,FILE_BIN|FILE_WRITE);
if (myFileType==1) myHandle=FileOpen(myFileName,FILE_CSV|FILE_WRITE,";");
FileClose(myHandle);
}
if (myFileMode==1 && myFileString!="") //创建写入字符串
{
if (myFileType==0) myHandle=FileOpen(myFileName,FILE_BIN|FILE_WRITE);
if (myFileType==1) myHandle=FileOpen(myFileName,FILE_CSV|FILE_WRITE,";");
FileWrite(myHandle,myFileString);
FileClose(myHandle);
}
if (myFileMode==2 && myFileString!="") //追加写入字符串
{
if (myFileType==0)
{
myHandle=FileOpen(myFileName,FILE_BIN|FILE_READ|FILE_WRITE);
FileSeek(myHandle,0,SEEK_END);
FileWrite(myHandle,myFileString);
FileClose(myHandle);
}
if (myFileType==1)
{
myHandle=FileOpen(myFileName,FILE_CSV|FILE_READ|FILE_WRITE,";");
FileSeek(myHandle,SEEK_SET,SEEK_END);
FileWrite(myHandle,myFileString);
FileClose(myHandle);
}
}
return(0);
}
tring iTimeFrameToString(int myTimeFrame)
{
witch(myTimeFrame)
{
case 1:
return("M1");
reak;
case 5:
return("M5");
reak;
case 15:
return("M15");
reak;
case 30:
return("M30");
reak;
case 60:
return("H1");
reak;
case 240:
return("H4");
reak;
case 1440:
return("D1");
reak;
case 10080:
return("W1");
reak;
case 43200:
return("MN1");
reak;
}
}
void iDrawSign(string myType,int myBarPos,double myPrice,color myColor,int mySymbol,string myString,int myDocSize)
{
if (myType=="Text")
{
tring TextBarString=myType+Time[myBarPos];
ObjectCreate(TextBarString,OBJ_TEXT,0,Time[myBarPos],myPrice);
ObjectSet(TextBarString,OBJPROP_COLOR,myColor);
//颜色ObjectSet(TextBarString,OBJPROP_FONTSIZE,myDocSize);
//大小ObjectSetText(TextBarString,myString);
//文字内容ObjectSet(TextBarString,OBJPROP_BACK,false);
}
if (myType=="Dot")
{
tring DotBarString=myType+Time[myBarPos];
ObjectCreate(DotBarString,OBJ_ARROW,0,Time[myBarPos],myPrice);
ObjectSet(DotBarString,OBJPROP_COLOR,myColor);
ObjectSet(DotBarString,OBJPROP_ARROWCODE,mySymbol);
ObjectSet(DotBarString,OBJPROP_BACK,false);
}
if (myType=="HLine")
{
tring HLineBarString=myType+Time[myBarPos];
ObjectCreate(HLineBarString,OBJ_HLINE,0,Time[myBarPos],myPrice);
ObjectSet(HLineBarString,OBJPROP_COLOR,myColor);
ObjectSet(HLineBarString,OBJPROP_BACK,false);
}
if (myType=="VLine")
{
tring VLineBarString=myType+Time[myBarPos];
ObjectCreate(VLineBarString,OBJ_VLINE,0,Time[myBarPos],myPrice);
ObjectSet(VLineBarString,OBJPROP_COLOR,myColor);
ObjectSet(VLineBarString,OBJPROP_BACK,false);
}
}
void iBatchClose(int myType,double myLots,int myMagicNum)
{
for (int cnt=0;cnt
{
if (OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber()==myMagicNum && OrderSymbol()==Symbol())
{
iWait(1000);
if ((myType==OP_BUY || (myType==9 && OrderType()==OP_BUY)) && (myLots==0 || myLots>OrderLots()))
{
myLots=OrderLots();
OrderClose(OrderTicket(),myLots,Bid,0);
}
if ((myType==OP_SELL || (myType==9 && OrderType()==OP_SELL)) && (myLots==0 || myLots>OrderLots()))
{
myLots=OrderLots();
OrderClose(OrderTicket(),myLots,Ask,0);
}
if (myType==OP_BUYLIMIT || myType==OP_SELLLIMIT || myType==OP_BUYSTOP || myType==OP_SELLSTOP
(myType==9 && (OrderType()==OP_BUYLIMIT || OrderType()==OP_SELLLIMIT || OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP)))
{
OrderDelete(OrderTicket());
}
}
}
return(0);
}
double iLotsFormat(double myLots)
{
myLots=MathRound(myLots/MarketInfo(Symbol(), MODE_MINLOT))*MarketInfo(Symbol(), MODE_MINLOT);
//开仓量整形return(myLots);
}
double iGroupEquity(int myOrderType,int myMagicNum)
{
double myReturn;
if (OrdersTotal()==0) return(0);
for (int cnt=0;cnt
{
if (OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)
amp;& OrderMagicNumber()==myMagicNum && OrderSymbol()==Symbol() && OrderType()==myOrderType)
{
myReturn=myReturn+OrderProfit();
}
}
return(myReturn);
}
double iGroupLots(int myOrderType,int myMagicNum)
{
double myReturn;
if (OrdersTotal()==0) return(0);
for (int cnt=0;cnt
{
if (OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)
amp;& OrderMagicNumber()==myMagicNum && OrderSymbol()==Symbol() && OrderType()==myOrderType)
{
myReturn=myReturn+OrderLots();
}
}
return(myReturn);
}
color iObjectColor(double myInput)
{
color myColor;
if (myInput > 0)
myColor = Green; //正值颜色为绿色
if (myInput < 0)
myColor = Red; //负值颜色为红色
if (myInput == 0)
myColor = DarkGray; //0颜色为灰色
return(myColor);
}
int iOrderStatistics(int myOrderType,int myMagicNum)
{
int myReturn;
if (OrdersTotal()==0) return(0);
for (int cnt=0;cnt
{
if (OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)
amp;& OrderMagicNumber()==myMagicNum && OrderSymbol()==Symbol() && OrderType()==myOrderType)
{
myReturn=myReturn+1;
}
}
return(myReturn);
}
int iOrdersSort(int myOrderType,int myOrderSort,int myMaxMin,int myMagicNum)
{
int myReturn,myArrayRange,cnt,i,j;
if (OrdersTotal()<=0) return(myReturn);
myArrayRange=OrdersTotal();
//持仓订单基本信息:0订单号,1开仓时间,2订单利润,3订单类型,4开仓量,5开仓价,
// 6止损价,7止赢价,8订单特质码,9订单佣金,10掉期,11挂单有效日期
double myOrdersArray[][12]; //定义订单数组,第1维:订单序号;第2维:订单信息
ArrayResize(myOrdersArray,myArrayRange);
//从新界定订单数组ArrayInitialize(myOrdersArray, 0.0);
//初始化订单数组//订单数组赋值
for (cnt=0; cnt
{
//选中目前货币对有关持仓订单
if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==myMagicNum)
{
myOrdersArray[cnt][0]=OrderTicket();
//0订单号myOrdersArray[cnt][1]=OrderOpenTime();
//1开仓时间myOrdersArray[cnt][2]=OrderProfit();
//2订单利润myOrdersArray[cnt][3]=OrderType();
//3订单类型myOrdersArray[cnt][4]=OrderLots();
//4开仓量myOrdersArray[cnt][5]=OrderOpenPrice();
//5开仓价myOrdersArray[cnt][6]=OrderStopLoss();
//6止损价myOrdersArray[cnt][7]=OrderTakeProfit();
//7止赢价myOrdersArray[cnt][8]=OrderMagicNumber();
//8订单特质码myOrdersArray[cnt][9]=OrderCommission();
//9订单佣金myOrdersArray[cnt][10]=OrderSwap();
//10掉期myOrdersArray[cnt][11]=OrderExpiration();
//11挂单有效日期}
}
double myTempArray[12]; //定义临时数组
//ArrayResize(myTempArray,myArrayRange);
//从新界定临时数组ArrayInitialize(myTempArray, 0.0);
//初始化临时数组//开始按条件排序
//---- 按时间降序排列数组,原始数组从新排序
if (myOrderSort==0)
{
for (i=0;i<=myArrayRange;i++)
{
for (j=myArrayRange;j>i;j--)
{
if (myOrdersArray[j][1]>myOrdersArray[j-1][1])
{
myTempArray[0]=myOrdersArray[j-1][0];
myTempArray[1]=myOrdersArray[j-1][1];
myTempArray[2]=myOrdersArray[j-1][2];
myTempArray[3]=myOrdersArray[j-1][3];
myTempArray[4]=myOrdersArray[j-1][4];
myTempArray[5]=myOrdersArray[j-1][5];
myTempArray[6]=myOrdersArray[j-1][6];
myTempArray[7]=myOrdersArray[j-1][7];
myTempArray[8]=myOrdersArray[j-1][8];
myTempArray[9]=myOrdersArray[j-1][9];
myTempArray[10]=myOrdersArray[j-1][10];
myTempArray[11]=myOrdersArray[j-1][11];
myOrdersArray[j-1][0]=myOrdersArray[j][0];
myOrdersArray[j-1][1]=myOrdersArray[j][1];
myOrdersArray[j-1][2]=myOrdersArray[j][2];
myOrdersArray[j-1][3]=myOrdersArray[j][3];
myOrdersArray[j-1][4]=myOrdersArray[j][4];
myOrdersArray[j-1][5]=myOrdersArray[j][5];
myOrdersArray[j-1][6]=myOrdersArray[j][6];
myOrdersArray[j-1][7]=myOrdersArray[j][7];
myOrdersArray[j-1][8]=myOrdersArray[j][8];
myOrdersArray[j-1][9]=myOrdersArray[j][9];
myOrdersArray[j-1][10]=myOrdersArray[j][10];
myOrdersArray[j-1][11]=myOrdersArray[j][11];
myOrdersArray[j][0]=myTempArray[0];
myOrdersArray[j][1]=myTempArray[1];
myOrdersArray[j][2]=myTempArray[2];
myOrdersArray[j][3]=myTempArray[3];
myOrdersArray[j][4]=myTempArray[4];
myOrdersArray[j][5]=myTempArray[5];
myOrdersArray[j][6]=myTempArray[6];
myOrdersArray[j][7]=myTempArray[7];
myOrdersArray[j][8]=myTempArray[8];
myOrdersArray[j][9]=myTempArray[9];
myOrdersArray[j][10]=myTempArray[10];
myOrdersArray[j][11]=myTempArray[11];
}
}
}
if (myMaxMin==0) //x,0,0
{
for (cnt=myArrayRange;cnt>=0;cnt--)
{
if (myOrdersArray[cnt][0]!=0 && myOrderType==NormalizeDouble(myOrdersArray[cnt][3],0))
{
myReturn=NormalizeDouble(myOrdersArray[cnt][0],0);
reak;
}
}
}
if (myMaxMin==1) //x,0,1
{
for (cnt=0;cnt
{
if (myOrdersArray[cnt][0]!=0 && myOrderType==NormalizeDouble(myOrdersArray[cnt][3],0))
{
myReturn=NormalizeDouble(myOrdersArray[cnt][0],0);
reak;
}
}
}
}
//---- 按订单净值降序排列数组,原始数组从新排序
if (myOrderSort==1 || myOrderSort==2)
{
ArrayInitialize(myTempArray, 0.0);
//初始化临时数组for (i=0;i<=myArrayRange;i++)
{
for (j=myArrayRange-1;j>i;j--)
{
if (myOrdersArray[j][2]>myOrdersArray[j-1][2])
{
myTempArray[0]=myOrdersArray[j-1][0];
myTempArray[1]=myOrdersArray[j-1][1];
myTempArray[2]=myOrdersArray[j-1][2];
myTempArray[3]=myOrdersArray[j-1][3];
myTempArray[4]=myOrdersArray[j-1][4];
myTempArray[5]=myOrdersArray[j-1][5];
myTempArray[6]=myOrdersArray[j-1][6];
myTempArray[7]=myOrdersArray[j-1][7];
myTempArray[8]=myOrdersArray[j-1][8];
myTempArray[9]=myOrdersArray[j-1][9];
myTempArray[10]=myOrdersArray[j-1][10];
myTempArray[11]=myOrdersArray[j-1][11];
myOrdersArray[j-1][0]=myOrdersArray[j][0];
myOrdersArray[j-1][1]=myOrdersArray[j][1];
myOrdersArray[j-1][2]=myOrdersArray[j][2];
myOrdersArray[j-1][3]=myOrdersArray[j][3];
myOrdersArray[j-1][4]=myOrdersArray[j][4];
myOrdersArray[j-1][5]=myOrdersArray[j][5];
myOrdersArray[j-1][6]=myOrdersArray[j][6];
myOrdersArray[j-1][7]=myOrdersArray[j][7];
myOrdersArray[j-1][8]=myOrdersArray[j][8];
myOrdersArray[j-1][9]=myOrdersArray[j][9];
myOrdersArray[j-1][10]=myOrdersArray[j][10];
myOrdersArray[j-1][11]=myOrdersArray[j][11];
myOrdersArray[j][0]=myTempArray[0];
myOrdersArray[j][1]=myTempArray[1];
myOrdersArray[j][2]=myTempArray[2];
myOrdersArray[j][3]=myTempArray[3];
myOrdersArray[j][4]=myTempArray[4];
myOrdersArray[j][5]=myTempArray[5];
myOrdersArray[j][6]=myTempArray[6];
myOrdersArray[j][7]=myTempArray[7];