bw-zonetrade

Author: 2009, MetaQuotes Software Corp.
# Understanding the BW-ZoneTrade Metatrader MQL Script

The **BW-ZoneTrade** script is a custom trading indicator designed to help traders visualize potential market conditions using candlestick patterns. This explanation will break down its logic and functionality in non-technical terms, suitable for an audience without programming expertise.

## Overview

This indicator uses two key technical indicators: the Accumulation/Distribution Line (AC) and the Awesome Oscillator (AO). These are used to identify areas of accumulation and distribution in the market. The script then colors candlesticks based on these conditions, helping traders make more informed decisions about potential trade zones.

### Key Components

1. **Data Inputs**:
   - **Open, High, Low, Close**: These represent the price data for each trading period (e.g., hourly, daily).
   - **Tick Volume and Volume**: Represent how much of a financial instrument has been traded.
   - **Spread**: The difference between the bid and ask prices.

2. **Indicator Buffers**:
   - Used to store calculated values such as open, high, low, close prices, and color indices for each candlestick.

3. **Main Indicators**:
   - **Accumulation/Distribution Line (AC)**: Helps identify buying or selling pressure.
   - **Awesome Oscillator (AO)**: Measures market momentum by comparing short-term price averages to longer-term ones.

## Logic Breakdown

### Initialization Phase
- The script sets up its environment, mapping necessary data buffers and configuring indicator settings. This ensures that the indicator only starts calculating from a sufficient number of past bars (in this case, 38), allowing for accurate results.

### Calculation Phase
1. **Data Availability Check**:
   - Ensures there are enough historical data points to perform calculations. If not, it exits early.
   
2. **Data Copying**:
   - Retrieves previously calculated values for AC and AO indicators into buffers. This step is crucial for analyzing past market behavior.

3. **Color Assignment Loop**:
   - For each candlestick from a certain point (after enough data has been gathered), the script assigns colors based on conditions derived from AC and AO.
   
   - **Gray Candle**: Default color indicating neutral or uncertain conditions.
   
   - **Green Candle**: Indicates an "accumulation zone" where both the AC is rising, suggesting buying pressure, and AO is also rising, suggesting increasing momentum. This might be a bullish signal for traders.
   
   - **Red Candle**: Represents a "distribution zone," characterized by falling AC and AO values, indicating selling pressure and potentially bearish conditions.

### Output
- The script updates the chart with colored candlesticks according to these rules, providing visual cues that help traders identify potential buy or sell opportunities based on historical data patterns.

## Conclusion

The **BW-ZoneTrade** script leverages technical indicators to provide a visual representation of market dynamics. By coloring candlesticks in different zones, it helps traders quickly spot areas where buying or selling pressure might influence future price movements, aiding decision-making without the need for deep technical knowledge.
Indicators Used
Bill Williams Accelerator/Decelerator oscillatorBill Williams Awesome oscillator
2 Views
0 Downloads
0 Favorites
bw-zonetrade
//+------------------------------------------------------------------+
//|                                                 BW-ZoneTrade.mq5 |
//|                        Copyright 2009, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_plots   1
#property indicator_type1   DRAW_COLOR_CANDLES
#property indicator_color1  Green,Red,Gray
#property indicator_width1  3
#property indicator_label1  "Open;High;Low;Close"
//--- indicator buffers
double ExtOBuffer[];
double ExtHBuffer[];
double ExtLBuffer[];
double ExtCBuffer[];
double ExtColorBuffer[];
double ExtAOBuffer[];
double ExtACBuffer[];
//--- handles of indicators
int    ExtACHandle;
int    ExtAOHandle;
//--- bars minimum for calculation
#define DATA_LIMIT 38
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtOBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtHBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,ExtLBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,ExtCBuffer,INDICATOR_DATA);
   SetIndexBuffer(4,ExtColorBuffer,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(5,ExtACBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(6,ExtAOBuffer,INDICATOR_CALCULATIONS);
//---
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- sets first bar from what index will be drawn
   IndicatorSetString(INDICATOR_SHORTNAME,"BW ZoneTrade");
//--- don't show indicator data in DataWindow
   PlotIndexSetInteger(0,PLOT_SHOW_DATA,false);
//--- sets first candle from what index will be drawn
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,DATA_LIMIT);
//--- get handles
   ExtACHandle=iAC(NULL,0);
   ExtAOHandle=iAO(NULL,0);
//--- initialization done
  }
//+------------------------------------------------------------------+
//| Trade zone by Bill Williams                                      | 
//+------------------------------------------------------------------+
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 &TickVolume[],
                const long &Volume[],
                const int &Spread[])
  {
   int i,limit;
//--- check for bars count
   if(rates_total<DATA_LIMIT)
      return(0);// not enough bars for calculation
//--- not all data may be calculated
   int calculated=BarsCalculated(ExtACHandle);
   if(calculated<rates_total)
     {
      Print("Not all data of ExtACHandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
     }
   calculated=BarsCalculated(ExtAOHandle);
   if(calculated<rates_total)
     {
      Print("Not all data of ExtAOHandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
     }
//--- we can copy not all data
   int to_copy;
   if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
   else
     {
      to_copy=rates_total-prev_calculated;
      if(prev_calculated>0) to_copy++;
     }
//--- get AC buffer
   if(CopyBuffer(ExtACHandle,0,0,to_copy,ExtACBuffer)<=0)
     {
      Print("Getting iAC is failed! Error",GetLastError());
      return(0);
     }
//--- get AO buffer
   if(CopyBuffer(ExtAOHandle,0,0,to_copy,ExtAOBuffer)<=0)
     {
      Print("Getting iAO is failed! Error",GetLastError());
      return(0);
     }
//--- set first bar from what calculation will start
   if(prev_calculated<DATA_LIMIT)
      limit=DATA_LIMIT;
   else
      limit=prev_calculated-1;
//--- the main loop of calculations
   for(i=limit;i<rates_total;i++)
     {
      ExtOBuffer[i]=Open[i];
      ExtHBuffer[i]=High[i];
      ExtLBuffer[i]=Low[i];
      ExtCBuffer[i]=Close[i];
      //--- set color for candle
      ExtColorBuffer[i]=2.0;  // set gray Color
      //--- check for Green Zone and set Color Green
      if(ExtACBuffer[i]>ExtACBuffer[i-1] && ExtAOBuffer[i]>ExtAOBuffer[i-1])
         ExtColorBuffer[i]=0.0;
      //--- check for Red Zone and set Color Red
      if(ExtACBuffer[i]<ExtACBuffer[i-1] && ExtAOBuffer[i]<ExtAOBuffer[i-1])
         ExtColorBuffer[i]=1.0;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---