KhaosAssault2_v1

Author: Sgalaise
KhaosAssault2_v1

Here's a breakdown of what the MetaTrader script does, explained in simple terms for someone who isn't a programmer:

Overall Purpose

This script is designed to visually represent the difference between two moving averages of a financial instrument's price. Think of it as a tool to quickly see if shorter-term price trends are above or below longer-term trends, and to what degree.

How it Works

  1. Moving Averages: The script uses two different moving averages. A moving average is simply a way to smooth out price data over a specified period.

    • Fast Moving Average: This average reacts more quickly to recent price changes. You can set the type (e.g., simple, exponential) and the period (e.g., 5 days) for this average.
    • Slow Moving Average: This average is less sensitive to short-term price fluctuations because it considers a larger period of time. Like the fast average, you can customize its type and period (e.g., 120 days).
  2. Calculating the Difference: The script constantly calculates the difference between the values of the fast moving average and the slow moving average. This difference is the core data that the script uses to generate its visuals.

  3. Visual Representation (Histogram): The script then displays this difference as a histogram (a bar chart) in a separate window on your trading platform.

    • Green Bars: If the fast moving average is above the slow moving average (meaning short-term trends are higher than long-term trends), the script draws a green bar. The height of the bar indicates the magnitude of the difference between the two averages.
    • Red Bars: If the fast moving average is below the slow moving average (short-term trends are lower than long-term trends), the script draws a red bar. Again, the height shows the size of the difference.
  4. Levels: The script also draws horizontal lines (levels) on the histogram. These levels are set to fixed values. If the currency pair contains "JPY", it uses one set of level values. If not, it uses a different set of level values. These levels serve as visual guides to help traders identify potentially significant areas where the difference between the moving averages may indicate a change in market momentum.

In essence:

The script takes two moving averages, finds the difference, and then visually represents whether short-term trends are above or below longer-term trends using colored bars and defined levels. This helps traders quickly assess the relationship between different timeframes and identify possible trading opportunities.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
KhaosAssault2_v1
//+------------------------------------------------------------------+
//|                                                 KhaosAssault.mq4 |
//|                                                         SGalaise |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Sgalaise"
//----
#property indicator_separate_window
#property indicator_buffers 3
#property  indicator_color1  Black
#property  indicator_color2  LawnGreen
#property  indicator_color3  Red
//---- input parameters
extern int       FastMovingMAType=3;
extern int       FastMovingMAPeriod=5;
extern int       SlowMovingMAType=1;
extern int       SlowMovingMAPeriod=120;
//---- buffers
double CAOBuffer0[];
double CAOBuffer1[];
double CAOBuffer2[];
//----
string SlowMA="";
string FastMA="";
//----
double prev,current;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   //IndicatorBuffers(3);
   switch(FastMovingMAType)
     {
      case 0: FastMA="SMA"; break;
      case 1: FastMA="EMA"; break;
      case 2: FastMA="SMMA"; break;
      case 3: FastMA="LWMA"; break;
     }
   switch(SlowMovingMAType)
     {
      case 0: SlowMA="SMA"; break;
      case 1: SlowMA="EMA"; break;
      case 2: SlowMA="SMMA"; break;
      case 3: SlowMA="LWMA"; break;
     }
   //   IndicatorBuffers(3);
//---- indicators
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_HISTOGRAM,0,3,LawnGreen);
   SetIndexStyle(2,DRAW_HISTOGRAM,0,3,Red);
   IndicatorDigits(Digits+1);
   SetIndexDrawBegin(0,SlowMovingMAPeriod);
   SetIndexDrawBegin(1,SlowMovingMAPeriod);
   SetIndexDrawBegin(2,SlowMovingMAPeriod);
   SetIndexBuffer(0,CAOBuffer0);
   SetIndexBuffer(1,CAOBuffer1);
   SetIndexBuffer(2,CAOBuffer2);
//----
   IndicatorShortName("KhaosAssault ("+FastMA+":"+FastMovingMAPeriod+", "+SlowMA+":"+SlowMovingMAPeriod+")");
   int findsymbol=StringFind(Symbol(),"JPY",0);
   //Alert(findsymbol);
   if(findsymbol<0)
     {
      SetLevelStyle(1,1,SteelBlue);
      SetLevelValue(1,0.0089);
      SetLevelValue(2,0.0055);
      SetLevelValue(3,0.0034);
      SetLevelValue(4,0.0021);
      SetLevelValue(5,0.0013);
      SetLevelValue(6,-0.0013);
      SetLevelValue(7,-0.0021);
      SetLevelValue(8,-0.0034);
      SetLevelValue(9,-0.0055);
      SetLevelValue(10,-0.0089);
     }
   else
     {
      SetLevelStyle(1,1,SteelBlue);
      SetLevelValue(1,0.89);
      SetLevelValue(2,0.55);
      SetLevelValue(3,0.34);
      SetLevelValue(4,0.21);
      SetLevelValue(5,0.13);
      SetLevelValue(6,-0.13);
      SetLevelValue(7,-0.21);
      SetLevelValue(8,-0.34);
      SetLevelValue(9,-0.55);
      SetLevelValue(10,-0.89);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    limit;
   int    counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- macd
   for(int i=0; i<limit; i++)
      CAOBuffer0[i]=iMA(NULL,0,FastMovingMAPeriod,0,FastMovingMAType,PRICE_CLOSE,i)-iMA(NULL,0,SlowMovingMAPeriod,0,SlowMovingMAType,PRICE_CLOSE,i);
//---- dispatch values between 2 buffers
   bool up=true;
   for(i=limit-1; i>=0; i--)
     {
      current=CAOBuffer0[i];
      prev=CAOBuffer0[i+1];
      if(current>prev) up=true;
      if(current<prev) up=false;
      if(!up)
        {
         CAOBuffer2[i]=current;
         CAOBuffer1[i]=0.0;
        }
      else
        {
         CAOBuffer1[i]=current;
         CAOBuffer2[i]=0.0;
        }
     }
   return(0);
  }
//+------------------------------------------------------------------+

Comments