habe leider nichts dazu gefunden gibt es eine Möglichkeit bzw. Einstellung bei MT5 das sich der Stopp automatisch immer auf die nächste Kerze anpasst?
Hallo,
hier ist der EA der den Stopp unter eine Kerze setzt. Wird aber ohne zusätzliche Strategie das Depot auf Null setzen! Deswegen nicht im realen Account Testen!!
//+------------------------------------------------------------------+//| Stop Unter Kerze.mq5 |//| Copyright 2021, Pay24Money |//| https://p24m.eu |//+------------------------------------------------------------------+#property copyright"Copyright 2021, Pay24Money"#property link"https://p24m.eu"#property version"1.00"#include <Trade/Trade.mqh>
#include <Trade/SymbolInfo.mqh>
CTrade m_trade;
CSymbolInfo m_symbol;
CPositionInfo m_position;
CHistoryOrderInfo m_history;
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+inputulong Magic = 0; // Magicnummer 0 alle orders beachten (12345) Nur unter bestimmte Magic Nummer)inputbool OrdersSetzen = true; // Auf false setzen, wenn Orders manuel gesetzt werden!inputdouble Lots = 0.10; // Volumeneingabe//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit() {
if(!m_symbol.Name(_Symbol)) // sets symbol name
RefreshRates();
//---
m_trade.SetExpertMagicNumber(Magic);
//---
m_trade.SetMarginMode();
m_trade.SetDeviationInPoints(100);
m_trade.SetTypeFillingBySymbol(m_symbol.Name());
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason) {
}
voidOnTick() {
double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); // Ask aktueller Preisdouble Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits); // Bid aktueller Preisulong Spread = SymbolInfoInteger(_Symbol,SYMBOL_SPREAD); // Aktueller Spreaddouble LetzteKerzeLow = iLow(NULL,PERIOD_CURRENT,1); // Tief von letzte Kerzedouble LetzteKerzeHigh = iHigh(NULL,PERIOD_CURRENT,1); // Hoch von letzte Kerze//+------------------------------------------------------------------+//| Trailing Funktion |//+------------------------------------------------------------------+if (Fun_New_Bar(_Symbol,PERIOD_CURRENT)==true) {
Trailing();
}
staticENUM_POSITION_TYPE tipe_letzte_position=-1;
for(int i=PositionsTotal()-1; i>=0; i--) // Gibt die Anzahl der aktuellen Positionen zurückif(m_position.SelectByIndex(i)) // wählt die Position nach Index für den weiteren Zugriff auf seine Eigenschaften ausif(m_position.Symbol()== _Symbol && m_position.Magic()==Magic) {
tipe_letzte_position=m_position.PositionType(); // Ruft den Positionstyp abreturn;
}
// Orders automatich setzen! Achtung es werden immer nach einem Stop ein Order gesetzt!// OrdersSetzen auf False setzen!!if(OrdersSetzen == true) {
string symbol = _Symbol; // specify the symbol, at which the order is placedint digits = (int)SymbolInfoInteger(symbol,SYMBOL_DIGITS); // number of decimal placesdouble point = SymbolInfoDouble(symbol,SYMBOL_POINT); // pointdouble bid = SymbolInfoDouble(symbol,SYMBOL_BID); // current bid pricedouble ask = SymbolInfoDouble(symbol,SYMBOL_ASK); // current buy priceif(bid > LetzteKerzeHigh) {
double price = ask*point; // unnormalized open price
price = NormalizeDouble(price,digits); // normalizing open pricedouble SL = LetzteKerzeLow - (Spread*point); // Stop Loss in points
SL = NormalizeDouble(SL,digits); // normalizing Stop Loss
m_trade.Buy(Lots,NULL,price,SL,0,NULL); // Order senden
RefreshRates();
} elseif(ask < LetzteKerzeLow) {
double price = bid*point; // unnormalized open price
price = NormalizeDouble(price,digits); // normalizing open pricedouble SL = LetzteKerzeHigh + (Spread*point); // Stop Loss in points
SL = NormalizeDouble(SL,digits); // normalizing Stop Loss
m_trade.Sell(Lots,NULL,price,SL,0,NULL); // Order senden
RefreshRates();
}
}
}
//+------------------------------------------------------------------+//| Refreshes the symbol quotes data |//+------------------------------------------------------------------+bool RefreshRates() {
//--- refresh ratesif(!m_symbol.RefreshRates())
return(false);
//--- protection against the return value of "zero"if(m_symbol.Ask()==0 || m_symbol.Bid()==0)
return(false);
//---return(true);
}
//+------------------------------------------------------------------+// Trailingstopvoid Trailing() {
bool TrailingStop = true;
ulong Spread = SymbolInfoInteger(_Symbol,SYMBOL_SPREAD); // Aktueller Spreaddouble LetzteKerzeLow = iLow(NULL,PERIOD_CURRENT,1); // Tief von letzte Kerzedouble LetzteKerzeHigh = iHigh(NULL,PERIOD_CURRENT,1); // Hoch von letzte Kerzestring symbol = _Symbol;
double bid = SymbolInfoDouble(symbol,SYMBOL_BID); // current bid pricedouble ask = SymbolInfoDouble(symbol,SYMBOL_ASK); // current buy pricefor(int i=PositionsTotal()-1; i>=0; i--) // Gibt die Anzahl der offenen Positionen zurückif(m_position.SelectByIndex(i)) {
RefreshRates();
//---double price_current = m_position.PriceCurrent();
double price_open = m_position.PriceOpen();
double stop_loss = m_position.StopLoss();
double take_profit = m_position.TakeProfit();
double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
double SLBUY = LetzteKerzeLow - (Spread*_Point); // Buy Stop Loss in pointsdouble SLSELL = LetzteKerzeHigh + (Spread*_Point); // Sell Stop Loss in pointsdouble TralStopBuy = SLBUY * _Point;
double TralStopSell = SLSELL * _Point;
//---if(m_position.Symbol()== _Symbol && m_position.Magic()==Magic) { // Prüft nach Symbol und Magicnummerif(m_position.PositionType()==POSITION_TYPE_BUY) {
if(TrailingStop && bid > price_open) {
if(!m_trade.PositionModify(m_position.Ticket(),m_symbol.NormalizePrice(SLBUY),take_profit))
RefreshRates();
continue;
}
}
if (m_position.PositionType()==POSITION_TYPE_SELL) {
if(TrailingStop && ask < price_open) {
if(!m_trade.PositionModify(m_position.Ticket(), m_symbol.NormalizePrice(SLSELL),take_profit))
RefreshRates();
continue;
}
}
}
}
}
//+------------------------------------------------------------------+//| Funktion Timeframe und Chartperiod |//+------------------------------------------------------------------+bool Fun_New_Bar(string symbol,ENUM_TIMEFRAMES timeframe) {
staticdatetime Prev_Time=0;
if(Prev_Time == 0) {
Prev_Time = iTime(symbol,timeframe,0);
return(false);
}
if(Prev_Time!=iTime(symbol,timeframe,0)) {
Prev_Time = iTime(symbol,timeframe,0);
return(true);
}
return(false);
}
//+------------------------------------------------------------------+
hier ist der EA der den Stopp unter eine Kerze setzt. Wird aber ohne zusätzliche Strategie das Depot auf Null setzen! Deswegen nicht im realen Account Testen!!
Ich hoffe, dass ich Ihnen helfen konnte.
Gruß Igor.
Danke schon mal von mir! :-) Eine daran angelehnte, etwas komplexere Trailing-Stopp-Logik nutze ich gerne in meinem manuellen Trading.
Diesen EA zu verstehen und zu modifizieren werde ich deshalb zu meinem ersten Projekt machen, aus dem ich hoffentlich viel lernen kann.
Wenn Sie kein Benutzerkonto haben, registrieren Sie sich
Erlauben Sie die Verwendung von Cookies, um sich auf der Website MQL5.com anzumelden.
Bitte aktivieren Sie die notwendige Einstellung in Ihrem Browser, da Sie sich sonst nicht einloggen können.
Sie sind angemeldet. Die Zwei-Faktor-Authentifizierung wurde deaktiviert. Richten Sie sie erneut ein und scannen Sie einen neuen QR-Code oder fahren Sie mit deaktivierter Zwei-Faktor-Authentifizierung fort.
Hallo,
habe leider nichts dazu gefunden gibt es eine Möglichkeit bzw. Einstellung bei MT5 das sich der Stopp automatisch immer auf die nächste Kerze anpasst?
Hallo,
hier ist der EA der den Stopp unter eine Kerze setzt. Wird aber ohne zusätzliche Strategie das Depot auf Null setzen! Deswegen nicht im realen Account Testen!!
Ich hoffe, dass ich Ihnen helfen konnte.
Gruß Igor.
Hallo,
hier ist der EA der den Stopp unter eine Kerze setzt. Wird aber ohne zusätzliche Strategie das Depot auf Null setzen! Deswegen nicht im realen Account Testen!!
Ich hoffe, dass ich Ihnen helfen konnte.
Gruß Igor.
Diesen EA zu verstehen und zu modifizieren werde ich deshalb zu meinem ersten Projekt machen, aus dem ich hoffentlich viel lernen kann.