//+------------------------------------------------------------------+ //| Trendlinie Expert Advisor | //| | //| Entwickelt von ChatGPT (OpenAI) | //+------------------------------------------------------------------+ // Externe Eingabeparameter input int trendline_period = 20; // Periode der Trendlinie input double stop_loss = 50.0; // Stop Loss in Pips input double take_profit = 100.0; // Take Profit in Pips input double lot_size = 0.1; // Lot Größe // Globale Variablen int trend_line = 0; // Trendlinien-Handle double prev_high = 0.0; // Vorheriges Hoch double prev_low = 0.0; // Vorheriges Tief bool is_buy_signal = false; // Buy Signal bool is_sell_signal = false; // Sell Signal //+------------------------------------------------------------------+ //| Expert Advisor Start Funktion | //+------------------------------------------------------------------+ void OnTick() { // Wenn eine Position bereits offen ist, dann nichts tun if (PositionSelect(_Symbol)) return; // Trendlinie berechnen if (trend_line == 0) trend_line = ObjectCreate(_Symbol, OBJ_TREND, 0, Time[0], Low[0], Time[trendline_period], High[trendline_period]); else ObjectSet(trend_line, OBJPROP_PRICE1, Low[0]); // Durchbruch der Trendlinie prüfen double cur_high = High[trendline_period - 1]; double cur_low = Low[trendline_period - 1]; if (prev_high == 0.0 || prev_low == 0.0) { prev_high = cur_high; prev_low = cur_low; } else { if (cur_high > prev_high && High[0] < ObjectGetDouble(_Symbol, OBJPROP_PRICE1, 0) && High[1] < ObjectGetDouble(_Symbol, OBJPROP_PRICE1, 1)) { // Buy Signal is_buy_signal = true; } else if (cur_low < prev_low && Low[0] > ObjectGetDouble(_Symbol, OBJPROP_PRICE1, 0) && Low[1] > ObjectGetDouble(_Symbol, OBJPROP_PRICE1, 1)) { // Sell Signal is_sell_signal = true; } prev_high = cur_high; prev_low = cur_low; } // Position eröffnen if (is_buy_signal) { // Buy Order double stop_loss_price = NormalizeDouble(ObjectGetDouble(_Symbol, OBJPROP_PRICE1, 0) - stop_loss * _Point, Digits); double take_profit_price = NormalizeDouble(ObjectGetDouble(_Symbol, OBJPROP_PRICE1, 0) + take_profit * _Point, Digits); double open_price = NormalizeDouble(ObjectGetDouble(_Symbol, OBJPROP_PRICE1, 0), Digits); int ticket = OrderSend(_Symbol, OP_BUY, lot_size, open_price, 3, stop_loss_price, take_profit_price); if (ticket > 0) is_buy_signal = false; } else if (is_sell_signal) { // Sell Order double stop_loss_price = NormalizeDouble(ObjectGetDouble(_Symbol, OBJPROP_PRICE1, 0) + stop_loss * _Point, Digits); double take_profit_price = NormalizeDouble(ObjectGetDouble(_Symbol, OBJPROP_PRICE1, 0) - take_profit * _Point, Digits); double open_price = NormalizeDouble(ObjectGetDouble(_Symbol, OBJPROP_PRICE1, 0), Digits); int ticket = OrderSend(_Symbol, OP_SELL, lot_size, open_price, 3, stop_loss_price, take_profit_price); if (ticket > 0) is_sell_signal = false; } } //+------------------------------------------------------------------+ //| Expert Advisor Initialisierungsfunktion | //+------------------------------------------------------------------+ int OnInit() { return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert Advisor Deinitialisierungsfunktion | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { // Trendlinie entfernen if (trend_line != 0) ObjectDelete(trend_line); } //+------------------------------------------------------------------+