Middle Bollinger Band

 

Is this the correct code to get the value of the Middle Bollinger Band?

double MiddleBand=iBands(NULL, PERIOD_M15,144,2,0,PRICE_WEIGHTED,MODE_MAIN,0);

Also, how do I get the value for the last bar?

Thanks

 
SMA 20 = Middle Bollinger Band
 
qjol:
SMA 20 = Middle Bollinger Band


so,

double MiddleBand=SMA 5;

will give me the value for the middle band on the current bar?

But that still leaves the question; how do I get the value for the previous bar? I need to be able to figure out if the moving average is rising or falling. If it is rising, I want to go long, if it is falling, I want to short. Simple enough.

 

double iBands( string symbol, int timeframe, int period, int deviation, int bands_shift, int applied_price, int mode, int shift)
Calculates the Bollinger bands indicator and returns its value.
Parameters:
symbol - Symbol the data of which should be used to calculate the indicator. NULL means the current symbol.
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.
period - Averaging period to calculate the main line.
deviation - Deviation from the main line.
bands_shift - The indicator shift relative to the chart.
applied_price - Applied price. It can be any of Applied price enumeration values.
mode - Indicator line index. It can be any of the Indicators line identifiers enumeration value.
shift - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).
Sample:
if(iBands(NULL,0,20,2,0,PRICE_LOW,MODE_LOWER,0)>Low[0]) return(0);

You have to know exactly what this means

iBands(NULL,0,20,2,0,PRICE_LOW,MODE_LOWER,0) to understand the formula

What means NULL

Then we have 0 (zero) what does this 0 mean

What is the 20 suppose to mean here

You can make a little program and in the comments you can print out some values when the programming is running

you can check with the mouse pointing to special points on the chart the value of that point.....

This way it is possible to check what the formula does

//+------------------------------------------------------------------+
//|                                                     Comments.mq4 |
//|                                Copyright © 2011, Tjipke de Vries |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Tjipke de Vries"
#property link      ""

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   subPrintDetails();
//----
   return(0);
  }
//+------------------------------------------------------------------+

//----------------------- PRINT COMMENT FUNCTION
void subPrintDetails()
{
   string sComment   = "";
   string sp         = "----------------------------------------\n";
   string NL         = "\n";

   double BollingerBand0 = iBands(NULL,0,20,2,0,PRICE_LOW,MODE_LOWER,0);
   double BollingerBand1 = iBands(NULL,0,20,2,0,PRICE_LOW,MODE_LOWER,1);
   
   sComment = "Comments EA              Copyright © 2011, Tjipke" + NL;
   sComment = sComment + NL;
   sComment = sComment + "BollingerBand zero " + DoubleToStr(BollingerBand0,5) + NL;
   sComment = sComment + "BollingerBand one " + DoubleToStr(BollingerBand1,5) + NL;
   sComment = sComment + NL;
   sComment = sComment + NL;


   Comment(sComment);
}
//+------------------------------------------------------------------+

And now play with the code to understand.......

 

This was very helpful and informative. Thank you very much! So, NULL means it doesn't matter what symbol, 0 means any periodicity, 20 is how many bars are we using to calculate the average, 2 is the deviation, 0 means we're looking at the current value, PRICE_LOW is the low price of the bar, MODE_LOWER is the lower band and 0 is the current bar.

I'm using NULL, H1, 5, 2, 0, PRICE_WEIGHTED, MODE_UPPER (and MODE_LOWER for a different variable), 0 (and 1 for a different variable)

I'm also using iMA(NULL,PERIOD_H1,5,0,MODE_SMA,PRICE_WEIGHTED,1); for the middle band. (last value is 0 for current bar)

So I think I have my parameters for my variables all well and good... but;

What logical statement can I use to make a condition true only if the current tick is the opening price of the current bar? (I have a more recent topic about this but I might as well ask directly)

For instance: My EA is looking for one of two conditions in order to send a trade to market. HOWEVER: This condition will continue to be true until the market changes direction. That means that EVERY SINGLE TICK will send an order to market. How can I make a condition true only if the current tick is in fact, the Opening Tick.

Once again, thank you.

 
trivates:

This was very helpful and informative. Thank you very much! So, NULL means it doesn't matter what symbol, 0 means any periodicity, 20 is how many bars are we using to calculate the average, 2 is the deviation, 0 means we're looking at the current value, PRICE_LOW is the low price of the bar, MODE_LOWER is the lower band and 0 is the current bar.

I'm using NULL, H1, 5, 2, 0, PRICE_WEIGHTED, MODE_UPPER (and MODE_LOWER for a different variable), 0 (and 1 for a different variable)

I'm also using iMA(NULL,PERIOD_H1,5,0,MODE_SMA,PRICE_WEIGHTED,1); for the middle band. (last value is 0 for current bar)

So I think I have my parameters for my variables all well and good... but;

What logical statement can I use to make a condition true only if the current tick is the opening price of the current bar? (I have a more recent topic about this but I might as well ask directly)

For instance: My EA is looking for one of two conditions in order to send a trade to market. HOWEVER: This condition will continue to be true until the market changes direction. That means that EVERY SINGLE TICK will send an order to market. How can I make a condition true only if the current tick is in fact, the Opening Tick.

Once again, thank you.



Be exact NULL means The Symbol of the chart the EA is Attached It won't trade GBPUSD if the chart is EURUSD

0 is not every periodicity but it is the periodicity of the chart...

 
trivates:


so,

double MiddleBand=SMA 5;

nope,

double MiddleBand0 = iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0); //Middle Band Last bar 
double MiddleBand1 = iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1); //Middle Band 1 candle Before Last bar
double MiddleBand2 = iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,2); //Middle Band 2 candles Before Last bar & so on

 
qjol:

nope,


double MiddleBand0 = iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0); //Middle Band Last bar 
double MiddleBand1 = iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1); //Middle Band 1 candle Before Last bar
double MiddleBand2 = iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,2); //Middle Band 2 candles Before Last bar & so on

qjol what is your period ?

Is this the same period as the BollingerBand....

What is your BollingerBand here ?

 
deVries:

qjol what is your period ?

can't u c iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0);

Is this the same period as the BollingerBand....

of course

What is your BollingerBand here ?

i don't get it, u need the bands or the Middle Band

 
qjol:


guys guys guys! we sorted this one out ages ago. I finished the EA and it failed so hard it might as well have crashed my computer too. Lost $2,901 worth of imaginary capital. I was so devastated that I called my fictitious wife and told her our virtual life savings were gone. She was so shocked that she became real and applauded my efforts for trying. It was almost as contradictory as the results of my EA.

true story!

 
i don't c what the story of your life has to do with the middle band LOL
Reason: