cant seem to call buffers

 

Hi guys,


Im trying to call the blue and yellow buffers for the attached indicator, im using icustom like this

"//Indicator Buffer 1

      if(iCustom(NULL, PERIOD_CURRENT, "trend-wave", 10, 21, false, false, 0, i) != 0 && iCustom(NULL, PERIOD_CURRENT, "trend-wave", 10, 21, false, false, 0, i) != EMPTY_VALUE "


but the buffer isnt read.

any idea why that would be?
//+------------------------------------------------------------------+
//|                                                       Trend Wave |
//|              Copyright 2011-2017, best-metatrader-indicators.com |
//|                        http://www.best-metatrader-indicators.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011-2017, best-metatrader-indicators.com"
#property link      "http://www.best-metatrader-indicators.com"
#property version   "2.02"
#property description "Risk Warning\nPlease note that forex trading entails substantial risk of loss, and may not\nbe suitable to everyone. Trading could lead to loss of your invested capital."

#property strict
#property indicator_buffers 8

#property indicator_separate_window
#property indicator_minimum               -100.0
#property indicator_maximum               100.0
#property indicator_levelcolor            clrSlateGray
#property indicator_levelstyle            1
#property indicator_color1                clrLime
#property indicator_color2                clrRed
#property indicator_width1                1
#property indicator_level1                60.0
#property indicator_width2                1
#property indicator_level2                53.0
#property indicator_level3                -50.0
#property indicator_level4                -60.0

//+------------------------------------------------------------------+
//| Externs                                                          |
//+------------------------------------------------------------------+
extern int        WavePeriod     = 10;       //Wave Period
extern int        AvgPeriod      = 21;       //Avg Period
extern bool       SoundAlert     = FALSE;    //Sound Alert
extern bool       EmailAlert     = FALSE;    //Sound Alert
//+------------------------------------------------------------------+
//| Buffers                                                          |
//+------------------------------------------------------------------+
double BullBuffer[];
double BearBuffer[];
double WaveMABuffer[];
double Buffer_4[];
double Buffer_5[];
double Buffer_6[];
double Buffer_7[];
double Buffer_8[];
//+------------------------------------------------------------------+
//| Variables                                                        |
//+------------------------------------------------------------------+
int BuyLevel      =  -50;
int SellLevel     =  53;
int LastSignalTime;
int gi_136 = 000000;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
   {
   IndicatorBuffers(8);
   IndicatorShortName("TrendWave");
   
   SetIndexBuffer(0, BullBuffer);
   SetIndexLabel(0, "Bull");
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 1, Lime);
   SetIndexDrawBegin(0, 0);
   SetIndexBuffer(1, BearBuffer);
   SetIndexLabel(1, "Bear");
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 1, Red);
   SetIndexDrawBegin(1, 0);
   
   
   
   SetIndexBuffer(2, WaveMABuffer);
   SetIndexLabel(2, "ESA");
   SetIndexStyle(2, DRAW_NONE);
   SetIndexDrawBegin(2, 0);
   SetIndexBuffer(3, Buffer_6);
   SetIndexLabel(3, "DD Values");
   SetIndexStyle(3, DRAW_NONE);
   SetIndexDrawBegin(3, 0);
   SetIndexBuffer(4, Buffer_4);
   SetIndexLabel(4, "DD");
   SetIndexStyle(4, DRAW_NONE);
   SetIndexDrawBegin(4, 0);
   SetIndexBuffer(5, Buffer_5);
   SetIndexLabel(5, "CI");
   SetIndexStyle(5, DRAW_NONE);
   SetIndexDrawBegin(5, 0);

   SetIndexBuffer(6, Buffer_7);
   SetIndexLabel(6, "Buy Dot");
   SetIndexStyle(6, DRAW_ARROW, STYLE_SOLID, 2, Aqua);
   SetIndexArrow(6, 108);
   SetIndexDrawBegin(6, 0);
   SetIndexBuffer(7, Buffer_8);
   SetIndexLabel(7, "Sell Dot");
   SetIndexStyle(7, DRAW_ARROW, STYLE_SOLID, 2, Yellow);
   SetIndexArrow(7, 108);
   SetIndexDrawBegin(7, 0);
   ArrayResize(WaveMABuffer, Bars);
   ArrayResize(Buffer_6, Bars);
   ArrayResize(Buffer_4, Bars);
   ArrayResize(Buffer_5, Bars);
   ArrayResize(BullBuffer, Bars);
   ArrayResize(BearBuffer, Bars);
   ArrayResize(Buffer_7, Bars);
   ArrayResize(Buffer_8, Bars);
   return (0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {

   double tempArr;
   int i;
   int counted = IndicatorCounted();
   if (counted < 0) return (-1);
   if (counted > 0) counted--;
   int limit = Bars - counted-1; //avil -1
   for (i = limit; i > 0; i--) {
      WaveMABuffer[i] = iMA(NULL, 0, WavePeriod, 0, MODE_EMA, PRICE_TYPICAL, i);
      ArraySetAsSeries(WaveMABuffer, TRUE);
   }
   for (i = limit; i > 0; i--) {
      Buffer_6[i] = MathAbs((iHigh(NULL, 0, i) + iClose(NULL, 0, i) + iLow(NULL, 0, i)) / 3.0 - WaveMABuffer[i]);
      ArraySetAsSeries(Buffer_6, TRUE);
   }
   for (i = limit; i > 0; i--) {
      tempArr = iMAOnArray(Buffer_6, 0, WavePeriod, 0, MODE_EMA, i);
      Buffer_4[i] = tempArr;
      ArraySetAsSeries(Buffer_4, TRUE);
   }
   for (i = limit; i > 0; i--) {
      if (Buffer_4[i] > 0.0) Buffer_5[i] = ((iHigh(NULL, 0, i) + iClose(NULL, 0, i) + iLow(NULL, 0, i)) / 3.0 - WaveMABuffer[i]) / (0.015 * Buffer_4[i]);
      else Buffer_5[i] = 0;
      ArraySetAsSeries(Buffer_5, TRUE);
   }
   for (i = limit; i > 0; i--) {
      tempArr = iMAOnArray(Buffer_5, 0, AvgPeriod, 0, MODE_EMA, i);
      BullBuffer[i] = tempArr;
      ArraySetAsSeries(BullBuffer, TRUE);
   }
   for (i = limit; i > 0; i--) {
      tempArr = iMAOnArray(BullBuffer, 0, 4, 0, MODE_SMA, i);
      BearBuffer[i] = tempArr;
      ArraySetAsSeries(BearBuffer, TRUE);
   }
    
//---- Signals
   for (i = limit-1; i > 0; i--) {
//--- Buy Signal    
      if (BullBuffer[i] >= BearBuffer[i] && BullBuffer[i + 1] <= BearBuffer[i + 1] && BullBuffer[i] < BuyLevel) {
         Buffer_7[i] = BullBuffer[i];
         SendAlert("buy");
      } else Buffer_7[i] = -1000;
      
//--- Sell Signal 
      if (BullBuffer[i] <= BearBuffer[i] && BullBuffer[i + 1] >= BearBuffer[i + 1] && BullBuffer[i] > SellLevel) {
         Buffer_8[i] = BearBuffer[i];
         SendAlert("sell");
      } else Buffer_8[i] = -1000;
   }
   return (0);
}

//+------------------------------------------------------------------+
//| SendAlert function                                               |
//+------------------------------------------------------------------+
void SendAlert(string SignalType) {
   if (Time[0] != LastSignalTime) {
      if (SoundAlert) {
         if (SignalType == "buy") Alert(Symbol() + " => " + TimeToStr(TimeCurrent()) + " buy");
         if (SignalType == "sell") Alert(Symbol() + " => " + TimeToStr(TimeCurrent()) + " sell");
      }
      if (EmailAlert) {
         if (SignalType == "buy") SendMail("TrendWave Alert", Symbol() + " => " + TimeToStr(TimeCurrent()) + " buy");
         if (SignalType == "sell") SendMail("TrendWave Alert", Symbol() + " => " + TimeToStr(TimeCurrent()) + " sell");
      }
      LastSignalTime = (int)Time[0];
   }
}
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Other Constants
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Other Constants
  • www.mql5.com
Other Constants - Named Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
 if(iCustom(NULL, PERIOD_CURRENT, "trend-wave", 10, 21, false, false, 0, i) != 0 && iCustom(NULL, PERIOD_CURRENT, NULL, PERIOD_CURRENT, "trend-wave", 10, 21, false, false, 0, i) != EMPTY_VALUE
 
Nagisa Unada:

hi Nagisa,


made that error while copying it the code im using is. i think the error im having is i use "if" and "else" but the buffers 0,1 always show as a value. how would i over com this?


 if(iCustom(NULL, PERIOD_CURRENT, "trend-wave", 10, 21, false, false, 0, i) != 0 && iCustom(NULL, PERIOD_CURRENT, "trend-wave", 10, 21, false, false, 0, i) != EMPTY_VALUE
 
shabaz:

hi Nagisa,

made that error while copying it the code im using is. i think the error im having is i use "if" and "else" but the buffers 0,1 always show as a value. how would i over com this?

I can't give you any advice based on this one line alone.

 
Nagisa Unada:

I can't give you any advice based on this one line alone.

hi mate,


thanks for your reply this is the code im trying to get to work

//+------------------------------------------------------------------+
//|                                         Indicator: moving av.mq4 |
//|                                       Created with EABuilder.com |
//|                                        https://www.eabuilder.com |
//+------------------------------------------------------------------+
#property copyright "Created with EABuilder.com"
#property link      "https://www.eabuilder.com"
#property version   "1.00"
#property description ""

#include <stdlib.mqh>
#include <stderror.mqh>

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 2

#property indicator_type1 DRAW_ARROW
#property indicator_width1 5
#property indicator_color1 0xFFAA00
#property indicator_label1 "Buy"

#property indicator_type2 DRAW_ARROW
#property indicator_width2 1
#property indicator_color2 0x0000FF
#property indicator_label2 "sell"

//--- indicator buffers
double Buffer1[];
double Buffer2[];

double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | moving av @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(2);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, EMPTY_VALUE);
   SetIndexArrow(0, 252);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, EMPTY_VALUE);
   SetIndexArrow(1, 241);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
  {
   int limit = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, EMPTY_VALUE);
      ArrayInitialize(Buffer2, EMPTY_VALUE);
     }
   else
      limit++;
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   
      
      //Indicator Buffer 1
      if(iCustom(NULL, PERIOD_CURRENT, "trend-wave", 10, 21, false, false, 6, i) != 0 && iCustom(NULL, PERIOD_CURRENT, "trend-wave", 10, 21, false, false, 6, i) != EMPTY_VALUE //TrendWave is not equal to fixed value
      )
        {
         Buffer1[i] = Low[1+i]; //Set indicator value at Candlestick Low
        }
      else
        {
         Buffer1[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 2
      if(iCustom(NULL, PERIOD_CURRENT, "trend-wave", 10, 21, false, false, 7, i) != 0 && iCustom(NULL, PERIOD_CURRENT, "trend-wave", 10, 21, false, false, 7, i) != EMPTY_VALUE //TrendWave is not equal to fixed value
      )
        {
         Buffer2[i] = High[1+i]; //Set indicator value at Candlestick High
        }
      else
        {
         Buffer2[i] = EMPTY_VALUE;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
 

I have made significant modifications to two programs.

Files:
trend-wave.mq4  16 kb
moving_av.mq4  9 kb
 

Hi Nagisa,


Thank you so much mate, i really appriciate the time and effort you put into making the changes. 

Reason: