Today, I would like to introduce the process of creating a product for an investment fund called EA Diamond Firms, which our team has worked on as a case study.

You may be a developer or someone new looking to create an EA for yourself. So, how can you create a profitable EA, and how can you know that it is profitable? What is the correct process for creating an EA?

In this article, I would like to share my perspective.

Please note: I'm not stating that this knowledge is either right or wrong; I just want to introduce our process.

Let's get started.

1. Generating EA Ideas

Whether you are a seasoned trader or new to the market, you have probably heard of the great investor Nicolas Darvas's strategy. He used the breakout strategy to make a lot of money in the market.

I also based my trading on this idea and developed this EA. The EA will execute trades based on the following 8 situations:

2. Programing

2.1.  Detect high and low to identify key price level areas.



      int indexHigh = findPeak(MODE_HIGH, lookBack, startLook);

      int indexLow = findPeak(MODE_LOW, lookBack, startLook);


      double highPrice = iHigh(_Symbol,PERIOD_CURRENT, indexHigh);

      double lowPrice = iLow(_Symbol,PERIOD_CURRENT, indexLow);

2.2.  Compare highPrice and lowPrice with the current peak and trough to assess the accuracy probability of the key level.


      if (highPrice != currentHigh && highPrice!=0) {

         currentHigh = highPrice;

         ObjectDelete(0, "KL Up");

         ObjectCreate(0,"KL Up",OBJ_TREND,0, iTime(_Symbol,Period(), indexHigh), iHigh(_Symbol,Period(), indexHigh), iTime(_Symbol,Period(), indexHigh-1), iHigh(_Symbol,Period(), indexHigh));        

         ObjectSetInteger(0,"KL Up", OBJPROP_RAY_RIGHT,false);

         ObjectSetInteger(0,"KL Up", OBJPROP_WIDTH, 5);



      if (lowPrice != currentLow && lowPrice!=0) {

         currentLow = lowPrice;

         ObjectDelete(0, "KL Down");

         ObjectCreate(0,"KL Down",OBJ_TREND,0, iTime(_Symbol,Period(), indexLow),iLow(_Symbol,Period(), indexLow), iTime(_Symbol,Period(), indexLow-1), iLow(_Symbol,Period(), indexLow) );

         ObjectSetInteger(0,"KL Down", OBJPROP_RAY_RIGHT,false);

         ObjectSetInteger(0,"KL Down", OBJPROP_WIDTH, 5);


2.3.  Execute buy/sell stop orders to capture the market breakout move.

  if (buySignal) {

      // open buy stop at currentHigh


      int ticket = OpenBuy(.GetHigh() + 3 * Point);



   if (sellSignal) {

      // open sell stop at currentLow


      int ticket = OpenSell(GetLow() - 3 * Point);


Note: When the key level changes, we will open a new trade based on the new key level and remove the trade at the old key level.

To ensure a breakout, we will set the buy/sell stop a distance of 3-5 points away from the entry point.

To ensure that we only have one trade open at a time, I use variables for marking purposes.


2.4.  Furthermore, to avoid double-sided fakeouts, we will check and open a trade only when we haven't opened a trade previously. In this case, the EA will not open a duplicate trade within 120 minutes.


// get last trade for this symbol

   COrder* order = _order.GetLastClosedOrder();

   if (order != NULL && (buySignal || sellSignal)) {

      // yes, then check number of minutes elapsed since this last trade has closed

      double timeElapsed =(double)(TimeCurrent() - order.CloseTime);

      timeElapsed /= 60.0;

      delete order;


      int minsSinceLastTrade = (int)timeElapsed;


      // did enough time pass since last trade ?

      if (minsSinceLastTrade < 120) {

         // no, then return






Above is the complete core algorithm code for the EA.



3. Explain each attached function of EA Diamond Firms or supplementary code for the finished product.


_stage: There are 5 stages from 1-5, and the EA will use this stage to detect key levels. There are many different ways and strategies to detect sideways zones or find key levels, so each strategy we use is referred to as a stage.

_timefiler: The EA will open trades based on the GMT time set in this section. You can adjust the hour to fit your preferences. If you don't have experience, you can use the default setting.

_orders: It manages the risk for each trade. There are 3 types to choose from: Fixed lots, fixed money, fixed % balance. Since the EA is designed to be suitable for Prop Firms, I recommend using fixed money or fixed % balance. The default backtest result is 0.5% per trade, which I think is suitable for the long term.

_news: It filters high, medium, and low impact news events. The EA will disable all trades and not execute any trading during the specified time. The default setting is to avoid trading 30 minutes before and after high-impact news events.

_smartmoney: The EA will manage capital based on mathematical probability formulas, helping the account grow by 1-2% each week.

_fund management: The EA will manage trades and prevent new trades from opening when violating daily drawdown or maximum loss limits as specified by investment funds. This ensures the safety of your account according to the criteria of the current investment fund. The default settings are a daily loss limit of 5% and a maximum loss limit of 8% for the account. This function helps keep your account healthy and prevents it from being wiped out or incurring excessive losses.



4. Back-test

After completing the code, we move on to the system's backtesting phase. Because with any trading strategy, there will be times of continuous wins and continuous losses. This is unavoidable for any system in the current world. However, if a trading strategy generates a long-term positive profit, it means that it has beaten the market.

To ensure accuracy, the system performs backtesting on real-data from 2008 to the present. The total data covers 15 years to ensure a long-term perspective and to avoid reliance on any specific period or luck.

The back-test is performed with default parameters.




5. Forward-test


Backtesting and generating profits alone do not guarantee that the EA will perform well. It is essential to undergo a forward test with real-time data to validate its effectiveness.

The EA has undergone a forward test, and the results are nearly identical to the back-test, with a 99.99% similarity. This demonstrates the EA's efficiency in the long term.




With an 88% win rate, it perfectly matches the backtest data. There are times when the market isn't favorable, and the EA experiences some drawdown. There are also times when the market is good, and the EA generates consecutive winning trades for over a month.

Currently, based on statistics, the EA is producing a positive profit, which is what we desire. All the data is in complete alignment with the backtest data.





6. Summarize


Above, I have presented and introduced the product. I hope this article will help you understand the process of coding and testing a winning product in the market.

Risk Warning: Trading is not always without risk, and past data cannot guarantee 100% certainty in the future. Please consider using your capital and risk management carefully.