Help with writing an 1/3 auto take profit ea

MQL5 Indicadores Asesores Expertos

Trabajo finalizado

Plazo de ejecución 4 días
Comentario del Ejecutor
Very good to work with.

Tarea técnica

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() {

}

Han respondido

1
Desarrollador 1
Evaluación
(21)
Proyectos
25
52%
Arbitraje
3
0% / 100%
Caducado
2
8%
Libre
2
Desarrollador 2
Evaluación
(101)
Proyectos
123
31%
Arbitraje
7
29% / 29%
Caducado
5
4%
Trabajando
3
Desarrollador 3
Evaluación
(44)
Proyectos
60
5%
Arbitraje
6
0% / 67%
Caducado
5
8%
Libre
4
Desarrollador 4
Evaluación
(7)
Proyectos
11
36%
Arbitraje
3
0% / 100%
Caducado
0
Libre
5
Desarrollador 5
Evaluación
(287)
Proyectos
359
29%
Arbitraje
37
27% / 65%
Caducado
10
3%
Trabaja
Ha publicado: 10 ejemplos
6
Desarrollador 6
Evaluación
(37)
Proyectos
59
27%
Arbitraje
26
19% / 54%
Caducado
10
17%
Trabaja
Ha publicado: 1 ejemplo
7
Desarrollador 7
Evaluación
(70)
Proyectos
91
25%
Arbitraje
26
19% / 54%
Caducado
25
27%
Libre
8
Desarrollador 8
Evaluación
(574)
Proyectos
945
47%
Arbitraje
309
58% / 27%
Caducado
125
13%
Libre
9
Desarrollador 9
Evaluación
(625)
Proyectos
733
34%
Arbitraje
48
52% / 40%
Caducado
14
2%
Trabajando
10
Desarrollador 10
Evaluación
(78)
Proyectos
246
74%
Arbitraje
7
100% / 0%
Caducado
1
0%
Libre
Ha publicado: 1 artículo
11
Desarrollador 11
Evaluación
(35)
Proyectos
50
42%
Arbitraje
3
33% / 33%
Caducado
4
8%
Libre
12
Desarrollador 12
Evaluación
(251)
Proyectos
400
54%
Arbitraje
9
67% / 22%
Caducado
36
9%
Libre
Ha publicado: 2 ejemplos
Solicitudes similares
‎A trending candle followed by a smaller trending candle which is the second candle with no 5EMA ‎ ‎The 3rd candle is a reversal candle in which it and it's immidiate previous candle must be at least 70% of each other's body or equal body, with no 5EMA touch ‎ ‎the 3rd candle candle is followed immediately by the 4th candle which is the signal candle in which it and the 1st cabdle must be also at least 70% of
LynxMT5algo 30 - 100 USD
An mt5 add on indicator like gainalgo style to show entrance and exit areas for gold silver and Btc scalping. It will be used to make trading more easy for beginners
I have the Fisher Indicator shown below the chart. I need an alert added for when the Fisher Indicator hits the 50 point at the end of each period. GBPUSD and EURUSD 4H charts are provided and I can provide additional
Hello here, I need someone who can work on pinescript and also with Renko charts. My entries for my strategy would be based on stop orders Kindly let me know if you can work on this for me and i will send necessary file and quote in the chat
Freelance Task — EA Recovery Layer Hello. I have a ready-made MQL5 EA. The signals, SL/TP and lot calculation should essentially not be touched. I need a recovery system added. I am not a programmer — below is how the robot should behave. What stays Entry only from an EA signal. Stop-loss is not a new signal. Trailing is already built into my EA — recovery does not implement its own trailing. If trailing is disabled
# SNRZ BOT — SESSION PROGRESS LOG Last updated: 2026-09-16 (local late-evening session) ## SAN BOT (new — cloned from SNRZ) - `MQL5\Experts\AutomatedOrderBot_SAN.mq5` / `.ex5` — v1.0, compiled 0 errors/0 warnings - Signal source: custom indicator "SAN" (InpSANName, buy buf 0 / sell buf 1, target bar 1), same SNRZ-style read, MA fallback if missing - Magic number 234567 (separate from SNRZ 123456 so both bots can run
Should be as it but no alarms, also we need to add a deep search so he can see all the preves candles and a memory function so its not slowing down the indicator. for higher time frames daily 4h 1h around 365 days and for lower time frames we do up to 20k bars but both flexible so i can change it later. the memory is important so the indicator is not always recalculating everything when a new candle shows especially
Hi, I need an experienced NinjaTrader 8/NinjaScript developer to finish or rebuild an automated futures strategy, ideally by the end of this week. I already have the complete TradingView Pine Script reference strategy, an existing ~2,000-line NinjaScript implementation, Playback logs, and known historical benchmark trades. MOST IMPORTANT REQUIREMENT: TRADINGVIEW ↔ NINJATRADER PARITY. The Pine Script is the reference
I need a custom MQL5 indicator for MetaTrader 5. The indicator must automatically print entry, stop loss, and take profit zones on the chart using dots. A critical requirement is that these dots must be non-lagging and absolutely non-repainting. Additionally, the indicator needs to identify and display current supply and demand zones. Please provide the mq5 source code and the ex5 file upon completion
I need an experienced trading-data specialist who can help me obtain 3–4 years of historical market data compatible with NinjaTrader 8 . The data will be used for trading strategy development, backtesting, and analysis

Información sobre el proyecto

Presupuesto
30 - 100 USD