I simply trying to calculate if the slope of the channel is either up or down.
In the screenshot, even though the slope is up, but the code below is producing a negative value of -0.08384 which is indicating the slope is negative/down:
double mySlope = ( Slope(RegressionChannel(128,2.5), 127, 0) );
Also, the following code should be grabbing the value of the regression channel middle line @ 127 bars ago:
RegressionChannel(128,2.5).Middle[127];
I visualized the "slope" by drawing as a magenta colored line. Instead of duplicating the middle orange line, it draws a completely different line with a contradictory slope.
What am I doing wrong? How can I get the value for the middle line @ 127 bars ago?
//Add your custom strategy logic here. if (CurrentBars[0] < 128) return; // -------------------------------------------------- // Draw Regression Channel on Chart // -------------------------------------------------- // https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?regressionchannel.htm // https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?draw_regressionchannel.htm NinjaTrader.NinjaScript.DrawingTools.RegressionChannel myRegChan = Draw.RegressionChannel(this, "myOuterChannel", false ,127, 0 // startBarsAgo = 127 (this matches 128), endBarsAgo = 0 ,Brushes.Orange, DashStyleHelper.Solid , 1 ,Brushes.Orange, DashStyleHelper.Solid , 1 ,Brushes.Orange, DashStyleHelper.Solid , 1 ); // Define Channel Width myRegChan.StandardDeviationUpperDistance = 2.5; myRegChan.StandardDeviationLowerDistance = 2.5; // -------------------------------------------------- // Regression Channels // -------------------------------------------------- double PriceUpper = RegressionChannel(128,2.5).Upper[0]; double PriceMiddle = RegressionChannel(128,2.5).Middle[0]; double PriceBottom = RegressionChannel(128,2.5).Lower[0]; // -------------------------------------------------- // Determine Slope // -------------------------------------------------- // https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?slope.htm // The "startBarsAgo" parameter MUST be greater than the "endBarsAgo" parameter double mySlope = ( Slope(RegressionChannel(128,2.5), 127, 0) ); // -------------------------------------------------- // Drawing the "Slope" // -------------------------------------------------- // grabbing the value of Middle line @ 127 bars ago: double PriceMiddleRear = RegressionChannel(128,2.5).Middle[127]; // drawing the slope as magenta colored line Draw.Line( this, "tag2", false, 127, PriceMiddleRear, 0, PriceMiddle, Brushes.Magenta, DashStyleHelper.Solid, 1); // -------------------------------------------------- // Displaying Variables on Chart // -------------------------------------------------- Draw.TextFixed(this, "myText" ,"\nPriceUpper: " + PriceUpper + "\nPriceBottom: " + PriceBottom + "\n\nPriceMiddle: " + PriceMiddle + "\nPriceMiddleRear: " + PriceMiddleRear + "\n\nmySlope: " + mySlope , TextPosition.TopRight );
Comment