BillWilliams_ATZ

Author: Copyright � Pointzero-indicator.com
BillWilliams_ATZ

Okay, here's a breakdown of the MQL4 script's logic in plain English, avoiding technical jargon and code snippets.

Overall Purpose

This script is a custom indicator for a trading platform (MetaTrader). It aims to generate buy and sell signals based on a combination of Bill Williams' technical indicators. It's designed to help traders identify potential entry points in the market.

Initialization (The init() Function)

  • Setting Up: The script first prepares the indicator for display. It defines how buy and sell signals will be visually represented on the chart (using arrows).
  • Adjusting for Timeframe: It calculates a nShift value. This value adjusts the position of the buy/sell signals on the chart, likely to account for the timeframe being used (e.g., a longer timeframe might need a larger shift).
  • Defining Constants: It sets up some constant values (like MACD_a, MACD_b, MACD_c) that are used later in the calculations. These likely represent parameters for the MACD indicator.

Main Calculation (The start() Function)

This is where the core logic happens. The script loops through each bar (candle) on the chart and performs calculations to determine if a buy or sell signal should be generated.

  1. Gathering Data: For each bar, the script retrieves a lot of data from various Bill Williams indicators:
    • Trade Zone: Calculates a "trade zone" value, which is a combination of Accelerator/Decelerator (AC) and Awesome Oscillator (AO) indicators. This helps determine the overall trend direction.
    • MACD (Moving Average Convergence Divergence): Calculates the MACD line, signal line, and their relationship. MACD is used to identify changes in momentum.
    • Alligator: Calculates the alligator indicator's jaws, teeth, and lips. The alligator indicator is used to measure market volatility and trend strength.
  2. Trend Assessment:
    • Alligator Trend: The script uses the alligator indicator to determine the overall trend. If the lips are above the teeth, which are above the jaws, it suggests an upward trend (potential buy signal). If the opposite is true, it suggests a downward trend (potential sell signal).
  3. Danger Assessment:
    • Long/Short Danger: The script checks if going long (buying) or short (selling) is "dangerous" based on the current price relative to the alligator's lips and the MACD's relationship.
  4. Signal Generation:
    • Buy Signal: A buy signal is generated if:
      • The trade zone is in a buy zone.
      • The trade zone changed from a buy zone to a neutral zone.
      • The alligator indicator suggests an upward trend.
      • The current price is higher than the opening price of the bar.
      • It's not considered a "dangerous" time to go long.
    • Sell Signal: A sell signal is generated if:
      • The trade zone is in a sell zone.
      • The trade zone changed from a sell zone to a neutral zone.
      • The alligator indicator suggests a downward trend.
      • The current price is lower than the opening price of the bar.
      • It's not considered a "dangerous" time to go short.
  5. Displaying Signals: When a buy or sell signal is generated, the script places an arrow on the chart at a specific price level (adjusted by nShift).

Trade Zone Calculation (The tradezone() Function)

This function calculates the trade zone value based on the Accelerator/Decelerator (AC) and Awesome Oscillator (AO) indicators. It returns a value indicating whether the trade zone is in a buy, sell, or neutral state.

Key Concepts

  • Bill Williams Indicators: The script heavily relies on a suite of indicators developed by Bill Williams, including the Trade Zone, MACD, Alligator, and Awesome Oscillator.
  • Momentum: The script uses the MACD to gauge the momentum of the price.
  • Trend Strength: The alligator indicator is used to measure the strength of the current trend.
  • Confirmation: The script uses multiple indicators to confirm potential trading signals, aiming to reduce false signals.

Let me know if you'd like a deeper dive into any specific part of the script!

Price Data Components
Series array that contains close prices for each barSeries array that contains open prices of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Indicators Used
MACD HistogramBill Williams AlligatorBill Williams Accelerator/Decelerator oscillatorBill Williams Awesome oscillator
Miscellaneous
Implements a curve of type %1
4 Views
0 Downloads
0 Favorites
BillWilliams_ATZ
//+------------------------------------------------------------------+
//| BillWilliams_ATZ.mq4 |
//| Copyright © Pointzero-indicator.com
//+------------------------------------------------------------------+
#property copyright "Copyright © Pointzero-indicator.com"
#property link      "http://www.pointzero-indicator.com"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#define OP_NOTHING 6

#define MACD_a         5
#define MACD_b         34
#define MACD_c         5

//-------------------------------
// Input parameters: none
//-------------------------------

//-------------------------------
// Buffers
//-------------------------------
double ExtMapBuffer1[];
double ExtMapBuffer2[];

//-------------------------------
// Internal variables
//-------------------------------
int    nShift;   

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   // Buffers and style
    SetIndexStyle(0, DRAW_ARROW, 0, 1);
    SetIndexArrow(0, 233);
    SetIndexBuffer(0, ExtMapBuffer1);
    SetIndexStyle(1, DRAW_ARROW, 0, 1);
    SetIndexArrow(1, 234);
    SetIndexBuffer(1, ExtMapBuffer2);

    // Data window
    IndicatorShortName("Bill Williams ATZ");
    SetIndexLabel(0, "Buy arrow");
    SetIndexLabel(1, "Sell arrow"); 
    
    Comment("Copyright © http://www.pointzero-indicator.com");
    
    // Chart offset calculation
    switch(Period())
    {
        case     1: nShift = 1;   break;    
        case     5: nShift = 3;   break; 
        case    15: nShift = 5;   break; 
        case    30: nShift = 10;  break; 
        case    60: nShift = 15;  break; 
        case   240: nShift = 20;  break; 
        case  1440: nShift = 80;  break; 
        case 10080: nShift = 100; break; 
        case 43200: nShift = 200; break;               
    }

    return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
    return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
    int limit;
    int counted_bars = IndicatorCounted();

    // check for possible errors
    if(counted_bars < 0) 
        return(-1);

   //last counted bar will be recounted
    if(counted_bars > 0) 
        counted_bars--;
    limit = Bars - counted_bars;

    // Check the signal foreach bar
    for(int i = 0; i < limit; i++)
    {   
        // Indicate the trend
        int ma_trend = OP_NOTHING;
        int a_trend = OP_NOTHING;
        
        // Bill williams zonetrade indicators to point detect early strenght
        int tz = tradezone(i);
        int tz1 = tradezone(i+1);
        
        // Open and close of the current candle to filter tz signals
        double CLOSE = iClose(Symbol(),0, i);
        double OPEN = iOpen(Symbol(),0, i);
        double HIGH = iHigh(Symbol(),0, i);
        double LOW = iLow(Symbol(),0, i);
        
        // Macd present and past
        double MACD_main         = iMACD(NULL,0, MACD_a, MACD_b, MACD_c, PRICE_CLOSE, MODE_MAIN, i);
        double MACD_signal       = iMACD(NULL,0, MACD_a, MACD_b, MACD_c, PRICE_CLOSE, MODE_SIGNAL, i);
        double MACD_main_last    = iMACD(NULL,0, MACD_a, MACD_b, MACD_c, PRICE_CLOSE, MODE_MAIN, i+1);
        double MACD_signal_last  = iMACD(NULL,0, MACD_a, MACD_b, MACD_c, PRICE_CLOSE, MODE_SIGNAL, i+1);
        
        // Alligator
        double a_jaw = iAlligator(Symbol(), 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORJAW, i);
        double a_teeth = iAlligator(Symbol(), 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORTEETH, i);
        double a_lips = iAlligator(Symbol(), 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORLIPS, i);
        
        // Calculate alligator trend
        if(a_lips > a_teeth && a_teeth > a_jaw)
            a_trend = OP_BUY;
        else if(a_lips < a_teeth && a_teeth < a_jaw)
            a_trend = OP_SELL;
            
        // Evaluate if going long or short is dangerous now
        bool long_dangerous = false;
        bool short_dangerous = false;
        if(CLOSE > a_lips && MACD_main < MACD_signal) long_dangerous = true;
        if(CLOSE < a_lips && MACD_main > MACD_signal) short_dangerous = true;
         
        // Long signal 
        if((tz == OP_BUY && tz1 != OP_BUY && a_trend == OP_BUY && CLOSE > OPEN && long_dangerous == false))
        {
            // Display only if signal is not repated
             ExtMapBuffer1[i] = Low[i] - nShift*Point;
             
             // Throw Message
             //Print("[BILL WILLIAMS ATZ] Buy stop at "+ HIGH);
        }
        
        // Short signal
        if(tz == OP_SELL && tz1 != OP_SELL && a_trend == OP_SELL && CLOSE < OPEN && short_dangerous == false)
        {
            // Display only if signal is not repeated
            ExtMapBuffer2[i] = High[i] + nShift*Point;
            
            // Throw Message
            //Print("[BILL WILLIAMS ATZ] Sell stop at "+ LOW);
        }
    }
    return(0);
}

/**
* Returns bill williams trade zone for the candle received has parameter.
* @param    int   shift
* @return   int
*/

int tradezone(int shift = 1)
{
   // AC and AO for current and last candle
   double AC = iAC(Symbol(), 0, shift);
   double AC_last = iAC(Symbol(), 0, shift+1);
   double AO = iAO(Symbol(), 0, shift);
   double AO_last = iAO(Symbol(), 0, shift+1);
   
   // Returns action for this candle
   if(AO < AO_last && AC < AC_last) return(OP_SELL);
   if(AO > AO_last && AC > AC_last) return(OP_BUY);
   return(OP_NOTHING);
}

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

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 ---