Debug / Fix Coding For EA

Trabajo finalizado

Plazo de ejecución 5 minutos
Comentario del Cliente
Abu is an excellent coder and easy to work with.
Comentario del Ejecutor
Nice meeting you.. above and beyound.. 100% recommended 🌟🌟🌟🌟🌟

Tarea técnica

I have a strategy EA in mq4 that I wrote and it has several problems I can't resolve.  The strategy is a long only breakout trading strategy designed to run on a basic bar chart.  It is fairly simple and does not have any elaborate money management, pyramiding, targets or stop losses.  It has roughly 100 lines of code.  The logic is there and it compiles OK (with one warning) but is not generating the expected trades in the strategy tester.  I previously coded this EA in Excel and it should be generating 50-100 trades per year on 30 min bars, but it's not.  I've tried to adapt code I found in the mql5 forums but it's not working right. 

I need this EA to do the following:

  1. Reference the last bar close[1] versus the highest close[2 and 3], lowest close[2] and moving average[1].  I tried to populate arrays with these values, but got array value access errors.  So I switched to using the shift parameter e.g. iMA(NULL,0,bar period,length,shift,...) but I don't think it's the same values and isn't working. I'd like to store these values in arrays and access them to compare to the last bar close[1].
  2. Enter and exit long trades on the current bar open
  3. Use the external variable EAid to identify trades and positions created by this EA, and only trade those.  (EAid is used as variable for MagicNumber)
  4. Allow only one open unfilled trade order at a time.   
  5. Allow only one open filled position at a time.  No pyramiding if the EA strategy conditions are met a second time after a position is opened.
  6. Trade only once per bar so it doesn't keep sending new orders on the current bar.
  7. Check for available account margin to enter a new trade and not allow trade orders if there is insufficient capital in the account
  8. Specify external variables to input / optimize: HH and HC lookback, MA length, Lots, Slippage, EAid, a variable to trade at market or max spread, a time variable to specify maximum time an entry order can be open before it's cancelled
  9. I generally trade at market, but may want to trade the EA with a maximum bid-ask spread (which I assume will result in some missed trades).  I would like an external variable to specify either, and if max spread is chosen, to use the Slippage value.  I would also like to specify the max time an entry order can be open, then have the EA automatically cancel that order if it's not filled within the specified time. 
  10. If the trade screen / symbol where the EA is running is closed or the EA is stopped with open orders or positions, then automatically cancel open orders and sell all positions in that screen at market.  If this is not possible (e.g. MetaTrader crashes, or is shut down too fast without sending orders, or the Internet goes out) then the EA should check for open positions when it is reopened. 
  11. All entry and exit trades should be displayed on the chart.

Problems to fix on this EA:

  • The EA only generates a single trade in strategy testing at the beginning of the test period and doesn't close the trade according to the exit conditions.  I'm expecting 50-100 trades per year on 30 minute bars.
  • Code the HC, LC and MAVG arrays correctly so they store the historical values for 4 past bars, and these values are accessed correctly in the entry / exit logic
  • Warning "return value of 'OrderSelect' should be checked"  (I eliminated this warning with some code found in the forums but I don't know if it's right)
  • Warning "return value of 'OrderClose' should be checked"
  • Keep the code that's good (including code I commented out but didn't know how to use) and delete the code that's wrong or useless
  • General cleanup of variables, etc. 
  • Any other problems 
  • Save as version 1.1 in mq5 format (it's currently in mq4 cuz I just started it that way for no reason)

My EA code is below, warts and all...


//+------------------------------------------------------------------+

//|                                       BreakoutModel_v1_FOREX.mq4 |

//|                             Copyright 2020, Lawrence H. Klamecki |

//|                                                                  |

//+------------------------------------------------------------------+

#property copyright "Copyright 2020, Lawrence H. Klamecki"

#property link      ""

#property version   "1.0"

#property strict


//--- input parameters

//extern allows you to change these variables from the strategy tester

extern int      Lookback=10;     //LOOKBACK PERIOD FOR HIGHEST HIGH AND LOWEST LOW

extern int      MAlen=50;        //SIMPLE MOVING AVERAGE LENGTH

extern double   Lots=0.1;       //FIXED NUMBER OF LOTS TO TRADE 1 LOT = 100,000 CURRENCY

extern int      Slip=10;       //SLIPPAGE PER TRADE = LOTS * PIP SIZE * PIP SPREAD  EX: 0.1 LOTS * $10 * 5 PIPS =  $5

int             EAid=1007;     //ID OF THIS EXPERT ADIVISOR USED TO IDENTIFY THE SOURCE OF ORDERS IT GENERATES

int  BarsCount, i, n, halt1, total ;

//extern double   StartEquity=1000.00;       //STARTING EQUITY IN USD

//extern double   Leverage=10.0;       //LEVERAGE USED PER TRADE

//int      Shift=1;   //SHIFT (0=current bar, 1 = last bar, 2 = 2 bars ago etc)



// START EA CODE

int start()

{

   //double HC[4];     //HC ARRAY CONTAINING 4 HIGHEST CLOSE VALUES

   //double LC[4];     //LC ARRAY CONTAINING 4 LOWEST CLOSE VALUES

   //double MAVG[4];   //MAVG ARRAY CONTAINING 4 MAVG VALUES

   double HC1, HC2, HC3, LC1, LC2, MAVG1;

   int ticket;

   int cnt = 0; 

   

   

   //POPULATE ARRAYS WITH LAST 4 HC AND LC VALUES i.e. positions 0 to 3

   //for (n = 0; n < 4; n++)  

   

   //NOTE - I SWITCHED TO SHIFTED VALUES BELOW INSTEAD OF ARRAY VALUES TO GET EA TO COMPILE.  LAST PARAMETER IS BAR SHIFT.

   // INSTEAD OF SHIFTED HC1, HC2, HC3 ETC I WANT TO USE HISTORICAL HC[1], HC[2], HC[3] ETC VALUES FROM ARRAYS IN ENTRY-EXIT LOGIC


      HC1 = Close[Highest(NULL, 0, MODE_CLOSE, Lookback, 1)];  //HIGHEST CLOSE[1] IN LOOKBACK PERIOD

      HC2 = Close[Highest(NULL, 0, MODE_CLOSE, Lookback, 2)];  //HIGHEST CLOSE[2] IN LOOKBACK PERIOD

      HC3 = Close[Highest(NULL, 0, MODE_CLOSE, Lookback, 3)];  //HIGHEST CLOSE[3] IN LOOKBACK PERIOD

      LC1 = Close[Lowest(NULL, 0, MODE_CLOSE, Lookback, 1)];  //LOWEST CLOSE[1] IN LOOKBACK PERIOD

      LC2 = Close[Lowest(NULL, 0, MODE_CLOSE, Lookback, 2)];  //LOWEST CLOSE[2] IN LOOKBACK PERIOD

      MAVG1 = iMA(NULL,0,MAlen,0,MODE_SMA,PRICE_CLOSE,1);   //MOVING AVERAGE VALUE[1] (SYMBOL(NULL=CHART SYMBOL),BAR PERIOD(0=BAR PERIOD OF CHART),LENGTH,MA SHIFT(+FWD,-BACK),MA TYPE,PRICE,VALUE SHIFT)

      

   //LONG ENTRIES

   //CHECK THAT EA HAS NO OPEN ORDERS

   if(OrdersTotal()<1) 

   {

     //THEN CHECK THAT EA HAS NO OPEN POSITIONS (THIS EA DOES NOT ALLOW PYRAMIDING)

     //TBD -- HOW TO CODE THIS?

     

     //THEN CHECK FOR INSUFFICIENT FUNDS IN ACCOUNT

     if(AccountFreeMargin()<(1000*Lots))

         {

         Print("Insufficient funds to enter new trade. Free Margin = ", AccountFreeMargin());

         return(0);  //exit

         }

     

     //THEN IF LONG TRADE CRITERIA ARE MET OPEN BUY ORDER

     //ENTER LONG IF CLOSE[1] > HIGHEST CLOSE[2] AND CLOSE[1] < HIGHEST CLOSE[3] AND CLOSE[1] > MAVG[1]

     //REFERENCE HIGHEST CLOSE, LOWEST CLOSE AND MAVG VALUES FROM ARRAYS ABOVE

     if((Close[1]>HC2) && (Close[2]<HC3) && (Close[1]>MAVG1))  //NOTE - THESE VARIABLES ARE THE SHIFTED VALUES I CREATED TO GET THE EA TO COMPILE.  I WANT TO USE HISTORICAL ARRAY VALUES IN THE ENTRY-EXIT LOGIC.

         //OPEN BUY TICKET

         ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,Slip,0,0,"BREAKOUT OPEN",EAid,0,Green);  //SYMBOL,BUY OR SELL OPERATION,LOTS,BID/ASK PRICE,SLIPPAGE,STOP LOSS,TARGET PROFIT(e.g. Ask+TakeProfit*Point),ORDER TEXT,MAGIC NUMBER,DATETIME EXPIRATION,COLOR

         if(ticket>0) 

            {

            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 

               Print("BUY order opened : ",OrderOpenPrice());

            }

         else Print("Error opening BUY order : ",GetLastError()); 

         return(0); // exit

         }

   

   else if(OrdersTotal()>0) 

     {

     //LONG EXITS

     for(cnt=0;cnt;)

         {

         if(!OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))break;

         if(OrderType()!=OP_BUY && OrderSymbol()!=Symbol() && OrderMagicNumber()!=EAid){continue;}

         if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==EAid)  // check for open long position, symbol & EAid

            {

            //EXIT IF EXISTING POSITION AND LAST CLOSE < PREVIOUS LOWEST CLOSE OR LAST CLOSE < LAST MAVG

            if(Close[1]<LC2 || Close[1]<MAVG1)    //NOTE - THESE VARIABLES ARE THE SHIFTED VALUES I CREATED TO GET THE EA TO COMPILE.   I WANT TO USE HISTORICAL ARRAY VALUES IN THE ENTRY-EXIT LOGIC.

               {

               OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slip,Gray);  //CLOSE LONG POSITION

               if(OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slip,Gray)==FALSE)

                  Print("Error closing BUY order : ",GetLastError()); 

               return(0); // exit

               }

            }

         }

      return(0); //exit

      }

   return(0); //exit

   }

return(0); //exit

}


//CODE PREVENTING MULTIPLE ORDERS FOR THE SAME SYMBOL ON THE SAME BAR - HOW TO USE THIS?

//int ticket(){

//  for (int t=0;t<OrdersTotal();t++)

//  {

//    if(OrderSelect(t,SELECT_BY_POS,MODE_TRADES))

//      if(OrderSymbol()==Symbol())return OrderTicket();

//  }

// return -1;

// }


//ALTERNATIVE CODE FOR EXITING OPEN POSITIONS - HOW TO USE THIS?

//   if(OrdersTotal()>0)

//   {

//      for(i=1; i<=OrdersTotal(); i++)   

//         {

//            if (OrderSelect(i-1,SELECT_BY_POS)==true)

//            {

//               if(OrderMagicNumber()==EAid) {halt1=1;} //IF THIS EA HAS AN ORDER OPEN THEN HALT!

//               {

               //LONG ENTRIES

               //ENTER LONG IF NO POSITION AND LAST CLOSE > PREVIOUS HIGHEST CLOSE 

               //AND PREVIOUS CLOSE < PREVIOUS PREVIOUS HIGHEST CLOSE AND LAST CLOSE > LAST MAVG

               //REFERENCE HC, LC AND MAVG VALUES FROM ARRAYS ABOVE USING POSITION VARIABLE IN BRACKETS [n]

//               if((Close[1]>HC[2]) && (Close[2]<HC[3]) && (Close[1]>MAVG[1]) && (halt1!=1))

//                  {

//                  int openbuy=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slip,0,0,"BREAKOUT OPEN",MagicNumber1,0,Green);

//                  }

//               }

//            }

//         }

//   }  

// }  


Han respondido

1
Desarrollador 1
Evaluación
(23)
Proyectos
45
20%
Arbitraje
25
28% / 48%
Caducado
12
27%
Libre
2
Desarrollador 2
Evaluación
(174)
Proyectos
199
12%
Arbitraje
38
37% / 34%
Caducado
5
3%
Trabaja
Ha publicado: 2 ejemplos
3
Desarrollador 3
Evaluación
(206)
Proyectos
333
35%
Arbitraje
66
12% / 58%
Caducado
87
26%
Libre
4
Desarrollador 4
Evaluación
(59)
Proyectos
81
43%
Arbitraje
27
11% / 70%
Caducado
8
10%
Libre
5
Desarrollador 5
Evaluación
(54)
Proyectos
53
17%
Arbitraje
7
0% / 100%
Caducado
5
9%
Libre
6
Desarrollador 6
Evaluación
(2642)
Proyectos
3357
68%
Arbitraje
77
48% / 14%
Caducado
342
10%
Libre
Ha publicado: 1 ejemplo
7
Desarrollador 7
Evaluación
(270)
Proyectos
552
49%
Arbitraje
57
40% / 37%
Caducado
227
41%
Trabaja
8
Desarrollador 8
Evaluación
(52)
Proyectos
89
25%
Arbitraje
8
75% / 13%
Caducado
44
49%
Trabajando
9
Desarrollador 9
Evaluación
(295)
Proyectos
474
39%
Arbitraje
103
41% / 23%
Caducado
79
17%
Ocupado
Ha publicado: 2 ejemplos
10
Desarrollador 10
Evaluación
(69)
Proyectos
146
34%
Arbitraje
13
8% / 62%
Caducado
26
18%
Libre
Ha publicado: 6 ejemplos
Solicitudes similares
I am looking for a professional MQL5 developer to build a MetaTrader 5 Expert Advisor from scratch. The EA will be called LadyKiller EA. It must trade only the following instruments: • XAUUSD (Gold) • US30 / Dow Jones Index Requirements: • Strong and reliable buy and sell entry logic • Stop Loss and Take Profit system • Risk management (lot size control) • Maximum trades protection • Drawdown protection • Trend
I need an mql5 EA which can be used with 100$ capital very low drawdown The EA should be high frequency trading special for XAUUSD and btcusd or binary options but also the EA should be testable via strategy tester and demo test for five days is needed NO SELECTION CAN BE DONE WITHOUT TESTING when applying make sure you send the backtester results with demo EA testable via strategy tester
I currently have a powerful and well-structured Expert Advisor available on the MT5 platform. This EA is designed with: ✅ Advanced entry and exit logic ✅ Smart risk management system ✅ Automatic lot sizing option ✅ Break-even and trailing stop protection ✅ Spread and session filters ✅ Drawdown control features ✅ Optimized for XAUUSD and scalping strategies ✅ Suitable for prop firm challenges like FTMO It is built for
Do you need a profitable and well-structured trading strategy converted into a fully automated Expert Advisor on the MT5 platform? I specialize in developing advanced, high-performance EAs with: ✅ Smart entry & exit logic ✅ Risk-based lot size calculation ✅ Break-even & trailing stop system ✅ Spread & session filters ✅ Daily drawdown protection ✅ Prop firm (FTMO-style) risk compliance ✅ Fully automated trade
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

Información sobre el proyecto

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