#MTF_4_solar
Download scriptThis script is a multi-timeframe technical analysis tool designed to provide visual cues on a trading chart by aggregating data from four different time intervals simultaneously. Instead of looking at just one timeframe (like the 5-minute chart alone), this tool scans four specific periods—5 minutes, 15 minutes, 30 minutes, and 1 hour—to help traders identify momentum across multiple scales at once.
Core Functionality
The primary purpose of the script is to "pull" information from a secondary indicator (specifically one named "SOLAR WIND") across those four different timeframes and project them onto your current screen. It acts as a bridge, allowing you to see what is happening on larger timeframes without having to constantly switch windows or tabs in your trading platform.
How the Logic Works
The tool follows a systematic process to organize this data:
- Timeframe Synchronization: The script automatically tracks and aligns the specific historical timestamps for the 5M, 15M, 30M, and 1H periods. It ensures that as the current price moves forward, it is accurately pulling the corresponding data point from each of those four independent timeframes.
- Data Retrieval: For every candle on your current chart, the script reaches out to the "SOLAR WIND" indicator for all four timeframes. It looks for specific values associated with those periods to determine the current market sentiment or trend strength.
- Visual Signaling: Once the data is gathered, the script translates these values into visual markers (arrows) on a separate window:
- Bullish Signals: If the data indicates an upward trend or positive momentum on a specific timeframe, it marks that signal accordingly.
- Bearish Signals: If the data indicates a downward trend or negative momentum, it places a corresponding signal.
- Layered Visualization: Each of the four timeframes is assigned its own distinct "buffer" or layer. This means you can see the signals for the 5-minute chart, 15-minute chart, 30-minute chart, and 1-hour chart all displayed in one place.
User Benefit
By using this script, a trader can quickly identify "confluence." For example, if the markers for all four timeframes are showing the same direction simultaneously, it may suggest a very strong trend. Conversely, if the 5-minute and 15-minute charts show one direction while the hourly chart shows another, it provides an immediate visual cue that the short-term move might be acting against a larger, long-term trend.
//+------------------------------------------------------------------+
//| #MTF_4_solar.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 5
#property indicator_buffers 8
#property indicator_color1 SeaGreen
#property indicator_color2 SeaGreen
#property indicator_color3 SeaGreen
#property indicator_color4 SeaGreen
#property indicator_color5 FireBrick
#property indicator_color6 FireBrick
#property indicator_color7 FireBrick
#property indicator_color8 FireBrick
//---- input parameters
//---- buffers
double UpBuffer_M5[];
double UpBuffer_M15[];
double UpBuffer_M30[];
double UpBuffer_H1[];
double DownBuffer_M5[];
double DownBuffer_M15[];
double DownBuffer_M30[];
double DownBuffer_H1[];
datetime dt5[200], dt15[200], dt30[200], dth1[200];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,159);
SetIndexBuffer(0,UpBuffer_M5);
SetIndexEmptyValue(0,-40.0);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,159);
SetIndexBuffer(1,UpBuffer_M15);
SetIndexEmptyValue(1,-40.0);
SetIndexStyle(2,DRAW_ARROW);
SetIndexArrow(2,159);
SetIndexBuffer(2,UpBuffer_M30);
SetIndexEmptyValue(2,-40.0);
SetIndexStyle(3,DRAW_ARROW);
SetIndexArrow(3,159);
SetIndexBuffer(3,UpBuffer_H1);
SetIndexEmptyValue(3,-40.0);
SetIndexStyle(4,DRAW_ARROW);
SetIndexArrow(4,159);
SetIndexBuffer(4,DownBuffer_M5);
SetIndexEmptyValue(4,-40.0);
SetIndexStyle(5,DRAW_ARROW);
SetIndexArrow(5,159);
SetIndexBuffer(5,DownBuffer_M15);
SetIndexEmptyValue(5,-40.0);
SetIndexStyle(6,DRAW_ARROW);
SetIndexArrow(6,159);
SetIndexBuffer(6,DownBuffer_M30);
SetIndexEmptyValue(6,-40.0);
SetIndexStyle(7,DRAW_ARROW);
SetIndexArrow(7,159);
SetIndexBuffer(7,DownBuffer_H1);
SetIndexEmptyValue(7,-40.0);
IndicatorShortName("MTF_4_solar M5,M15,M30,M60");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit, shift;
if(counted_bars<0) return(-1);
if (counted_bars==0) limit=Bars-1; // limit = Bars-MinBars-1;
//---- last counted bar will be recounted
if(counted_bars>0) limit=Bars-counted_bars;
limit--;
int i5 = 0, i15 = 0, i30 = 0, ih1 = 0;
static bool fft = true;
//if (NewBar()) // Update array every 15 minutes
{
ArrayCopySeries(dt5,MODE_TIME,Symbol(),PERIOD_M5);
ArrayCopySeries(dt15,MODE_TIME,Symbol(),PERIOD_M15);
ArrayCopySeries(dt30,MODE_TIME,Symbol(),PERIOD_M30);
ArrayCopySeries(dth1,MODE_TIME,Symbol(),PERIOD_H1);
}
if ((fft) && (Symbol() == "EURUSD"))
{
fft = false;
datetime d = iTime(NULL, PERIOD_D1, 0);
for (int j=0; j<80; j++)
{
Print(j,") ",dt5[j]-d," ",dt15[j]-d, " ", dt30[j]-d," ", dth1[j]-d);
}
}
for(int i=0; i<limit; i++)
{
datetime ddt = iTime(NULL, 0, i);
if (ddt<dt5[i5]) i5++;
if (ddt<dt15[i15]) i15++;
if (ddt<dt30[i30]) i30++;
if (ddt<dth1[ih1]) ih1++;
double COG5=iCustom(NULL,PERIOD_M5,"SOLAR WIND",0,i5);
double COG5S=0;
double COG15=iCustom(NULL,PERIOD_M15,"SOLAR WIND",0,i15);
double COG15S=0;
double COG30=iCustom(NULL,PERIOD_M30,"SOLAR WIND",0,i30);
double COG30S=0;
double COGH1=iCustom(NULL,PERIOD_H1,"SOLAR WIND",0,ih1);
double COGH1S=0;
UpBuffer_M5[i] = -40; DownBuffer_M5[i] = -40;
UpBuffer_M15[i] = -40; DownBuffer_M15[i] = -40;
UpBuffer_M30[i] = -40; DownBuffer_M30[i] = -40;
UpBuffer_H1[i] = -40; DownBuffer_H1[i] = -40;
if (COG5 >COG5S) UpBuffer_M5[i] = 1; if (COG5 <COG5S) DownBuffer_M5[i] = 1;
if (COG15 >COG15S) UpBuffer_M15[i] = 2; if (COG15 <COG15S) DownBuffer_M15[i] = 2;
if (COG30 >COG30S) UpBuffer_M30[i] = 3; if (COG30 <COG30S) DownBuffer_M30[i] = 3;
if (COGH1 >COGH1S) UpBuffer_H1[i] = 4; if (COGH1 <COGH1S) DownBuffer_H1[i] = 4;
}
return(0);
}
//+------------------------------------------------------------------+
/*
bool NewBar()
{
static datetime dt = 0;
if (dt != iTime(NULL, PERIOD_M15, 0))
{
dt = iTime(NULL, PERIOD_M15, 0);
}
return(false);
}
*/
Comments