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

Trabajo finalizado

Plazo de ejecución 22 horas
Comentario del Ejecutor
Great customer. I look forward to working with you again.
Comentario del Cliente
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.

Tarea técnica

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
}

Archivos adjuntos:

Han respondido

1
Desarrollador 1
Evaluación
(240)
Proyectos
301
28%
Arbitraje
33
24% / 61%
Caducado
9
3%
Trabaja
2
Desarrollador 2
Evaluación
(3)
Proyectos
6
17%
Arbitraje
0
Caducado
1
17%
Libre
Ha publicado: 3 ejemplos
3
Desarrollador 3
Evaluación
(9)
Proyectos
9
11%
Arbitraje
0
Caducado
2
22%
Libre
4
Desarrollador 4
Evaluación
Proyectos
0
0%
Arbitraje
0
Caducado
0
Libre
5
Desarrollador 5
Evaluación
(206)
Proyectos
333
35%
Arbitraje
66
12% / 58%
Caducado
87
26%
Libre
6
Desarrollador 6
Evaluación
(269)
Proyectos
397
27%
Arbitraje
38
39% / 50%
Caducado
1
0%
Trabaja
7
Desarrollador 7
Evaluación
(1)
Proyectos
1
0%
Arbitraje
2
0% / 0%
Caducado
0
Trabaja
8
Desarrollador 8
Evaluación
(47)
Proyectos
66
38%
Arbitraje
5
20% / 40%
Caducado
1
2%
Trabaja
9
Desarrollador 9
Evaluación
(361)
Proyectos
643
26%
Arbitraje
92
72% / 14%
Caducado
12
2%
Trabaja
Ha publicado: 1 ejemplo
10
Desarrollador 10
Evaluación
(12)
Proyectos
9
33%
Arbitraje
11
0% / 100%
Caducado
2
22%
Libre
11
Desarrollador 11
Evaluación
(1)
Proyectos
0
0%
Arbitraje
4
0% / 75%
Caducado
0
Libre
12
Desarrollador 12
Evaluación
(17)
Proyectos
21
10%
Arbitraje
4
50% / 50%
Caducado
1
5%
Trabaja
13
Desarrollador 13
Evaluación
(250)
Proyectos
460
26%
Arbitraje
140
20% / 59%
Caducado
100
22%
Trabaja
14
Desarrollador 14
Evaluación
(8)
Proyectos
12
33%
Arbitraje
0
Caducado
3
25%
Trabaja
15
Desarrollador 15
Evaluación
(2)
Proyectos
2
0%
Arbitraje
3
0% / 100%
Caducado
1
50%
Libre
16
Desarrollador 16
Evaluación
(270)
Proyectos
552
49%
Arbitraje
58
40% / 36%
Caducado
228
41%
Trabaja
Solicitudes similares
I am looking of an Expert Advisor (EA) that has undergone independent validation and demonstrates a capability to successfully navigate prop firm challenges, as well as efficiently manage funded accounts. It is imperative that you provide a comprehensive explanation of the strategy utilized by your EA, along with a demo version that has a 30-day expiration. This will facilitate extensive back testing and forward
Hellow,l hope you are well,l am writing to place an order for a professional trading robot.l am looking for a reliable,well optimized robot that can trade efficiently,manage risk properly and deliver consistent performance in the market,I am particularly interested in a trading robot that uses a proven and transparent strategy,has strong risk management features,works well on common trading platforms,is suitable for
I am looking for an experienced MQL5 developer to build a professional MT5 software (indicator or semi-automated EA) for metals and major forex pairs. 📌 PLATFORM & MARKETS Platform: MetaTrader 5 Instruments: XAUUSD (Gold vs USD) XAGUSD (Silver vs USD) EURUSD GBPUSD USDJPY Trading styles: Scalping Intraday / short-term swing 🎯 MAIN OBJECTIVE I do NOT want an aggressive fully automated robot. I want a
The robot will take buy trades when the 2 ema cross over the 10 ema and price has closed above the 50 ema. The take profit and stop loss can be set as an optional level by the user. The robot will take sell trades when the 2 ema cross under the 10 ema and price has closed under the 50 ema. The take profit and stop loss can be set as an optional level by the user. The entry timeframe will be 15 minutes, but it could
I want to check if this indicator is repainting or not Whick mean the results of back testing is legit or not if anyone can help me to review it kindly to well to contact me i will be happy to work and go on long term work with anyone thanks
Specifications – Development of an MQL5 Expert Advisor (Reverse Engineering) Project context: I have access to a real trading history consisting of more than 500 trades executed over a period of approximately 3 years. These trades have been exported into a CSV file containing all available information, including date, time, symbol, order type, entry price, and exit price. Important: I do not have access to the
1.Sinyal Perdagangan : Sinyal beli: garis MACD utama memotong garis sinyal ke atas (macd_current>signal_current && macd_previous<signal_previous). Sinyal jual: garis MACD utama memotong garis sinyal ke bawah (macd_current<signal_current && macd_previous>signal_previous). Gambar di bawah menunjukkan kasus beli dan jual. 2. Posisi ditutup pada sinyal yang berlawanan: Posisi beli ditutup pada sinyal jual, dan posisi
Trading Bot Executes Trades on Specific Days via TradingView Alerts **As a** trader, **I want** to develop a trading bot that integrates with TradeLocker and MTS, **So that** when a TradingView alert (based on a 2,4,5,10,15,30 minute break and retest strategy whichever one) is triggered first. the bot will execute trades on both platforms, but only on specific days of the week. --- ## Acceptance Criteria 1
Project Description I am looking to collaborate with an experienced MQL5 / algorithmic trading developer who also has hands-on experience with Large Language Models (LLMs) and AI-driven systems. This is a long-term partnership opportunity , not a one-off paid freelance job. I bring 9 years of practical Elliott Wave trading experience , applied in live market conditions. The objective is to translate Elliott Wave
Hello, I’m looking for an experienced MT4 (MQL4) developer to convert the Lucky Reversal indicator from indicatorspot.com into a fully functional Expert Advisor (EA). Project Scope Code an MT4 EA that replicates the exact logic and signals of the Lucky Reversal indicator Trades should open and close automatically based on the indicator’s rules Must match indicator behavior 1:1 (no approximations) EA Requirements MT4

Información sobre el proyecto

Presupuesto
30 - 50 USD
Plazo límite de ejecución
de 1 a 20 día(s)