Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Essentially the same code but one is giving me errors

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

    #16
    Hi Chelsea,
    I tried exporting and the error message: You have custom NinjaScript files on your PC that have programming errors. These errors must be resolved before you can export a NinjaScript Archive.
    file.

    An the error belongs to the file that I'm trying to export to you and the error message is "Cannot convert type 'char' to 'string'.

    Any suggestions?

    I can post it here if you like.

    Code:
    public class MyCustomIndicatortest : Indicator
    {
    
    #region Variables
    
    private List<string> DemandLines;
    
    
    #endregion
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "MyCustomIndicatortest";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    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;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    DemandLines = new List<string>();
    
    }
    }
    
    protected override void OnBarUpdate()
    {
    foreach (string drawTag in DemandLines[DemandLines.Count-1])
    {
    
    }
    }
    }

    Comment


      #17
      Hello kaywai,

      "DemandLines[DemandLines.Count-1]"

      This would be an index for a specific value, specifically the last element in the collection. Are you not wanting to loop over the list?

      Code:
      foreach (string drawTag in DemandLines)
      {
      Print(drawTag);
      }
      The above code would loop through the list.


      If you are actually trying to loop over the last element in the collection, then the last element would need to be a collection itself. The outer list would need to be a collection of collections.

      private List<List<string>> DemandLines;

      DemandLines = new List<List<string>>();

      DemandLines.Add(new List<string>() { "string 1", "string 2"});

      DemandLines.Add(new List<string>());

      DemandLines[DemandLines.Count - 1].Add("string 3");
      DemandLines[DemandLines.Count - 1].Add("string 4");



      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        Hi ChelseaB,

        I've attached the code that I've been working on over the long weekend. Please take a look.

        I'm still at a loss at why, when I'm removing the oldest line on the chart for every new line printed after the count hits the max of 10, I end up with only 3 lines, when I should be having 9 or 10 at any time. And I've been trying to debug the code through trial and error. Could it be the foreach loop that is causing the issue because that's where the RemoveDrawObject is? How do you print statements for foreach loops? This is the first time I've used foreach loops and list. So I hope you understand when most times I seem confused.

        Initially the code seemed to only remove the newer lines and kept the old. Right now, it keeps the new but only 3 lines when I have a cap of 10. If I increase the cap, more lines populate and they are still the newer lines and no longer the old.

        Another thing is how do you do a Print statement for a DrawRay? I tried printing the tags (but I could be printing it incorrectly) because I'm getting a tag at every bar. Technically though, if every ray is printing correctly, there shouldn't be an issue, right?

        I look forward to your assistance.

        Regards
        Kay Wai
        Attached Files

        Comment


          #19
          Hi ChelseaB,

          With respect to your post on thread #17, I don't think I need a list within a list. I was just looking for ways to remove the oldest ray in the chart once it hits the cap (in this case, the cap is 10). I was at a lostt when it said I was trying to convert a char type when I didn't have any char type in my code. As I just mentioned above which you probably haven't had a chance to read it yet, since i just posted it), it's really a trial and error process that I try to achieve the desired result.

          But I'm keen to learn more and I haven't even scrapped the surface. That I know. I can't even combine Buys and Sells Indicators together. But I'm happy to keep them separate for now as I absorb the new knowledge and examples as I progress on this journey.

          Regards
          Kay Wai
          Last edited by kaywai; 05-31-2022, 12:19 PM.

          Comment


            #20
            Hello Kay Wai,

            "DemandLines[DemandLines.Count-1]"
            This would be an index for a specific value, specifically the last element in the collection.

            Use 'foreach (string drawTag in DemandLines)' if you want to loop through a list.

            DemandLines.ToList() is redundant. It's already a list.

            If you want to remove an object, supply the tag name.
            RemoveDrawObject(drawTag);
            DemandLines.Remove(drawTag);

            If you want to remove by index, then use a for loop and not a foreach loop.

            'for (int i = 0; i<DemandLines.Count; ++i)
            {
            Print(DemandLines[i]);
            RemoveDrawObject(DemandLines[i]);
            DemandLines.RemoveAt(i);
            }
            Last edited by NinjaTrader_ChelseaB; 05-31-2022, 03:31 PM.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #21
              Hi ChelseaB,

              Just discovered why I'm having an issue with my code. It's the "for" loop which does a lookback for the second pivot low and then draws the ray.

              It's drawing over itself for approximately 5 bars. Need to figure a way to overcome that so that it only draws once.

              Any suggestions?

              Regards
              Kay Wai

              Comment


                #22
                Kay Wai,

                You can use a bool to know an action has occurred.

                Set the bool to true when the condition is true. Require the bool to be false in the condition.

                private bool actionOccured;

                if (actionOccurred == false && Open[0] > Close[0])
                {
                actionOccurred = true;
                }

                Chelsea B.NinjaTrader Customer Service

                Comment


                  #23
                  Thanks ChelseaB. Will have a think how to move forward . Thx again for the pointers. Will be reaching out soon enough!!!

                  Comment


                    #24
                    Hi ChelseaB,

                    I think I got it right this time! See attached!

                    It was a case of whether a few lines of code are placed within the same block or code or in a separate block of code.

                    Thanks again for your patience and understanding.

                    Regards
                    Kay Wai
                    Attached Files

                    Comment


                      #25
                      Hi ChelseaB,

                      Need a little bit of help regarding scale of chart.

                      Almost half my chart (see chart a.png) is a blank space because of 2 rays which began from much lower prices. I tried unselecting the Autoscale in the Indicator properties but it did nothing. The other thing I did was to reduce the lookback number from 250 to 150 (see chart b.png). That worked.

                      Are there any other alternatives regarding scaling of charts?

                      Regards
                      Kay Wai
                      Attached Files

                      Comment


                        #26
                        Hello Kay Wai,

                        Are these drawing objects drawn by a script?

                        Is false being supplied to the draw method overload for the isAutoScale?

                        Draw.Ray(NinjaScriptBase owner, string tag, bool isAutoScale, int startBarsAgo, double startY, int endBarsAgo, double endY, Brush brush, DashStyleHelper dashStyle, int width)
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #27
                          Hi ChelseaB,

                          Yes, these objects are drawn by a script. I've left default to true. Just tried as you suggested above. Looks fine. Thank you.

                          Regards

                          Kay Wai

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          574 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          333 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          101 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          553 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          551 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X