© 本贴为 wuwei 原创/首发,严禁抄袭!
最后由 wuwei 于 2023-5-25 08:58 编辑
- <b>//11破位开仓
-
- void po_open()
-
- {
-
- G_po_open = GlobalVariableGet("G_po_open");
-
- if(!G_po_open)
-
- return;
-
- double ask = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
-
- double bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);
-
- if(bid > iHigh(Symbol(), PERIOD_M1, 1))
-
- {
-
- //准备开多单
-
- int ticket = OrderSend(Symbol(), OP_BUY, lots, ask, Slippage, 0, 0);
-
- if(ticket < 0)
-
- Print("破位开多失败! ", error());
-
- else
-
- {
-
- G_po_open = false;
-
- GlobalVariableSet("G_po_open", G_po_open);
-
- SetRed(G_po_open, "破位开仓");
-
- }
-
- }
-
- if(bid < iLow(Symbol(), PERIOD_M1, 1))
-
- {
-
- //准备开空单
-
- int ticket = OrderSend(Symbol(), OP_SELL, lots, bid, Slippage, 0, 0);
-
- if(ticket < 0)
-
- Print("破位开空失败! ", error());
-
- else
-
- {
-
- G_po_open = false;
-
- GlobalVariableSet("G_po_open", G_po_open);
-
- SetRed(G_po_open, "破位开仓");
-
- }
-
- }
-
- }
-
- //11破位平仓
-
- void po_close()
-
- {
-
- G_po_close = GlobalVariableGet("G_po_close");
-
- if(!G_po_close)
-
- return;
-
- int iOrders = OrdersTotal(), i;//订单序号是从0开始,订单总数是1开始。所以要减1
-
- for(i = iOrders - 1; i >= 0; i--)
-
- {
-
- if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
-
- {
-
- if(OrderSymbol() != Symbol())
-
- continue;
-
- double ask = SymbolInfoDouble(OrderSymbol(), SYMBOL_ASK);
-
- double bid = SymbolInfoDouble(OrderSymbol(), SYMBOL_BID);
-
- if(OrderType() == OP_SELL)
-
- {
-
- if(bid > iHigh(OrderSymbol(), PERIOD_M1, 1))
-
- {
-
- if(!OrderClose(OrderTicket(), OrderLots(), ask, Slippage))//平仓 OrderType()0=买 1 =卖
-
- Print(OrderTicket(), error());
-
- else
-
- {
-
- G_po_close = false;
-
- GlobalVariableSet("G_po_close", G_po_close);
-
- SetRed(G_po_close, "破位平仓");
-
- }
-
- }
-
- }
-
- if(OrderType() == OP_BUY)
-
- {
-
- if(bid < iLow(OrderSymbol(), PERIOD_M1, 1))
-
- {
-
- if(!OrderClose(OrderTicket(), OrderLots(), bid, Slippage))//平仓 OrderType()0=买 1 =卖
-
- Print(OrderTicket(), error());
-
- else
-
- {
-
- G_po_close = false;
-
- GlobalVariableSet("G_po_close", G_po_close);
-
- SetRed(G_po_close, "破位平仓");
-
- }
-
- }
-
- }
-
- else
-
- error();
-
- }
-
- }
-
- }</b>
复制代码
|