Author: Copyright � 2008, MetaQuotes Software Corp.
SvmPower

Overview of Tool Logic

This script is designed as a visual monitoring tool for trading platforms. Its primary purpose is to track, display, and organize specific "power signals" or data points in a dedicated window, allowing traders to see real-time numerical values that fluctuate based on market conditions.

Core Functional Logic

1. Data Retrieval & Synchronization The script acts as a listener for external data. It specifically looks for shared global variables (labeled as Signal Power 1, 2, and 3). Instead of calculating these values internally from raw price action alone, it fetches them from the system's memory. This means the tool is intended to work in tandem with other processes or scripts that "broadcast" these signals.

2. Real-Time Visual Updates The script manages several visual "buffers" (lines and text objects) that update dynamically:

  • Dynamic Shifting: To ensure the data remains readable as new price information arrives, the script employs a shifting mechanism. It moves existing data points to make room for new ones, creating a scrolling effect that maintains a consistent history on the screen.
  • Automatic Cleaning: To prevent the platform from becoming slow or cluttered, the script includes a "Maximum Draw" limit. Once the history exceeds a certain amount of data (ticks), it automatically clears the oldest information to maintain performance.

3. Structural Markers and Organization To help the user navigate the timeline, the script performs several organizational tasks:

  • Time Delimiters: Every time a new 5-minute candle appears, the script creates a vertical dashed line. This acts as a visual "separator," allowing you to see exactly where different segments of time begin.
  • Data Labeling: The script converts numerical data into readable text labels. These labels are positioned specifically on the chart so that you can see the exact values of the signals (e.g., Signal Power 1 and 2) directly associated with their corresponding points in time.

4. Performance Monitoring The logic includes a background automated process that captures "screenshots" of the indicator window at specific intervals. This is typically used by developers or advanced traders to create a visual log or "trail" of how the signals behaved during a live trading session or backtest.

Summary for the User

In plain terms, this tool takes complex hidden data (Signal Power), pulls it into your view, organizes it into a scrollable history with clear time-based dividers, and labels the most important numbers so you can monitor market "power" levels at a glance without having to manually track the underlying raw data.

Miscellaneous
Implements a curve of type %1
7 Views
0 Downloads
0 Favorites
SvmPower
//+------------------------------------------------------------------+
//|                                                     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 5
#property indicator_color1 Aqua
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Magenta
#property indicator_color5 Silver

#property indicator_style2 2
#property indicator_style3 2

#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 1

#property indicator_level1 0
#property indicator_level2 30
#property indicator_level3 -30
#property indicator_level4 60
#property indicator_level5 -60
#property indicator_level6 90
#property indicator_level7 -90

extern int MaxDrawTicks=1500;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
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);

   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4, ExtMapBuffer5);
   SetIndexEmptyValue(4,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("SignalPower1");
  double p2=GlobalVariableGet("SignalPower2");
  double p3=GlobalVariableGet("SignalPower3");  

  if(isNewBarM5())
  {
    SetDelimeter();
    if(p1 != EMPTY_VALUE)
    {
      ExtMapBuffer1[0]=p1;      
      ExtMapBuffer2[0]=-30;      
      ExtMapBuffer3[0]=30; 
      ExtMapBuffer4[0]=-p2;      
      //ExtMapBuffer5[0]=p3;            
    }  
    /*
    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]=-30;      
      ExtMapBuffer3[0]=30;      
      ExtMapBuffer4[0]=-p2;      
     // ExtMapBuffer5[0]=p3;            
    }  
    /*
    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),DoubleToStr(p3,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;            
     // for (i1=tickCounter;i1>=MaxDrawTicks;i1--) ExtMapBuffer5[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];      
     // ExtMapBuffer5[cnt]=ExtMapBuffer5[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, string s3)
{
  int FontSize=8;
  color FontColor1=Aqua;
  color FontColor2=Magenta;
  color FontColor3=Silver;
  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,ExtMapBuffer5[0+offset1]);
	else
		ObjectMove(objname3,0,Time[0+offset1]+Period()*60,ExtMapBuffer5[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,""+s3+"",FontSize,"Courier",FontColor3);
/*  
  ObjectSetText(objname4,"4-"+Symbol4Long+"",FontSize,"Courier",FontColor);
*/
}

  

Comments