Moin,
mein Code funktionierte noch vorhin, und jetzt irgendwie nicht mehr und ich verstehe nicht wieso.
Ziel des ganzen ist folgendes:
1. Take Profit Bestimmung durch 2*ATR Wert + Triggerzone (der Strategie, also einfach ein fester Wert.)
2. Breakeven setzen wenn der Trade 1*ATR im Profit ist.
3. SL Bestimmung durch 1*ATR abgezogen (oder addiert je nachdem obs Buy oder Sell ist ) von der Triggerzone.
Code:
bool bResult=false;
double EinmalATR = iATR(OrderSymbol(),_Period,14,1);
double ZweimalATR = 2*iATR(OrderSymbol(),_Period,14,1);
double dBuyTPatr = dZoneHigh + ZweimalATR;
double dSellTPatr = dZoneLow - ZweimalATR;
double dBuySLatr = dZoneHigh - EinmalATR;
double dSellSLatr = dZoneLow + EinmalATR;
if (Schritt1 == true && Schritt2 == true && Schritt3 == true && Schritt4 == true && IsNewCandle ()) {
int BuyStop = OrderSend
(
Symbol(), // currency pair on the chart
OP_BUYSTOP, // place a buystop
Lotsize, // how much lot
dBuyStop, // entry
20, // allow only 3 pips of deviation
dBuySLatr, // StopLoss
dBuyTPatr, // TakeProfit
NULL, // no comment
0, // no ID number
ExpirationTime, // expiration date
Green // color of the order in the chart
);
int SellStop = OrderSend
(
Symbol(), // currency pair on the chart
OP_SELLSTOP, // place a buystop
Lotsize, // how much lot
dSellStop, // entry
20, // allow only 3 pips of deviation
dSellSLatr, // StopLoss
dSellTPatr, // TakeProfit
NULL, // no comment
0, // no ID number
ExpirationTime, // expiration date
Green // color of the order in the chart
);
for(int i = OrdersTotal() - 1; i >= 0; i--) {
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if(OrderType() == OP_BUY && OrderOpenPrice() > OrderStopLoss() && Bid - OrderOpenPrice() >= EinmalATR) {
bResult = OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), 0);
}
if(OrderType() == OP_SELL && OrderOpenPrice() < OrderStopLoss() && OrderOpenPrice() - Ask >= EinmalATR){
bResult = OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), 0);
}
}
}
}
else {
return;
}
Mein Problem ist nun folgendes. Die Orders setzt er jeweils nur einmal und sie laufen auch nach der genauen Zeit ab.
Allerdings werden die Takeprofits komisch bestimmt (ich habe das ganze auf GBPJPY getestet, was ein sehr volatiles Währungspaar ist und das auf H1), und die Stoplosse immer clean auf 15 Pips, und das versteh ich nicht.
HTML-Code:
13 2019.10.03 04:05 sell stop 6 9.98 (Preis)131.585 (SL)131.736 (TP)131.582 (Gewinn)0.00 (Kontostand)99899.64
kann mir da vllt jemand mal erklären was ich falsch gemacht habe?
das ganze ist übrigens in MQL 4 geschrieben..