ObjectGetValuue_ByCurrent_en

Download script
Author: Aleksandr Pak, Alma-Ata
ObjectGetValuue_ByCurrent_en

This script is designed as a diagnostic and demonstration tool for the MetaTrader platform. Its primary purpose is to visualize and calculate how price movement "flows" or distributes across individual bars (candles) in real-time, specifically focusing on the progression of a line object over time.

Core Functionality

The script creates a visual trend line on your chart to serve as a reference point. Instead of simply looking at where a price ended, the logic focuses on the rate of change. It calculates the "delta"—the specific amount of movement that occurred between two points—and attempts to map out how much of that movement belongs to the current live candle versus previous ones.

How it Works (Step-by-Step)

  • Initialization: When you run the script, it automatically places a "Demo Line" on your chart. This line acts as a baseline for the calculations.
  • Time Tracking: The script monitors the passage of time. It waits for specific intervals (every 5 seconds) to perform its calculations, ensuring it doesn't overload the platform while still providing constant updates.
  • Movement Calculations: The logic breaks down price movement into three main components:
    1. The Historical Delta: It looks at the distance between the start and end of a finished bar to determine how much the price moved over that period.
    2. The Current Progression: It identifies the current "live" bar and calculates how far into that bar's timeframe we currently are.
    3. Dynamic Interpolation: By combining the total movement of a bar with the current percentage of time elapsed, the script estimates the "correction" or the specific price value at this exact micro-moment during the bar's formation.

Real-Time Reporting

As the script runs, it generates a detailed log in the platform’s terminal. This log provides a live data feed showing:

  • The current time of the bar.
  • The current value of the reference line.
  • The specific "delta" (movement amount) for the previous bar.
  • The estimated value of the current live bar based on the current percentage of time elapsed.

Summary for the User

In simple terms, this script is a mathematical magnifying glass. While standard charts show you where the price is, this script calculates how fast it is moving and projects that movement proportionally across the current timeframe. It is primarily used to observe the mechanics of bar formation and to see how price "delta" is distributed over time.

Price Data Components
Series array that contains open time of each bar
11 Views
0 Downloads
0 Favorites
ObjectGetValuue_ByCurrent_en
//+------------------------------------------------------------------+
//|  Set of functions and testing script                              |
//|                                      ObjectGetValueByCurrent.mq4 |
//|                                          Aleksandr Pak, Alma-Ata |
//|                                                   ekr-ap@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Aleksandr Pak, Alma-Ata"
#property link      "ekr-ap@mail.ru"

//+------------------------------------------------------------------+
//|CORRECTED from 19-04-2008ã.                                       |
//+------------------------------------------------------------------+
/*
Shows process of formation of bars on occurrence of a tic

*/

string d="Demo Line";
int init()
{
      if(ObjectFind(d)!=0)
      ObjectCreate(d,OBJ_TREND,0, iTime(NULL,0,7),WindowPriceMax(0), iTime(NULL,0,0)+15*60*Period(),WindowPriceMin(0));
      WindowRedraw();
}

int deinit()
{
ObjectDelete("Demo");
ObjectDelete("Demo Line");
return (0);
}


int start()
  {
 
   double t2,t=TimeLocal()-5;
   int i=0;
   
   while(i<300)
   { if(IsStopped()) return(0);
   
  
   t2=TimeLocal();
   if(t2-t>=5) 
      { 
      
      i+=1;
      t=TimeLocal();
      RefreshRates();  
      double rb=ObjectGetValueByShift (d,0);
      if(rb!=0) rb+=ObjectGetDelta_PerBar(d);
      
      Print( "Time[0]=",iTime(Symbol(),0,0), 
      " Line[0]=", ObjectGetValueByShift (d,0),
      " current value at formation 0 bars=",DoubleToStr(ObjectGetValue_ByCurrent (d,0),Digits+2),
      " Line (- 1)=",DoubleToStr(rb,Digits+2),
      " delta on (1) bar=",DoubleToStr(ObjectGetDelta_PerBar(d),Digits+2),
      " delta on (2) bar=",DoubleToStr(ObjectGetDelta_ByTimeShift(d,2*60*Period()),Digits+2));
     
      }
   }  
   Print("The end of demonstration");
   return(0);
  }
//+------------------------------------------------------------------+
//*******************************
double ObjectGetValue_ByCurrent(string c, int shift) //Value of 
{

double r=ObjectGetValueByShift (c,shift);
      if(r!=0) return(r+ObjectGetDelta_ByCurrent(c)); else return(0);
}
//*******************************


double ObjectGetDelta_PerBar(string c) //Increment of Y-ordinate per Bar
{ 
 double p=  ObjectGet(c,OBJPROP_PRICE1);
 double p2= ObjectGet(c,OBJPROP_PRICE2);
 
 int b =    ObjectGetShiftByValue(c,p);
 int b2=    ObjectGetShiftByValue(c,p2);        
 double     z=b-b2;  
            if(z!=0)
               {
               double delta=(p2-p)/z;
               }
 return(delta);
}

//***************************************
double ObjectGetDelta_ByCurrent(string c)
{ 
 
      double t=TimeCurrent()-iTime(Symbol(),0,0);
      double tf=60*Period();
      double delta=ObjectGetDelta_PerBar(c);
      double r=delta*(t/tf);
/*For demonstration!!!!*/      Print("              Time of the (0)Bar=",DoubleToStr(100*t/tf,0),"%", 
/*For demonstration!!!!*/      "                      Value of correction of the price=",DoubleToStr(r,Digits+2));

 return(r);
 
}
//****************************************************************************
double ObjectGetDelta_ByTimeShift(string c, double t) //double=datetime
{ 
      double tf=60*Period();
      double delta=ObjectGetDelta_PerBar(c);
      double r=delta*(t/tf); 
 return(r);
 
}






Comments