I am new to c# and NinjaScript and furiously trying to learn it... I will eventually but the learning curve is there.
I'm trying to convert my "stuff" from ToS to NT8 and I'm getting close but one thing I cannot sort out is what I talk about below.
The code below (below the NinjaScript) simply plots the slope of the EMA of the prices and also plots an AVG of the slope itself. It's in ThinkScript. It works, have used it for years.
I tried converting the code below (below the NinjaScript snippet, which I put in as a reference) with no luck.
I tried using slope() and slope() must be outputting something different than what I need as it looks nothing like what I have on my ThinkOrSwim charts with the code below.
I got the slope() code from a NT8 staffer... and like I said, it works in that it shows something but not what I was expecting so it must be outputting the slope differently... because even when the EMA is sloping up... sometimes the code I was given is below 0... and the spikes it has don't coincide with the charts.
This is the NinjaScript I was given:
protected override void OnStateChange(){
if (State == State.SetDefaults){
AddPlot(Brushes.Goldenrod, "MyPlot");
}
}
protected override void OnBarUpdate()
{ double m = Slope(EMA(14), 10, 0);
Values[0][0] = m;
}
Anyways, can anyone convert the ThinkScript code below to NinjaScript. It's not that long... and I would think an expert in NinjaScript could do it quickly... and the ThinkScript is pretty straight forward and would be easy to understand for a coder, even if you don't know thinkscript... hopefully one day I can get that good in NS as well.
THE THINKSCRIPT TO CONVERT TO NINJASCRIPT:
input slopelength = 7;
input slopeprice = OHLC4;
input slopeaverageType = AverageType.WEIGHTED;
def slopeavg = MovingAverage(slopeaverageType, slopeprice, slopelength);
def height = slopeavg - slopeavg[1];
input slopeEMAlength = 21;
input slopeEMAprice = OHLC4;
input slopeEMAaverageType = AverageType.WEIGHTED;
plot slope = Atan(height/slopelength) * 180 / Double.Pi;
plot slopeEMAavg = MovingAverage(slopeEMAaverageType, slope, slopeEMAlength);
Basically, the end result that I'm looking for is where it plots the slope of the EMA and the AVG of the Slope... and if the Price EMA is heading up, the plot will be above 0 for the slope... now the slope may head up or down, depending on how strong the EMA is going up or down but as long as the EMA is heading higher... even if kind of flat, it will be higher than 0... and I paint the slope line green on my charts.
And if the EMA is heading down - ie. the slope of the EMA is going down (because prices are going down)... the slope plot will be below 0 and I paint it red on my charts (I left out the thinkscript coloring of the lines).
I also have an average of the actual slope itself and I plot it in the same panel as the slope.
Thanks in advance if someone can help me out.
I looked around on NT support and just found old scripts that didn't work in NT8... or didn't produce the desired result.
Based on my initial research, I don't think slope() is the right thing to use, I think a custom indicator has to be made... as slope() outputs the slope in a different format (for lack of a better term) than what I'm looking for.
Comment