Adding features to an ea orderClose, Highertrend filters, moneymgmt, trailing TP

Работа завершена

Время выполнения 22 часа
Отзыв от исполнителя
Great customer. I look forward to working with you again.
Отзыв от заказчика
Excellent developer knows what he is talking about and is easy to communicate with great reviser and able to get all the tasks done on time. i will return with my next work.

Техническое задание

Hello, 


i am a experienced programmer but I am newish to mql 4 and mql 5 i have been trying to add some code to my EA so it can close orders after three day but this not working.


I have created one of my first EA that is profitable, but there is a big flaw in this EA. it has massive drawdown, which cut massive profit, I found that that the orders that do this can be fixed through two rules, order max open time and higher timeframe filters, both options will be implemented but the closing order older then three days would be the best first fix. other features like trailing take profit and compounding lots size will further increase profits.

It is late and I need some sleep, but i would love it if someone could help me with this i have so amazing backrest with this EA as the rules are simple..


the next set of feature i am trying to add is...

trailing takeprofit in step of 50 points

higher trend filters up, down consolidation so trade, wait

close trades after three days.



this is the function code...


//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
    // Open new buy order if none exist
    if(OrdersTotal() == 0)
    {
        int buyTicket = OrderSend(_Symbol, OP_BUY, 0.01, Ask, 3, 0, Ask+10*_Point, NULL, 0, 0, clrGreen);
        if(buyTicket < 0)
        {
            Print("Buy order failed. Error: ", GetLastError());
        }
        else
        {
            Print("Buy order opened. Ticket: ", buyTicket);
        }
    }
    
    // Check and close orders older than 60 minutes
    int maxDuration = 60 * 60; // 60 minutes in seconds
    
    for(int i = OrdersTotal()-1; i >= 0; i--) // Loop backwards for safety
    {
        if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
            if(OrderSymbol() == _Symbol) // Only process orders for this symbol
            {
                int duration = TimeCurrent() - OrderOpenTime();
                
                if(duration >= maxDuration)
                {
                    // Determine correct close price based on order type
                    double closePrice = (OrderType() == OP_BUY) ? Bid : Ask;
                    
                    // Attempt to close the order
                    bool closed = OrderClose(
                        OrderTicket(),
                        OrderLots(),
                        closePrice,
                        5,        // Slippage
                        clrRed    // Closing arrow color
                    );
                    
                    if(!closed)
                    {
                        Print("Failed to close order #", OrderTicket(),
                              " Error: ", GetLastError(),
                              " Type: ", OrderType(),
                              " Ask: ", Ask,
                              " Bid: ", Bid);
                    }
                    else
                    {
                        Print("Closed order #", OrderTicket(),
                              " after ", duration/60, " minutes");
                    }
                }
            }
        }
        else
        {
            Print("OrderSelect failed for index ", i, " Error: ", GetLastError());
        }
    }
}
//+------------------------------------------------------------------+

the ea code....

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Print initialization message
   Print("EA initialized successfully");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
// --- input parameters
input int HigherTimeframeIndex = 1; // e.g., 1 for H1 if current timeframe is M5
input int  TimeframeLength = 1; // e.g., 1 if current timeframe is M5 (5 minutes)
input int  HigherTimeframePeriod = 60; //e.g., 60 minutes for H1 timeframe
string INDICATOR_CALC_ERROR;
string INDICATOR_CALC_FINISHED;
string INDICATOR_REQUIRED_MORE_DATA;

void OnTick()
  {
  
  double previous_high = iHigh(_Symbol,_Period,1);
      double previous_low = iLow(_Symbol,_Period,1);
      double current_high = iHigh(_Symbol,_Period,1);
      double current_low = iLow(_Symbol,_Period,1);
      double current_Open = iOpen(_Symbol,_Period,0);
      double current_Close = iClose(_Symbol,_Period,0);
      int trendStatus = GetHigherTimeframeTrend(PERIOD_H4);
      string HTS = "";
      
//--- Debugging information
   static int lastTickTime = 0;
   if(TimeCurrent() == lastTickTime) return; // Only run once per tick
   lastTickTime = TimeCurrent();
   
   string TradingSignal = CheckEntryEMA();
   string Filter = CheckEntrySTOCHASTIC();
   

//--- Print signals for debugging
   Print("EMA Signal: ", TradingSignal, " | Stochastic Filter: ", Filter);
   
//---- check higher time frame
   
//--- Buy condition
   if((TradingSignal == "buy") && (Filter == "buy") && (OrdersTotal() <= 0))
     {
      double stopLoss = Ask - 1500 * _Point;
      double takeProfit = Ask + 50 * _Point;
      
      if(current_high>=previous_high && current_low<previous_low && current_Close >= current_Open){
      
      int ticket = OrderSend(_Symbol, OP_BUY, 0.03, Ask, 3, stopLoss, takeProfit, "EMA+Stoch Buy", 0, 0, Green);
      
         if(ticket < 0)
           {
            Print("Buy Order Failed. Error: ", GetLastError());
           }
         else
           {
            Print("Buy Order Placed. Ticket: ", ticket);
           }
        }
      }
//--- Sell condition
   if((TradingSignal == "sell") && (Filter == "sell") && (OrdersTotal() <= 0))
     {
       stopLoss = Bid + 1500 * _Point;
       takeProfit = Bid - 50 * _Point;
       
      
       if(previous_high<=current_high && previous_low>=current_low){
       
       ticket = OrderSend(_Symbol, OP_SELL, 0.03, Bid, 3, stopLoss, takeProfit, "EMA+Stoch Sell", 0, 0, Red);
      
      if(ticket < 0)
        {
         Print("Sell Order Failed. Error: ", GetLastError());
        }
      else
        {
         Print("Sell Order Placed. Ticket: ", ticket);
        }
     }
    }
  }
//+------------------------------------------------------------------+

string CheckEntryEMA()
  {
   string signal = "";
   double ma20 = iMA(NULL, 0, 8, 0, MODE_EMA, PRICE_CLOSE, 0);
   double ma50 = iMA(NULL, 0, 13, 0, MODE_EMA, PRICE_CLOSE, 0);
   double ma20_prev = iMA(NULL, 0, 8, 0, MODE_EMA, PRICE_CLOSE, 1);
   double ma50_prev = iMA(NULL, 0, 13, 0, MODE_EMA, PRICE_CLOSE, 1);

   if(ma20 > ma50 && ma20_prev <= ma50_prev)
      signal = "buy";
   else if(ma20 < ma50 && ma20_prev >= ma50_prev)
      signal = "sell";
      
   return signal;
  }
  
// Higher time frame trend Reversal, consolidation and breakout.

string CheckEntrySTOCHASTIC()
  {
   string signal = "";
   double K0 = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 0);
   double D0 = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_SIGNAL, 0);
   double K1 = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 1);
   double D1 = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_SIGNAL, 1);

   if(K0 < 35 && D0 < 35 && K0 > D0 && K1 < D1)
      signal = "buy";
   else if(K0 > 65 && D0 > 65 && K0 < D0 && K1 > D1)
      signal = "sell";
      
   return signal;
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Function to get higher time frame trend direction                |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Function to analyze higher timeframe trend                       |
//+------------------------------------------------------------------+
/*
Returns:
 1 = Strong Uptrend
 2 = Weak Uptrend
 0 = Ranging/No Clear Trend
-1 = Weak Downtrend
-2 = Strong Downtrend
*/
int GetHigherTimeframeTrend(int higherTimeframe, int maPeriod = 50, double rangeThreshold = 0.005)
{
      // hts
      string HTS = "";
    // Get moving averages
    double maFast = iMA(NULL, higherTimeframe, maPeriod, 0, MODE_EMA, PRICE_CLOSE, 0);
    double maSlow = iMA(NULL, higherTimeframe, maPeriod*2, 0, MODE_EMA, PRICE_CLOSE, 0);
    double currentPrice = iClose(NULL, higherTimeframe, 0);
    
    // Get recent price range (last 20 bars)
    double highestHigh = iHigh(NULL, higherTimeframe, iHighest(NULL, higherTimeframe, MODE_HIGH, 20, 0));
    double lowestLow = iLow(NULL, higherTimeframe, iLowest(NULL, higherTimeframe, MODE_LOW, 20, 0));
    double rangeSize = (highestHigh - lowestLow) / lowestLow;
    
    // Check for ranging market
    if(rangeSize < rangeThreshold) 
    {
        return 0; // Market is ranging
    }
    
    // Determine trend strength
    if(currentPrice > maFast && maFast > maSlow)
    {
        // Strong uptrend conditions
        if(currentPrice > maFast * (1 + rangeThreshold/2) && maFast > maSlow * (1 + rangeThreshold/2))
            return 2; // Strong uptrend
        return 1; // Weak uptrend
        HTS = "buy";
        return HTS;
        printf(HTS);
    }
    else if(currentPrice < maFast && maFast < maSlow)
    {
        // Strong downtrend conditions
        if(currentPrice < maFast * (1 - rangeThreshold/2) && maFast < maSlow * (1 - rangeThreshold/2))
            return -2; // Strong downtrend
        return -1; // Weak downtrend
        HTS = "sell";
        return HTS;
        printf(HTS);
    }
    return HTS = "NoTrade";
    return 0; // No clear trend
}

Файлы:

Откликнулись

1
Разработчик 1
Оценка
(250)
Проекты
313
28%
Арбитраж
33
27% / 64%
Просрочено
10
3%
Работает
2
Разработчик 2
Оценка
(3)
Проекты
6
17%
Арбитраж
0
Просрочено
1
17%
Свободен
Опубликовал: 3 примера
3
Разработчик 3
Оценка
(15)
Проекты
16
25%
Арбитраж
1
0% / 0%
Просрочено
2
13%
Работает
4
Разработчик 4
Оценка
Проекты
0
0%
Арбитраж
0
Просрочено
0
Свободен
5
Разработчик 5
Оценка
(206)
Проекты
333
35%
Арбитраж
66
12% / 58%
Просрочено
87
26%
Свободен
6
Разработчик 6
Оценка
(272)
Проекты
401
27%
Арбитраж
39
41% / 49%
Просрочено
1
0%
Свободен
7
Разработчик 7
Оценка
(2)
Проекты
4
0%
Арбитраж
2
0% / 0%
Просрочено
1
25%
Работает
8
Разработчик 8
Оценка
(47)
Проекты
67
37%
Арбитраж
5
40% / 40%
Просрочено
1
1%
Свободен
9
Разработчик 9
Оценка
(361)
Проекты
643
26%
Арбитраж
92
72% / 14%
Просрочено
12
2%
Работает
Опубликовал: 1 пример
10
Разработчик 10
Оценка
(12)
Проекты
9
33%
Арбитраж
11
0% / 100%
Просрочено
2
22%
Свободен
11
Разработчик 11
Оценка
(1)
Проекты
0
0%
Арбитраж
4
0% / 75%
Просрочено
0
Свободен
12
Разработчик 12
Оценка
(18)
Проекты
22
9%
Арбитраж
6
33% / 50%
Просрочено
1
5%
Работает
13
Разработчик 13
Оценка
(250)
Проекты
460
26%
Арбитраж
140
20% / 59%
Просрочено
100
22%
Работает
14
Разработчик 14
Оценка
(10)
Проекты
14
43%
Арбитраж
0
Просрочено
3
21%
Свободен
15
Разработчик 15
Оценка
(2)
Проекты
2
0%
Арбитраж
3
0% / 100%
Просрочено
1
50%
Свободен
16
Разработчик 16
Оценка
(270)
Проекты
552
49%
Арбитраж
57
40% / 37%
Просрочено
227
41%
Работает
Похожие заказы
Hello, I'm looking to find out the cost of creating a mobile trading robot. I've tried to describe it as thoroughly as possible in the following document. I look forward to your response. I'd like to know the costs, delivery time, and how you plan to implement it before making a decision
I have an existing MT5 Expert Advisor (“E-Core”). I need an experienced MQL5 developer to integrate a structured risk management upgrade and a higher timeframe trend filter into the current code. Two files will be provided: 1️⃣ E-Core Source Code (Current Version) 2️⃣ Update Instructions File (contains exact inputs, functions, and logic to integrate) The developer must: Integrate the update logic
DO NOT RESPOND TO WORK WITH ANY AI. ( I CAN ALSO DO THAT ) NEED REAL DEVELOPING SKILL Hedge Add-On Rules for Existing EA Core Idea SL becomes hypothetical (virtual) for the initial basket and for the hedge basket . When price hits the virtual SL level , EA does not close the losing trades. Instead, EA opens one hedge basket in the opposite direction. Original basket direction Hedge basket direction (opposite) Inputs
Billionflow 30 - 100 USD
Trading specifications: Indicators: Bollinger band ( Period 40, Deviation 1 apply to close) Moving Average (Exponential ) Period 17 applied to high Moving Average ( Exponential ) Period 17 applied to low But Signal enter a buy trade when prices crosses the lower band of the bollinger band up and also crosses the moving average channel of high and low the reverse is true for sell signal
Hello, I am a user of the "BUY STOP SELL STOP V6" trading bot, which is an advanced Grid System bot. The bot is primarily designed for Gold (XAUUSD), but I want it to work on all currency pairs. "The bot contains a privacy/protection code that prevents it from running on other accounts or being modified on any platform, as it has a client account number lock mechanism" --- Bot Description & Current Settings Bot Type
I am looking for a highly experienced Pine Script v5 developer to build a professional, non repaint price action indicator for TradingView. or a ready made one so i can purchase. This is a structured two phase project. The goal is to create a clean, intelligent price action tool that works for both fast intraday trading and swing trading. Only apply if you have strong Pine experience and understand liquidity
Hello, I’m looking for an experienced MQL4/MQL5 developer to work with me on an ongoing basis. My clients request services such as: Converting TradingView Pine Script indicators/strategies into MT4 or MT5 Expert Advisors Converting MT4 EAs to MT5 (and MT5 to MT4) Compiling and fixing existing MQL4 / MQL5 EA code Adding simple features like alerts, SL/TP, lot size, and basic money management This job is for
I am looking someone to create an EA based on my MACD Histo indicator / strategy from Pinescript. I will send it to you for you to replicate. The EA shall have: - Divergence length in bars, min and max values. - Pivot Logic - Entry on close of divergence confirmation bar. - Dynamic lot size dependent on SL/TP, in monetary value. - SL / TP in percent away from entry, separate values for long and short. - Time, day and
Hello, I have a breakout EA with reversal logic. I own the full source code for both MT4 and MT5 versions. I need the modifications implemented for both MT4 and MT5 versions. I need several modifications: – Multiple reversals with configurable parameters – Breakeven functionality – Entry only after candle close beyond range + offset – Time-based activation – Alternative offset calculation logic – Automatic close at
simple automated trading system with adaptive risk management and trend-based execution. The EA manages trades with dynamic position handling and built-in stability filters. Designed for single-position trading and disciplined execution 30 usd budget

Информация о проекте

Бюджет
30 - 50 USD
Сроки выполнения
от 1 до 20 дн.