ObjectGetValuue_ByCurrent_

Download script
Author: Aleksandr Pak, Alma-Ata
ObjectGetValuue_ByCurrent_

This script is designed to demonstrate how price data and visual objects (like trend lines) behave dynamically within a trading platform. Its primary purpose is to calculate and display how "real-time" values change based on the elapsed time of a current candle, rather than waiting for a candle to close.

Core Functionality

The script creates a visual demonstration line on your chart. Instead of simply showing a static price, it performs complex calculations to estimate where a trend line's value should be at any specific second during the formation of a new bar.

How the Logic Works

  • Real-Time Estimation: The logic calculates the "delta" (the change in price) between completed bars. It then takes that historical change and applies it to the current, unfinished bar based on how many seconds have passed since that bar started.
  • Dynamic Updates: Every five seconds, the script refreshes its data. It looks at the current time, calculates the percentage of completion for the active candle, and adjusts the line's value proportionally.
  • Coordinate Mapping: The script possesses the ability to look back at previous price points to determine the slope of a trend. It uses this slope to "predict" the current value of the line in real-time, providing a smooth visual representation of price movement.

Key Technical Processes

  1. Initialization: When you start the script, it automatically draws a demonstration line on your chart.
  2. Continuous Monitoring: The script runs a loop that checks the time constantly. If the platform is stopped or the cycle finishes, it halts; otherwise, it keeps updating the data points.
  3. Proportional Calculation: By comparing the current time against the standard duration of a candle (e.g., 1 minute, 5 minutes), the script determines exactly how much the price "should" have moved by that exact second.
  4. Data Logging: Throughout the demonstration, the script prints a detailed log to the terminal. This log shows you the specific time, the current value of the line, the previous bar's value, and the calculated deltas for both the current and previous bars.

In essence, this tool is a mathematical bridge between static historical data and live price action, showing how one can calculate "in-progress" values by understanding the rate of change over time.

Price Data Components
Series array that contains open time of each bar
9 Views
0 Downloads
0 Favorites
ObjectGetValuue_ByCurrent_
//+------------------------------------------------------------------+
//|  Íàáîð ôóíêöèé è òåñòèðóþùèé ñêðèïò                              |
//|                                      ObjectGetValueByCurrent.mq4 |
//|                                          Aleksandr Pak, Alma-Ata |
//|                                                   ekr-ap@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Aleksandr Pak, Alma-Ata"
#property link      "ekr-ap@mail.ru"

//+------------------------------------------------------------------+
//| ÈÑÏÐÀÂËÅÍÎ îò 19 àïðåëÿ 2008ã.                                 |
//+------------------------------------------------------------------+
/*
Êîñâåííî äåìîíñòðèðóåò ïðîöåññ ôîðìèðîâàíèÿ áàðîâ ïî ïðèõîäó òèêà
*/

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( "Âðåìÿ[0]=",iTime(Symbol(),0,0), 
      " ëèíèÿ[0]=", ObjectGetValueByShift (d,0),
      " òåêóùåå çíà÷åíèå âíóòðè 0 áàðà=",DoubleToStr(ObjectGetValue_ByCurrent (d,0),Digits+2),
      " ëèíèÿ (- 1)=",DoubleToStr(rb,Digits+2),
      " delta íà (1) áàð=",DoubleToStr(ObjectGetDelta_PerBar(d),Digits+2),
      " delta íà (2) áàðà=",DoubleToStr(ObjectGetDelta_ByTimeShift(d,2*60*Period()),Digits+2));
     
      }
   }  
   Print("Êîíåö äåìîíñòðàöèè");
   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);
/*Äëÿ äåìîíñòðàöèè*/      Print("              Ïðîöåíò âðåìåíè Áàðà=",DoubleToStr(100*t/tf,0),"%", 
/*Äëÿ äåìîíñòðàöèè*/      "                                 ïîïðàâêà öåíû ëèíèè=",DoubleToStr(r,Digits+2));

 return(r);
 
}
//****************************************************************************
double ObjectGetDelta_ByTimeShift(string c, double t) //t=TimeShift â ñåêóíäàõ
{ 
      double tf=60*Period();
      double delta=ObjectGetDelta_PerBar(c);
      double r=delta*(t/tf); 
 return(r);
 
}






Comments