Help with writing an 1/3 auto take profit ea

MQL5 Indikatoren Experten

Auftrag beendet

Ausführungszeit 4 Tage
Bewertung des Entwicklers
Very good to work with.

Spezifikation

I need an expert advisor to check for existing positions with a set take profit target and to close 1/3 of the position if the price reaches 1/3 of the take profit target and close another 1/3 of the position if price reaches 2/3 of the take profit target.


This is what google bard wrote but has too many errors.

If it could auto get the symbol from the chart that it is loaded onto that would be better too.


//+------------------------------------------------------------------+

//| Expert Advisor code generated by MetaTrader 5 |
//|                                                   |
//| Author: Bard                                       |
//| Date: 2023-05-14                                   |
//|                                                   |
//+------------------------------------------------------------------+

#property copyright "Bard"
#property link "https://bard.ai"
#property version "1.00"

#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\AccountInfo.mqh>

//--- variables
CPositionInfo m_position; // trade position object
CTrade m_trade; // trading object
CSymbolInfo m_symbol; // symbol info object
CAccountInfo m_account; // account info wrapper

//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit() {

  // Get the symbol info
  m_symbol = SymbolInfo("US30.a");

  // Get the account info
  m_account = AccountInfo();

  // Set the expert magic number
  m_trade.SetExpertMagicNumber(13324);

  // Set the deviation in points
  m_trade.SetDeviationInPoints(10);

  return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit() {}

//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick() {

  // Get the current price
  double price = MarketInfo("US30.a", MODE_BID);

  // Check if there are any open orders
  if (m_trade.GetOrdersTotal() > 0) {

    // Loop through the open orders
    for (int i = 0; i < m_trade.GetOrdersTotal(); i++) {

      // Get the current order
      CTrade order = m_trade.GetOrder(i);

      // Check if the order is a buy or sell order
      if (order.GetType() == ORDER_TYPE_LONG || order.GetType() == ORDER_TYPE_SHORT) {

        // Calculate the 1/3 take profit price
        double takeProfit1 = price + (m_symbol.GetStopLoss() / 3);

        // Calculate the 2/3 take profit price
        double takeProfit2 = price + (m_symbol.GetTakeProfit() / 2);

        // Check if the price has reached the 1/3 take profit price
        if (price >= takeProfit1) {

          // Sell 1/3 of the position
          if (order.GetType() == ORDER_TYPE_LONG) {
            m_trade.Sell(order.GetLots() / 3, order.GetPrice());
          } else {
            m_trade.Buy(order.GetLots() / 3, order.GetPrice());
          }
        }

        // Check if the price has reached the 2/3 take profit price
        if (price >= takeProfit2) {

          // Sell another 1/3 of the position
          if (order.GetType() == ORDER_TYPE_LONG) {
            m_trade.Sell(order.GetLots() / 3, order.GetPrice());
          } else {
            m_trade.Buy(order.GetLots() / 3, order.GetPrice());
          }
        }
      }
    }
  }
}

//+------------------------------------------------------------------+
//| Expert start function |
//+------------------------------------------------------------------+
void OnStart() {

}

//+------------------------------------------------------------------+
//| Expert stop function |
//+------------------------------------------------------------------+
void OnStop() {

}

Bewerbungen

1
Entwickler 1
Bewertung
(16)
Projekte
17
65%
Schlichtung
3
0% / 100%
Frist nicht eingehalten
1
6%
Frei
2
Entwickler 2
Bewertung
(92)
Projekte
109
34%
Schlichtung
5
40% / 20%
Frist nicht eingehalten
5
5%
Arbeitet
3
Entwickler 3
Bewertung
(41)
Projekte
54
4%
Schlichtung
5
0% / 60%
Frist nicht eingehalten
4
7%
Frei
4
Entwickler 4
Bewertung
(7)
Projekte
11
36%
Schlichtung
3
0% / 100%
Frist nicht eingehalten
0
Frei
5
Entwickler 5
Bewertung
(137)
Projekte
160
23%
Schlichtung
7
0% / 43%
Frist nicht eingehalten
4
3%
Beschäftigt
6
Entwickler 6
Bewertung
(37)
Projekte
59
27%
Schlichtung
25
20% / 52%
Frist nicht eingehalten
10
17%
Arbeitet
7
Entwickler 7
Bewertung
(63)
Projekte
84
26%
Schlichtung
23
22% / 48%
Frist nicht eingehalten
23
27%
Frei
8
Entwickler 8
Bewertung
(563)
Projekte
932
47%
Schlichtung
301
59% / 25%
Frist nicht eingehalten
124
13%
Arbeitet
9
Entwickler 9
Bewertung
(453)
Projekte
512
33%
Schlichtung
25
40% / 48%
Frist nicht eingehalten
7
1%
Beschäftigt
10
Entwickler 10
Bewertung
(56)
Projekte
175
71%
Schlichtung
4
100% / 0%
Frist nicht eingehalten
1
1%
Frei
11
Entwickler 11
Bewertung
(35)
Projekte
50
42%
Schlichtung
3
33% / 33%
Frist nicht eingehalten
4
8%
Frei
12
Entwickler 12
Bewertung
(251)
Projekte
400
54%
Schlichtung
9
67% / 22%
Frist nicht eingehalten
36
9%
Frei
Ähnliche Aufträge
I installed the E.A. into the Experts folder in MT4. When I double click on it nothing happens. When I right click and "attach to chart" nothing happens. The E.A. is not grayed out, it simply will not attach. Any help would be greatly Appreciated
I have an EA and want to add few new logic to fetch profit taking factors and other values from an external master data and use it in existing EA
Hello Every one, Good day, I want from someone professional to create an EA is working on Mt5, This EA is working by depend on some indicators, and all those indicators must be working on MACD window, not on the chart, for more details please read my attached pdf file carefully. Many Thanks
I'm looking for an expert MQL5 developer that can create an EA that's based on my price action trading strategy with no indicators. The EA must analyze trades based on my price action rules, enter trades based on my price action rules, manage trades based on my price action rules and exit trades based on my price action rules
hi hi there i have an strategy on tradingview and i want to automate it like metatrader EA so i want the strategy to open and close trade automaticlly on tradingview
We are looking for an experienced Expert Advisor Developer who can build a customized MT5 Expert Advisor for us. The Expert Advisor would use two built-in indicators as entry/exit signals and our own risk management strategy with customizable inputs. The goal is to create a reliable and efficient trading tool that can automate our trading process on the MT5 platform. Skills required: - Strong understanding of
I need stochastic div (hidden &regular ea) that should perform task in all tf's ..divergence is a repaint stly so i want to use it with candlestick flips .. so bet for it
Hello, I have an indicator from a friend and I'd like to replicate it on my own TradingView or MT5 platform. Could you assist me with that?. Here is the link
so basically I have an EA(mql5), AI script(python), flask server and socket server both on python. Now this is an experimental script as I am trying to learn. However the EA is not entering any trades. How much would it cost for you to troubleshoot this for me? Thank you in advance
NEW FUNCTION 50+ USD
La idea es la siguiente, sería un EA semi automático. Yo como trader opero en zonas. En adelante las vamos a denominar ``zonas calientes´´. El EA debe que necesito debe operar conforme a 4 zonas calientes que yo configure en el mismo. ¿Qué hará el EA en cada una de esas zonas calientes que yo he configurado? En cada una de estas zonas el EA debe realizar hedging (crear un rango en el cual el EA entrara en sell o en

Projektdetails

Budget
30 - 100 USD
Für die Entwickler
27 - 90 USD