下载MetaTrader 5
要添加评论,请登录注册
您知道MQL5的事件处理吗?
牛牛
11
牛牛 2011.04.21 07:57 
//+------------------------------------------------------------------+
//| 交易系统.mq4 |
//| 交易系统 |
//| 交易系统 |
//+------------------------------------------------------------------+

#property copyright "交易系统"
#property link "交易系统"

extern int FasterMode = 1; //0=sma, 1=ema, 2=smma, 3=lwma
extern int FasterMA = 5; //均线周期
extern int SlowerMode = 1; //0=sma, 1=ema, 2=smma, 3=lwma
extern int SlowerMA = 15;//均线周期
extern int MN = 2011;
extern int SL=10; //止损价格。
extern int SL1=30; //止盈价格
extern double Prots= 20; //仓位百分比
int last_t = 0;

double Lot;
double biao;
double Lots()
{
//============================================================================================
biao=10000/AccountLeverage();
Lot=NormalizeDouble(AccountEquity()*Prots/100/biao,1);
double Min_Lot = MarketInfo(Symbol(), MODE_MINLOT);
if (Lot == 0 ) Lot = Min_Lot;
//============================================================================================
return(Lot);
}
int init()
{
return(0);
}
int deinit()
{
return(0);
}
int start() {
int limit, i, counter,j;
double fasterMAnow, slowerMAnow, fasterMAprevious, slowerMAprevious, fasterMAafter, slowerMAafter;
double Range, AvgRange;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;
for(i = 0; i <= limit; i++) {
j=OrdersTotal();
counter=i;
Range=0;
AvgRange=0;
for (counter=i ;counter<=i+9;counter++)
{
AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
}
Range=AvgRange/10;
fasterMAnow = iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i);
fasterMAprevious = iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i+1);
fasterMAafter = iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i-1);

slowerMAnow = iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_CLOSE, i);
slowerMAprevious = iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_CLOSE, i+1);
slowerMAafter = iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_CLOSE, i-1);
if ((fasterMAnow > slowerMAnow) && (fasterMAprevious < slowerMAprevious) && (fasterMAafter > slowerMAafter))
{
if (OrderType()==OP_SELL)
{ //空单平仓
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);
//多单建仓
RefreshRates();
OrderSend(Symbol(), OP_BUY, Lots(), NormalizeDouble(Ask,Digits), 3, NormalizeDouble(Ask-SL*Point,Digits),
NormalizeDouble(Ask+SL1*Point,Digits), "", MN, 0, Blue);
last_t = Time[0];
}return;
}
if ((fasterMAnow < slowerMAnow) && (fasterMAprevious > slowerMAprevious) && (fasterMAafter < slowerMAafter))
{
if (OrderType()==OP_BUY)
{ //多单平仓
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
//空单建仓
RefreshRates();
OrderSend(Symbol(), OP_SELL, Lots(), NormalizeDouble(Bid,Digits), 3, NormalizeDouble(Bid+SL*Point,Digits),
NormalizeDouble(Bid-SL1*Point,Digits), "", MN, 0, Blue);
last_t = Time[0];
}return;
}
}
return(0);
}


fff
3
fff 2011.10.23 15:27  
一种可能是你的平台不支持直接在ordersend中就设置止损和止盈。 有的平台是接受的。
WANGGUANG
81
WANGGUANG 2012.01.27 08:11  

两种可能:1、你的平台不支持带有止损止盈的订单 2、你的平台是5位报价,你设置止损止盈的距离太小了

/
要添加评论,请登录注册