Kamikaze[1]
Download scriptThis script is designed as a multi-timeframe technical indicator for the MetaTrader platform. Its primary purpose is to monitor price trends across four different timeframes simultaneously—specifically the 5-minute, 15-minute, 30-minute, and 60-minute (hourly) charts—and display visual signals based on where the current price sits in relation to a moving average.
How the Logic Works
1. Multi-Timeframe Synchronization The core logic of the script involves "looking ahead" at different time horizons. Regardless of which chart you are currently viewing, the script calculates data for four specific periods. It automatically adjusts its calculations so that the data remains synchronized with your current screen, ensuring that the signals displayed are relevant to the present moment.
2. Trend Identification via Moving Averages To determine the "trend," the script uses a Simple Moving Average (SMA). Specifically, it calculates a "Typical Price" for each timeframe—which is the average of the high, low, and closing prices. It then measures the distance between this price and the 50-period moving average.
- Positive Deviation: If the current price is above the moving average, the script identifies a specific trend state.
- Negative Deviation: If the current price is below the moving average, it identifies the opposite trend state.
3. Visual Signaling Instead of drawing continuous lines, the script uses "buffers" to place distinct markers (arrows) on a separate window at the bottom of your chart.
- It processes all four timeframes independently.
- For each timeframe, it assigns a specific signal: if the price is above the trend line, it marks one signal; if it is below, it marks another.
- These are plotted as eight distinct data points, allowing a trader to see at a glance whether the 5, 15, 30, and 60-minute trends are all aligned in the same direction or if they are conflicting with one another.
Summary for the User
In simple terms, this tool acts as a "trend compass." It constantly checks four different time horizons to see if the market is currently trending upward or downward relative to its recent average. By looking at the resulting markers on your screen, you can quickly determine if the short-term momentum (like the 5-minute trend) matches the long-term momentum (the 60-minute trend).
//+------------------------------------------------------------------+
//| Kamikaze.mq4 |
//| Copyright © 2009, klentz |
//| periods are fixed: 5, 15, 30, 60 minutes |
//+------------------------------------------------------------------+
#property copyright "klentz"
#property indicator_separate_window
#property indicator_buffers 8
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red
#property indicator_color5 Blue
#property indicator_color6 Red
#property indicator_color7 Blue
#property indicator_color8 Red
#property indicator_minimum -0.5
#property indicator_maximum 5
extern int SMA = 50;
double buffer1[], buffer2[], buffer3[], buffer4[], buffer5[], buffer6[], buffer7[], buffer8[];
int init()
{
for (int i=0; i<8; i++)
{
SetIndexStyle(i,DRAW_ARROW); SetIndexArrow(i,110); SetIndexEmptyValue(i,EMPTY_VALUE);
}
SetIndexBuffer(0,buffer1); SetIndexBuffer(1,buffer2); SetIndexBuffer(2,buffer3); SetIndexBuffer(3,buffer4);
SetIndexBuffer(4,buffer5); SetIndexBuffer(5,buffer6); SetIndexBuffer(6,buffer7); SetIndexBuffer(7,buffer8);
return(0);
}
int start()
{
int limit;
int counted_bars = IndicatorCounted();
if(counted_bars < 0) return(-1);
if(counted_bars > 0) counted_bars-=60/Period()+1;
limit = Bars - counted_bars;
double tf_scale5 = Period()/5.0;
double tf_scale15 = Period()/15.0;
double tf_scale30 = Period()/30.0;
double tf_scale60 = Period()/60.0;
int i5 = 0, i15 = 0, i30 = 0, i60 = 0;
for(int i = 0; i < limit; i++)
{
if (tf_scale5<1.0 && Time[i]<iTime(NULL,PERIOD_M5,i5)) i5++;
if (tf_scale5>1.0) i5 = i+1;
if (tf_scale5==1.0) i5 = i;
double price_typical5 = (iHigh(NULL, PERIOD_M5, i5) + iLow(NULL, PERIOD_M5, i5) + iClose(NULL, PERIOD_M5, i5)) / 3;
double sma_trend5 = price_typical5 - iMA(NULL, PERIOD_M5, SMA, 0, MODE_SMA, PRICE_TYPICAL, i5);
if (tf_scale15<1.0 && Time[i]<iTime(NULL,PERIOD_M15,i15)) i15++;
if (tf_scale15>1.0) i15 = i+1;
if (tf_scale15==1.0) i15 = i;
double price_typical15 = (iHigh(NULL, PERIOD_M15, i15) + iLow(NULL, PERIOD_M15, i15) + iClose(NULL, PERIOD_M15, i15)) / 3;
double sma_trend15 = price_typical15 - iMA(NULL, PERIOD_M15, SMA, 0, MODE_SMA, PRICE_TYPICAL, i15);
if (tf_scale30<1.0 && Time[i]<iTime(NULL,PERIOD_M30,i30)) i30++;
if (tf_scale30>1.0) i30 = i+1;
if (tf_scale30==1.0) i30 = i;
double price_typical30 = (iHigh(NULL, PERIOD_M30, i30) + iLow(NULL, PERIOD_M30, i30) + iClose(NULL, PERIOD_M30, i30)) / 3;
double sma_trend30 = price_typical30 - iMA(NULL, PERIOD_M30, SMA, 0, MODE_SMA, PRICE_TYPICAL, i30);
if (tf_scale60<1.0 && Time[i]<iTime(NULL,PERIOD_H1,i60)) i60++;
if (tf_scale60>1.0) i60 = i+1;
if (tf_scale60==1.0) i60 = i;
double price_typical60 = (iHigh(NULL, PERIOD_H1, i60) + iLow(NULL, PERIOD_H1, i60) + iClose(NULL, PERIOD_H1, i60)) / 3;
double sma_trend60 = price_typical60 - iMA(NULL, PERIOD_H1, SMA, 0, MODE_SMA, PRICE_TYPICAL, i60);
buffer1[i]=EMPTY_VALUE; buffer2[i]=EMPTY_VALUE; buffer3[i]=EMPTY_VALUE; buffer4[i]=EMPTY_VALUE;
buffer5[i]=EMPTY_VALUE; buffer6[i]=EMPTY_VALUE; buffer7[i]=EMPTY_VALUE; buffer8[i]=EMPTY_VALUE;
if (sma_trend5 > 0) buffer1[i] = 1; else buffer2[i] = 1;
if (sma_trend15 > 0) buffer3[i] = 2; else buffer4[i] = 2;
if (sma_trend30 > 0) buffer5[i] = 3; else buffer6[i] = 3;
if (sma_trend60 > 0) buffer7[i] = 4; else buffer8[i] = 4;
}
return(0);
}
Comments