Forex Factory (https://www.forexfactory.com/forum.php)
-   Trading Systems (https://www.forexfactory.com/forumdisplay.php?f=71)
-   -   LRSF - TMS Expert Advisor (https://www.forexfactory.com/showthread.php?t=723493)

jansb000 Dec 16, 2017 10:44am | Post# 1

LRSF - TMS Expert Advisor
 
4 Attachment(s)
Welcome,

I used to post updates of my little Expert Advisor in the Trading Made Simple forum. However as I forsee that I will have several versions to go before it turns into a useful EA that one can trust with a real account I decided to start this thread to make it easy for everyone to follow my progress and to add comments to this specific take on Trading Made Simple.

To learn the TMS way of trading you can go to the Trading Made Simple Thread:
https://www.forexfactory.com/showthread.php?t=291622

Note: This programming project is still in an early stage and the versions (that I regularly post here) are not intended for real trading.

  1. As of version 13 you might run the EA on a demo account and manually copy the trades that you like to a real account.
  2. As of version 18 the EA will trade real accounts for 26 weeks. After that period you will have to move on to a newer version.


Previous & current versions can be found here:
Version 1.04: https://www.forexfactory.com/showthr...4#post10125984
Version 1.05: https://www.forexfactory.com/showthr...0#post10134710
Version 1.06: https://www.forexfactory.com/showthr...3#post10184663
Version 1.07: https://www.forexfactory.com/showthr...4#post10227464
Version 1.08: https://www.forexfactory.com/showthr...4#post10312684
Version 1.09: Post #23
Version 1.10: Post #24
Version 1.11: Post #42
Version 1.12: Post #58
Version 1.13: Post #66
Version 1.14: Post #72
Version 1.15: Post #96, Version 1.15.s: Post #520
Version 1.16: Post #169
Version 1.17: Post #326
Version 1.18: Post #401, Post #791 and #792
Version 1.19: Post #979
Version 1.20: Post #1017
Version 1.21: Post #1047
Version 1.22: Post #1077

Other goodies:

  1. See post #14 and #485 for the TDI indicator. See post #600 for installation instructions.
  2. See post #819 and #1146 for the very handy LRSF Magnified Price indicator. [new]
  3. See post #192 for scripts to add trades manually.
  4. See this post for my tool to maintain a list of SR-Lines.
    https://www.forexfactory.com/showthr...7#post10865147

LRSF Monitor
Work in Progress versions:
LRSF Monitor wip v1.04.ex4
LRSF Monitor wip v1.05.ex4
(See post #500, #533, #557)

Indicators for testing (technical)
This is the Heiken Ashi filter:
LRSF filter HA v1.00.ex4
This is the TDI filter:
LRSF filter TDI v1.00.ex4
Cheers...


25blackogres Dec 16, 2017 12:14pm | Post# 2

Good luck and thanks for your effort


25

diamonddbw Dec 16, 2017 5:32pm | Post# 3

Thanks. As traders we can use all the help we can get.

emmanuel7788 Dec 16, 2017 11:28pm | Post# 4

Welcome, I used to post updates of my little Expert Advisor in the Trading Made Simple forum. However as I forsee that I will have several versions to go before it turns into a useful EA that one can trust with a real account I decided to start this thread to make it easy for everyone to follow my progres and to add comments to this specific take on Trading Made Simple. * Currently not able to upload files
If you are considering to develop a trade manager type of expert advisor,

You may want to include the use of on-chart objects to execute limit and stop orders .

For example, the use of segment lines on chart with specific line object names such as - buy limit, sell limit, buy stop, sell stop, buy SL, sell SL, buy target1, buy target2, sell target1, sell target2 etc. depending on your exit strategy.

your expert advisor must be able to detect these objects and execute the trades and manage thereafter.

see Tipster thread.

https://www.forexfactory.com/showthread.php?t=526703

other than the use of segment lines on chart, there are a lot more other objects (wingdings code) on charts which you can program in your trade manager to activate trade functions.

Have fun!

jansb000 Dec 21, 2017 4:29pm | Post# 5

{quote}see Tipster thread.
Thanks for your comments. I never saw the Tipster's Trade Manager before. But it looks very good. I will study this thread next week (as I finally have a week off work).

Later this weekend I will post here my plan for how I plan to proceed with my expert advisor. I will definitely include MEME and the use of SR-lines in a similar way that RickM has recently explained in the TMS forum. It's no coincidence that I programmed that SR-Lines tool that I posted in the TMS forum. That tool stores SR-Lines in a format that I can use in my EA.

Cheers...

emmanuel7788 Dec 21, 2017 7:30pm | Post# 6

{quote} Thanks for your comments. I never saw the Tipster's Trade Manager before. But it looks very good. I will study this thread next week (as I finally have a week off work). Later this weekend I will post here my plan for how I plan to proceed with my expert advisor. I will definitely include MEME and the use of SR-lines in a similar way that RickM has recently explained in the TMS forum. It's no coincidence that I programmed that SR-Lines tool that I posted in the TMS forum. That tool stores SR-Lines in a format that I can use in my EA. Cheers...

when you have those SR lines drawn on your monthly charts and also on the weekly charts, you can write an EA and perform count of the number of times the TDI (RSI MA) crosses in M5 between any two of the SR lines.

hint: Use the TDI(RSI MA) M5 cross for trade entries.... between the buy and sell zones identified by your selected SR lines in HTF.
the rest is risk and money management.

... more next , will be on exit strategies, trade management.

jansb000 Dec 26, 2017 4:02pm | Post# 7

In this thread I will describe my journey of developing an Expert Advisor for the TMS method. For an extensive discussion on how this method works I refer to the thread about "Trading Made Simple". https://www.forexfactory.com/showthread.php?t=291622
In this thread I like to focus the discussion on the techniques that I use to get from a written and well documented trading method to an implementation as an Expert Advisor. So I do not discuss if TMS is a good method or not. The thing is, with developing a program, one has to choose what the program is supposed to do. And then stick to it. Otherwise, when the definition of what needs to be done keeps changing, programs will never be finished.

Many traders (including very experienced ones) claim that it is not possible to create a fully automated trading program. And they may be right. The outcome of this journey therefore might be that we merely achieve an approximation of a succesfull trading program. On the other hand, parts of the trading proces are definitely suitable for automation.
My goals are:

  1. Create a good TMS trade-manager. A trade-manager is an Expert Advisor that does not initiate any trades, but manages trades that are otherwise initiated.

    1. Monitor trades for exit conditions
    2. Break-even detection
    3. Profit protection
    4. Managing Stop Loss, Take Profit and Trailing Stop
    5. Apply Multiple Entries and Multiple Exits (MEME)

  2. Abilty to initiate trades based on the mechanical rules. The mechanical rules are a set of rules that mostly based on simply reading hard data from indicators or price action.

    1. Detect entry conditions based on PAC or 5MA
    2. Detect entry conditions based on TDI
    3. Detect entry conditions based on Stochastic
    4. Detect entry conditions based on trend

  3. Additional entry conditions

    1. Position of Support and resistance lines
    2. Price Action Patterns

So thats it for now.
Cheers...


jansb000 Dec 29, 2017 8:45am | Post# 8

Many versions

When I start with a new EA-project I immediately start creating versions. Every major change gets a new version. I do it like that because I have learned that it is not wise to fiddle with existing code of a working program. If the new change doesn't work out it's easy to go back to the previous version. It is however nearly impossible to undo changes to restore a broken program to its former working state.

Because I develop my project in these steps it follows that for a new project, version 1.00 is usually not a working version. Simply because not all necessary parts are yet finished. It usually takes me a couple of versions to have a first working version of my EA-project. (A "working" version in this sense means it implements the basic strategy. Not that it actually is a "succesful" trading engine).

The versions that I publish in this thread have all been tested for at least a month on a demo account. Some parts of the code are stable from the very first version, and hence have been tested for many months. Some parts of the code are inherited from previous projects and hence have been tested for years.

At the time of writing I have posted version 1.09 a couple of days ago. At this time I am working on versions 1.10, 1.11, 1.12 and 1.13. All of these versions have significant additions or changes that I want to develop further as a separate version. I don't like adding too many changes between versions, so I'll do it step by step.

As long as version 1.10 is not posted I will add bugfixes to version 1.09 if the bug is serious enough to need a quick fix. So version 1.09, the last published version, can be regarded as the current "stable" version.

Cheers...

jansb000 Dec 29, 2017 9:08am | Post# 9

Version 1.10, whats new?
Inserted Code
* 15-09-2017 Version 1.10
* - Using the class cl_symbol where possible.
* - Better messages on screen about status.
* - No new orders after 18:00 on friday.
* - Close positive orders on friday after 23:50.
* - Some classes are now suitable for multi-curency and multi-timeframe
*   operation. This is needed if we want this program to run on a single
*   instance but still trade multiple currencies.
* - Exit trade when we are under 3 pips profit and the MA10 on M1 is against us.
* - Make use of extra ma_fast and ma_slow optional.
* - Set BE SL when the price reaches BE trigger. The old algo would wait
*   for the current bar to finish and then set BE to the LOW of the previous bar
*   (the one just completed) if that would be above the open-price.
* - Made PAC-check a separate function.
* - Made MA-check a separate function.
* - Redesigned code to check the conditions from the TDI.
From this list you might get an idea what I means when I say that a new development deserves a new version. Even if the end-result might not show it that obvious in the way users see the finished product. A lot has been going on under the hood.

goodways100 Dec 30, 2017 2:18am | Post# 10

Subs. thanks and
Regards

jansb000 Dec 31, 2017 6:47am | Post# 11

Working with classes

I love the MQL programming language. It supports both ""procedural" programming and "object-oriented" programming. When you read books about OO-programming it is often assumed that one will use either one or the other apprach. However I like to mix both methods so I can enjoy the benefits of both.

I use classes in a little bit different way then what you might find in official OO-progrtamming textbooks. I like to keep things simple, so I will use classes when I think they will make my programming life easier. For me that means that I usually create a class to simply combine a structure and all the methods that work with that structure. Usually I leave it at that and and stay clear of the more complex stuff that one could do with classes. Usually I leave inheritance and polymorphism to a bare minimum.

I will create and use classes:

  1. When a certain structure or object clearly needs its own handling routines.
  2. When I think I might re-use the structure of object on other projects.
  3. When I find that my main programming file becomes to cluttered and I can combine certain tasks in a separate class (or include file).


Example of an include: I have made a library of extended string handling functions. That is just a collection of functions that would otherwise clutter my main programming file. Some example code from that include:

Inserted Code
/** before
  * ------
  * This function returns the part of a string BEFORE a certain
  * search pattern. If the pattern is not found then the whole
  * string s is returned.
  *
  * s   The string to search
  * pat The pattern to search for
  * pos The position to start searching
  */
string strBefore(const string &s, const string &pat, const int pos = 0) {
    int it = StringFind(s, pat, pos);
    //if (it <= StringLen(s))
    if (it > -1)
      return strMid(s, 0, it);
    else
      return s;
        
}
string strBefore(const string &s, const char c, const int pos = 0) {
   string s_pat;
   StringInit(s_pat,1,c);
   return strBefore(s,s_pat,pos);
}
    
/** after
  * -----
  * This function returns the part of a string AFTER a certain
  * search pattern. If the pattern is not found then the empty
  * string s is returned.
  *
  * s   The string to search
  * pat The pattern to search for
  * pos The position to start searching
  */
string strAfter(const string &s, const string &pat, const int pos = 0) {
   int    it;
   string x = "";    
   int slen = StringLen(s);
   int plen = StringLen(pat);
   it = StringFind(s, pat, pos);
   if ( it > -1)
      x = strMid(s, it + plen, slen - it - plen);
   return x;    
}
string strAfter(const string &s, const char c, int pos = 0) {
   string s_key;
   StringInit(s_key,1,c);
   return strAfter(s,s_key,pos);
}

Example of a class: I have made a set of classes to make the usage of certain indicators a lot easier (Moving Average, Stochastic, HA, TDI, PAC). The class that I show below is called 'cl_symbol' and it contains methods that I frequently use when I want to know something about the symbol that I am trading with. The reason I collected all those functions in a class is because it will make a move from MT4 to MT5 easier. In MT5 there is already a class for handling symbols that MetaQuotes has prepared. So when that day comes I can keep adaptations to my main program to a minimum as I only have to adapt this class for handling the new symbol-related functions.

Inserted Code
//+------------------------------------------------------------------+
//|                                                    cl_symbol.mqh |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, JANSB000"
#property link      "https://www.forexfactory.com/showthread.php?p=10597594#post10597594"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| This class is suited for a future translation to MT5.  
//+------------------------------------------------------------------+
class cl_symbol {
   private:  
      string _symbol;    // Symbol
      double _stoplevel; // Stop level corrected for 3/5 digit brokers
      double _point;     // Point corrected for 3/5 digit brokers
        
    public:
      cl_symbol(const string i_sym);
      
      string get_symbol()    const { return _symbol; }
      double get_bid()       const { return MarketInfo(_symbol,MODE_BID); }
      double get_ask()       const { return MarketInfo(_symbol,MODE_ASK); }      
      double get_lotsize()   const { return MarketInfo(_symbol,MODE_LOTSIZE); }
      double get_lotstep()   const { return MarketInfo(_symbol,MODE_LOTSTEP); }
      double get_tickvalue() const { return MarketInfo(_symbol,MODE_TICKVALUE); }
      double get_ticksize()  const { return MarketInfo(_symbol,MODE_TICKSIZE); }      
      double get_basepoint() const { return MarketInfo(_symbol,MODE_POINT); }          
      int    get_digits()    const { return (int)MarketInfo(_symbol,MODE_DIGITS); }          
      double get_stoplevel() const { return _stoplevel; }  
      double get_point()     const { return _point; }
      
      double get_volume_min() const { return SymbolInfoDouble(_symbol,SYMBOL_VOLUME_MIN); }
      double get_volume_max() const { return SymbolInfoDouble(_symbol,SYMBOL_VOLUME_MAX); }
      
      double get_spread()    const;
          
      double normpoint() const;
      double pointvalue() const;
      void   get_infotick(MqlTick &tick) { SymbolInfoTick(_symbol, tick); }
      void   update(const string i_symbol);          
};
cl_symbol::cl_symbol(const string i_sym) {
   update(i_sym);
}
double cl_symbol::get_spread() const {
   double lv_basespread = MarketInfo(_symbol, MODE_SPREAD);
   int    lv_digits     = get_digits();
   if ( lv_digits == 3 || lv_digits == 5 )
      return (lv_basespread /= 10);
   else
      return lv_basespread;  
}
// === update
// Update and set those parameters that will not change or with a vary
// low frequency. The update should be executed during initialisation
// and then once per minute to keep it up to date.
void cl_symbol::update(const string i_symbol) {
   _symbol    = i_symbol;
   int lv_digits  = get_digits();
 
   // Calculate the normalised stoplevel
   double lv_stplvl = MarketInfo(_symbol,MODE_STOPLEVEL);
   if ( lv_digits == 3 || lv_digits == 5 )
      _stoplevel = lv_stplvl /= 10;
   else
      _stoplevel = lv_stplvl;
      
   double lv_bpoint = get_basepoint();
   if( lv_digits == 3 || lv_digits == 5 ) {
      _point = lv_bpoint * 10.0;      
   } else {
      _point = lv_bpoint;
   }      
}
 
// === pointvalue
// This method calculates the value of a one point move for 1 lot.
double cl_symbol::pointvalue() const {
   double t_value = get_tickvalue();
   double t_size  = get_ticksize();  
   double p_size  = get_point();
   return t_value * (p_size / t_size); // Not Point.  
}
  
cl_symbol gSymbol(_Symbol); //Global symbol parameters

fxenthusiast Jan 1, 2018 2:55am | Post# 12

Happy New Year! I just came across this thread just now. I'm interested in this EA and I think it has a lot of potential. By the way, may I know what indicators to be attached to the chart in order for the EA to function?

pamc Jan 1, 2018 3:39am | Post# 13

The Long and Winding Road. Putting EA's together seems so so complicated. Good luck with this project and Happy New Year

jansb000 Jan 1, 2018 7:37am | Post# 14

2 Attachment(s)
Happy New Year! I just came across this thread just now. I'm interested in this EA and I think it has a lot of potential. By the way, may I know what indicators to be attached to the chart in order for the EA to function?
You do not have to attach any indicator to the chart. The EA will do that itself internally. However the TDI indicator must be available in your indicators folder as shown in this post. The TDI indicator does not come standard with MetaTrader4 so You must add it yourself. Please refer to this post:
https://www.forexfactory.com/showthr...4#post10125984

The installation instructions are straitforward, but if you are not sure this post describes a similar procedure for installing a script. Of course for installing an indicator you would have to open the Indicators-folder instead of the Script folder:
https://www.forexfactory.com/showthr...1#post10043041

And this is the Indicator that you need. I got this from the TMS thread so I am reposting it as is:
TradersDynamicIndex.ex4
TradersDynamicIndex.mq4

jansb000 Jan 1, 2018 7:48am | Post# 15

The Long and Winding Road. Putting EA's together seems so so complicated. Good luck with this project and Happy New Year
What I actually try to do is simply translate an excisting trading approach into a program so that it can do some of the tasks automatically. It might seem complicated at first, but hey, if you would write down all steps and decisions that YOU would make to open and manage a trade it would probably be a lot more complicated. By writing a program a lot of time is spend in finding out, in micro-steps, what a human would do in certain circumstances. And therefore it also helps in mastering a proces better.

fxenthusiast Jan 1, 2018 8:23am | Post# 16

[quote=jansb000;10631496]{quote} You do not have to attach any indicator to the chart. The EA will do that itself internally. However the TDI indicator must be available in your indicators folder as shown in this post. The TDI indicator does not come standard with MetaTrader4 so You must add it yourself. Please refer to this post: https://www.forexfactory.com/showthr...4#post10125984.............

Thanks

Abhimanyu Jan 1, 2018 9:31am | Post# 17

I am getting the following errors. I have tdi indicator in /expert/indicator folder.

2018.01.01 09:26:52.014 GBPUSD,M5: 74314 tick events (75314 bars, 149622 bar states) processed in 0:00:15.928 (total time 0:00:18.939)
2018.01.01 09:26:52.013 2017.12.29 23:59:59 cannot open file 'C:\Users\medcenter\AppData\Roaming\MetaQuotes\Terminal\8E768FE62C7F3F1D539F3B0724A84FDA\MQL4\indicators\bim\tms\TradersDynamicIndex.ex4' [3]
2018.01.01 09:26:52.012 2017.12.29 23:59:59 cannot open file 'C:\Users\medcenter\AppData\Roaming\MetaQuotes\Terminal\8E768FE62C7F3F1D539F3B0724A84FDA\MQL4\indicators\bim\tms\TradersDynamicIndex.ex4' [3]
2018.01.01 09:26:52.012 2017.12.29 23:50:00 cannot open file 'C:\Users\medcenter\AppData\Roaming\MetaQuotes\Terminal\8E768FE62C7F3F1D539F3B0724A84FDA\MQL4\indicators\bim\tms\TradersDynamicIndex.ex4' [3]
2018.01.01 09:26:52.011 2017.12.29 23:50:00 cannot open file 'C:\Users\medcenter\AppData\Roaming\MetaQuotes\Terminal\8E768FE62C7F3F1D539F3B0724A84FDA\MQL4\indicators\bim\tms\TradersDynamicIndex.ex4' [3]
2018.01.01 09:26:52.011 2017.12.29 23:45:00 cannot open file 'C:\Users\medcenter\AppData\Roaming\MetaQuotes\Terminal\8E768FE62C7F3F1D539F3B0724A84FDA\MQL4\indicators\bim\tms\TradersDynamicIndex.ex4' [3]
2018.01.01 09:26:52.010 2017.12.29 23:45:00 cannot open file 'C:\Users\medcenter\AppData\Roaming\MetaQuotes\Terminal\8E768FE62C7F3F1D539F3B0724A84FDA\MQL4\indicators\bim\tms\TradersDynamicIndex.ex4' [3]
2018.01.01 09:26:52.010 2017.12.29 23:40:00 cannot open file 'C:\Users\medcenter\AppData\Roaming\MetaQuotes\Terminal\8E768FE62C7F3F1D539F3B0724A84FDA\MQL4\indicators\bim\tms\TradersDynamicIndex.ex4' [3]
2018.01.01 09:26:52.009 2017.12.29 23:40:00 cannot open file 'C:\Users\medcenter\AppData\Roaming\MetaQuotes\Terminal\8E768FE62C7F3F1D539F3B0724A84FDA\MQL4\indicators\bim\tms\TradersDynamicIndex.ex4' [3]
2018.01.01 09:26:52.009 2017.12.29 23:35:00 cannot open file 'C:\Users\medcenter\AppData\Roaming\MetaQuotes\Terminal\8E768FE62C7F3F1D539F3B0724A84FDA\MQL4\indicators\bim\tms\TradersDynamicIndex.ex4' [3]
2018.01.01 09:26:52.008 2017.12.29 23:35:00 cannot open file 'C:\Users\medcenter\AppData\Roaming\MetaQuotes\Terminal\8E768FE62C7F3F1D539F3B0724A84FDA\MQL4\indicators\bim\tms\TradersDynamicIndex.ex4' [3]
2018.01.01 09:26:52.008 2017.12.29 23:30:00 cannot open file 'C:\Users\medcenter\AppData\Roaming\MetaQuotes\Terminal\8E768FE62C7F3F1D539F3B0724A84FDA\MQL4\indicators\bim\tms\TradersDynamicIndex.ex4' [3]
2018.01.01 09:26:52.007 2017.12.29 23:30:00 cannot open file 'C:\Users\medcenter\AppData\Roaming\MetaQuotes\Terminal\8E768FE62C7F3F1D539F3B0724A84FDA\MQL4\indicators\bim\tms\TradersDynamicIndex.ex4' [3]
2018.01.01 09:26:52.007 2017.12.29 23:25:00 cannot open file 'C:\Users\medcenter\AppData\Roaming\MetaQuotes\Terminal\8E768FE62C7F3F1D539F3B0724A84FDA\MQL4\indicators\bim\tms\TradersDynamicIndex.ex4' [3]

jansb000 Jan 2, 2018 3:42am | Post# 18

I am getting the following errors. I have tdi indicator in /expert/indicator folder. 2018.01.01 09:26:52.014 GBPUSD,M5: 74314 tick events (75314 bars, 149622 bar states) processed in 0:00:15.928 (total time 0:00:18.939) 2018.01.01 09:26:52.013 2017.12.29 23:59:59 cannot open file 'C:\Users\medcenter\AppData\Roaming\MetaQuotes\Terminal\8E768FE62C7F3F1D539F3B0724A84FDA\MQL4\indicators\bim\tms\TradersDynamicIndex.ex4' [3] 2018.01.01 09:26:52.012 2017.12.29 23:59:59
It must be in this folder: ....\indicators\bim\tms\
Please refer to this post: https://www.forexfactory.com/showthr...4#post10125984

There are many versions available of the TDI-Indicator. Most people that trade the Trading Made Simple method have several versions of the TDI Indicator in their Indicators folder. Therefore I decided to use a unique folder for the indicators that my program uses. Just to prevent any confusion.

jansb000 Jan 2, 2018 4:08am | Post# 19

Hi all,
I just published version 1.10. See post #1 for downloads.
Cheers...

jansb000 Jan 3, 2018 1:40pm | Post# 20

I have updated version 10 in post 1. The opening of trading after the new year revealed a small bug. I was already filtering that any trade must be in the direction of the next higher timeframe. I now added that it must also be in the direction of the next-next higher timeframe.

Example: You have the EA running on the H4. It wil now only open a buy if both the D1 and W1 are moving up!


© Forex Factory