Short Trend Reversal
- Experts
- Tomasz Adrian Bialous
- Version: 1.6
- Updated: 25 April 2024
- Activations: 5
end year promotion /EA is a part of my Nash Equilibrium/
With this EA you can build a good profitable system. The EA was created to test signals for the main EA that I am creating, but when I saw the backtest results, I thought I would add a few lines and put it on the market. After adding over 1000 lines of code, here it is. It works on any classic currency pair /you just need to find the right settings/. It probably works on many other instruments, but you need to choose the right TakeProfit, StopLoss, min_dist, pending_dist. If you want to test other instruments, it is best to do large tests from methodology 2 with your own TP. Sample settings for GOLD, SILVER, OIL, SP500, DAX40 can be found in the params.txt file.
For EUR,USD,GBP,CHF,CAD,JPY,AUD,NZD between them crosses, pips calculated as for a 4-digit broker (inside multiplied by 10). The rest of the instruments as your broker has.
EA has the following settings coded Built-in settings: SAFE, MODERATE, AGGRESIVE, start by checking what it looks like with your broker /it was backtested with Vantage on an STP account in 2023/.
I recommend turning on several charts of one currency, for example several crosses EUR or USD or ... or mixed, and several TFs, this way you will obtain indirect hedging.
During the sale of promotional copies, will expand EA to multitimeframe and upgrade to version 2.0
Important: This EA should have StopLoss set to 0 while running. StopLoss is used to create a statistics file in the tester folder during backtests. There you will see useful information about the amounts of losing and profitable trades. Pips in this EA are calculated as for 4-digit-broker /FOR CURRENCIES ONLY/. The rest of the instruments as your broker has.
Rules and my backtest methodology:
- Disable the genetic algorithm if you want to use my statistics file
- Open prices only testing model. There is no need to test every tick because EA takes a position only on new candles
- set mine TP first: M15 TP=15, M30: TP =20, H1: TP=30, H4: TP=40 /change if you want, but try mine/
method 1 /detailed/
step one:
- EA default values: and disable the final_optimization parameter (enabled, averages trades, and we don't want that now), Built-in settings set to user
- BarsRange1: range 5-50 with step 5 (pattern higher lower trades)
- BarsRange2: range 3-15 with step 2 (pattern higher lower trades)
- TakeProfit as above (unless you prefer otherwise, I recommend mine to start with)
- StopLoss you accept (100,150,200 it depends on the symbol and is only used to count bad signals)
Run optimization with BarsRange1 and BarsRange2 selected. The results that the tester shows or does not show are not important. Important information is saved in the MT4/tester/files/ShortTrendReversal/*.txt file. The file is only created when StopLoss is greater than 0. Now open the created file. I recommend notepad++ for this because it reloads the file if it changes. Analyze the results.
step two:
- narrow the ranges of BarsRange1 and 2
- min_dist: range 10-70 with step 10 /minimum distance from the previous order, 0 completely disables the limit/
- pending_dist: range 10-70 with step 10 /pending order distance, 0 disables pending orders/
- StopLoss set to 0
- enable final_optimization
Run optimization. Now choose what suits you. Additionally, once you have your optimization results, you can set StopLoss as above call up the individual results. At this point /with StopLoss/ the result itself won't matter, but you can see and compare the new statistics in the file (MT4/tester/files/ShortTrendReversal/*.txt). Statistics will be different than before and will certainly be very helpful in making decisions. You can save selected results to a file with external parameters (MQL4/files/ShortTrendReversal/params.txt). Details can be found in the file.
My rules when backtesting Built-in settings: SAFE,MODERATE,AGGRESIVE
SAFE: BarsRange2 range 7-11MODERATE: BarsRange2 range 5-7,9
AGGRESIVE: BarsRange2 range 3-5,7
method 2 /fast and simple/
Everything as above in one go.
- EA default values
- BarsRange1: range 5-50 with step 5 /pattern higher lower trades/
- BarsRange2: range 3-15 with step 2 /pattern higher lower trades/
- min_dist: range 10-70 with step 10 /minimum distance from the previous order, 0 completely disables the limit/
- pending_dist: range 10-70 with step 10 /pending order distance, 0 disables pending orders/
- TakeProfit set my TP first: M15 TP=15, M30: TP =20, H1: TP=30, H4: TP=40
- StopLoss set to 0
- enable final_optimization
While writing this description, I extended the pending_dist functionality and did not backtested it. When you set a negative value, the EA will set a buy stop order a few pips above the local high and sell stop a few pips below.
here is the formula:BUY STOP at the highest high of the last 10 bars + ((-1)*pending_dist + spread)
SELL STOP at the lowest low of the last 10bars - ((-1)*pending_dist)
=======================================================================================================
Settings:
BarsRange1: | main signal 1 /pattern higher lower trades/ |
BarsRange2: | main signal 2 /pattern higher lower trades/ |
min_dist: | minimum distance from the previous order, 0 completely disables the limit |
pending_dist: | distance of pending order, 0 disables pending orders, negative value: distance from local maximums and minimums for pending orders |
TakeProfit: | M15 TP=15, M30: TP =20, H1: TP=30, H4: TP=40 |
StopLoss: | 100,150,200 /depends on the symbol/ |
final_optimization: | enable/disable averaging |
Built-in settings: | user,SAFE,MODERATE,AGGRESIVE,ReadFromFile |
TP,SL in %: | calculation in % for other instruments than currencies |
StartTrading: | the beginning of trading, set Start and Stop to 0:00, trading is active all the time, set Start and Stop to 9:9, trading is inactive all the time |
StopTrading: | end of trade, Start and Stop disabled for backtests |
MagicNumber: | EA recognizes orders by number and _Period |
Lots: | trade volume |
dynamic_lots: | each subsequent order will be increased modes: none,simple,fibo_sequence,martingale up to 10 trades. on chart you'll see (N),(S),(F),(M) |
UseRiskManager: | you know, risk manager |
EntryRisk: | % of capital per trade for accounts with leverage>=100. the position size is always calculated as for an account with leverage = 100 (for secure) |
GUI_enable: | two graphical interface modes, simple GUI, also works in visual mode |
UseSounds: | on/off sounds |
LogLvL: | silent/MT4logs/alerts |
ShowInitConfig: | shows a window with parameters at startup |
Built-in settings: user: all settings can be changed by the user for use or backtesting SAFE,MODERATE,AGGRESIVE: all parameters from the first section are permanently set:
ReadFromFile: During the first launch, EA will create a params.txt file in the folder MQL4/files/ShortTrendReversal/ with a saved SAFE table as an example of use. After backtesting, you can save the parameters there and you don't have to do anything else. EA will reload the file on the new D1 candle. You can also restart MataTrader.
- BarsRange1, BarsRange2, min_dist, pending_dist are saved in arrays
- TakeProfit: M15 TP=15, M30: TP =20, H1: TP=30, H4: TP=40
- StopLoss set to 0
- final_optimization enabled
Due to the fact that importing external DLL libraries is prohibited, I moved the window resize to the indicator. Source code below.
https://www.mql5.com/en/code/48973
script that opens a set of charts:
#property copyright "https://www.mql5.com/en/market/product/Short Trend Reversal" #property link "https://www.mql5.com/en/market/product/114909" #property description "script that opens a set of charts" #property version "1.00" #property strict #property show_inputs #import "stdlib.ex4" string ErrorDescription(int error_code); #import #import "user32.dll" int GetParent(int hWnd); void MoveWindow(int hWnd,int X,int Y,int nWidth,int nHeight,int bRepaint); #import #define INITIAL_PAIRS "EURUSD,GBPUSD,USDCHF,USDCAD,USDJPY,AUDUSD,NZDUSD,EURGBP,EURCHF,EURCAD,EURJPY,EURAUD,EURNZD,GBPCHF,GBPCAD,GBPJPY,GBPAUD,GBPNZD,CADCHF,CHFJPY,AUDCHF,NZDCHF,CADJPY,AUDCAD,NZDCAD,AUDJPY,NZDJPY,AUDNZD" string all_pairs[]; input string basket = "EUR"; input ENUM_TIMEFRAMES period = PERIOD_H1; input string inp_template = "default.tpl"; input int Monitor = 0; extern int _X = -5; input int _Y = -15; input int Width = 332; input int Height = 363; input string prefix = ""; input string suffix = ""; //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ void OnStart() { StringSplit(INITIAL_PAIRS,',',all_pairs); if(Monitor > 0) _X += 1920; for(char i=0; i<ArraySize(all_pairs); i++) { if(StringFind(all_pairs[i],basket) != -1) { long chart = ChartOpen(prefix+all_pairs[i]+suffix,period); ChartApplyTemplate(chart,"\\Files\\ShortTrendReversal\\"+inp_template); int parent = GetParent((int)ChartGetInteger(chart,CHART_WINDOW_HANDLE)); MoveWindow(parent,_X,_Y,Width,Height,true); ObjectCreate(chart,"ShortTrendReversal",OBJ_LABEL,0,0,0); ObjectSetInteger(chart,"ShortTrendReversal",OBJPROP_CORNER,CORNER_RIGHT_LOWER); ObjectSetInteger(chart,"ShortTrendReversal",OBJPROP_XDISTANCE,30); ObjectSetInteger(chart,"ShortTrendReversal",OBJPROP_YDISTANCE,15); ObjectSetString(chart,"ShortTrendReversal",OBJPROP_TEXT,basket); ObjectSetString(chart,"ShortTrendReversal",OBJPROP_FONT,"Arial Black"); ObjectSetInteger(chart,"ShortTrendReversal",OBJPROP_FONTSIZE,7); ObjectSetInteger(chart,"ShortTrendReversal",OBJPROP_ALIGN,ALIGN_CENTER); ObjectSetInteger(chart,"ShortTrendReversal",OBJPROP_COLOR,clrGainsboro); ObjectSetInteger(chart,"ShortTrendReversal",OBJPROP_BGCOLOR,clrNONE); ObjectSetInteger(chart,"ShortTrendReversal",OBJPROP_BORDER_COLOR,clrNONE); ObjectSetInteger(chart,"ShortTrendReversal",OBJPROP_SELECTABLE,false); ObjectSetInteger(chart,"ShortTrendReversal",OBJPROP_HIDDEN,true); ObjectSetInteger(chart,"ShortTrendReversal",OBJPROP_READONLY,true); ChartRedraw(chart); _X+=274;Sleep(100); } } }