Indicator for evaluation of trading strategies

 

Many of us have often wanted to see in a visual way where a certain trading strategy has its flaws. And if we could see the objective trading statistics at the same time it would be really great.

There is a backtester in MT4 but running a backtest in a visual mode for each change in the EA takes a lot of time. Also, its visual capabilities are quite limited. Then, you cannot test multi-currency strategies with it, at least not in an efficient way.

I have tried to address all of these issues and the result is this open-source indicator for visually testing trading strategies. If you want to see the indicator in action please open the attached screen image. Of course it is not possible to make a completely universal indicator for all purposes but the current framework can easily be modified and expanded for specific needs (like multi-currency strategies).

Special attention has been put into spread management. The indicator takes spread into consideration in the same way as it is present in real trading and in the MT4 backtester. If you modify the indicator for your purposes you have to study the spread management in detail, otherwise you may see great strategy results on an M1 time frame, while in reality it would be a disaster.

For the demonstration also a sample trading indicator is attached, with a simple trading strategy. The strategy rules are based on MA crosses with respect to price action (so that trades can be placed even before they actually cross, to remove the lag). Exit strategy is also present (using opposite signals and slow MA crossing in an opposite way), as well as stop loss handling is implemented via a modified Chandelier SL strategy. Some people find this indicator good enough for their manual trading.

The idea behind the whole system

The system is built in a modular way. First, we have to implement the trading strategy into the trading indicator, where two buffers are currently used for entry signals, two for exit signals and one for stop loss. A sample trading indicator with full functionality is the attached StrategyIndi_1.0.

We can then evaluate that strategy with the strategy testing indicator StrategySym_1.0. If we are not satisfied with the results, we just optimize the trading indicator and we can see the results of changes in real-time and objectively, via statistics.

If we want later to implement a corresponding EA, it is very easy to do so, since by calling a custom trading indicator we get all the entry and exit signals, as well as SL values.

How to use this system and adapt it to your own needs?

To use the system as it is, you just copy both indicators to your Metatrader\experts\indicators folder. Make sure you restart the terminal before using them so that they get compiled.

There are certain settings you might want to modify, most are self-evident from their names so I will describe only the others:

StrategyIndi parameters:

ChandBars = 7 ________ number of bars for the Chandelier SL strategy

ChandATRFact = 2.0 ____ factor to multiply the long-term ATR, to get the Chandelier distance

RiskPercent = 2.0 ______ risk in percent of the free account balance for lot calculation according to the starting SL (this is used for manual trading information only)

Offset = 10 ____________ offset from bars on the chart for placing arrows, in 4-digit pips

BarsBack = 2000 _______ number of bars to process, from the past

AlertSound = "alert.wav" __ WAV file for sound alerts

UseSoundAlert = true ____ if we want sound alerts (for manual trading)

UsePopupAlert = true ____ if we want pop-up window alerts (for manual trading)

WriteToLog = false ______ if we want to write log details (for debugging)

StrategySim parameters

MaxLossAtSL = 200.0 ____ how much money (in account currency) we are ready to lose at each SL (for some it is more intuitive instead of percent, but is can be easily changed)

BarsBack = 2000 ________ number of bars to process for the strategy evaluation

WriteToLog = false _______ if we want to write log details (for debugging)

If you are adapting the system to your own needs you have to add to the StrategySym indicator all the parameters from your own StrategyIndi indicator � those that matter for the simulation. They are used later in the GetIndiSignals method and you just put fixed values for other parameters (like UseSoundAlert). Nothing else needs to be changed in the StrategySim, unless you want it for other purposes (like multi-currency strategies). In this case code comments and variable names will hopefully be helpful enough. If you need assistance we will be glad to help, just contact us at the web address below.

With this system I would like to contribute to the objectivity in evaluating trading strategies (for manual systems or EAs) as the current marketing approaches are often very manipulative and as such they (have) caused many beginners to lose their hard-earned money.

It would be great and fruitful for all traders and analysts if you could contribute evaluations of various strategies, as well as modifications of this system, to this thread.

Sincerely,

Robert Leskovar, MQLTools

For any MT4 programming requests or advising on the subject please contact me via e-mail robert [dot] leskovar [at] gmail [dot] com. The MQLTools web address in the MQ4 code is not active anymore.

 

!

Very interesting!...Tell me...how do I input my own strategy/indicators into indicator?...

 
Pava:
Very interesting!...Tell me...how do I input my own strategy/indicators into indicator?...

Hi Pava,

if you already have some kind of a signal or alert indicator it is quite easy. You should modify StrategyIndi code first so that you insert your indicator's logic to produce the following signals:

  1. buy and sell entry signals (put the logic in the TradeSignalmethod)
  2. buy and sell exit signals (put the exit strategy logic in the ExitManagement method. There is also a related SimSLHit method that produces exit signals when SL gets hit in history and in real-time, but you probably won't need to modify it)
  3. SL values when in trade (put the SL logic in the SetSL method)

After your StrategyIndi trading indicator signals work well, copy its extern variables to the strategy simulator indicator - (StrategySim). After that just change calls to the trading indicator accordingy - in the method GetIndiSignals of the StrategySim. There are iCustom calls and you should insert your trading indicator extern variable names - those that are important for the simulation, for others you can just fix values.

The proper name of the trading indicator should be inserted in the variable CustomIndName of the StrategySim indicator.

After you have many versions of StrategySim and StrategyIndi indicators, make sure you pay attention to the object prefixes (ObjPref variable values) in these indicators. They should be unique to each indicator and each version to prevent object interferences.

Hope this helps and - a lot of success.

 

Looking for Heiken Ashi indicator

Hi guys, do any of you know where I can get the Heiken Ashi indicator for Metatrader4 but where the indicator is placed BENEATH the main chart just like for example any oscillator indicator would be positioned?

 
jud500:
Hi guys, do any of you know where I can get the Heiken Ashi indicator for Metatrader4 but where the indicator is placed BENEATH the main chart just like for example any oscillator indicator would be positioned?

Don't have one but you have to place the indicator in the separate window (#property indicator_separate_window) and then reprogram the indicator to draw H A candles with objects. In existing H A indicators (those that I know, maybe someone already made the modification) they are drawn as the histogram, which is not usable for H A in separate windows.

 

automatation

How do you automate this indicator into an EA after the modifications have been made.

Thank you

 
sharwell:
How do you automate this indicator into an EA after the modifications have been made.

In the EA you just have to retrieve trading signals from the StrategyIndi indicator via iCustom function (just like it's done in the StrategySim indicator).

After each finished bar your EA will have to react to the signals. The StrategyIndi indicator is not written for trading inside bars but it's better to call it in the EA with iCustom after each tick so that all the inside logic (i.e. other indicators that you use inside of StrategyIndi) processes the current price data. But it has to react to signals only after the bar is finished.

So, the EA has to open orders when it gets buy/sell signals, close orders when it gets buy exit/sell exit signals and change SL according to the SL signal (optionally, as some traders prefer to exit with the buy exit/sell exit only).

 

Okay Thank you. I absolutely love how this tool test strategies and give you a visual on the chart. It's great.

Reason: