MT4摊平下单
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);
    }
}
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇