NexusFi: Find Your Edge


Home Menu

 





Need help writing/adding Slope() code to existing indicator.


Discussion in NinjaTrader

Updated
    1. trending_up 2,260 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
enterjcs
Clemson sc/USA
 
Posts: 1 since Oct 2018
Thanks Given: 0
Thanks Received: 0

I'm new to coding and want to learn enough C# to create or modify the indicators that I use. I have an ema slope indicator that i want to add specific parameters to but don't know how to go about writing the code. For example, If parameter setting 10 is met then I want the ema to plot green and stay green. if -10, then plot red. If in between 10 and -10 plot blue. Here is a copy of the existing code.

//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class EMASlopeColor : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Exponential Moving Average. The Exponential Moving Average is an indicator that shows the average value of a security's price over a period of time. When calculating a moving average. The EMA_Slope_Color applies more weight to recent prices than the SMA. Colors based on IsRising or IsFalling";
Name = "EMASlopeColor";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
Period = 14;
UpColor = Brushes.LimeGreen;
DnColor = Brushes.Red;
ColorSlope = true;
AddPlot(Brushes.Orange, "EMA_Slope_Color");
}

}

protected override void OnBarUpdate()
{
Value[0] = (CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1]);


if(IsRising(Value))
{
if(ColorSlope)
PlotBrushes[0][0] = UpColor;
}
if(IsFalling(Value))
{
if(ColorSlope)
PlotBrushes[0][0] = DnColor;
}
}


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
requesting .nrd replay files from 2026 spy and qqq
The Elite Circle
What we know about Binances $6.3bn hack - BBC News
Cryptocurrency
Bitcoin’s 2022 low, 2025 high and 2026 low so far arou …
Cryptocurrency
[WTS] ATAS Lifetime ULTRA license – EU buyers only – …
Platforms and Indicators
Building a free browser DOM/SMC simulator - need some ad …
Platforms and Indicators
 
  #3 (permalink)
 
DavidHP's Avatar
 DavidHP 
Isla Mujeres, MX
Legendary Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Ninjatrader / Optimus Futures / AmpFutures
Trading: NQ / ES / 6E / 6B / CL
Frequency: Every few days
Duration: Minutes
Posts: 1,830 since Aug 2009
Thanks Given: 11,805
Thanks Received: 3,057


Because the charts are dynamic, slopes are relative to the chart and are not static as in real life.

There are many threads about this on Futures.io I suggest you search for them in the search box to the upper right of the screen.

Here is one to get you started but I think you will find slope is not very valuable in the long run.


Rejoice in the Thunderstorms of Life . . .
Knowing it's not about Clouds or Wind. . .
But Learning to Dance in the Rain ! ! !
Follow me on X Reply With Quote




Last Updated on October 30, 2018


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts