该函数针对止损盈利为零的订单执行修改,添加止损盈利数值,可以调用到EA或脚本文件中使用。
- extern int StopLoss = 200; //在这里设置止损点数
- extern int TakeProfit = 400; //在这里设置盈利点数
- void onStart()
- {
- bool chenggong = false;
- int i = 0;
-
- if(TakeProfit!=0)
- {
- for(i=0;i<OrdersTotal();i++)
- {
- if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==Symbol() && OrderTakeProfit()==0)
- {RefreshRates();
- if(OrderType()==OP_BUY||OrderType()==OP_BUYLIMIT||OrderType()==OP_BUYSTOP)
- {
- chenggong=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()+TakeProfit*Point,0);
- }
- if(OrderType()==OP_SELL||OrderType()==OP_SELLLIMIT||OrderType()==OP_SELLSTOP)
- {
- chenggong= OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()-TakeProfit*Point,0);
- }
- }
- }
- }
- if(StopLoss!=0)
- {
- for(i=0;i<OrdersTotal();i++)
- {
- if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==Symbol() && OrderStopLoss()==0)
- {RefreshRates();
- if(OrderType()==OP_BUY||OrderType()==OP_BUYLIMIT||OrderType()==OP_BUYSTOP)
- {
- chenggong=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-StopLoss*Point,OrderTakeProfit(),0);
- }
- if(OrderType()==OP_SELL||OrderType()==OP_SELLLIMIT||OrderType()==OP_SELLSTOP)
- {
- chenggong= OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+StopLoss*Point,OrderTakeProfit(),0);
- }
- }
- }
- }
- }
|