Support Board
Date/Time: Wed, 15 Jan 2025 16:16:31 +0000
Post From: Subgraph display bug?
[2017-07-28 14:41:57] |
User540518 - Posts: 6 |
Thanks for pointing this code out, its a bit too convoluted. I ended up using my own slope function. Hopefully this helps out someone else. //Solves for y in the equation y = mx + b, we look for Y on based on the X value of the line (MidpointX) passed to us. double CalculateY(int X1, double Y1, int X2, double Y2, double MidpointX) { double Y = 0, //used to solve for equation of our line X = 0, //current bar index we are searching for M = 0, //slope of the line B = 0; //y intercept //We are always in Quadrant II in terms of Cartesian coordinates //we have to accomodate this by making our X1 and X2 values negative, now we are in Quadrant I X1 = -1 * X1; X2 = -1 * X2; //Calculate our slope //there is a possible divide by zero error here if we get to the latest bar (ArrazySize) and dont check for that condition if ((X2 - X1) != 0) { M = (Y2 - Y1) / (X2 - X1); } else { M = 1; } //must solve for b to get y intercept, equation then becomes b = Y1 - M*X1 B = Y1 - (M*X1); //Print("B1 is: " + B); //B = Y2 - (M*X2); //double check our y intercept, B1 and B2 should be the same //Print("B2 is: " + B); //find the Y that resides on our line for the previous bar. y = mx + b X = -1 * MidpointX; //adjusts for Quandrant II by multiplying (-1) to MidpointX Y = M*X + B; //Print("MidpointX: " + X + " MidpointY is: " + NormalizeDouble(Y,5)); return(Y); }//end of CalculateY Thanks for the tips. Mike Date Time Of Last Edit: 2017-07-28 14:42:16
|