Morse code - page 4

 

I left out the"length of the pattern " parameter to specify the length for the numeric pattern (this parameter is only used for optimization mode).

#property version   "1.003"
#property description "Bull candle - \"1\", bear candle - \"0\""
//---
#include <Trade\Trade.mqh>
CTrade         m_trade;                      // trading object
//+------------------------------------------------------------------+
//| Enum pattern type: numerical or string                           |
//+------------------------------------------------------------------+
enum ENUM_PATTERN_TYPE
  {
   PATTERN_TYPE_NUMERICAL=0,  // numerical
   PATTERN_TYPE_STRING=1,     // string 
  };
//---
input ENUM_PATTERN_TYPE    InpPatternType          = PATTERN_TYPE_STRING;  // pattern type
input uchar                InpLenNumerical         = 3;                    // length of the pattern (use only if pattern "numerical")
input string               InpsMorseCode           = "101";                // string Morse code (max 5 characters)
input ENUM_POSITION_TYPE   InpPosType              = POSITION_TYPE_BUY;    // posinion type
input double               InpLot                  = 0.1;                  // lot
sinput ulong               m_magic                 = 88430400;             // magic number
input ulong                m_slippage              = 30;                   // slippage
//---
string sExtMorseCode="";
int max_string_len=5;         // limitation of the length of the pattern "string"
int i_morse_code=0;           // int Morse code (use only if pattern type=numerical)
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   if(InpPatternType==PATTERN_TYPE_STRING)
     {
      //--- check start mode
      if(MQLInfoInteger(MQL_OPTIMIZATION))
         return(INIT_PARAMETERS_INCORRECT);
      //--- info print
      Print("The type of the pattern \"string\" is set - the parameters \"pattern length\" and \"int Morse code\" are ignored");

      sExtMorseCode=InpsMorseCode;

And a quick defence - if you select a string pattern type in optimization mode, the Expert Advisor will return "INIT_PARAMETERS_INCORRECT"

 
Vitalii Ananev:


You have to think of everything right away, so that you don't have to redo it later.

....

Again, if we return to the "Evening Star" pattern, it can be seen as a bullish-small candle-bearish and a bullish-bearish takeover. It means that we have a composite pattern consisting of a bullish candle and a bearish absorption. And if we sum up all three candlesticks from the pattern we get a pin bar again.



Let me insert my 5 kopeck.

This task has not been set and it is impossible to foresee everything at once. In this case the initial concept which was planned as the basic one will be lost: a user builds the sequence of bullish and bearish candlesticks and the program looks for these sequences and trades, so why do we sum up the candlesticks in one pattern?

 
Pyxis:


Allow me to insert my five cents.

This was not the task, and it is impossible to provide for everything at once, in which case we lose the original concept, which was conceived as the main one: the user makes a sequence of bullish and bearish candles, and the program looks for these sequences and trades, so why sum up the candles in a single pattern?


Why do we summarize them? Well, for example, to simplify the model. In fact, it was given as an example.

Why is it not possible? All of the frequently occurring combinations of Japanese candlesticks can be encoded one way or another. Another thing is that the 1-th bit (I wrote about it above) is not enough, you must use at least 2 bits, and they are also not enough if you don't summarize (simplify) the pattern model.

 

So far Morse code version "1.003": you can manually specify a string description of the pattern and even run single passes in the tester.

Files:
Morse_code.mq5  15 kb
 
Vladimir Karputov:


The program will be used by a user, not a programmer (it was said above and not once) - and for him "101" and "5" are two different numbers, and for him "5" doesn't contain any information about the relative position of candles, but "101" clearly says "bullish, bearish, bullish".

Got it. Well, then - a string of symbols and a parser. I think it's the most flexible option.
 
George Merts:

I don't quite get it - are these programmers or suckers?

Why translate something into something?

If we need a code 101 - that's the normal value of 5. That's it. What's the problem? Translate mentally from decimal to binary?

I made similar experiments, only my candle had four more sizes - from small to large. That makes eight different candle sizes. And, consequently, three bits. In the pattern we write the number (ulong) - the grid is larger than in the twenty-bar pattern.

The problem is, in my opinion, far-fetched.

First sort it out and then criticize. Here is a task for you to think about:

Encode the number int for the following combinations of candlesticks:

  • 1011;
  • 01011;
  • 001011

Hint: these are different combinations.

George Merts:
Got it. Well, then - character string and parser. Seems like the most flexible option to me.
Once again: optimizer_not_optimize_string_parameters. How will you search for a combination of profitable patterns without the optimizer?
 
Vasiliy Sokolov:
Once again: the optimizer_will_not_optimize_string_parameters. How will you search for the combination of profitable patterns without the optimizer?

If an optimiser is needed, I think the user should be 'savvy' enough to translate the number into binary code (at least with a regular Windows calculator).

You, friends, have a contradictory request. If a user is such a dummy that he/she cannot use a calculator to translate binary code into decimal code - he/she cannot handle optimization anyway. At most he/she can just run it once to find the best value.

If the user is advanced enough to use the optimizer, it's reasonable to encode the input parameters with a regular unsigned long,

 
Vasiliy Sokolov:

Figure it out first and then criticise. Here's a thought-provoking task for you:

Encode the number int with the following combinations of candles:

  • 1011;
  • 01011;
  • 001011

Hint: these are different combinations.

Moreover - they are different in length. The first combination - includes four six-digit combinations.

The second combination includes two six-bit ones.

Correspondingly, we should just take 64 six-bit combinations during optimization.

Moreover, the last one is a subset of the first two options, and the penultimate one is a subset of the first one.

So, at the moment of registration of the last combination we have to identify the second and the first combination at the same time. In my opinion, this is clearly an incorrect request.

 
What is the purpose of this event - to find the most profitable sequence? You do not need a robot or a tester for that - an indicator, in which the length of the sequence and the rules for closing the position (by TP or by the opposite signal or anywhere else) are specified, is enough. The indicator will code all variants within the specified length of the sequence and a specified depth of history, it will sort out the result (including the drawdown) and print it wherever you want. But the problem looks farfetched indeed. Well, if it's not a guessing toy like 0101 to occupy the user
 
George Merts:

Accordingly, when optimising - just take 64 six-digit combinations.

Question: What is the probability of a combination appearing on the market that matches the required 64 digits? Answer: (1/2^64)*BarsCount. It means that there is almost 100% probability that no such combination will be found. It is obvious that only one number int or long cannot fully describe the pattern, so we need an additional parameter specifying the length of the pattern.

By such small steps you will soon come to what I said on the second page.

Reason: