거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Facebook에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
라이브러리

Binary Flags - MetaTrader 5용 라이브러리

조회수:
3602
평가:
(11)
게시됨:
2020.06.01 08:23
업데이트됨:
2020.06.13 12:31
BinFlags.mq5 (2.13 KB) 조회
BinFlags.mqh (1.94 KB) 조회
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

You can use binary flags to minimize bool parameters in a function signature.

For example, MQL int size is 32 bits, so you can pack 32 1/0 parameters in a single int flag variable.

Before:

void Function(bool flag1,bool flag2,bool flag3,bool flag4,bool flag5,bool flag6,bool flag7,bool flag8,...flagN);

After:

void Function(int flags);

BinFlags can be initialized with any integer data type:char, bool, short, int, color, long, datetime.

Your maximum flag length will vary: 1 byte = 8 bits, 2 bytes = 16 bits, etc.

A flag represents a number which has only one '1' bit in any position.

Such numbers are 1, 2, 4, 8, 16, 32, etc. You get it.

Large numbers of this kind look better in hex: 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, etc.

This class works with flags, which follow the rule.

BinFlags must be initialized first. You can overwrite later the internal flags with Write.

You can check, set, reset any number of flags.

Multiple flags should be separated by '|'.

template<typename T>class BinFlags
  {
public:
                     BinFlags():mflags(NULL) {} BinFlags(T flags):mflags(flags) {}
   void              Write(T flags) {mflags=flags;}
   T                 Read() {return mflags;}
   bool              Chk(T flags) {return (mflags&(flags))==flags;}
   void              Set(T flags) {mflags|=(flags);}
   void              Rst(T flags) {mflags&=~(flags);}
   string            Format();
protected:
   int               Bits() {int i=0; for(i; i<sizeof(T)*8; i+=4) {if(mflags<(int)pow(2,i)) {break;}} return (i)?i:1;}
   T                 mflags;
  };

Flag names can be enumerated for convenience.

Example of BinFalgs usage.


void OnStart()
  {
   BinFlags<int>bf(A|B);         //init & write
   /*MANIPULATE*/
   Print(bf.Format());           //0011 (2 flags on)
   Print("A:",bf.Chk(A));        //A:true
   Print("AD:",bf.Chk(A|D));     //AD:false
   bf.Set(C|D);                  //set C & D
   Print(bf.Format());           //1111 (all flags on)
   bf.Rst(A);                    //reset A
   Print("BCD:",bf.Chk(B|C|D));  //BCD:true
   Print(bf.Format());           //1110 (one flag down)
  }

Output:

/**
   BinFlags:0011
   A:true
   AD:false
   BinFlags:1111
   BCD:true
   BinFlags:1110
/**/



    Quick Market-watch Launcher v1.1 Quick Market-watch Launcher v1.1

    This script opens all market watch symbols with the default template using the selected period. Save prefferred template as default.tpl to have all charts open with same template of your choice. Happy Trading.

    Base64Encrypt Class Base64Encrypt Class

    This a library for a quick and easy encryption and decryption using base64. The usage is very simple and can be done in a few lines of code. <<< The return value of a method is the required output. <<< Feel free to use this library at your convenience.If it is helpful, please reward me by rating this item on mql5 site. >>From a developer, for developers.<<

    EMA on RSI EMA on RSI

    Calculates a Exponential Moving Average based on RSI Data, instead of the regular Pricing data. Simple and and to the point.

    Alphabet structure Alphabet structure

    Sets of latin, russian characters, digits, punctuation, etc.