NexusFi: Find Your Edge


Home Menu

 





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


Discussion in NinjaTrader

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




 
Search this Thread

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

  #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?
Better Renko Gaps
The Elite Circle
What broker to use for trading palladium futures
Commodities
About a successful futures trader who didnt know anythin …
Psychology and Money Management
Quantum physics & Trading dynamics
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
  #3 (permalink)
 
DavidHP's Avatar
 DavidHP 
Isla Mujeres, MX
Legendary Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Ninjatrader / Optimus Futures / AmpFutures
Trading: ES / 6E / 6B / CL
Frequency: Every few days
Duration: Minutes
Posts: 1,612 since Aug 2009
Thanks Given: 11,343
Thanks Received: 2,747


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 Twitter Reply With Quote




Last Updated on October 30, 2018


© 2024 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 - Privacy Policy - Downloads - Top
no new posts