Thema: Trailing-Stop
Einzelnen Beitrag anzeigen
  #2 (permalink)  
Alt 25.10.14
traderdoc traderdoc ist offline
Elite Mitglied
 
Registriert seit: Apr 2011
Beiträge: 1.875
traderdoc befindet sich auf einem aufstrebenden Ast
Standard

Code:
//Trailing-Function-Inputs******************************************** ************************************************** *************************
extern int TrailingStop = 500; 
extern int TrailingStep = 30; 
extern bool UseSound = True; 
string NameFileSound = "expert.wav"; 
//End Trailing-Function-Inputs******************************************** ************************************************** *********************


//+------------------------------------------------------------------+
//| TRAILING für S1-S6 |
//+------------------------------------------------------------------+
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) )
{
TrailingPositions_S1(OrderSymbol());
}
}
//+----------------------------------------------------------------+
//| END |
//+----------------------------------------------------------------+



//+------------------------------------------------------------------+
//| TRAILING S1 |
//+------------------------------------------------------------------+
void TrailingPositions_S1(string symbol) {
double pBid, pAsk, pp;

pp = MarketInfo(symbol, MODE_POINT);
if (OrderType()==OP_BUY) {
pBid = MarketInfo(symbol, MODE_BID);

if (pBid-OrderOpenPrice()>TrailingStop*pp) {
if (OrderStopLoss()<pBid-(TrailingStop+TrailingStep-1)*pp) {
ModifyStopLoss_S1(pBid-TrailingStop*pp);
return;
}
}
}
if (OrderType()==OP_SELL) {
pAsk = MarketInfo(symbol, MODE_ASK);

if (OrderOpenPrice()-pAsk>TrailingStop*pp) {
if (OrderStopLoss()>pAsk+(TrailingStop+TrailingStep-1)*pp || OrderStopLoss()==0) {
ModifyStopLoss_S1(pAsk+TrailingStop*pp);
return;
}
}
}
}
void ModifyStopLoss_S1(double ldStopLoss) {
bool fm;
fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldSt opLoss,OrderTakeProfit(),0,CLR_NONE);
if (fm && UseSound) PlaySound(NameFileSound);
}
//+----------------------------------------------------------------+
//| END |
//+----------------------------------------------------------------+
traderdoc
__________________
Ich erfülle Euch gern Eure EA-, Indikator- und Script-Programmierungswünsche auf Honorarbasis.