|
开仓后自动设置止盈止损并在浮盈30点后移动止损到开仓价之后便不再变化完整版
- #property copyright "FRLIN2003"
- extern double stoploss= 1200;
- extern double takeprofit=1200;
- extern double TrailingStop =500;
- double OriginalLot,My;
- int start()
- {
- My=0.00001;
- if(StringFind(Symbol(),"JPY",3)==3) My=0.001;
- if(StringFind(Symbol(),"XAU",0)==0) My=0.01;
- if(StringFind(Symbol(),"XAG",0)==0) My=0.001;
- for(int cnt=0;cnt<OrdersTotal();cnt++)
- {
- if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
- {
- if(OrderSymbol()==Symbol())
- {
- double stp=OrderStopLoss();
- double tpt=OrderTakeProfit();
- double OpenPrice = OrderOpenPrice();
- bool res;
- if (OriginalLot == 0)
- {
- OriginalLot=OrderLots();
- }
- if(OrderType()==OP_BUY )
- {
- if ( stp==0 && tpt==0)
- res=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-My*stoploss,OrderOpenPrice()+My*takeprofit,0,Green);
- else
- {
- if ((Ask - OpenPrice) > My*TrailingStop)
- {
- res=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Green);
- }
- }
- }
- if(OrderType()==OP_SELL)
- {
- if ( stp==0 && tpt==0)
- res=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+My*stoploss,OrderOpenPrice()-My*takeprofit,0,Green);
- else
- {
- if((OpenPrice-Bid) > My*TrailingStop )
- {
- res=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Green);
- }
- }
- }
- }
- }
- else
- {
- OriginalLot=0;
- }
- }
- return(0);
- }
复制代码 |
|