Codice Morse - pagina 2

 

Approfittane))

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

Usa)).


È praticamente) - ma il problema è QUELLO che l'utente vedrà. Vedrà il NUMERO "2314". Quali informazioni riguardanti il numero e il tipo di candele - toro, orso? Giusto, zero informazioni. Sto cercando un'opzione, quando l'utente vede "101" o "011" nei parametri di input ...

Ma è possibile tramite la stringa. Sì, sarà bello e informativo, ma: la stringa non funzionerà nel tester :( . Bada.

 
НО: string не прогонишь в тестере
Puoi dirmi cosa c'è che non va con il tester e la stringa? (non impegnato attivamente in MT4/MT5)
 
Vladimir Karputov:


Questo è praticamente) - ma il problema è QUELLO che l'utente vedrà. E vedrà il NUMERO "2314". Che informazioni ha questo numero e tipo di candela - rialzista, ribassista? Giusto, zero informazioni. Sto cercando un'opzione, quando l'utente vede "101" o "011" nei parametri di input ...

Ma è possibile con una stringa. Sì, sarà bello e informativo, ma: la stringa non può essere eseguita nel tester :( . Il dolore.


Forum sul trading, sistemi di trading automatico e test di strategia

Codice Morse

Vladimir Pastushak, 2017.04.05 12:45


rendere il parametro di input come tipo int, poi cambiare il tipo int in stringa e analizzare ....


 
Oh, non puoi incrementare il valore delle stringhe nel tester?
Create un file, metteteci dentro tutte le stringhe e usate l'indice delle stringhe per determinare cosa volete testare.
L'indice può essere incrementato
 
Avete provato le operazioni bitwise >>, <<, & , | , ^
 
Sergey Dzyublik:
Oh, non puoi incrementare il valore delle stringhe nel tester?
Create un file, metteteci dentro tutte le stringhe e usate l'indice delle stringhe per determinare cosa volete testare.
L'indice può essere incrementato.

No, non puoi. Tutte le stringhe sono grigie nel tester delle strategie quando si cerca di ottimizzare.
 
Vladimir Karputov:


Questo è praticamente) - ma il problema è QUELLO che l'utente vedrà. Vedrà il NUMERO "2314". Quali informazioni riguardanti il numero e il tipo di candele - toro, orso? Giusto, zero informazioni. Sto cercando un'opzione, quando l'utente vede "101" o "011" nei parametri di input ...

Ma è possibile con una stringa. Sì, sarà bello e informativo, ma: la stringa non può essere eseguita nel tester :( . Bada.


Allora rimane solo un'opzione:

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;
...
 

Finora ho deciso per lo spago.

versione "1.000": parametro di ingresso della combinazione di candele come stringa.

//+------------------------------------------------------------------+
//|                                                   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() controlla

  • I caratteri di trasporto, gli spazi e le tabulazioni a sinistra e a destra vengono rimossi per primi
  • verifica il superamento della lunghezza massima (in questo codice "5")
  • controllare la lunghezza zero
  • controlla solo "0" e "1" (CheckCode)
In OnTick() confronta già il tipo di candela e si riferisce al parametro di input (combinazione di candele) come un 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;
           }
        }
     }
File:
Morse_code.mq5  12 kb
 
Vladimir Karputov:


Questo è praticamente) - ma il problema è QUELLO che l'utente vedrà. Vedrà il NUMERO "2314". Quali informazioni riguardanti il numero e il tipo di candele - toro, orso? Giusto, zero informazioni. Sto cercando un'opzione, quando l'utente vede "101" o "011" nei parametri di input ...

Ma è possibile con una stringa. Sì, sarà bello e informativo, ma: la stringa non può essere eseguita nel tester :( . Bada.

Il problema non è solo la chiarezza. Supponiamo che ci sia il numero 13 in DEC, che tipo di schema è: 1101 o 001101 o 0001101? Dopo tutto, tutte le combinazioni danno lo stesso numero 13.
Motivazione: