本程序适合跟单交易,只要在MT4或者MT5上写好跟单代码即可实现下单到期货账户
实现逻辑:
1.MtctpServer.exe 负责登录期货账户并同时开通http服务器默认80端口,
2.使用MT4或者MT5的WebRequest进行提交下单,目前只做了开多空单和平多空单操作
期货账户信息在Accountlogin.json里面配置好即可,可以实现多账户操作,默认只开通了十个
启动程序后 当界面显示出来账户和总权益即表示登录成功,此时就可以提交下单了
程序免费使用,带来的任何问题自己负责,开发这个小工具纯属个人爱好,有时间也会更新功能。目前仅仅是个玩具,实现不了复杂的操作。
目前期货MT5:赫兹和MT5CTP两个平台做的比较好,本人均可代写他们的期货EA
赫兹地址:https://www.herzqt.com/?mark=YBZO4K4
期货跟单MT4MT5
期货跟单MT4MT5免费版
期货跟单MT4MT5免费版
以下是MT4/5的代码(需要注意的是开单平仓用涨跌停价格,否则会处于委托状态不能及时下进去,需要在软件打钩允许WebRequest)
- //+------------------------------------------------------------------+
- //| ProjectName |
- //| Copyright 2018, CompanyName |
- //| http://www.companyname.net |
- //+------------------------------------------------------------------+
- #property copyright "不才编程"
- #property link "http://www.mtctp.com/"
- #property description "www.mtctp.com"
- #property description "\n业务范围 :专业MT4MT5EA指标脚本编程"
- #property description "\n联系方式 :微信:bucaiea / QQ;280726108"
- #property version "1.0"
- #property strict
- input string url="http://127.0.0.1/";
- input int 手数=1;
- int OnInit()
- {
- Createbutton(m_url+"做多"," 做多 ...","做多",105,35+105,100,28,CORNER_RIGHT_LOWER,clrAqua,clrNavy,10);
- Createbutton(m_url+"做空"," 做空 ...","做空",105,35+70,100,28,CORNER_RIGHT_LOWER,clrCrimson,clrWhite,10);
- Createbutton(m_url+"平多"," 平多 ...","平多",105,35+35,100,28,CORNER_RIGHT_LOWER,clrSkyBlue,clrNavy,10);
- Createbutton(m_url+"平空"," 平空 ...","平空",105,35,100,28,CORNER_RIGHT_LOWER,clrLightSalmon,clrNavy,10);
- return(INIT_SUCCEEDED);
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void OnChartEvent(const int id,
- const long& lparam,
- const double& dparam,
- const string& sparam
- )
- {
- if(ObjectGetInteger(0,m_url+"做多",OBJPROP_STATE)==1)
- {
- OrderSend(Symbol(),0,手数,SymbolInfoDouble(Symbol(),SYMBOL_ASK));
- ObjectSetInteger(0,m_url+"做多",OBJPROP_STATE,0);
- }
- if(ObjectGetInteger(0,m_url+"做空",OBJPROP_STATE)==1)
- {
- OrderSend(Symbol(),1,手数,SymbolInfoDouble(Symbol(),SYMBOL_BID));
- ObjectSetInteger(0,m_url+"做空",OBJPROP_STATE,0);
- }
- if(ObjectGetInteger(0,m_url+"平多",OBJPROP_STATE)==1)
- {
- OrderClose(Symbol(),0,手数,SymbolInfoDouble(Symbol(),SYMBOL_BID));
- ObjectSetInteger(0,m_url+"平多",OBJPROP_STATE,0);
- }
- if(ObjectGetInteger(0,m_url+"平空",OBJPROP_STATE)==1)
- {
- OrderClose(Symbol(),1,手数,SymbolInfoDouble(Symbol(),SYMBOL_ASK));
- ObjectSetInteger(0,m_url+"平空",OBJPROP_STATE,0);
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- int OrderSend(string symbol,int cmd,int volume,double price,int AccountNumber=0)
- {
- string tmp=cmd==0?"kd":"kk";
- string mtctp=url+"?Mode="+"1";
- mtctp=mtctp+"&Symbol="+symbol;
- mtctp=mtctp+"&Type="+tmp;
- mtctp=mtctp+"&Lots="+IntegerToString(volume);
- mtctp=mtctp+"&price="+DoubleToString(price,int(SymbolInfoInteger(symbol,SYMBOL_DIGITS)));
- mtctp=mtctp+"&AccountNumber="+string(AccountNumber);
- string cookie=NULL,headers;
- char post[],result[];
- int res;
- ResetLastError();
- int timeout=2000;
- res=WebRequest("GET",mtctp,cookie,NULL,timeout,post,0,result,headers);
- if(res==-1)
- {
- Print(__FUNCTION__,"失败:"+mtctp);
- }
- else
- {
- Print(__FUNCTION__,"成功:"+mtctp);
- Print(__FUNCTION__,"成功:"+CharArrayToString(result,0,-1,CP_UTF8));
- Comment(CharArrayToString(result,0,-1,CP_UTF8));
- return 1;
- }
- return 0;
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- int OrderClose(string symbol,int cmd,int volume,double price,int AccountNumber=0)
- {
- string tmp=cmd==0?"pd":"pk";
- string mtctp=url+"?Mode="+"0";
- mtctp=mtctp+"&Symbol="+symbol;
- mtctp=mtctp+"&Type="+tmp;
- mtctp=mtctp+"&Lots="+IntegerToString(volume);
- mtctp=mtctp+"&price="+DoubleToString(price,int(SymbolInfoInteger(symbol,SYMBOL_DIGITS)));
- mtctp=mtctp+"&AccountNumber="+string(AccountNumber);
- string cookie=NULL,headers;
- char post[],result[];
- int res;
- ResetLastError();
- int timeout=2000;
- res=WebRequest("GET",mtctp,cookie,NULL,timeout,post,0,result,headers);
- if(res==-1)
- {
- Print(__FUNCTION__,"失败:"+mtctp);
- }
- else
- {
- Print(__FUNCTION__,"成功:"+mtctp);
- Print(__FUNCTION__,"成功:"+CharArrayToString(result,0,-1,CP_UTF8));
- Comment(CharArrayToString(result,0,-1,CP_UTF8));
- return 1;
- }
- return 0;
- }
- //+------------------------------------------------------------------+
- void Createbutton(string name,string txt1,string txt2,int XX,int YX,int XL,int YL,int WZ,color A,color B,int size)
- {
- // ObjectSetInteger(0,"X做多",OBJPROP_STATE,0);
- if(ObjectFind(0,name)==-1)
- ObjectCreate(0,name,OBJ_BUTTON,0,0,0);
- ObjectSetInteger(0,name,OBJPROP_XDISTANCE,XX);
- ObjectSetInteger(0,name,OBJPROP_YDISTANCE,YX);
- ObjectSetInteger(0,name,OBJPROP_XSIZE,XL);
- ObjectSetInteger(0,name,OBJPROP_YSIZE,YL);
- ObjectSetString(0,name,OBJPROP_FONT,"微软雅黑");
- ObjectSetInteger(0,name,OBJPROP_FONTSIZE,size);
- ObjectSetInteger(0,name,OBJPROP_CORNER,WZ);
- if(ObjectGetInteger(0,name,OBJPROP_STATE)==1)
- {
- ObjectSetInteger(0,name,OBJPROP_COLOR,A);
- ObjectSetInteger(0,name,OBJPROP_BGCOLOR,B);
- ObjectSetString(0,name,OBJPROP_TEXT,txt1);
- }
- else
- {
- ObjectSetInteger(0,name,OBJPROP_COLOR,B);
- ObjectSetInteger(0,name,OBJPROP_BGCOLOR,A);
- ObjectSetString(0,name,OBJPROP_TEXT,txt2);
- }
- }
- string m_url="mtctp";
- void OnDeinit(const int reason)
- {
- for(int i=ObjectsTotal(0,-1,-1)-1; i>=0; i--)
- if(StringFind(ObjectName(0,i),m_url,0)!=-1)
- ObjectDelete(0,ObjectName(0,i));
- }
- //+------------------------------------------------------------------+
- //| Expert tick function |
- //+------------------------------------------------------------------+
- void OnTick()
- {
- }
- //+------------------------------------------------------------------+
复制代码
|