Einzelnen Beitrag anzeigen
  #8 (permalink)  
Alt 07.06.16
HansLuftibus HansLuftibus ist offline
Neues Mitglied
 
Registriert seit: Jun 2016
Beiträge: 2
HansLuftibus befindet sich auf einem aufstrebenden Ast
Standard Trailing Stopp Luss

Ist einfach falsch programmiert. Code findet man überall.

Hier ein Beispiel:

/+------------------------------------------------------------------+
//-------------------
// Zieht Stopp Loss über Break even nach, gibt besseres Resultat als trailToBreakEven
// benötigt globale pippoints
// Globale Variablen
// promilleAbstand
//-------------------
void trailingSL(double slLong,double slShort)
{
//Stopp Loss
static double vorherigerLong=0;
static double vorherigerShort=20000;
static double newstopLong;
static double newstopShort;

//SL kann bei Short sehr gross werden, hatte damit am 6.4.16 grossen Verlust
// slLong=2*ATR;
// slShort=2*ATR;

// if(Bid>OrderOpenPrice()+StopLoss_long)

for(int counter1=0; counter1<=OrdersTotal()-1; counter1++)
{
RefreshRates();

bool order=OrderSelect(counter1,SELECT_BY_POS,MODE_TRAD ES);
if(OrderSymbol()==Symbol())
{

if(OrderType()==OP_BUY)
{
if(OrderStopLoss()==0) //fehlender SL
bool modify=OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() -(slLong*pippoints),0,0,CLR_NONE);
if(OrderStopLoss()>0)
{
if(DEBUGGING)
Print("Open Price "+DoubleToStr(OrderOpenPrice()));
if(Bid>OrderOpenPrice()+minimalGewinn*pippoints)

{ //erst Nachziehen, falls Stopp loss drin
newstopLong=Bid -(slLong*pippoints);
if(DEBUGGING)
Print("newstoplong "+DoubleToStr(OrderOpenPrice()));
//SL 2 %0 Abstand vom mittlerem MA
// newstopLong=currma2-promilleAbstand*currma2;

if(newstopLong>OrderStopLoss() && newstopLong>vorherigerLong)
{
bool modify=OrderModify(OrderTicket(),OrderOpenPrice(), newstopLong,0,0,CLR_NONE);
if(DEBUGGING)
Print("newstopLong: "+DoubleToStr(newstopLong));
}
}
}//Ende OrderStopLoss
}

if(OrderType()==OP_SELL)
{
if(OrderStopLoss()==0)
bool modify=OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice()+(slShort*pippoints),0,0,CLR_NONE) ;
if(OrderStopLoss()>0)
{
if(Ask<OrderOpenPrice()-minimalGewinn*pippoints)
{
newstopShort=Ask+(slShort*pippoints);
//newstopShort=currma2+promilleAbstand*currma2;
if(newstopShort<OrderStopLoss() && newstopShort<vorherigerShort)//&& newstop>OrderOpenPrice()
bool modify=OrderModify(OrderTicket(),OrderOpenPrice(), newstopShort,0,0,CLR_NONE);
}
}
}

}//Ende OrderSymbol

}//Ende For
vorherigerLong=newstopLong;
vorherigerShort=newstopShort;

}