2017/3/19
一.
1.MT5和MT4的对比 (结论MT5好很多)
https://www.metatrader5.com/zh/brokers/comparison-mt5-mt4
mt5简介
2017/3/20
一.6种类型单子
1.limit是亏损方向
buy limit
sell limit
2.stop是盈利方向
buy stop
sell stop
3.buy stop limit 先突破盈利方向 在回调
sell stop limit
二.代码格式化 ctrl+,
以下其实没什么用【 tab 选择代码块右移, shift+tab选择代码块左右】
三.常用入门接口
//| Common.mqh
#define yes true
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void pd(double num)
{
printf(DoubleToString(num,Digits()));
}
//| 1.常用入门接口.mq5
#include <..\Include\Common.mqh>
datetime openTime;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
getMqlTick();
getMqlRates();
getIndicatorTest();
}
//+------------------------------------------------------------------+
void getMqlTick()
{
//double a = Ask;
MqlTick result[];
ArraySetAsSeries(result,yes);
CopyTicks(NULL,result,COPY_TICKS_ALL,0,1);
pd(result[0].ask);//bid ask
}
//+------------------------------------------------------------------+
void getMqlRates()
{
//double o1 = Open[0];
MqlRates result[];
ArraySetAsSeries(result,yes);
CopyRates(NULL,0,0,10,result);
pd(result[0].open); //high open low close
}
//+------------------------------------------------------------------+
void getIndicatorTest()
{
double adx1[];
double adx2[];
double adx3[];
ArraySetAsSeries(adx1,yes);
ArraySetAsSeries(adx2,yes);
ArraySetAsSeries(adx3,yes);
int adx_h=iADX(NULL,0,14);
CopyBuffer(adx_h,0,0,10,adx1);
CopyBuffer(adx_h,1,0,10,adx2);
CopyBuffer(adx_h,2,0,10,adx3);
pd(adx1[0]);
pd(adx2[0]);
pd(adx3[0]);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void sendOrderOneTime()
{
//获取时间
datetime t[];
ArraySetAsSeries(t,yes);
CopyTime(NULL,0,0,2,t);
//一个k线只下一个订单
if(openTime!=t[0])
{
sendOrder();
openTime=t[0];
}
}
//+------------------------------------------------------------------+
void sendOrder()
{
MqlTradeRequest request={0};
MqlTradeResult result={0};
//--- 请求的参数
request.action=TRADE_ACTION_DEAL; // 交易操作类型
request.symbol=Symbol(); // 交易品种
request.volume=0.1; // 0.1手交易量
request.type=ORDER_TYPE_BUY; // 订单类型
request.price=SymbolInfoDouble(Symbol(),SYMBOL_ASK); // 持仓价格
request.deviation=5; // 允许价格偏差
request.magic=123456; // 订单幻数
if(OrderSend(request,result))
{
PrintFormat("retcode=%u deal=%I64u order=%I64u",result.retcode,result.deal,result.order);
}
else
{
PrintFormat("OrderSend error %d",GetLastError()); // 如果不能发送请求,输出错误代码
}
}
//+------------------------------------------------------------------+
//遍历持仓单
void traversePosition()
{
int pt=PositionsTotal();
for(int i=0;i0)
{
//do something
double openPrice=PositionGetDouble(POSITION_PRICE_OPEN);
}
}
}
//+------------------------------------------------------------------+
//一般用不到
void testPositionSelect()
{
if(PositionSelect(Symbol())==true)
{
//do something
double openPrice=PositionGetDouble(POSITION_PRICE_OPEN);
}
}
//+------------------------------------------------------------------+
//遍历挂单
void traversePendingOrder()
{
int ot=OrdersTotal();
for(int i=0;i0)
{
//do something
double orderPriceOpen=OrderGetDouble(ORDER_PRICE_OPEN);
}
}
}
//+------------------------------------------------------------------+
void testOrderSelect()
{
if(OrderSelect(1234)==true)//根据订单号选择
{
//do something
double orderPriceOpen=OrderGetDouble(ORDER_PRICE_OPEN);
}
}
//+------------------------------------------------------------------+
如果您发现本文对你有所帮助,如果您认为其他人也可能受益,请把它分享出去。