MQL5 Wizard - Trading signals based on Morning Star/Evening Star + Stochastic indicator - MetaTrader 5 Expert











There is the book "Strategies of the Best Traders " (in Russian), where many trading strategies are considered, we will focus on the reversal candlestick pattern, which has been represented by Stochastic , CCI , MFI and RSI oscillators.
The best way is to create a separate class derived from Expert Signal for checking the formation of candlestick patterns. For the confirmation of trading signals generated by candlestick patterns, it is enough to write a class derived from CCandlePattern and add in it the necessary functionality (for example, confirmation by oscillator).
Here we will consider signals based on the Morning Star/Evening Star (Morning Doji/Evening Doji) reversal candlestick pattern, confirmed by the Stochastic indicator. The trading signals module is based on the CC candle pattern class, which is a simple example of creating trading signals using candlestick patterns.
1. “Morning Star” and “Evening Star” Reversal Candlestick Patterns
1.1.Morning Star
This pattern signals a reversal in a downtrend and consists of three candles (Figure 1). After the long black candle, there is a candle with a smaller body (the color does not matter) that is outside the body of the black candle. A smaller candle body means bulls and bears have equal power and the market is ready to change trend.
The third candle of the pattern is a bullish candle, its body does not overlap with the body of the second candle, and the closing price is within the body of the first (bearish) candle. The candlesticks generated by the model are also plotted in Figure 1.
In the case where the second candle is a Doji candle, the model is named "Morning Star Doji".

Figure 1. “Morning Star” and “Morning Star Doji” candlestick patterns
The recognition of the "Morning Star" pattern is implemented in the CheckPatternMorningStar() and CheckPatternMorningDoji() methods of the CC candle pattern class:
//+------------------------------------------------------------------+ //|Check the formation of the "Morning Star" pattern | //+------------------------------------------------------------------+ Boolean valueCCandlePattern ::CheckPatternMorningStar() { //--- Morning Star if ((open( 3 )-close( 3 )>average body( 1 )) && // bearish candle whose real body is greater than the average body of the candle ( mathematical antibody (close( 2 )-open( 2 )))( 1 ) The closing price of the last completed candle is higher than the center of the first candle Return ( True ) ; // --- Return ( False ) ; } //+------------------------------------------------------------------+ //|Check the formation of the "Morning Doji" pattern | //+------------------------------------------------------------------+ BooleanCCandlePattern ::CheckPatternMorningDoji() { //--- Morning Doji if ((open( 3 )-close( 3 ))>average body( 1 )) && // bearish candle with candle body greater than average candle body (average body( 2 ) 1 )* 0.1 ) && // The real body of the second candle is very small (Doji) (Close( 2 )<Close( 3 )) && //The close of the second candle is lower than the close of the first candle (Open( 2 )<Open( 3 )) && //The open of the second candle is lower than the open of the first candle (Open( 1 )>Close( 2 )) && //Upward gap of the last completed candle (Close( 1 ) )>Close( 2 ))) //The closing price of the last completed candle is higher than the closing price of the second candle return ( true ); //--- return ( false ); }
CheckCandlestickPattern(CANDLE_PATTERN_MORNING_STAR) and CheckCandlestickPattern(CANDLE_PATTERN_MORNING_DOJI) methods CC Candlestick Pattern class are used to check the formation of "Morning Star" and "Morning Star Doji" candlestick patterns.
1.2.Evening Star
This pattern indicates a reversal in an uptrend and consists of three candles (Figure 2). After the long white candle, there is a candle (color is not important) with a very small body, outside the body of the white candle. A smaller candle body means bulls and bears have equal power and the market is ready to change trend.
The third candle of the pattern is a bearish candle, its body does not overlap with the body of the second candle, and the closing price is within the body of the first (bullish) candle. The candlesticks generated by the model are also plotted in Figure 2.
For the case where the second candle is a Doji candle, the model is named "Evening Doji Star".

Figure 2. “Evening Star” and “Evening Doji” candlestick patterns
Here's how to identify the "Evening Star" and "Evening Doji" patterns:
//+------------------------------------------------------------------+ //|Check the "Formation of Evening Stars" pattern | //+------------------------------------------------------------------+ BooleanCCandlePattern ::CheckPatternEveningStar() { //--- Evening Star if ((Close( 3 )-Open( 3 ))>Average Body( 1 )) && // Bullish Candle with Real Body Above Average Body ( Mathematical Ab (Close( 2 )-Open( 2 )))( 1 ) The closing price of the last completed candle is below the center of the first candle Return ( True ) ; // --- Return ( False ) ; } //+------------------------------------------------------------------+ //|Check the "Formation of Evening Cross Stars " pattern | //+------------------------------------------------------------------+ BooleanCCandlePattern ::CheckPatternEveningDoji() { //--- Evening Cross if ((close( 3 )) - open( 3 )>average body( 1 )) && // Bullish candle with body above average (average body( 2 ) 1 )* 0.1 ) && // The real body of the second candle is very small (Doji) (Close( 2 )>Close( 3 )) && //The close of the second candle is higher than the close of the first candle (Open( 2 )>Open( 3 )) && //The open of the second candle is higher than the open of the first candle (Open( 1 )<Close( 2 )) && //The downward gap of the last completed candle (Close(2)) 1 ) < close ( 2 ))) // The closing price of the last completed candle is lower than the closing price of the second candle return ( true ); // --- return ( false ); }
CheckCandlestickPattern(CANDLE_PATTERN_EVENING_STAR) and CheckCandlestickPattern(CANDLE_PATTERN_EVENING_DOJI) methods CC Candlestick Pattern class are used to check the formation of "Evening Star" and "Evening Doji Star" candlestick patterns.
2. Trading signals, confirmed by stochastic indicator
The closing of an open position depends on the value of the %D indicator. This can be done in two situations:

Figure 3. “Evening Star” pattern confirmed by stochastics
2.1. Open long position/close short position
The formation of the "Morning Star" pattern must be determined by the Stochastic indicator: StochSignal(1)<30 (the value of the signal line of the last completed bar of the Stochastic indicator must be less than 30).
If the signal line Stochastic has crossed the 20 or 80 levels upwards.
//+------------------------------------------------------------------+ //|Check the conditions for entering and exiting the market | //| 1) Enter the market (open long position, result = 80) | //| 2) Market Exit (Close Position, Result=40) | //+------------------------------------------------------------------+ Integer CMS_ES_Stoch::LongCondition() { Integer result = 0 ; //--- idx can be used to determine the Expert Advisor working mode //--- idx=0 - in this case the EA checks the trading conditions on every price move //--- idx=1 - in this case the EA only checks the trading status of the news bar integer idx =StartIndex(); //--- checks the conditions for opening a long position //--- Morning star pattern and signal line < 30 are formed if (CheckCandlestickPattern(CANDLE_PATTERN_MORNING_STAR) && (StochSignal( 1 ) < 30 )) Result = 80 ; //--- check closing conditions //--- Signal line crossover for overbought/oversold levels (down 20, up 80) if ((((StochSignal( 1 )> 20 ) && (StochSignal( 2 )< 20 )) || ((StochSignal( 1 )> 80 ) && (StochSignal( 2 )< 80 )))) result = 40 ; //--- return result return (result); }
2.2. Open short position/close long position
The "Evening Star" pattern must be formed by the Stochastic indicator: StochSignal(1)>70 (the value of the Stochastic indicator signal line of the last completed bar must be greater than 70).
If the signal line Stochastic has crossed below the 80 or 20 levels.
//+------------------------------------------------------------------+ //|Check the conditions for entering and exiting the market | //| 1) Enter the market (short position, result=80) | //| 2) Market Exit (Close Position, Result=40) | //+------------------------------------------------------------------+ Integer CMS_ES_Stoch::ShortCondition() { Integer result = 0 ; //--- idx can be used to determine the Expert Advisor working mode //--- idx=0 - in this case the EA checks the trading conditions on every price move //--- idx=1 - in this case the EA only checks the trading status of the news bar integer idx =StartIndex(); //--- checks the conditions for opening a short position //--- Evening Star formation and signal line > 70 if (CheckCandlestickPattern(CANDLE_PATTERN_EVENING_STAR) && (StochSignal( 1 ) > 70 )) result = 80 ; //--- Check closing conditions //--- Signal line crossover for overbought/oversold levels (80 down, 20 up) if ((((StochSignal( 1 ) < 80 ) && (StochSignal( 2 ) > 80 )) || ((StochSignal( 1 )< 20 ) && (StochSignal( 2 )> 20 )))) result = 40 ; //--- return result return (result); }
2.3. Use the MQL5 Wizard to create an Expert Advisor
The CMS_ES_Stoch class is not included in the standard library classes, to use it you need to download the acms_es_stoch.mqh file (see attachment) and save it to client_terminal_data\folder\MQL5\Include\Expert\Signal\MySignals. The same operation should be performed for the candlepatterns.mqh file. After restarting MetaEditor, you can use it in the MQL5 Wizard.
Create Expert Advisor Launch MQL5 Wizard :

Figure 4. Creating an Expert Advisor using the MQL5 Wizard
Let's specify the name of the Expert Advisor:

Figure 5. General properties of EA trading
After that we need to choose the trading signal module to use.

Figure 6. Signal properties of EA trading
In our case we use only one trading signals module.

Figure 7. Signal properties of EA trading
Added trading signals module:

Figure 8. Signal properties of EA trading
You can choose any trailing attribute, but we will use "Unused Trailing Stop":

Figure 9. Tracking properties of Expert Advisor
Regarding the money management properties, we will use "Fixed Volume Trading":

Figure 10. Money management attributes of EA trading
Press the "Finish" button and we will get the code of the generated Expert Advisor in Expert_AMS_ES_Stoch.mq5, which will be saved in terminal_data_folder\MQL5\Experts\.
Default input parameters of the generated Expert Advisor:
//--- Main signal input Input integer Signal_ThresholdOpen = 10 ; //Open signal threshold[0...100] Input integer Signal_ThresholdClose = 10 ; // Close signal threshold [0...100] Enter double Signal_PriceLevel = 0.0 ; // price level at which to execute the trade Enter double Signal_StopLevel = 50.0 ; // Stop loss level in pips Enter double Signal_TakeLevel = 50.0 ; // Take profit level (in pips)
Must be replaced with:
//--- Main signal input Input integer Signal_ThresholdOpen = 40 ; //Open signal threshold[0...100] Input integer Signal_ThresholdClose = 20 ; // Close signal threshold [0...100] Enter double Signal_PriceLevel = 0.0 ; // price level at which to execute the trade Enter double Signal_StopLevel = 0.0 ; // Stop loss level in points Enter double Signal_TakeLevel = 0.0 ; // Take profit level (in pips)
Signal_ThresholdOpen/Signal_ThresholdClose input parameters allow specifying threshold levels for opening and closing positions.
In the code of the LongCondition() and ShortCondition() methods of the trading signal class, we specify the fixed value of the threshold:
The Expert Advisor generates opening and closing positions by the MQL5 Wizard using "votes" in the Trading Signals module. The vote of the main module (which acts as a container and consists of all added modules) is also used, but its LongCondition() and ShortCondition() methods always return 0.
The voting results from the main module are also used for "voting" averaging. In our case we have: main module + 1 trading signals module, so we need to take this fact into account when setting the thresholds. Therefore, ThresholdOpen and ThresholdClose must be set to 40=(0+80)/2 and 20=(0+40)/2.
The value of the Signal_StopLevel and Signal_TakeLevel input parameters is set to 0, which means that the position will be closed only if the closing conditions are met.
2.4. Historical backtest results
Let's consider the EA's backtesting of historical data (EURUSD H1, test period: 2000.01.01-2011.03.16, PeriodK=12, PeriodD=8, PeriodSlow=29, MA_period=4).
When creating the EA, we used a fixed trading volume ( fixed lot size for trading , 0.1) and did not use the trailing stop algorithm ( trailing was not used ).

Figure 11. EA trading test results based on Morning Star/Evening Star + Stochastic indicator
The best set of input parameters for the Strategy Tester MetaTrader 5 client can be found using the following command.
The EA trading code created by the MQL5 Wizard is attached in Expert_ams_es_stoch.mq5 .
Attachment download
📎 acandlepatterns.mqh (20.34 KB)
📎 acms_es_stoch.mqh (8.47 KB)
📎expert_ams_es_stoch.mq5 (7.24 KB)
Source: MQL5 #301
MQL5 Wizard - Trading Signals Based on Morning Star/Evening Star + Stochastic Indicator - MetaTrader 5 Expert Pre-Use Tips
This page has been supplemented with structured instructions, focusing on the use of foreign exchange indicators, MT4/MT5 platform compatibility, testing procedures and risk control. Before downloading or deploying, it is recommended to first determine whether it is consistent with your own variety, cycle and account environment.
Suitable for who to use
- Users who want to quickly screen foreign exchange indicators and are willing to do simulation verification first.
- People who need to compare MT4/MT5 EAs, indicators, scripts or source code projects.
- Traders who wish to record backtests, parameters and risk boundaries before placing a trade.
Testing and risk control suggestions
- First verify the default parameters in the strategy tester or demo account, and then adjust the symbol, period, spread and trading period one by one.
- Scalping, grid, martin, and high-frequency strategies should focus on observing maximum drawdowns, consecutive losses, slippage, and trading frequency.
- It is not recommended to run any document directly on the real disk. At least observe the simulated disk performance for 2-4 weeks first.
FAQ
Can MT4 and MT5 be used interchangeably?
Usually cannot be used directly. EX4/MQ4 corresponds to MT4, EX5/MQ5 corresponds to MT5, and the source code needs to be compiled in the corresponding MetaEditor.
Is this resource guaranteed to be profitable?
cannot. EAs, indicators and scripts can only be used as trading tools, and the results depend on parameters, market environment, spreads, slippage and risk control.
What else can I continue to watch?
Forex EA download , foreign exchange indicator download , EA evaluation , MQL5 CodeBase .
English Search Notes
This page is also optimized for English search intent around MQL5 Wizard - Trading signals based on Morning Star/Evening Star + Stochastic indicator - MetaTrader 5 Expert . Related search terms include: Forex indicator, MT4 indicator, MT5 indicator. Test any Forex EA, Expert Advisor, MT4/MT5 indicator, script or MQL source code with historical data and a demo account before live trading.
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •