Works miracles :-). If someone needs, here's the code, which calculates vertical difference between main and auxiliary lines of the OBJ_CHANNEL:
string BorderChannel = "MyChannel";
datetime T1 = ObjectGet(BorderChannel, OBJPROP_TIME1);
datetime T2 = ObjectGet(BorderChannel, OBJPROP_TIME2);
datetime T3 = ObjectGet(BorderChannel, OBJPROP_TIME3);
double P1 = ObjectGet(BorderChannel, OBJPROP_PRICE1);
double P2 = ObjectGet(BorderChannel, OBJPROP_PRICE2);
double P3 = ObjectGet(BorderChannel, OBJPROP_PRICE3);
double Diff = 0;
// Simple cases
if (T3 == T1) // Auxiliary point with the same time as the first point of the main line
Diff = P1 - P3;
else if (T3 == T2) // Auxiliary point with the same time as the second point of the main line
Diff = P2 - P3;
// Difficult case
// Use linear function to calculate auxiliary price at T1
// Find bar numbers of T1 and T2
// double because will be used in division
double B1 = ObjectGetShiftByValue(BorderChannel, P1);
double B2 = ObjectGetShiftByValue(BorderChannel, P2);
// Normalize T3 by removing excess time values. For example, hours and minutes on D1 timeframe.
T3 = T3 - T3 % (Period() * 60);
if (T3 > Time) // If T3 is placed in the future, need to calculate its negative shift
double B3 = (Time - T3) / (Period() * 60);
else // Otherwise shift can be found by scrolling through bars
for (int i = 0; i < Bars; i++)
if (Time[i] == T3)
B3 = i;
double k = (P2 - P1) / (B2 - B1);
// Y-intercept is calculated for auxiliary line (it has the same Slope)
double b = P3 - k * B3;
// Find auxiliary line's price at point T1
double AuxP = k * B1 + b;
Diff = P1 - AuxP;
Nicely done - a calculation I had on my to-do list!
Thanks for sharing the code!
Helped me a lot!
You're broked your neck with this code. Just use the "ObjectGetValueByTime" command.
//For the first line
//For the second line
I guess this function had not yet been added to MetaTrader 4 when I was creating this workaround.