SvmPower_002
Download scriptThe provided script is a specialized technical indicator designed for the MetaTrader trading platform. Its primary purpose is to visualize and track specific market data signals—referred to in the code as "Signal Power"—by plotting them on a dedicated sub-window of the chart.
Core Logic and Functionality
Data Retrieval and Visualization The script retrieves numerical values from the system's global variables (specifically identifying "SignalPower" and "SignalPowerA"). Instead of calculating these values itself, it acts as a visual bridge, fetching these pre-existing numbers and displaying them dynamically. It manages four distinct data streams (buffers), which allow it to show different types of information simultaneously on the same chart window.
Time-Based Synchronization The logic is designed to be highly sensitive to timeframes. It includes specific checks for new price bars at both the 1-minute and 5-minute intervals. This ensures that the indicator updates its visual data accurately as new trading periods begin, rather than just reacting to every individual price tick.
Dynamic Chart Management One of the script's primary functions is maintaining an organized visual space:
- Delimiters: Every time a new 5-minute bar appears, the script automatically creates a vertical dashed line (a "delimiter") on the chart. This helps the user visually separate different periods of trading activity.
- Array Shifting: To prevent the chart from becoming cluttered or slowing down, the script uses a "shifting" logic. It maintains a specific window of data (defined by the
MaxDrawTicksparameter). When new data arrives, it moves older data forward and clears out the oldest entries to keep the display clean and relevant.
On-Screen Information Display In addition to drawing lines on the chart, the script generates real-time text labels. It takes the numerical values of your signals and converts them into readable text, placing them directly on the chart. This allows a trader to see the exact status of the "Signal Power" at a glance without having to manually inspect raw data.
Automated Reporting The script includes a built-in feature to take a screenshot of the chart window during specific events (such as a new bar). This is typically used for logging activities or providing visual confirmation of market conditions during automated testing.
Summary of User Experience
For a non-programmer, this script functions as a live dashboard. It monitors background signals provided by other sources, organizes them into a clean visual timeline with automatic separators, and provides real-time text readouts of "Signal Power," all while automatically managing the chart's history to ensure the display remains smooth and uncluttered.
//+------------------------------------------------------------------+
//| SvmPower.mq4 |
//| Copyright © 2008, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Aqua
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Lime
#property indicator_style2 2
#property indicator_style3 2
#property indicator_width1 2
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 2
#property indicator_level1 0
#property indicator_level2 20
#property indicator_level3 -20
#property indicator_level4 40
#property indicator_level5 -40
#property indicator_level6 60
#property indicator_level7 -60
extern int MaxDrawTicks=1500;
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
int tickCounter;
string shortname;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
shortname=WindowExpertName();
IndicatorShortName(shortname);
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0, ExtMapBuffer1);
SetIndexEmptyValue(0,EMPTY_VALUE);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1, ExtMapBuffer2);
SetIndexEmptyValue(1,EMPTY_VALUE);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2, ExtMapBuffer3);
SetIndexEmptyValue(2,EMPTY_VALUE);
SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(3, ExtMapBuffer4);
SetIndexEmptyValue(3,EMPTY_VALUE);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
double p1=GlobalVariableGet("SignalPower");
double p2=GlobalVariableGet("SignalPowerA");
if(isNewBarM5())
{
SetDelimeter();
if(p1 != EMPTY_VALUE)
{
ExtMapBuffer1[0]=p1;
ExtMapBuffer2[0]=-50;
ExtMapBuffer3[0]=50;
ExtMapBuffer4[0]=p2;
}
/*
if(p1>0)
{
ExtMapBuffer1[0]=p1;
ExtMapBuffer2[0]=0;
}
else if(p1<0)
{
ExtMapBuffer2[0]=p1;
ExtMapBuffer1[0]=0;
}
*/
//ExtMapBuffer1[0]=Bid;
//ExtMapBuffer2[0]=Ask;
//ExtMapBuffer3[0]=Open[0];
}
else
{tickCounter++;
ShiftArray();
if(p1 != EMPTY_VALUE)
{
ExtMapBuffer1[0]=p1;
ExtMapBuffer2[0]=-50;
ExtMapBuffer3[0]=50;
ExtMapBuffer4[0]=p2;
}
/*
if(p1>0)
{
ExtMapBuffer1[0]=p1;
ExtMapBuffer2[0]=0;
}
else if(p1<0)
{
ExtMapBuffer2[0]=p1;
ExtMapBuffer1[0]=0;
}
*/
//ExtMapBuffer1[0]=Bid;
//ExtMapBuffer2[0]=Ask;
//ExtMapBuffer3[0]=Open[0];
}
//----
Obj1(DoubleToStr(p1,0),DoubleToStr(p2,0));
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
bool isNewBarM1()
{
static datetime BarTimeM1;
bool res=false;
if (BarTimeM1!=iTime(NULL,PERIOD_M1,0))
{
BarTimeM1=iTime(NULL,PERIOD_M1,0);
res=true;
}
return(res);
}
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
bool isNewBarM5()
{
static datetime BarTimeM5;
bool res=false;
if (BarTimeM5!=iTime(NULL,PERIOD_M5,0))
{
BarTimeM5=iTime(NULL,PERIOD_M5,0);
res=true;
}
return(res);
}
void SetDelimeter()
{
//----
string delimeterDate=TimeToStr(Time[0]);
//Print("Ñòàâèì ðàçäåëèòåëü");
int handle=WindowFind("SvmPower");
if(!ObjectCreate(delimeterDate,OBJ_VLINE,handle,Time[0],0))
{
//Alert("Íåäà÷íàÿ ïîïûòêà ñîçäàíèÿ ðàçäåëèòåëÿ â îêíå ",
//handle," ïî âðåìåíè ",TimeToStr(CurTime()));
//Print("Îøèáêà ¹",GetLastError(),", èìÿ ðàçäåëèòåëÿ ",delimeterDate);
}
else
{
ObjectSet(delimeterDate,OBJPROP_COLOR,Yellow);
ObjectSet(delimeterDate,OBJPROP_STYLE,STYLE_DASHDOT);
ObjectsRedraw();
}
WindowScreenShot("shots\\tester"+Symbol()+TimeCurrent()+".gif",640,480);
//----
return(0);
}
void ShiftArray()
{
//----
int V_lines,i1;
string delimeterName;
datetime firstTime;
int BarFirstTime;
if (tickCounter>2*MaxDrawTicks)
{
for (i1=tickCounter;i1>=MaxDrawTicks;i1--) ExtMapBuffer1[i1]=0.0;
for (i1=tickCounter;i1>=MaxDrawTicks;i1--) ExtMapBuffer2[i1]=0.0;
for (i1=tickCounter;i1>=MaxDrawTicks;i1--) ExtMapBuffer3[i1]=0.0;
for (i1=tickCounter;i1>=MaxDrawTicks;i1--) ExtMapBuffer4[i1]=0.0;
tickCounter=MaxDrawTicks;
}
for(int cnt=tickCounter;cnt>0;cnt--)
{
ExtMapBuffer1[cnt]=ExtMapBuffer1[cnt-1];
ExtMapBuffer2[cnt]=ExtMapBuffer2[cnt-1];
ExtMapBuffer3[cnt]=ExtMapBuffer3[cnt-1];
ExtMapBuffer4[cnt]=ExtMapBuffer4[cnt-1];
}
V_lines=ObjectsTotal();
for (int z=0;z<V_lines;z++)
{
delimeterName=ObjectName(z);
if (ObjectFind(delimeterName)!=-1)
{
if (ObjectType(delimeterName)==OBJ_VLINE)
{
firstTime=ObjectGet(delimeterName,OBJPROP_TIME1);
BarFirstTime=iBarShift(NULL,0,firstTime);
firstTime=Time[BarFirstTime+1];
ObjectSet(delimeterName,OBJPROP_TIME1,firstTime);
}
}
}
//----
return(0);
}
//---------------------------------------------------------------------+
void Obj1(string s1, string s2)
{
int FontSize=8;
color FontColor1=Aqua;
color FontColor2=Lime;
int offset1=0;
string objname1=shortname+1;
string objname2=shortname+2;
//string objname3=shortname+3;
//string objname4=shortname+4;
if(ObjectFind(objname1)<0)
ObjectCreate(objname1,OBJ_TEXT,WindowFind(shortname),Time[0+offset1]+Period()*60,ExtMapBuffer1[0+offset1]);
else
ObjectMove(objname1,0,Time[0+offset1]+Period()*60,ExtMapBuffer1[0+offset1]);
if(ObjectFind(objname2)<0)
ObjectCreate(objname2,OBJ_TEXT,WindowFind(shortname),Time[0+offset1]+Period()*60,ExtMapBuffer4[0+offset1]);
else
ObjectMove(objname2,0,Time[0+offset1]+Period()*60,ExtMapBuffer4[0+offset1]);
/*
if(ObjectFind(objname3)<0)
ObjectCreate(objname3,OBJ_TEXT,WindowFind(shortname),Time[0+offset1]+Period()*60,ExtMapBuffer4[0+offset1]);
else
ObjectMove(objname3,0,Time[0+offset1]+Period()*60,Buffer4[0+offset1]);
if(ObjectFind(objname4)<0)
ObjectCreate(objname4,OBJ_TEXT,WindowFind(shortname),Time[0+offset1]+Period()*60,Buffer5[0+offset1]);
else
ObjectMove(objname4,0,Time[0+offset1]+Period()*60,Buffer5[0+offset1]);
*/
ObjectSetText(objname1,""+s1+"",FontSize,"Courier",FontColor1);
ObjectSetText(objname2,""+s2+"",FontSize,"Courier",FontColor2);
/* ObjectSetText(objname3,"3-"+Symbol3Long+"",FontSize,"Courier",FontColor);
ObjectSetText(objname4,"4-"+Symbol4Long+"",FontSize,"Courier",FontColor);
*/
}
Comments