input double lots = 0.01;
input double slippage = 3;
input int Fast_MA = 5;
input int Slow_MA = 15;
input double nampin = 5;
input int maxnampin = 5;
input int MagicNumber = 12345;
static int TicketNumber;
int OnInit() {
return (INIT_SUCCEEDED);
}
void OnDeinit(const int reason) {
}
void OnTick() {
int cnt;
int CurrentPosition;
double profit;
CurrentPosition = -1;
for (cnt = 0; cnt < OrdersTotal(); cnt++) {
if (OrderSelect(cnt, SELECT_BY_POS) == false)
continue;
if (OrderMagicNumber() != MagicNumber)
continue;
profit = profit + OrderProfit();
if (OrderMagicNumber() == MagicNumber)
CurrentPosition = cnt;
}
if (CurrentPosition == -1) {
double kako_Fast, kako_Slow;
double gen_Fast, gen_Slow;
kako_Fast = iMA(NULL, 0, Fast_MA, 0, MODE_SMA, PRICE_CLOSE, 1);
kako_Slow = iMA(NULL, 0, Slow_MA, 0, MODE_SMA, PRICE_CLOSE, 1);
gen_Fast = iMA(NULL, 0, Fast_MA, 0, MODE_SMA, PRICE_CLOSE, 0);
gen_Slow = iMA(NULL, 0, Slow_MA, 0, MODE_SMA, PRICE_CLOSE, 0);
if (kako_Fast < kako_Slow && gen_Fast >= gen_Slow) {
TicketNumber = OrderSend(Symbol(), OP_BUY, lots, Ask, slippage, 0, 0, "buy", MagicNumber, 0, Red);
}
if (kako_Fast > kako_Slow && gen_Fast <= gen_Slow) {
TicketNumber = OrderSend(Symbol(), OP_SELL, lots, Bid, slippage, 0, 0, "sell", MagicNumber, 0, Blue);
}
} else {
OrderSelect(CurrentPosition, SELECT_BY_POS);
if (OrderSymbol() == Symbol()) {
if (OrderType() == OP_BUY) {
if (OrdersTotal() < (maxnampin + 1) && Close[0] < (OrderOpenPrice() - nampin * Point)) {
TicketNumber = OrderSend(Symbol(), OP_BUY, OrderLots() * 2, Ask, slippage, 0, 0, "buy2", MagicNumber, 0, Blue);
}
if (profit > 10) {
allClose(Green);
}
}
if (OrderType() == OP_SELL) {
if (OrdersTotal() < (maxnampin + 1) && Close[0] > (OrderOpenPrice() + nampin * Point)) {
TicketNumber = OrderSend(Symbol(), OP_SELL, OrderLots() * 2, Bid, slippage, 0, 0, "sell2", MagicNumber, 0, Red);
}
if (profit > 10) {
allClose(Yellow);
}
}
}
}
}
void allClose(color clr) {
int i;
for (i = OrdersTotal() - 1; i >= 0; i--) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false)
continue;
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber)
continue;
if (OrderType() == OP_BUY)
OrderClose(OrderTicket(), OrderLots(), Bid, NormalizeDouble(slippage, 0), clr);
if (OrderType() == OP_SELL)
OrderClose(OrderTicket(), OrderLots(), Ask, NormalizeDouble(slippage, 0), clr);
}
}
暂无评论