Morse code - page 2

 

Take advantage))

 input uint m=2314;//Входной набор двоичных данных в виде десятичного числа
 ...
 int i1;
 for(i1=0;i1<32;i1++) //Пример получения каждого бита с позиции i1 начиная с младших бит
   {
    Print((m>>i1)&1);
   }
 
Aliaksandr Hryshyn:

Use)).


It's practically) - but the problem is WHAT THE USER WILL SEE. He will see the NUMBER "2314". What information concerning the number and type of candlesticks - bull, bear? Right, zero information. I am looking for an option, when the user sees "101" or "011" in the input parameters ...

But it is possible via string. Yes, it will be nice and informative, but: you cannot run string in the tester :( . Bada.

 
НО: string не прогонишь в тестере
Can you tell me what is wrong with the tester and the string? (not actively engaged in MT4/MT5)
 
Vladimir Karputov:


This is practically) - but the problem is WHAT THE USER WILL SEE. And he will see NUMBER "2314". What information does this number and type of candlestick have - bullish, bearish? Right, zero information. I am looking for an option, when the user sees "101" or "011" in the input parameters ...

But it is possible with a string. Yes, it will be nice and informative, but: string cannot be run in the tester :( . Grief.


Forum on trading, automated trading systems & strategy testing

Morse code

Vladimir Pastushak, 2017.04.05 12:45


make input parameter as int type then change int type to string and parse ....


 
Oh, you can't increment the value for strings in the tester?
Create a file, put all the strings into it, and use the string index to determine what you want to test.
The index can be incremented
 
Have you tried bitwise operations >>, <<, & , | , ^
 
Sergey Dzyublik:
Oh, you can't increment the value for strings in the tester?
Create a file, put all the strings into it, and use the string index to determine what you want to test.
The index can be incremented.

No, you can't. All strings are grayed out in the strategy tester when you try to optimize.
 
Vladimir Karputov:


This is practically) - but the problem is WHAT THE USER WILL SEE. He will see the NUMBER "2314". What information concerning the number and type of candlesticks - bull, bear? Right, zero information. I am looking for an option, when the user sees "101" or "011" in the input parameters ...

But it is possible with a string. Yes, it will be nice and informative, but: string cannot be run in the tester :( . Bada.


Then there is only one option left:

extern int  bars=4;//Количество используемых свечей
extern bool bar1=true;//1-я свеча
extern bool bar2=true;//...
extern bool bar3=false;
extern bool bar4=true;
extern bool bar5=true;
...
 

So far I've settled on string.

version "1.000": input parameter of the candlestick combination as string.

//+------------------------------------------------------------------+
//|                                                   Morse code.mq5 |
//|                              Copyright © 2017, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2017, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.000"
#property description "Bull candle - \"1\", bear candle - \"0\""
//---
#include <Trade\Trade.mqh>
CTrade         m_trade;                      // trading object
//---
input string               InpMorseCode   = "101";             // maximum quantity of symbols: 5
input ENUM_POSITION_TYPE   InpPosType     = POSITION_TYPE_BUY; // posinion type
input double               InpLot         = 0.1;               // lot
input ulong                m_magic        = 88430400;          // magic number
input ulong                m_slippage     = 30;                // slippage
//---
string sExtMorseCode="";
int max_len=5;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   sExtMorseCode=InpMorseCode;

   StringTrimLeft(sExtMorseCode);
   StringTrimRight(sExtMorseCode);

   if(StringLen(sExtMorseCode)>max_len)
     {
      Print("PARAMETERS INCORRECT: Code length is more than ",IntegerToString(max_len)," characters");
      return(INIT_PARAMETERS_INCORRECT);
     }

   if(StringLen(sExtMorseCode)==0)
     {
      Print("PARAMETERS INCORRECT: Length of a code is equal to zero");
      return(INIT_PARAMETERS_INCORRECT);
     }

   if(!CheckCode(sExtMorseCode))
     {
      Print("PARAMETERS INCORRECT");
      return(INIT_PARAMETERS_INCORRECT);
     }
//---
   m_trade.SetExpertMagicNumber(m_magic);

   if(IsFillingTypeAllowed(Symbol(),SYMBOL_FILLING_IOC))
      m_trade.SetTypeFilling(ORDER_FILLING_IOC);

   m_trade.SetDeviationInPoints(m_slippage);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- we work only at the time of the birth of new bar
   static datetime PrevBars=0;
   datetime time_0=iTime(0);
   if(time_0==PrevBars)
      return;
   PrevBars=time_0;

   int count=StringLen(sExtMorseCode);

   MqlRates rates[];
   ArraySetAsSeries(rates,true);
   int copied=CopyRates(NULL,0,1,count,rates);
//--- Example:
//--- rates[2].time -> D'2015.05.28 00:00:00'
//--- rates[0].time -> D'2015.06.01 00:00:00'
   if(copied<=0)
     {
      Print("Error copying price data ",GetLastError());
      return;
     }

   bool result=true;

   for(int i=0;i<StringLen(sExtMorseCode);i++)
     {
      if(sExtMorseCode[i]=='0')
        {
         if(rates[i].open<rates[i].close)
           {
            result=false;
            break;
           }
        }
      else  if(sExtMorseCode[i]=='1')
        {
         if(rates[i].open>rates[i].close)
           {
            result=false;
            break;
           }
        }
     }

   if(!result)
      return;

//--- 
   if(InpPosType==POSITION_TYPE_BUY)
      m_trade.Buy(InpLot);
   else
      m_trade.Sell(InpLot);

   int d=0;
  }
//+------------------------------------------------------------------+
//| TradeTransaction function                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
  {
//---

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool CheckCode(const string text)
  {
   bool result=true;
   for(int i=0;i<StringLen(text);i++)
     {
      if(text[i]!='0' && text[i]!='1')
         return(false);
     }
//---
   return(result);
  }
//+------------------------------------------------------------------+ 
//| Checks if the specified filling mode is allowed                  | 
//+------------------------------------------------------------------+ 
bool IsFillingTypeAllowed(string symbol,int fill_type)
  {
//--- Obtain the value of the property that describes allowed filling modes 
   int filling=(int)SymbolInfoInteger(symbol,SYMBOL_FILLING_MODE);
//--- Return true, if mode fill_type is allowed 
   return((filling & fill_type)==fill_type);
  }
//+------------------------------------------------------------------+ 
//| Get Time for specified bar index                                 | 
//+------------------------------------------------------------------+ 
datetime iTime(const int index,string symbol=NULL,ENUM_TIMEFRAMES timeframe=PERIOD_CURRENT)
  {
   if(symbol==NULL)
      symbol=Symbol();
   if(timeframe==0)
      timeframe=Period();
   datetime Time[1];
   datetime time=0;
   int copied=CopyTime(symbol,timeframe,index,1,Time);
   if(copied>0) time=Time[0];
   return(time);
  }
//+------------------------------------------------------------------+

In OnInit() checks

  • carriage characters, spaces and tabs on the left and right are removed first
  • check for exceeding the maximum length (in this code "5")
  • check for zero length
  • check for "0" and "1" only (CheckCode)
In OnTick() it already compares the type of candlestick and refers to the input parameter (combination of candlesticks) as an array:

   for(int i=0;i<StringLen(sExtMorseCode);i++)
     {
      if(sExtMorseCode[i]=='0')
        {
         if(rates[i].open<rates[i].close)
           {
            result=false;
            break;
           }
        }
      else  if(sExtMorseCode[i]=='1')
        {
         if(rates[i].open>rates[i].close)
           {
            result=false;
            break;
           }
        }
     }
Files:
Morse_code.mq5  12 kb
 
Vladimir Karputov:


This is practically) - but the problem is WHAT THE USER WILL SEE. He will see the NUMBER "2314". What information concerning the number and type of candlesticks - bull, bear? Right, zero information. I am looking for an option, when the user sees "101" or "011" in the input parameters ...

But it is possible with a string. Yes, it will be nice and informative, but: string cannot be run in the tester :( . Bada.

The problem is not just about clarity. Suppose there is number 13 in DEC, what kind of pattern is it: 1101 or 001101 or 0001101? After all, all combinations yield the same number 13.