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

I messed up my first indicator...helllpp!!!

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

    I messed up my first indicator...helllpp!!!

    hey guys,

    Im trying to code my first indicator, but since im a noob at this im having some trouble..

    THE IDEA:

    It should be a simple indicator to build: i just want to have some text plotted in the chart, as well as some sound alerts, if some conditions are met.
    • im using a zero lag MACD and ECO2.
    • Id like it to plot "possible short signal" when the MACD gets bellow the zero line AND ECO2's falling (ie, bellow signal line).
    • The oposite for long signals...


    I'd like it to plot that text at the bar in which these conditions are met...


    Im having a lot of errors... and i cant get anywhere.. can anybody help me?

    Heres what i did so far:
    Attached Files

    #2
    Hello,

    We don't get into debugging peoples scripts for them, but we can assist with specific issues you are having. Here are some suggestions:


    Also:
    -Actually paste in your actual code, or sections of code, so we can cut and paste it in our scripts to test it quicker.
    -Ask specific questions on a specific issue. To assist with this, comment out most of the code and try to get small parts of the code to work/compile. If you can't figure it out, post that small section of code. To comment parts of the code out type "//" (without the quotes) on the left side of the line of code.
    - Use brackets, (these --> { }) like do here:
    if(...some condition here...)
    { //<--bracket
    //some code here
    } //<--end bracket

    Hope that helps.
    DenNinjaTrader Customer Service

    Comment


      #3
      here it is copy + paste:

      #region Using declarations
      using System;
      using System.ComponentModel;
      using System.Diagnostics;
      using System.Drawing;
      using System.Drawing.Drawing2D;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Data;
      using NinjaTrader.Gui.Chart;
      #endregion

      // This namespace holds all indicators and is required. Do not change it.
      namespace NinjaTrader.Indicator
      {
      /// <summary>
      /// Enter the description of your new custom indicator here
      /// </summary>
      [Description("Enter the description of your new custom indicator here")]
      public class MyCustomIndicator : Indicator
      {
      #region Variables
      // Wizard generated variables
      private int myInput0 = 1; // Default setting for MyInput0
      // User defined variables (add any user defined variables below)
      #endregion

      /// <summary>
      /// This method is used to configure the indicator and is called once before any bar data is loaded.
      /// </summary>
      protected override void Initialize()
      {
      Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
      CalculateOnBarClose = true;
      Overlay = false;
      PriceTypeSupported = false;
      }

      /// <summary>
      /// </summary>
      protected override void OnBarUpdate()
      {
      if ((ToTime(Time[0]) <=110000 || ToTime(Time[0]) >=230000)) return;

      // manage and clean
      if (direction == "long")
      if (Close [0] < DoubleMA(12, NinjaTrader.Indicator.MAV.MAType.EMA, 18, NinjaTrader.Indicator.MAV.MAType.EMA).RisingPlot[0])
      direction = null;

      if (direction == "short")
      if (Close [0] > DoubleMA(12, NinjaTrader.Indicator.MAV.MAType.EMA, 18, NinjaTrader.Indicator.MAV.MAType.EMA).RisingPlot[0])
      direction = null;

      if (direction == "long")
      if (TSSuperTrend(Close[0], 3, SMA, 2.618, 12, ATR).Signal[0] == -1)
      direction = null;

      if (direction == "short")
      if (TSSuperTrend(3, 12).Signal[0] == 1)
      direction = null;
      // longs
      if (MACD(Close, 12, 26, 9).Macd[0] > 0 || ECO2New2(20, 14, 15).Main[0] < 0 )
      if (Rising(MACD(Close, 1, 12, 26, 9, 0).Macd))
      if (ECO2New2(20, 14, 15).Main[0] > ECO2New2(20, 14, 15).Signal[0])
      if (Rising(ECO2New2(20, 14, 15).Main))
      if (TSSuperTrend(3, 12).Signal[0] == 1)
      if (Close[0] >DoubleMA(DoubleMA(12, NinjaTrader.Indicator.MAV.MAType.EMA, 18, NinjaTrader.Indicator.MAV.MAType.EMA).RisingPlot[0]
      || Close[0] >DoubleMA(DoubleMA(12, NinjaTrader.Indicator.MAV.MAType.EMA, 18, NinjaTrader.Indicator.MAV.MAType.EMA).FallingPlot[0])))

      if (direction !="long")
      {
      Direction.Set(1);
      direction = "long";
      entryprice = Close[0];
      DrawArrowUp("Up" + CurrentBar, true, 0, Low[0] - (4 * TickSize), Color.Lime);
      DrawText("Up info" + CurrentBar, Close[0].ToString("0.00"), 0, Low[0] - (10 * TickSize), Color.Lime);
      targethit = false;

      }
      }

      #region Properties
      [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
      [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
      public DataSeries Plot0
      {
      get { return Values[0]; }
      }

      [Description("")]
      [Category("Parameters")]
      public int MyInput0
      {
      get { return myInput0; }
      set { myInput0 = Math.Max(1, value); }
      }
      #endregion
      }
      }

      Comment


        #4
        You need to declare your variables before you can use them. You can't just start going direction == ____ without first creating the direction variable.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by funk10101, Today, 09:43 PM
        0 responses
        3 views
        0 likes
        Last Post funk10101  
        Started by pkefal, 04-11-2024, 07:39 AM
        11 responses
        36 views
        0 likes
        Last Post jeronymite  
        Started by bill2023, Yesterday, 08:51 AM
        8 responses
        44 views
        0 likes
        Last Post bill2023  
        Started by yertle, Today, 08:38 AM
        6 responses
        26 views
        0 likes
        Last Post ryjoga
        by ryjoga
         
        Started by algospoke, Yesterday, 06:40 PM
        2 responses
        24 views
        0 likes
        Last Post algospoke  
        Working...
        X