Added some screenshots showing what it looks like in Meta5 vs my working solution using ThinkScripts in ThinkOrSwim.
Files:
Meta5_BB.png
26 kb
TOS_BB.png
113 kb
I've been working on something like this for a while and cannot figure it out too. This will make things easier to see the direction of the bands.
Tony N #:
Added some screenshots showing what it looks like in Meta5 vs my working solution using ThinkScripts in ThinkOrSwim.
Added some screenshots showing what it looks like in Meta5 vs my working solution using ThinkScripts in ThinkOrSwim.
There was so much wasteful processing and mistakes that I had to reprogram.
//+------------------------------------------------------------------+ //| BB v2.mq5 | //| Naguisa Unada | //| https://www.mql5.com/en/users/unadajapon/news | //+------------------------------------------------------------------+ #property copyright "Naguisa Unada" #property link "https://www.mql5.com/en/users/unadajapon/news" #property version "1.00" #property indicator_chart_window #property indicator_buffers 6 #property indicator_plots 3 //--- plot ExtML_ #property indicator_label1 "ExtML_" #property indicator_type1 DRAW_COLOR_LINE #property indicator_color1 clrRed,clrLimeGreen #property indicator_style1 STYLE_DASH #property indicator_width1 1 //--- plot ExtTL_ #property indicator_label2 "ExtTL_" #property indicator_type2 DRAW_COLOR_LINE #property indicator_color2 clrLimeGreen,clrWhite #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot ExtBL_ #property indicator_label3 "ExtBL_" #property indicator_type3 DRAW_COLOR_LINE #property indicator_color3 clrRed,clrWhite #property indicator_style3 STYLE_SOLID #property indicator_width3 1 //--- input parameters input int InpBandsPeriod = 20; // Period input int InpBandsShift = 0; // Shift input double InpBandsDeviations = 2.0; // Deviation //--- indicator buffers double ExtML_Buffer[]; double ExtML_Colors[]; double ExtTL_Buffer[]; double ExtTL_Colors[]; double ExtBL_Buffer[]; double ExtBL_Colors[]; int BolBandsHandle; // Bolinger Bands handle int ExtBandsPeriod, ExtBandsShift; double ExtBandsDeviations; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0, ExtML_Buffer, INDICATOR_DATA); SetIndexBuffer(1, ExtML_Colors, INDICATOR_COLOR_INDEX); SetIndexBuffer(2, ExtTL_Buffer, INDICATOR_DATA); SetIndexBuffer(3, ExtTL_Colors, INDICATOR_COLOR_INDEX); SetIndexBuffer(4, ExtBL_Buffer, INDICATOR_DATA); SetIndexBuffer(5, ExtBL_Colors, INDICATOR_COLOR_INDEX); //--- check for input values if(InpBandsPeriod < 2) { ExtBandsPeriod = 5; PrintFormat("Incorrect value for input variable InpBandsPeriod=%d. Indicator will use value=%d for calculations.", InpBandsPeriod, ExtBandsPeriod); } else ExtBandsPeriod = InpBandsPeriod; if(InpBandsShift < 0) { ExtBandsShift = 0; PrintFormat("Incorrect value for input variable InpBandsShift=%d. Indicator will use value=%d for calculations.", InpBandsShift, ExtBandsShift); } else ExtBandsShift = InpBandsShift; if(InpBandsDeviations == 0.0) { ExtBandsDeviations = 2.0; PrintFormat("Incorrect value for input variable InpBandsDeviations=%f. Indicator will use value=%f for calculations.", InpBandsDeviations, ExtBandsDeviations); } else ExtBandsDeviations = InpBandsDeviations; IndicatorSetString(INDICATOR_SHORTNAME, "Cloud Bollinger Bands"); BolBandsHandle = iBands(Symbol(), PERIOD_CURRENT, ExtBandsPeriod, ExtBandsShift, ExtBandsDeviations, PRICE_CLOSE); IndicatorSetInteger(INDICATOR_DIGITS, _Digits + 1); //--- 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 i, limit, to_copy; if (prev_calculated < 0) return (-1); if (prev_calculated == 0) { limit = ExtBandsPeriod; to_copy = rates_total; } else { limit = prev_calculated - 1; to_copy = rates_total - prev_calculated + 1; } if(CopyBuffer(BolBandsHandle, 0, 0, to_copy, ExtML_Buffer) < 0 || CopyBuffer(BolBandsHandle, 1, 0, to_copy, ExtTL_Buffer) < 0 || CopyBuffer(BolBandsHandle, 2, 0, to_copy, ExtBL_Buffer) < 0) return(0); for (i = limit; i < rates_total && !IsStopped(); i++) { if (ExtML_Buffer[i] < ExtML_Buffer[i - 1]) ExtML_Colors[i] = 0; else ExtML_Colors[i] = 1; if (ExtTL_Buffer[i] > ExtTL_Buffer[i - 1]) ExtTL_Colors[i] = 0; else ExtTL_Colors[i] = 1; if (ExtBL_Buffer[i] < ExtBL_Buffer[i - 1]) ExtBL_Colors[i] = 0; else ExtBL_Colors[i] = 1; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello guys,
This is my first time using MQL 5. But the goal for this indictor is just checking the `current value vs the previous` to determine the color coding for the BB Lines ( Middle, Upper and Lower ).
Currently the only way I was able to make progress was using the COPYBUFFER to get some values. But the value compared from the Arrays does not match what is displayed on chart. I verify the values in the debugger are being compared correctly. Any inputs or directions on this would be appreciated.
Another issue I saw was debugging/testing. Array out of range (195,33)rror message, I used `to_copy` as the array size.
Again thanks to the community for all the knowledge sharing.