• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Printing a ticker

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

    Printing a ticker

    Hi,
    Is there any way to display a security ticker in the print for debugging purposes? My strategy works OK when tested on a single instrument, but when I test it against the whole list of instruments (NASDAQ for instance) I got an error message in the middle of the run. So I know it actually does something wrong when processing one of the instrument. But I can't find out which one, and I do not want to go one by one :-(. Printing the ticker when entering the market would help me quickly locate the instrument with a problem.

    Thank you

    Petr

    #2
    Hello Domek_69,
    Thanks for your post.

    What error are you getting?

    Please see the following link for more information on debugging your NinjaScript with Print() statements

    https://ninjatrader.com/support/help...script_cod.htm
    JoshNinjaTrader Customer Service

    Comment


      #3
      HIJosh,
      I am getting an error: "Error on calling 'OnStateChange' method: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."

      As I said it seems to be ok when I test on 1 instrument, but I got 1 message when I run the strategy for the whole list. The run finishes OK, but there must clearly something wrong for on instrument.

      I think I know how to use print command, but It just does not help unless I find the one instrumenting giving me the error message.

      Comment


        #4
        I think the error will be simpler to find than that. Can you post your OnStateChange method here?
        JoshNinjaTrader Customer Service

        Comment


          #5
          sorry, still new to C# and this forum - do you mean copy part of the code here?

          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = @"Long trades with Highest Highentry and Lowest High exit + % SL + Volume";
          Name = "HHATRSLUnlocked";
          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 = 55;
          // Disable this property for performance gains in Strategy Analyzer optimizations
          // See the Help Guide for additional information
          IsInstantiatedOnEachOptimizationIteration = true;
          Highest = 55;
          Lowest = 21;
          V = 150000;
          MALong = 254;
          ATR_multiple = 3.4;
          PerLimit = 7;

          StopLoss = 0;
          Percentage1 = 0;
          ATRticks = 0;
          SLline = 0;

          }
          else if (State == State.Configure)
          {
          }
          else if (State == State.DataLoaded)
          {
          DonchianChannel1 = DonchianChannel(Close, Convert.ToInt32(Highest));
          VOL1 = VOL(Close);
          SMA1 = SMA(Close, 100);
          SMA2 = SMA(Close, Convert.ToInt32(100));
          SMA3 = SMA(Close, 100);
          SMA4 = SMA(Close, Convert.ToInt32(100));
          SMA5 = SMA(Close, 50);
          SMA6 = SMA(Close, Convert.ToInt32(MALong));
          ATR1 = ATR(Close, 10);

          //it must be here because this influence the setTrailStop - therefore ATR is take for all trades of one stock taken from first measure bar ?!
          ATRticks = (ATR1[0] * ATR_multiple * 100) ;
          StopLoss = ATRticks;
          Percentage1 = Math.Round((ATR1[0] * ATR_multiple * 100)/ (Close[0] ),1 );

          DonchianChannel2 = DonchianChannel(Close, Convert.ToInt32(Lowest));
          DonchianChannel1.Plots[0].Brush = Brushes.Transparent;
          DonchianChannel1.Plots[1].Brush = Brushes.DodgerBlue;
          DonchianChannel1.Plots[2].Brush = Brushes.Transparent;
          SMA2.Plots[0].Brush = Brushes.Blue;
          SMA5.Plots[0].Brush = Brushes.Green;
          SMA6.Plots[0].Brush = Brushes.Firebrick;
          DonchianChannel2.Plots[0].Brush = Brushes.Transparent;
          DonchianChannel2.Plots[1].Brush = Brushes.Transparent;
          DonchianChannel2.Plots[2].Brush = Brushes.Red;
          AddChartIndicator(DonchianChannel1);
          AddChartIndicator(SMA2);
          AddChartIndicator(SMA5);
          AddChartIndicator(SMA6);
          AddChartIndicator(DonchianChannel2);
          SetTrailStop("", CalculationMode.Ticks, StopLoss, false);
          }
          }

          Comment


            #6
            Do you still get the error when you comment out this part? You are not going to be able to access index values like that from OnStateChange()

            Code:
            ATRticks = (ATR1[0] * ATR_multiple * 100) ;
            StopLoss = ATRticks;
            Percentage1 = Math.Round((ATR1[0] * ATR_multiple * 100)/ (Close[0] ),1 );
            JoshNinjaTrader Customer Service

            Comment


              #7
              By coincidence, I had changed the code here, deleting something and moving the rest to OnBarUpdate (). And I don't get the error.

              But I still don't understand why it worked for most of the instruments and had a problem with only one. Mind you when I run it for a single instrument I did not get any message. And in both the single or the list - the code finished and gave me some results

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Birdseye, Today, 04:52 AM
              0 responses
              3 views
              0 likes
              Last Post Birdseye  
              Started by U0000999, Today, 03:43 AM
              0 responses
              4 views
              0 likes
              Last Post U0000999  
              Started by NinjaCustomer, Today, 03:22 AM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Marco  
              Started by MarianApalaghiei, Today, 01:26 AM
              0 responses
              9 views
              0 likes
              Last Post MarianApalaghiei  
              Started by seagraph, Yesterday, 03:27 PM
              0 responses
              14 views
              0 likes
              Last Post seagraph  
              Working...
              X