Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools

Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools (http://www.expert-advisor.com/forum/index.php)
-   Programmierung MQL4 (http://www.expert-advisor.com/forum/forumdisplay.php?f=220)
-   -   Trailing-Stop (http://www.expert-advisor.com/forum/showthread.php?t=3930)

halobungie 25.10.14 09:15

Trailing-Stop
 
Hallo,
kann mir jemand helfen diesen Trailing-Stop so abzuändern, dass er ALLE offenen Positionen trailt und dann ALLE im Gewinn schliesst? So wie er jetzt programmiert ist, trailt er nur einzelne Positionen und schliesst diese im Gewinn.

Hier der Code:

extern string S1 = "EURUSD";

//Trailing-Function-Inputs******************************************** ************************************************** *************************
extern bool ProfitTrailing_S1 = true;
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 |
//+------------------------------------------------------------------+
if (!ProfitTrailing_S1){
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) )
{
TrailingPositions_S1();
}
}
}
//+----------------------------------------------------------------+
//| END |
//+----------------------------------------------------------------+



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

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

if (!ProfitTrailing_S1 || (pBid-OrderOpenPrice())>TrailingStop*pp) {
if (OrderStopLoss()<pBid-(TrailingStop+TrailingStep-1)*pp) {
ModifyStopLoss_S1(pBid-TrailingStop*pp);
return;
}
}
}
if (OrderType()==OP_SELL) {
pAsk = MarketInfo(S1, MODE_ASK);
if (!ProfitTrailing_S1 || 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 25.10.14 10:32

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

FXClicks 25.10.14 15:25

http://www.expert-advisor.com/forum/...html#post10922

Agricolas 25.02.15 14:48

Servus & Hallo,

Hab es mal versucht bei meinem Code einzufügen...
Aber es funzt nicht ganz.
Woran liegt es, dass der Kompiler immer von "illigeal use of void ..." spricht?

Nordlicht 25.02.15 19:57

Habe da eine Ahnung. ;)

Stell doch mal Deinen Code rein. Sonst wird Dir ohnehin schwer Hilfe zu Teil werden.

Agricolas 28.02.15 11:05

Hallo & Danke für Deine Antwort - hab es bereits lösen können :-) Der Teil wurde von mir an der falschen Stelle eingefügt - nun steht es vor "int start" und alles ist gut.

Grüße aus Franken


Alle Zeitangaben in WEZ +2. Es ist jetzt 16:21 Uhr.

Powered by vBulletin® Version 3.8.5 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.1
Powered by vBCMS® 2.7.0 ©2002 - 2024 vbdesigns.de
Copyright ©2009 - 2023 by Expert-Advisor.com - Das Metatrader Forum