LONNV #: this is because object trendline value take from barshift 0, but in formula value , index value take from 2nd coordinate point. if index value in formula value zero, they will be nearly same.
No! Do you even understand what the ObjectGetValueByShif() does?
The function, does exactly the same thing as the "y=mx+c" equation. It calculates the price for the bars either inside or outside of the two connecting points of the trend-line.
Here is an example code of a Script, to demonstrate the two methods, that has been fully tested with log results:
#property strict#property script_show_inputs// Script input parametersinputuint
nStartPointBarShift = 5, // Bar shift of starting point of trend-line
nEndPointBarShift = 15, // Bar shift of ending point of trend-line
nQueryPointBarShift = 10; // Bar shift of query point of trend-line// Script start event handlervoidOnStart()
{
// Check if parameters are acceptableif( nStartPointBarShift == nEndPointBarShift )
{
Print( "Invalid Parameters!" );
return;
};
// Calculate valuesint
nDeltaBarShift = (int) nEndPointBarShift - (int) nStartPointBarShift; // Change in bar shiftdatetime
dtStartPointTime = iTime( _Symbol, _Period, nStartPointBarShift ), // Time at starting point
dtEndPointTime = iTime( _Symbol, _Period, nEndPointBarShift ); // Time at ending pointdouble
dbStartPointPrice = iClose( _Symbol, _Period, nStartPointBarShift ), // Price at starting point
dbEndPointPrice = iClose( _Symbol, _Period, nEndPointBarShift ), // Price at ending point
dbDeltaPrice = dbEndPointPrice - dbStartPointPrice, // Change in price
dbLineSlope = dbDeltaPrice / nDeltaBarShift, // Slope is the value of "m"
dbOffset = dbEndPointPrice - dbLineSlope * nEndPointBarShift; // Offset is the value of "c"// Draw trend-line objectstring sObjectName = "Test-Trendline";
if( ObjectCreate( sObjectName, OBJ_TREND, 0, // Create trend-line object
dtStartPointTime, dbStartPointPrice, // Starting point of trend-line
dtEndPointTime, dbEndPointPrice ) ) // Ending point of trend-line
{
// Get price by both methodsdouble
dbValueByShift = ObjectGetValueByShift( sObjectName, nQueryPointBarShift ),
dbPriceByShift = dbLineSlope * nQueryPointBarShift + dbOffset;
// Print out the values to the logPrintFormat( "Starting Point: %s @ %d", DoubleToString( dbStartPointPrice, _Digits ), nStartPointBarShift );
PrintFormat( "Ending Point: %s @ %d", DoubleToString( dbEndPointPrice, _Digits ), nEndPointBarShift );
PrintFormat( "Query Point: %s @ %d (by ObjectGetValueByShift)", DoubleToString( dbValueByShift, _Digits ), nQueryPointBarShift );
PrintFormat( "Query Point: %s @ %d (by y=mx+c calculation)", DoubleToString( dbPriceByShift, _Digits ), nQueryPointBarShift );
// Delete ObjectObjectDelete( sObjectName ); // Delete trend-line object
};
};
No! Do you even understand what the ObjectGetValueByShif() does?
The function, does exactly the same thing as the "y=mx+c" equation. It calculates the price for the bars either inside or outside of the two connecting points of the trend-line.
Here is an example code of a Script, to demonstrate the two methods, that has been fully tested with log results: