Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CongestionBoxLite not displying on strategy

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

    CongestionBoxLite not displying on strategy

    Hello, I cannot display the CongestionBoxLite indictor, nor have access to the upperboundaryseries and lowerboundaryseries from my strategy. Here is a simplified code example that replicates the the issue.

    May I ask for your wisdom on this matter?

    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 MyCustomStrategy3 : Strategy
    {
    public NinjaTrader.NinjaScript.Indicators.BobC.Congestion BoxLite CongestionBoxLite1;


    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "MyCustomStrategy3";
    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)
    {
    AddDataSeries("ES 12-22", Data.BarsPeriodType.Range, 12, Data.MarketDataType.Last);
    }
    else if (State == State.DataLoaded)
    {
    CongestionBoxLite1 = CongestionBoxLite(Closes[1], 70, 70, 70, 0);
    //CongestionBoxLite1.Plots[0].Brush = Brushes.Goldenrod;

    AddChartIndicator(CongestionBoxLite1);
    }
    }

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

    if (CurrentBars[0] < BarsRequiredToTrade
    || CurrentBars[1] < BarsRequiredToTrade)
    return;

    // Set 1

    double chopbox0 = CongestionBoxLite1.UpperBoundarySeries[0];
    double chopbox1 = CongestionBoxLite1.UpperBoundarySeries[1];

    if (Close[0] > chopbox0) //&& chopbox0 != chopbox1 )
    {
    BackBrush = Brushes.CornflowerBlue;
    Draw.Text(this, "BoxBar"+CurrentBar,CongestionBoxLite1.boxBarN umSe ries[0].ToString(),1, High[1]+2*TickSize);
    Draw.Text(this, "UBound"+CurrentBar,chopbox0.ToString(),1, High[1]+4*TickSize);

    }

    }
    }
    }

    Thanks, BobPerez

    #2
    Hello BobPerez,

    Thank you for your post.

    Is CongestionBoxLite an indicator that you developed or was it imported by a third party? Do you have access to the source code for the script or is it a protected add-on from a third party?

    I look forward to your reply.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply. Here is the indicator I downloaded from Ninjatrader resources.

      You may notice that if you don't add the secondary series, the indicator display ok in the chart.

      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 CongestionBox : Strategy
          {
              private NinjaTrader.NinjaScript.Indicators.BobC.CongestionBoxLite CongestionBoxLite1;
      
              protected override void OnStateChange()
              {
                  if (State == State.SetDefaults)
                  {
                      Description                                    = @"Enter the description for your new custom Strategy here.";
                      Name                                        = "CongestionBox";
                      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;
                      PT                    = 12;
                      SL                    = 18;
                  }
                  else if (State == State.Configure)
                  {
                          //AddDataSeries("ES 12-22", Data.BarsPeriodType.Range, 12, Data.MarketDataType.Last);
                  }
                  else if (State == State.DataLoaded)
                  {                
                      CongestionBoxLite1                = CongestionBoxLite(Closes[1], 70, 70, 70, 0);
                      CongestionBoxLite1.Plots[0].Brush = Brushes.Transparent;
                      AddChartIndicator(CongestionBoxLite1);
                      SetProfitTarget("", CalculationMode.Ticks, PT);
                      SetStopLoss("", CalculationMode.Ticks, SL, false);
                  }
              }
      
              protected override void OnBarUpdate()
              {
                  if (BarsInProgress != 0)
                      return;
      
                  if (CurrentBars[0] < 1)
                      return;
      
                   // Set 1
                  if (CrossAbove(Close, CongestionBoxLite1.UpperBoundarySeries, 1))
                  {
                      BackBrush = Brushes.CornflowerBlue;
                      Draw.ArrowUp(this, @"CongestionBox Arrow up_1 " + Convert.ToString(CurrentBars[0]), false, 0, (Low[0] - 2) , Brushes.White);
                      //EnterLong(Convert.ToInt32(DefaultQuantity), "");
                  }
      
                   // Set 2
                  if (CrossBelow(Close, CongestionBoxLite1.LowerBoundarySeries, 1))
                  {
                      BackBrush = Brushes.MistyRose;
                      Draw.ArrowDown(this, @"CongestionBox Arrow down_1 " + Convert.ToString(CurrentBars[0]), false, 0, (High[0] + 2) , Brushes.White);
                      //EnterShort(Convert.ToInt32(DefaultQuantity), "");
                  }
      
              }
      
              #region Properties
              [NinjaScriptProperty]
              [Range(1, int.MaxValue)]
              [Display(Name="PT", Order=1, GroupName="Parameters")]
              public int PT
              { get; set; }
      
              [NinjaScriptProperty]
              [Range(1, int.MaxValue)]
              [Display(Name="SL", Order=2, GroupName="Parameters")]
              public int SL
              { get; set; }
              #endregion
      
          }
      }
      ​
      Attached Files
      Last edited by bobperez; 11-22-2022, 01:49 PM.

      Comment


        #4
        Hello BobPerez,

        I appreciate your patience.

        I was able to successfully import the CongestionBoxLite indicator and display it on a chart on its own. I understand you are trying to access it inside of MyCustomStrategy3 and encountering issues. Do you receive errors on the screen or on the Log tab of the Control Center? If so, what do the errors report? I understand you have provided a sample to replicate; please export this script by going to Control Center > Tools > Export > NinjaScript Add-On. Attach the exported file to your answer so I may import into my platform and test if I experience the same results.

        I look forward to resolving this with you.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          Hi Emily, Thanks, I'll do that. Please be aware that the issue only appears when a secondary data series is used to display the Congestion indicator. If you run the strategy without a secondary data series it runs well.

          I added a switch in the Properties section to the MyCustomStrategy3 so you can include or not the secondary series.

          THank you for your support

          BobPerez

          Attached Files

          Comment


            #6
            Hello BobPerez,

            I appreciate your patience.

            When I download the zip from your post, it imports successfully but I am not seeing the indicator in my installation. When I open up the zip folder and look at the MyCustom3.cs file I am not seeing any indicator logic beyond the Using declarations and NinjaScript generated code sections. I suspect that the file did not export properly or the incorrect file was exported. Please try again so I may test on my end.

            Additionally, you did not answer my previous questions:
            Do you receive errors on the screen or on the Log tab of the Control Center? If so, what do the errors report?

            I am also curious, since the issue only appears when using a secondary data series, what are the steps you are taking to use a secondary series? You mentioned you added a switch; are there error messages depending on whether it is set to a single series or secondary series?

            I look forward to your reply.
            Emily C.NinjaTrader Customer Service

            Comment


              #7
              Hi Emily,

              Thanks again for your support.

              To answer your questions, there are no errors on the screen or on the Log tab.

              The zipped file contains a copy of the CongestionBoxLite.cs. You may need to rename your copy of that file before importing the zip I'm attaching.

              How strange that the MyCustomStrategy3.cs had no code. I exported it again from Ninja and the same issue appeared, so I added the file manually instead, into the zip file and it seemed to work. Hopefully, you receive it well.

              Regards,

              BobPerez
              Attached Files

              Comment


                #8
                Hello BobPerez,

                Thank you for your patience.

                I was able to import the strategy and enable it on a chart with and without the added data series. With the added data series, it won't display on a minute chart but I am able to see it if the chart Data Series is set to range:


                In the indicator summary for CongestionBoxLite, it notes "This indicator was designed for Range Bars but been used by minute bars by others." I suspect that this indicator might only work on range charts in this case, but you would need to reach out to the developer directly for additional information on how the indicator functions and what is expected vs. not expected.

                Please let us know if we may be of further assistance.
                Emily C.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Emily,

                  Thank you again. The reason for the developer to say it was designed for Range bars really has nothing to do with the fact that the indicator does not show if set to a secondary series. It has to do more with the logic behind the way Range bars behave compared to minute bars, for example.

                  Even if you set up a Range bar chart and try to turn on the secondary series on the strategy, it won´t show. Watch the video



                  I've been on the forum watching some related threads regarding secondary data series not showing on the charts. I even tried a solution provided by Ninjatrader_Kate.but it did not work for me.​

                  https://ninjatrader.com/support/foru...a-series-chart

                  Perhaps you can talk with her and see how to approach this issue.

                  Regards,

                  BobPerez
                  Last edited by bobperez; 11-23-2022, 04:06 PM.

                  Comment


                    #10
                    Emily,

                    My strategy needs to access variables from the CongestionBoxLite indicator to define entries based on such information. It is not enough to display the indicator by using two data series, as you show in your screencast, which would be Ok if I were to take manual trades. For automatic trades, the visual information provided by the indicator placed on the screen as you did, won´t work.

                    BobPerez

                    Comment


                      #11
                      Hello BobPerez,

                      Thank you for your patience.

                      What is the result of adding Print() statements to your script that try to access the CongestionBoxLite values bring calculated from an added data series as input to the indicator? I recommend adding prints to see if your script is able to read those values properly. You can also add prints to your script to see which conditions and actions are being met. For more information about using prints to debug your script:


                      You could try adding prints for the values of upperboundaryseries and lowerboundaryseries as well as assign those values to variables and try to print the variables to see if your script is assigning the values properly.

                      You mentioned in your original post that you were not able to display the indicator or access the upperboundaryseries and lowerboundaryseries from your script. I was simply addressing the issue of being able to display it or not and still trying to work toward a resolution. If you do not need the indicator to be displayed on your chart, you could remove the line with AddChartIndicator() which is a method used solely for displaying an indicator on a chart when a strategy is active.

                      Please let me know if I may be of further assistance.
                      Emily C.NinjaTrader Customer Service

                      Comment


                        #12
                        Thank you, Emily. I'll try that.

                        BobPerez

                        Comment


                          #13
                          Bob the original CongestionBoxLite did not have plots so it will not work for conditions in the Strategy Builder or any Strategy to my knowledge. Active Trader Setups had the code modified by their coders and removed the VPOC from Calculation as this was a big drag on the system, as well if you are plotting the drawing of the Boxes on several charts is a huge draw on memory.

                          They then left the original plots of the charts and added plots for the strategy builder use. It will work with secondary as well, I have on strategy with multiple uses

                          ATSConsolidationTrader1 = ATSConsolidationTrader(Close, 70, 70, 70, 0);
                          ATSConsolidationTrader2S = ATSConsolidationTrader(Closes[3], 70, 70, 70, 0);

                          ATSConsolidationTraderD = ATSConsolidationTrader(Closes[4], 70, 70, 7​0, 0);​

                          Once you try to use in a strategy you will find that you have to identify the actual Current Box for it to work, They added a plot for that too.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by fx.practic, 10-15-2013, 12:53 AM
                          5 responses
                          5,404 views
                          0 likes
                          Last Post Bidder
                          by Bidder
                           
                          Started by Shai Samuel, 07-02-2022, 02:46 PM
                          4 responses
                          95 views
                          0 likes
                          Last Post Bidder
                          by Bidder
                           
                          Started by DJ888, Yesterday, 10:57 PM
                          0 responses
                          8 views
                          0 likes
                          Last Post DJ888
                          by DJ888
                           
                          Started by MacDad, 02-25-2024, 11:48 PM
                          7 responses
                          159 views
                          0 likes
                          Last Post loganjarosz123  
                          Started by Belfortbucks, Yesterday, 09:29 PM
                          0 responses
                          8 views
                          0 likes
                          Last Post Belfortbucks  
                          Working...
                          X