//+------------------------------------------------------------------+
//| EA_Arbitrage.mq4 |
//| Copyright 2015, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "跟单EA - 有道[url=]智能交易[/url]"
#property link "https://shop136951533.taobao.com"
#property version "1.00"
#property description "EA委托开发 请联系 QQ15826744."
#property strict
#import "kernel32.dll"
int CopyFileW(string SrcDirectory,string DstDirectory,bool ReWrite);
bool CreateDirectoryW(string DstDirectory,int createType);
#import
enum COPY_TYPE {发送端,接收端};
input COPY_TYPE EA_TYPE = 接收端; //= 运行模式
input string Switch = "C:\\COPYLOT_TEMP_YD"; //= 交换目录(除非必要 不要更改)
input int CopySpeed = 50; //= 检索订单速度(越小越快)
input bool ShowPanel = true; //= 接收端显示主账户订单列表
struct POSITION {
uint tk;
string symbol;
datetime openTime;
uint odType;
double lots;
double openprice;
double stoploss;
double takeprofit;
double profit;
int magic;
int copytk;
};
int file_handle;
string FilePath,FilePath_Absolute,SwitchPath;
string FILE_NAME = "SwitchFile.csv";
POSITION Pos[];
int PanelTop = 18;
int RowH = 18;
int EditWidth[] = {90,70,125,80,65,65,65,65,65,90,90};
double EditWidthPec[] = {0.1,0.085,0.1445,0.0925,0.0925,0.0751,0.0751,0.0751,0.0751,0.1,0.1};
int OnInit(){
FilePath = "CopyLotsTemp" + "\\" + FILE_NAME;
FilePath_Absolute = TerminalInfoString(TERMINAL_DATA_PATH) + "\\MQL4\\Files\\" + FilePath;
SwitchPath = Switch + "\\" + FILE_NAME;
if(EA_TYPE == 1){
if(ShowPanel) PosPanelCreate();
}
if(EA_TYPE == 0){
CreateDirectoryW(Switch,0);
}
EventSetMillisecondTimer(CopySpeed);
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason){
ObjectsDeleteAll();
EventKillTimer();
}
void OnTimer(){
int i,cnt;
if(EA_TYPE == 0){
file_handle = FileOpen(FilePath,FILE_WRITE|FILE_SHARE_WRITE|FILE_REWRITE|FILE_CSV,",");
if(file_handle!=INVALID_HANDLE){
//Print("File opened..");
for(cnt = 0; cnt eadString(file_handle));//OrderTicket(),
Pos.symbol = (string) (FileReadString(file_handle));//OrderSymbol(),
Pos.openTime = (long) (FileReadString(file_handle));//OrderOpenTime(),
Pos.odType = (uint) (FileReadString(file_handle));//OrderType(),
Pos.lots = (double) (FileReadString(file_handle));//OrderLots(),
Pos.openprice = (double) (FileReadString(file_handle));//OrderOpenPrice(),
Pos.stoploss = (double) (FileReadString(file_handle));//OrderStopLoss(),
Pos.takeprofit = (double) (FileReadString(file_handle));//OrderTakeProfit(),
Pos.profit = (double) (FileReadString(file_handle));//OrderProfit(),
Pos.magic = (int) (FileReadString(file_handle));//OrderMagicNumber());*/
//Print("next::",FileReadString(file_handle));
//Print(/*"i:",i," ",*/Pos.tk);
i++;
}
} else Print(GetLastError());
FileClose(file_handle);
//根据条件跟踪下单/平仓
bool tkCopyed,tkClosed;
int odTicket,odType,tkSend,tkClose;
double odLot,odOpenprice,odStoploss,odTakeprofit;
string odSymbol;
for(i = 1; i 0) {tkCopyed = true; continue;}
for(cnt = 0; cnt = 0){
PosRowDestory(i);
i++;
} else break;
}
}
//PosPanelRedrow();
}
}
void OnTick(){
}
//+------------------------------------------------------------------+
//| PosPanelRedrow 主账户订单列表创建
//+------------------------------------------------------------------+
void PosPanelCreate(){
RectLabelCreate(0,"PosPanel",0,0,PanelTop,ChartGetInteger(0,CHART_WIDTH_IN_PIXELS),200,clrWheat,BORDER_FLAT,CORNER_LEFT_UPPER,clrBlack,STYLE_SOLID,1,false,false,true,0);
LabelCreate(0,"TT",0,10,PanelTop+10,0,"主账户订单列表","Arial",9,111,0,ANCHOR_LEFT_UPPER,false,false,true,0);
if(!PosRowIsExist(0)) PosRowCreate(0);
}
//+------------------------------------------------------------------+
//| PosPanelRedrow 主账户订单列表重画
//+------------------------------------------------------------------+
void PosPanelRedrow(){
int i = 0;
while(true){
if(ObjectFind(0,"PosRow_"+i+"_"+1) >= 0){
PosRowRedrow(i);
i++;
} else break;
}
}
//+------------------------------------------------------------------+
//| PosRowIsExist 确定特定行号记录存在
//+------------------------------------------------------------------+
bool PosRowIsExist(int row){
if(ObjectFind(0,"PosRow_"+row+"_"+1) >= 0) return(true);
else return(false);
}
//+------------------------------------------------------------------+
//| ODType 返回订单类型文本
//+------------------------------------------------------------------+
string ODType(int odType){
string type;
switch(odType){
case 0: return("BUY");
case 1: return("SELL");
case 2: return("BUY LIMIT");
case 3: return("SELL LIMIT");
case 4: return("BUY STOP");
case 5: return("SELL STOP");
default: return("NULL");
}
}
//+------------------------------------------------------------------+
//| PosRowRedrow 主账户订单列表单条记录创建
//+------------------------------------------------------------------+
void PosRowCreate(int row){
int i;
int EditX[11];
int txSize = 8;
EditX[0] = 10;
if(ChartGetInteger(0,CHART_WIDTH_IN_PIXELS) 6){
return(StringSubstr(Symbol(),6,StringLen(Symbol()) - 6));
} else {
return("");
}
}
//+------------------------------------------------------------------+
//| 改变 rectangle label 控件尺寸
//+------------------------------------------------------------------+
bool RectLabelChangeSize(const long chart_ID=0, // chart's ID
const string name="RectLabel", // label name
const int width=50, // label width
const int height=18) // label height
{
//--- reset the error value
ResetLastError();
//--- change label size
if(!ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width))
{
Print(__FUNCTION__,
": failed to change the label's width! Error code = ",GetLastError());
return(false);
}
if(!ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height))
{
Print(__FUNCTION__,
": failed to change the label's height! Error code = ",GetLastError());
return(false);
}
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
//| 创建 rectangle label 控件
//+------------------------------------------------------------------+
bool RectLabelCreate(const long chart_ID=0, // chart's ID
const string name="RectLabel", // label name
const int sub_window=0, // subwindow index
const int x=0, // X coordinate
const int y=0, // Y coordinate
const int width=50, // width
const int height=18, // height
const color back_clr=C'236,233,216', // background color
const ENUM_BORDER_TYPE border=BORDER_SUNKEN, // border type
const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // chart corner for anchoring
const color clr=clrRed, // flat border color (Flat)
const ENUM_LINE_STYLE style=STYLE_SOLID, // flat border style
const int line_width=1, // flat border width
const bool back=false, // in the background
const bool selection=false, // highlight to move
const bool hidden=true, // hidden in the object list
const long z_order=0) // priority for mouse click
{
//--- reset the error value
ResetLastError();
//--- create a rectangle label
if(!ObjectCreate(chart_ID,name,OBJ_RECTANGLE_LABEL,sub_window,0,0))
{
Print(__FUNCTION__,
": failed to create a rectangle label! Error code = ",GetLastError());
return(false);
}
//--- set label coordinates
ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//--- set label size
ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
//--- set background color
ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);
//--- set border type
ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_TYPE,border);
//--- set the chart's corner, relative to which point coordinates are defined
ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//--- set flat border color (in Flat mode)
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set flat border line style
ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- set flat border width
ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,line_width);
//--- display in the foreground (false) or background (true)
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving the label by mouse
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- hide (true) or display (false) graphical object name in the object list
ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chart
ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
//| 创建 Label 控件
//+------------------------------------------------------------------+
bool LabelCreate(const long chart_ID=0, // chart's ID
const string name="Label", // label name
const int sub_window=0, // subwindow index
const int x=0, // X coordinate
const int y=0, // Y coordinate
const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // chart corner for anchoring
const string text="Label", // text
const string font="Arial", // font
const int font_size=10, // font size
const color clr=clrRed, // color
const double angle=0.0, // text slope
const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // anchor type
const bool back=false, // in the background
const bool selection=false, // highlight to move
const bool hidden=true, // hidden in the object list
const long z_order=0) // priority for mouse click
{
//--- reset the error value
ResetLastError();
//--- create a text label
if(!ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0))
{
Print(__FUNCTION__,
": failed to create text label! Error code = ",GetLastError());
return(false);
}
//--- set label coordinates
ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//--- set the chart's corner, relative to which point coordinates are defined
ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//--- set the text
ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
//--- set text font
ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
//--- set font size
ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
//--- set the slope angle of the text
ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
//--- set anchor type
ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
//--- set color
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- display in the foreground (false) or background (true)
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving the label by mouse
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- hide (true) or display (false) graphical object name in the object list
ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chart
ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
//| 创建 Edit 控件
//+------------------------------------------------------------------+
bool EditCreate(const long chart_ID = 0, // chart's ID
const string name = "Edit", // object name
const int sub_window = 0, // subwindow index
const int x = 0, // X coordinate
const int y = 0, // Y coordinate
const int width = 50, // width
const int height = 18, // height
const string text = "Text", // text
const string font = "Arial", // font
const int font_size = 10, // font size
const ENUM_ALIGN_MODE align = ALIGN_CENTER, // alignment type
const bool read_only = false, // ability to edit
const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring
const color clr = clrBlack, // text color
const color back_clr = clrWhite, // background color
const color border_clr = clrNONE, // border color
const bool back = false, // in the background
const bool selection = false, // highlight to move
const bool hidden = true, // hidden in the object list
const long z_order = 0){ // priority for mouse click
//--- reset the error value
ResetLastError();
//--- create edit field
if(!ObjectCreate(chart_ID,name,OBJ_EDIT,sub_window,0,0)){
Print(__FUNCTION__,
": failed to create \"Edit\" object! Error code = ",GetLastError());
return(false);
}
//--- set object coordinates
ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//--- set object size
ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
//--- set the text
ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
//--- set text font
ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
//--- set font size
ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
//--- set the type of text alignment in the object
ObjectSetInteger(chart_ID,name,OBJPROP_ALIGN,align);
//--- enable (true) or cancel (false) read-only mode
ObjectSetInteger(chart_ID,name,OBJPROP_READONLY,read_only);
//--- set the chart's corner, relative to which object coordinates are defined
ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//--- set text color
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set background color
ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);
//--- set border color
ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr);
//--- display in the foreground (false) or background (true)
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving the label by mouse
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- hide (true) or display (false) graphical object name in the object list
ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chart
ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
//| 删除 Edit 控件
//+------------------------------------------------------------------+
bool EditDelete(const long chart_ID = 0, // chart's ID
const string name = "Edit"){ // object name
//--- reset the error value
ResetLastError();
//--- delete the label
if(!ObjectDelete(chart_ID,name)){
Print(__FUNCTION__,
": failed to delete \"Edit\" object! Error code = ",GetLastError());
return(false);
}
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
//| 更改 Edit 控件尺寸
//+------------------------------------------------------------------+
bool EditChangeSize(const long chart_ID = 0, // chart's ID
const string name = "Edit", // object name
const int width = 0, // width
const int height = 0){ // height
//--- reset the error value
ResetLastError();
//--- change the object size
if(!ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width)){
Print(__FUNCTION__,
": failed to change the object width! Error code = ",GetLastError());
return(false);
}
if(!ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height)){
Print(__FUNCTION__,
": failed to change the object height! Error code = ",GetLastError());
return(false);
}
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
//| 移动 Edit 控件位置
//+------------------------------------------------------------------+
bool EditMove(const long chart_ID = 0, // chart's ID
const string name = "Edit", // object name
const int x = 0, // X coordinate
const int y = 0){ // Y coordinate
//--- reset the error value
ResetLastError();
//--- move the object
if(!ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x)){
Print(__FUNCTION__,
": failed to move X coordinate of the object! Error code = ",GetLastError());
return(false);
}
if(!ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y)){
Print(__FUNCTION__,
": failed to move Y coordinate of the object! Error code = ",GetLastError());
return(false);
}
//--- successful execution
return(true);
}
|