Bollinger and Buffer

 

With this code I always get in BOLL_U and BOLL_L the values of the average of the Bollinger, buffer 0 according to the doc, whereas I specify that I want upper, buffer 1 according to the doc, and lower, buffer 2 according to the doc.


What did I not understand?


double CCI[],ATR_D[],ATR_T[],BOLL_L[],BOLL_U[];
...

int OnInit()
        {
        ...
        for(int i=0;i<28;i++)
        {
        indichandle[i][0]=iCCI(pair[i],PERIOD_D1,14,PRICE_TYPICAL);
        indichandle[i][1]=iATR(pair[i],PERIOD_D1,12);
        indichandle[i][2]=iATR(pair[i],TFrame,12);
        indichandle[i][3]=iBands(pair[i],TFrame,20,2,0,PRICE_LOW);
        }


void OnTick()
        {
        ...
        CopyBuffer(indichandle[topair][3],2,1,2,BOLL_L);
        CopyBuffer(indichandle[topair][3],1,1,2,BOLL_U);
        ArraySetAsSeries(BOLL_L,true);
        ArraySetAsSeries(BOLL_U,true);
 
  1. indichandle[i][0]=iCCI …
    indichandle[i][1]=iATR …
    indichandle[i][2]=iATR …
    indichandle[i][3]=iBan …
    ⋮
    CopyBuffer(indichandle[topair][3],2,1,2,BOLL_L);
    
    You should never do that as constants are not self-documenting and error prone.

  2. enum INDI {ICCI, IATR_D1, IATR_TF, IBANDS};
    indichandle[i][ICCI   ]=iCCI …
    indichandle[i][IATR_D1]=iATR …
    indichandle[i][IATR_TF]=iATR …
    indichandle[i][IBANDS ]=iBan …
    ⋮
    CopyBuffer(indichandle[topair][IBANDS],UPPER_BAND,1,2,BOLL_L);
    Replacing constants with an enumeration is better. Using predefined constants is also better.

  3. Best is a structure and simplifying methods.
    struct Indi{ string symbol; int hCCI, hATR_D1, hATR_TF, hBB;
      int get_BB(int iBuf, int iBeg, int n, double &a[]){ 
        int r=CopyBuffer(hBB,iBuf,iBeg,n,a);
        if(r < n) PrintFormat("%s:CB-BB(%i,%n) failed: %i", __FUNCTION__, hBB, _LastError);
        return r;
      ⋮
    };
    Indi indi[28];
    ⋮
       indi[i].symbol = …
       indi[i].hCCI   =iCCI(  indi[i].symbol,PERIOD_D1,14,PRICE_TYPICAL);
       indi[i].hATR_D1=iATR(  indi[i].symbol,PERIOD_D1,12);
       indi[i].hATR_TF=iATR(  indi[i].symbol,TFrame,12);
       indi[i].hBB    =iBands(indi[i].symbol,TFrame,20,2,0,PRICE_LOW);
    ⋮
    void OnTick(){
            ⋮
            indi[topair].get_BB(UPPER_BAND,1,2,BOLL_L);

  4. stanislass: What did I not understand?
    You would know why, if you check your return codes for errors, and report them including GLE/LE. Don't look at it unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

  5. On MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
              Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
              Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum
 
William Roeder:
  1. You should never do that as constants are not self-documenting and error prone.

  2. Replacing constants with an enumeration is better. Using predefined constants is also better.

  3. Best is a structure and simplifying methods.

  4. You would know why, if you check your return codes for errors, and report them including GLE/LE. Don't look at it unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

  5. On MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
              Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
              Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum

Terminal and server are synchronized.

There is no error return.

In a visual backtest, on the topair / TFrame graph only the average of the bollinger is traced. There are no upper and lower bands.(?)


Ps. I do not see any error or you report it.

Reason: