Help with writing an 1/3 auto take profit ea

MQL5 Indicadores Experts

Trabalho concluído

Tempo de execução 4 dias
Comentário do desenvolvedor
Very good to work with.

Termos de Referência

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

}

Respondido

1
Desenvolvedor 1
Classificação
(16)
Projetos
17
65%
Arbitragem
3
0% / 100%
Expirado
1
6%
Livre
2
Desenvolvedor 2
Classificação
(92)
Projetos
109
34%
Arbitragem
5
40% / 20%
Expirado
5
5%
Trabalhando
3
Desenvolvedor 3
Classificação
(41)
Projetos
54
4%
Arbitragem
5
0% / 60%
Expirado
4
7%
Livre
4
Desenvolvedor 4
Classificação
(7)
Projetos
11
36%
Arbitragem
3
0% / 100%
Expirado
0
Livre
5
Desenvolvedor 5
Classificação
(137)
Projetos
160
23%
Arbitragem
7
0% / 43%
Expirado
4
3%
Carregado
6
Desenvolvedor 6
Classificação
(37)
Projetos
59
27%
Arbitragem
25
20% / 52%
Expirado
10
17%
Trabalhando
7
Desenvolvedor 7
Classificação
(63)
Projetos
84
26%
Arbitragem
23
22% / 48%
Expirado
23
27%
Livre
8
Desenvolvedor 8
Classificação
(563)
Projetos
932
47%
Arbitragem
301
59% / 25%
Expirado
124
13%
Trabalhando
9
Desenvolvedor 9
Classificação
(453)
Projetos
512
33%
Arbitragem
25
40% / 48%
Expirado
7
1%
Carregado
10
Desenvolvedor 10
Classificação
(56)
Projetos
175
71%
Arbitragem
4
100% / 0%
Expirado
1
1%
Livre
11
Desenvolvedor 11
Classificação
(35)
Projetos
50
42%
Arbitragem
3
33% / 33%
Expirado
4
8%
Livre
12
Desenvolvedor 12
Classificação
(251)
Projetos
400
54%
Arbitragem
9
67% / 22%
Expirado
36
9%
Livre
Pedidos semelhantes
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

Informações sobre o projeto

Orçamento
30 - 100 USD
Desenvolvedor
27 - 90 USD