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

Strategy won't compile this Indicator

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

    Strategy won't compile this Indicator

    HI everybody, I have an indicator which I can include in my charts, but unfortunately I can't use it in a Strategy since NT won't compile it.
    I think there might be something wrong on the script or in the desgin of the Indicator.
    Could someone give me a hand with it?
    I have attached the zip file of the indicator called "QLD"
    Thank you very much,
    Andrés
    Attached Files

    #2
    Hi plenamar27, thanks for posting. The indicator is accessing EMA(Close,Period)[-1] which is not a valid index. This index starts at 0 and counts up for every bar on the chart. When I run this indicator I am getting a bar indexing error in the Log tab of the Control Center.

    Best regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris, thanks for your answer!

      Unfortunately I'm not familiar with NT; I had this indicator in Thinkorswim and it has been translated to NT script by a third person.
      What I have in Thinkorswim is as follows:

      input period = 6;

      def openMA;
      def closeMA;

      openMA = ExpAverage(open, period);
      closeMA = ExpAverage(close, period);

      plot neutro = 1;
      plot trigger = closeMA[-1]/ openMA;

      The idea of the indicator is to show the relationship between the Exponential Average of Close and Open with 1 bar of lag.
      In Thinkorswim I have been able to graph it and to use it on Conditional Orders.

      How could I fix it on NT 8?

      Thanks,

      Andrés

      Comment


        #4
        Hi plenamar27, thanks for your reply.

        ThinkScript will let you write negative indexes to anticipate the price of the next slot, so we would need to do the opposite and reference the previous bar of the Open EMA. Im not completely sure if this is the correct output, but it does produce plot values:

        Code:
        protected override void OnBarUpdate()
        {
            //Add your custom indicator logic here.
            if(CurrentBar<1) return;
            Trigger1[0]=EMA(Close,Period)[0]/EMA(Open,Period)[1];
        }
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Chris, I'm sorry, but it can't compile either with this modification.
          It can graph it on the chart, but cannot compile a simple Strategy: Buy when QLD crosses above 1; Sell when QLD crosses below 1.
          What could be going on?
          Thanks!
          Andrés

          Comment


            #6
            Hi plenamar27,

            The indicator is compiling on my machine. If the strategy is not compiling can you post the code from the strategy? You can access the plot its generating like this: var x = QLD(14)[0]; //x will hold the latest plot value.

            Best regards,
            -ChrisL
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Yes sure, this is the Code:

              #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.Indicators;
              using NinjaTrader.NinjaScript.DrawingTools;
              #endregion

              //This namespace holds Strategies in this folder and is required. Do not change it.
              namespace NinjaTrader.NinjaScript.Strategies
              {
              public class Scalping : Strategy
              {
              private QLD QLD1;

              protected override void OnStateChange()
              {
              if (State == State.SetDefaults)
              {
              Description = @"Enter the description for your new custom Strategy here.";
              Name = "Scalping";
              Calculate = Calculate.OnBarClose;
              EntriesPerDirection = 1;
              EntryHandling = EntryHandling.AllEntries;
              IsExitOnSessionCloseStrategy = true;
              ExitOnSessionCloseSeconds = 30;
              IsFillLimitOnTouch = false;
              MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
              OrderFillResolution = OrderFillResolution.Standard;
              Slippage = 0;
              StartBehavior = StartBehavior.WaitUntilFlat;
              TimeInForce = TimeInForce.Gtc;
              TraceOrders = false;
              RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
              StopTargetHandling = StopTargetHandling.PerEntryExecution;
              BarsRequiredToTrade = 20;
              // Disable this property for performance gains in Strategy Analyzer optimizations
              // See the Help Guide for additional information
              IsInstantiatedOnEachOptimizationIteration = true;
              }
              else if (State == State.Configure)
              {
              }
              else if (State == State.DataLoaded)
              {
              QLD1 = QLD(Close, 6);
              }
              }

              protected override void OnBarUpdate()
              {
              if (BarsInProgress != 0)
              return;

              if (CurrentBars[0] < 1)
              return;

              // Set 1
              if (CrossAbove(QLD1, 1, 1))
              {
              }

              // Set 2
              if (CrossBelow(QLD1, 1, 1))
              {
              }

              }
              }
              }

              Comment


                #8
                Hi, thanks for posting that.

                I don't see anything wrong with this, it compiles for me. When you compile in the platform it compiles every script, so please look at the compile error message and make sure you are viewing the correct script.

                Best regards,
                -ChrisL
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Hes saying to look in the Ninja Script Editor, it should show there

                  Comment


                    #10
                    Hi Chris and Ezrollin, I have been able to compile the strategy with the indicator!
                    Couldn't get to notice what was wrong, but now it's ok.
                    Thank's for your time!!
                    Andrés

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by seq2seq, 05-07-2023, 07:26 PM
                    6 responses
                    563 views
                    0 likes
                    Last Post duniya_trader  
                    Started by i2ogu3, Yesterday, 11:31 PM
                    4 responses
                    22 views
                    0 likes
                    Last Post i2ogu3
                    by i2ogu3
                     
                    Started by reynoldsn, Yesterday, 07:11 PM
                    3 responses
                    16 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by manueldecastro, Today, 10:26 AM
                    2 responses
                    12 views
                    0 likes
                    Last Post manueldecastro  
                    Started by cmtjoancolmenero, 04-29-2024, 03:40 PM
                    23 responses
                    71 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Working...
                    X