BBMA ZoneZeroLoss (ZZL) Oma Ally

Author: Copyright © 2025, Alexander Piechotta

Here's a breakdown of what this MetaTrader script does, explained in a way that doesn't require programming knowledge:

Overall Purpose

This script is designed to be a custom indicator for the MetaTrader platform. Indicators are tools that help traders analyze price charts and make decisions about when to buy or sell. This particular indicator, named "BBMA ZoneZeroLoss (ZZL) Oma Ally", aims to visually highlight potential "zero loss zones" on a chart. These zones are identified based on a combination of different moving averages and their relationship to Bollinger Bands.

How it Works

  1. Data Input: The script takes standard price data (open, high, low, close prices) for each period (e.g., each minute, hour, or day) of a financial instrument (like a currency pair) as its input. It also uses tick volume, volume and spread as inputs.

  2. Moving Averages: The core of the script involves calculating several types of moving averages:

    • Simple Moving Average (SMA): A simple average of prices over a specific period (defined by the input "InpBandsPeriod", which defaults to 20). This SMA is used to create the mid band of the bollinger band.
    • Exponential Moving Average (EMA): Gives more weight to recent prices (defined by the input "InpEMA50Period", which defaults to 50).
    • Linear Weighted Moving Average (LWMA): Similar to EMA, but the weighting is linear for a specified periods (defined by the inputs "InpMa5Period" and "InpMa10Period" which default to 5 and 10 respectively).
  3. Zero Loss Zone Identification: The script looks for specific conditions where the different moving averages are positioned relative to the SMA based mid band of the bollinger bands. The core logic:

    • Downtrend Zero Loss Zone: For each period, it checks if the EMA50 is equal to or above the Middle Bollinger Band. Also, LWMA5, LWMA10 calculated with High and Low price data must be below the Mid BB band.
    • Uptrend Zero Loss Zone: For each period, it checks if the EMA50 is equal to or below the Middle Bollinger Band. Also, LWMA5, LWMA10 calculated with High and Low price data must be above the Mid BB band.
  4. Visual Representation: The script displays its findings as a histogram in a separate window below the main chart:

    • Histogram Columns:
      • The up histogram (named "Zero Loss Zone UP") marks with green color trend confirmation for a buy signal, by default
      • The down histogram (named "Zero Loss Zone DOWN") marks with red color trend confirmation for a sell signal, by default

In Summary

The script is designed to automatically analyze price data and highlight potential trading opportunities (zero loss zones) based on a specific set of rules involving moving averages. It provides a visual aid to traders by displaying this information as a histogram.

Price Data Components
8 Views
1 Downloads
0 Favorites
BBMA ZoneZeroLoss (ZZL) Oma Ally
ÿþ//+------------------------------------------------------------------+

//|                             BBMA ZoneZeroLoss (ZZL) Oma Ally.mq5 |

//|                            Copyright © 2025, Alexander Piechotta |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2025, Alexander Piechotta"

#property link      "alepie@outlook.de"

#property version   "1.0"



#include <MovingAverages.mqh>



#property indicator_separate_window

#property indicator_buffers 10

#property indicator_plots   2



//--- Histogram

#property indicator_label1  "Zero Loss Zone UP"

#property indicator_type1   DRAW_COLOR_HISTOGRAM



#property indicator_label2  "Zero Loss Zone DOWN"

#property indicator_type2   DRAW_COLOR_HISTOGRAM

//---

#property indicator_color1  clrNONE,clrGreen,clrRed

#property indicator_style1  STYLE_SOLID

#property indicator_width1  5



#property indicator_color2  clrNONE,clrGreen,clrRed

#property indicator_style2  STYLE_SOLID

#property indicator_width2  5



int     InpBandsPeriod=20;  // Period

int     InpEMA50Period=50;

int     InpMa5Period=5; // Period

int     InpMa10Period=10;



//--- buffer of values

double         HistogramBufferUp[];

double         HistogramColorsUp[];



double         HistogramBufferDown[];

double         HistogramColorDown[];



double         Mahi5Buffer[];

double         Mahi10Buffer[];



double         Malo5Buffer[];

double         Malo10Buffer[];



double         MidBBBuffer[];

double         EMA50Buffer[];

//---

int m_digits=-1;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

   m_digits=Digits();

   if(m_digits<0)

      m_digits=0;



//--- indicator buffers mapping



   SetIndexBuffer(0,HistogramBufferUp,INDICATOR_DATA);

   SetIndexBuffer(1,HistogramColorsUp,INDICATOR_COLOR_INDEX);



   SetIndexBuffer(2,HistogramBufferDown,INDICATOR_DATA);

   SetIndexBuffer(3,HistogramColorDown,INDICATOR_COLOR_INDEX);



   SetIndexBuffer(4,MidBBBuffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(5,EMA50Buffer,INDICATOR_CALCULATIONS);



   SetIndexBuffer(6,Mahi10Buffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(7,Mahi5Buffer,INDICATOR_CALCULATIONS);



   SetIndexBuffer(8,Malo10Buffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(9,Malo5Buffer,INDICATOR_CALCULATIONS);



//---

   IndicatorSetDouble(INDICATOR_MINIMUM,0.0);

   IndicatorSetDouble(INDICATOR_MAXIMUM,1.0);

//---

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,0.0);

//--- set accuracy

   IndicatorSetInteger(INDICATOR_DIGITS,0);

   IndicatorSetString(INDICATOR_SHORTNAME,"BBMA ZoneZeroLoss (ZZL) Oma Ally");

//---

   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=prev_calculated-1;

   if(prev_calculated==0)

      limit=0;

//---

   SimpleMAOnBuffer(rates_total, prev_calculated, 0, InpBandsPeriod, close, MidBBBuffer);

   ExponentialMAOnBuffer(rates_total, prev_calculated, 0, InpEMA50Period, close, EMA50Buffer);



   LinearWeightedMAOnBuffer(rates_total, prev_calculated, 0, InpMa10Period, high, Mahi10Buffer);

   LinearWeightedMAOnBuffer(rates_total, prev_calculated, 0, InpMa5Period, high, Mahi5Buffer);



   LinearWeightedMAOnBuffer(rates_total, prev_calculated, 0, InpMa10Period, low, Malo10Buffer);

   LinearWeightedMAOnBuffer(rates_total, prev_calculated, 0, InpMa5Period, low, Malo5Buffer);



   for(int i=limit;i<rates_total;i++)

     {

      HistogramBufferDown[i]=0;

      HistogramColorDown[i]=0;

      HistogramBufferUp[i]=0;

      HistogramColorsUp[i]=0;



      //---

      if(EMA50Buffer[i]>=MidBBBuffer[i] && Mahi10Buffer[i]<=MidBBBuffer[i] && Mahi5Buffer[i]<=MidBBBuffer[i] && Malo10Buffer[i]<=MidBBBuffer[i] && Malo5Buffer[i]<=MidBBBuffer[i])

        {

         HistogramBufferDown[i]=1;

         HistogramColorDown[i]=2;

        }



      if(EMA50Buffer[i]<=MidBBBuffer[i] && Mahi10Buffer[i]>=MidBBBuffer[i] && Mahi5Buffer[i]>=MidBBBuffer[i] && Malo10Buffer[i]>=MidBBBuffer[i] && Malo5Buffer[i]>=MidBBBuffer[i])

        {

         HistogramBufferUp[i]=1;

         HistogramColorsUp[i]=1;

        }

     }



//--- return value of prev_calculated for next call

   return(rates_total);

  }



//+------------------------------------------------------------------+

Comments