Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

returning a value to market analyzer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    returning a value to market analyzer

    hello,

    I want to return a 1 for an uptrend and -1 for a downtrend to the market analyzer.
    Please see code below and let me know how i can do this.


    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class Trend : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "Trend";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    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;
    AddPlot(new Stroke(Brushes.Transparent), PlotStyle.Line, "Plot1");
    }
    else if (State == State.Configure)
    {
    AddPlot(new Stroke(Brushes.Transparent), PlotStyle.Line, "Plot1");
    }
    }



    protected override void OnBarUpdate()


    {

    if (CurrentBars[0] < 95 )
    return;



    int FirstUpswingHighh = ZigZag(DeviationType.Points, .0000001, true).HighBar(0,1,100);
    int FirstDnswingLowl = ZigZag(DeviationType.Points,.0000001 , true).LowBar(0,1,100);

    int FirstUpswingLow = ZigZag(DeviationType.Points, .0000001, false).LowBar(0,1,100);
    int FirstUpswingLowl = ZigZag(DeviationType.Points, .0000001, true).LowBar(0,1,100);

    double trend=0;

    if (
    EMA(18)[FirstUpswingHighh]> EMA(40)[FirstUpswingHighh]
    && EMA(40)[FirstUpswingHighh]> EMA(90)[FirstUpswingHighh]


    && (Slope(EMA(40), 10, 0) >0 || Slope(EMA(20), 10, 0) >0 )
    && (Slope(EMA(40), 10, 0) >0 || Slope(EMA(90), 10, 0) >0 )
    )
    {
    trend =1;
    }

    else if ( EMA(18)[FirstDnswingLowl] < EMA(40)[FirstDnswingLowl]
    && EMA(40)[FirstDnswingLowl] < EMA(90)[FirstDnswingLowl]

    && (Slope(EMA(40), 10, 0) <0 ||Slope(EMA(20), 10, 0) <0 )
    && (Slope(EMA(40), 10, 0) <0 ||Slope(EMA(90), 10, 0) <0 )
    )
    {
    trend=-1;

    }
    else
    {

    trend =0;
    }

    Values[0][0]=trend;



    }
    }
    }

    #region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private Trend[] cacheTrend;
    public Trend Trend()
    {
    return Trend(Input);
    }

    public Trend Trend(ISeries<double> input)
    {
    if (cacheTrend != null)
    for (int idx = 0; idx < cacheTrend.Length; idx++)
    if (cacheTrend[idx] != null && cacheTrend[idx].EqualsInput(input))
    return cacheTrend[idx];
    return CacheIndicator<Trend>(new Trend(), input, ref cacheTrend);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.Trend Trend()
    {
    return indicator.Trend(Input);
    }

    public Indicators.Trend Trend(ISeries<double> input )
    {
    return indicator.Trend(input);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.Trend Trend()
    {
    return indicator.Trend(Input);
    }

    public Indicators.Trend Trend(ISeries<double> input )
    {
    return indicator.Trend(input);
    }
    }
    }

    #endregion

    #2
    Hello russ123,

    Thank you for your note.

    Have you opened a market analyzer, added a column and tried adding the indicator you created?

    The following section of our helpguide covers adding a column that is an indicator.


    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by xiinteractive, 04-09-2024, 08:08 AM
    3 responses
    11 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by Johnny Santiago, 10-11-2019, 09:21 AM
    95 responses
    6,193 views
    0 likes
    Last Post xiinteractive  
    Started by Irukandji, Today, 09:34 AM
    1 response
    3 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by RubenCazorla, Today, 09:07 AM
    1 response
    5 views
    0 likes
    Last Post RubenCazorla  
    Started by TraderBCL, Today, 04:38 AM
    3 responses
    25 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X