Help with writing an 1/3 auto take profit ea

MQL5 지표 전문가

작업 종료됨

실행 시간 4 일
피고용인의 피드백
Very good to work with.

명시

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

}

응답함

1
개발자 1
등급
(17)
프로젝트
18
61%
중재
3
0% / 100%
기한 초과
1
6%
무료
2
개발자 2
등급
(94)
프로젝트
112
33%
중재
5
40% / 20%
기한 초과
5
4%
무료
3
개발자 3
등급
(41)
프로젝트
54
4%
중재
5
0% / 60%
기한 초과
4
7%
무료
4
개발자 4
등급
(7)
프로젝트
11
36%
중재
3
0% / 100%
기한 초과
0
무료
5
개발자 5
등급
(146)
프로젝트
172
23%
중재
7
29% / 43%
기한 초과
4
2%
로드됨
6
개발자 6
등급
(37)
프로젝트
59
27%
중재
25
20% / 52%
기한 초과
10
17%
작업중
7
개발자 7
등급
(63)
프로젝트
84
26%
중재
23
22% / 48%
기한 초과
23
27%
무료
8
개발자 8
등급
(563)
프로젝트
932
47%
중재
302
59% / 25%
기한 초과
124
13%
바쁜
9
개발자 9
등급
(463)
프로젝트
524
33%
중재
28
39% / 43%
기한 초과
7
1%
바쁜
10
개발자 10
등급
(61)
프로젝트
186
73%
중재
4
100% / 0%
기한 초과
1
1%
무료
11
개발자 11
등급
(35)
프로젝트
50
42%
중재
3
33% / 33%
기한 초과
4
8%
무료
12
개발자 12
등급
(251)
프로젝트
400
54%
중재
9
67% / 22%
기한 초과
36
9%
무료
비슷한 주문
Creating of an expert advisor or trading bot that uses a Top Down analysis (using monthly, weekly, daily, hourly, minutes ( 30, 15, 5, 1) to determine trade direction or trend direction and makes multiple trade decisions for mt4. You can use or combine accurate trend indicators
Hello The EA will work on particular zone choose by the user and can mark it on any TF and with some rules can open trades and mange the trade by some unique rules. the EA need to check the difference by RSI as well and with some extra rules . developer should have good attitude and good communication (englsih) with high performence and knowledge with coding EA
I am looking forward to automate my trading strategy where I use renko bars on Tradingview. I really want to use unirenkos too, but unfortunately I couldn't figure out how to use ninjatrader on my MacBook and Tradingview does not offer unirenkos. As far as I see from your offered services you are very familiar with ninjatrader. I wanted to ask you if you could code me an Indicator for unirenkos for Tradingview so I
I am looking forward to automate my trading strategy where I use renko bars on Tradingview. I really want to use unirenkos too, but unfortunately I couldn't figure out how to use ninjatrader on my MacBook and Tradingview does not offer unirenkos. As far as I see from your offered services you are very familiar with ninjatrader. I wanted to ask you if you could code me an Indicator for unirenkos for Tradingview so I
Hello The EA will work on particular zone choose by the user and can mark it on any TF and with some rules can open trades and mange the trade by some unique rules. the EA need to check the difference by RSI as well and with some extra rules . developer should have good attitude and good communication (englsih) with high performence and knowledge with coding EA
Hello, I want to create an EA that can be able to take and optimise trade bids using the trend tracker concept I have developed. The tracker will monitor 2 lines to determine the trend of the market and afterwards take bids towards the correct direction. It will also be able to use a distance between the bids for the direction of the trend and plan a reverse bid when the price of the extreme doesn’t change again. The
Gradient boosting and L2 100 - 200 USD
I am looking for a well experienced programmer to put/implement a gradient boosting algorithm and an L2 to reduce overfitting in my ea which l already have which uses indicators . If you are experienced please adhere
Hello, I'm looking for a developer for repair calendar in EA MT4/MT5 (News Filter - https://ec.forexprostools.com ) for all windows servers. Note: EA MT4/MT5 works with calendar on PC Win 10, 11 but not on all windows servers. I have the source code and will post within the comments section for review. If you are able to do this and quality. Please apply. Thanks
Create mt4 ea 50+ USD
To convert the provided MT4 indicator script into an Expert Advisor (EA) and implement prompt functionality for user input, we need to modify the code to handle external parameters and provide a user-friendly interface. Below is the EA code that incorporates prompts for user inputs
SCALP MARTINCALE SPY TIMEFRAME 1MIN CANDLE - SHORT SIDE ONLY 1-SET RISK : A IS A VARIABLE (HOW MUCH $) 2-SET ATR(3) : SET THE TIME AT WHICH THE ATR SHOULD BE TAKEN, IF SET 933AM THEN THE ATR OF THE 1MIN CANDLE AT 933AM CANDLE WILL BE USED (ROUND AT 0.25 UP OR DOWN) *USE NEW YORK TIME 3-SET MAX NUMBER OF ENTRY : B IS A VARIABLE 4-SET RSI(14) / C IS A VARIABLE, IF RSI(14) > C = ORDERS OPEN 5-IF RSI(14) > C IS TRIGGERED

프로젝트 정보

예산
30 - 100 USD
개발자에게
27 - 90 USD