该函数执行的是提损功能,即订单盈利到达水平后将止损价修改为开仓价,这样确保订单不会亏损出场。
- //这里函数带有开仓部分,调用时请自行过滤所需要的函数
- extern double 下单量=0.1;
- extern double 止损=30;
- extern double 止盈=90;
- extern double 滑点=3;
- extern double TrailingStop=20; //盈利的点数,你这里是 20
- int start()
- { int i;int ticket1;
- //+---------- 自定义做多条件 --------------------------------------------------------+
- if( OrdersTotal()==0
- && Close[1]-Open[1]>1*Point
- //+------------------------------------------------------------------+
- )
- {ticket1=OrderSend(Symbol(),OP_BUY, 下 单 量 ,Ask, 滑 点 ,Ask- 止 损
- *Point,Ask+止盈*Point,"",20101018,0,0);
- }
- if( OrdersTotal()==0
- && Open[1]-Close[1]>1*Point
- //+------------------------------------------------------------------+
- ){ticket1=OrderSend(Symbol(),OP_SELL, 下 单 量 ,Bid, 滑 点 ,Bid+ 止 损
- *Point,Bid-止盈*Point,"",20101018,0,0);
- }
- //+---------以下为当有利润 20 点时,调整止损位到入场价-----------------+
- int total=OrdersTotal();
- for(int cnt=0;cnt<total;cnt++)
- {
- OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
- if(OrderType()<=OP_SELL && // check for opened position
- OrderSymbol()==Symbol()) // check for symbol
- {
- if(OrderType()==OP_BUY) // long position is opened
- {
- if(TrailingStop>0)
- {
- if(Bid-OrderOpenPrice()>Point*TrailingStop)
- {
- {
- OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Green);
- return(0);
- }
- }
- }
- }
- else // go to short position
- {
- // should it be closed?
- if(TrailingStop>0)
- {
- if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
- {
- {
- OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Red);
- return(0);
- }
- }
- }
- }
- }
- }
- //+------------------------------------------------------------------+
- return(0);}
|