//--- int handleMA=INVALID_HANDLE,handleBands=INVALID_HANDLE; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- if((handleMA=iMA(_Symbol,_Period,MAPeriod,0,MAMethod,MAPrice))==INVALID_HANDLE || (handleBands=iBands(_Symbol,_Period,BandsPeriod,0,BandsDeviation,handleMA))==INVALID_HANDLE) return(INIT_PARAMETERS_INCORRECT); //--- //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { //--- int toCopy=(rates_total!=prev_calculated)?rates_total-prev_calculated:1; //--- if(CopyBuffer(handleMA,0,0,toCopy,MABuffer)!=toCopy || CopyBuffer(handleBands,1,0,toCopy,UpperBuffer)!=toCopy || CopyBuffer(handleBands,0,0,toCopy,CentrBuffer)!=toCopy || CopyBuffer(handleBands,2,0,toCopy,LowerBuffer)!=toCopy) return(0);
Another question @Ernst Van Der Merwe , I'm trying to use calculated Bollinger bands based on MA in an expert adviser, once I use your code, the metatrader detect my Expert as an indicator (I know now that it's because of the onCalculate function). Is there any way to use this code inside an Expert without without altering its functioning?
Best regards
Another question @Ernst Van Der Merwe , I'm trying to use calculated Bollinger bands based on MA in an expert adviser, once I use your code, the metatrader detect my Expert as an indicator (I know now that it's because of the onCalculate function). Is there any way to use this code inside an Expert without without altering its functioning?
Best regards
Yes, works exactly the same way.
//+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- int toCopy=2; if(CopyBuffer(handleMA,0,0,toCopy,MABuffer)!=toCopy || CopyBuffer(handleBands,1,0,toCopy,UpperBuffer)!=toCopy || CopyBuffer(handleBands,0,0,toCopy,CentrBuffer)!=toCopy || CopyBuffer(handleBands,2,0,toCopy,LowerBuffer)!=toCopy) return; //--- if(MABuffer[1]<UpperBuffer[1] && MABuffer[0]>UpperBuffer[0]) { Print("Buy!"); } } //+------------------------------------------------------------------+

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello
I'm trying to use Bollinger bands indicator with data from MA indicator. I read in the documentation that I can use iBands to handle buffer of data from my MA indicator, but the example seems complex o me. can anyone please explain me how to do this?
Let's say I used this code to calculate the MA and copy it to a handler:
How can I use iBands with this maFastHandler?