Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple series indicator

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

    #16
    Hello vitaly_p,

    The error is with how you are casting the object. It should be like this:

    Code:
    tmpRay = draw as DrawingTools.Ray;
    Keep in mind that the DrawObjects collection is not managed by the indicator so this would only populate in realtime after a few ticks/bars into realtime. If you wanted to more accurately work with the objects and support working historically it would be better to store a list of the objects you drew so you can loop over that list later to do the actions you wanted.

    That would be like the following:
    Code:
    private List<DrawingTools.Ray> drawings = new List<DrawingTools.Ray>();
    
    protected override void OnBarUpdate()
    {
    
       if(someConditionl)
       {
          Ray myRay = Draw.Ray(....);
          drawings.Add(myRay);
       }
    
       if(someOtherConditionl)
       {
           for(int i = 0; i <= drawings.Count - 1; i++)
           {
                DrawingTools.Ray ray = drawings[i];
                //your conditions checking the objects anchors and times
                RemoveDrawObject(ray.Tag);
                drawings.RemoveAt(i);
           }
       }​
    
    }
    One other item to keep in mind would be if you plan to export this script as an assembly, if so you need to work with drawing objects like explained here: https://ninjatrader.com/support/help...tsub=considera

    Comment


      #17
      Thank you Jesse!!

      You are very helpful!​

      Comment


        #18
        And I think, that cycle must be reverse, like

        for (int i = drawings.Count - 1; i >= 0; i--)

        because if erase some Rays - ray[i+1] after erasing will be with index [i], so it will be lost for next step of cycle.

        Comment


          #19
          Hello vitaly_p,

          The example that i provided has a list of Ray type objects so you can use any properties of a Ray: https://ninjatrader.com/support/help...ghlightsub=ray

          The code (DrawingTools.Ray ray = drawings[i] extracts the Ray object for the given index from the list and assigns it to a variable named ray. To access properties on that variable you would use

          double startAnchor = ray.StartAnchor.Price;

          That may not show up in intelleprompt in the editor but it should compile and work.

          The loop i used iterates from the first drawn to the last drawn so that would be in the order drawn. The loop you have shown is reversed or most recent drawn to oldest drawn. You can use whichever suits your needs.





          Comment


            #20
            I understand it, thank you.

            I tried code like on your example with my condition:

            f(ToTime(Time[0]) >= Convert.ToInt32(ZoneRTH_start_time.ToString("HHmms s")) && ToTime(Time[0]) <= Convert.ToInt32(ZoneRTH_end_time.ToString("HHmmss" )))
            {
            for(int i = 0; i <= drawings.Count - 1; i++)

            {

            DrawingTools.Ray ray = drawings[i];

            if(CrossAbove( High , ray.StartAnchor.Price, 1) || CrossBelow( Low , ray.StartAnchor.Price, 1) )

            {

            Brush tmpBrush = ray.Stroke.Brush;

            int nrayBarsAgo = CurrentBar - ray.StartAnchor.DrawnOnBar;

            Draw.Line(this, "Line"+(CurrentBar - nrayBarsAgo), false, nrayBarsAgo+1, ray.StartAnchor.Price, 0, ray.StartAnchor.Price, tmpBrush, DashStyleHelper.Dash, 4);


            RemoveDrawObject(ray.Tag);
            drawings.RemoveAt(i);
            }
            }
            }​

            And have a problem with Draw.Line... The code see ALL Rays (I print information Tag, DrawnOnLine and ray.StartAncor.Price), eliminate all crossing rays and I see information for creating all new lines, BUT Draw.Line don't print all Lines... and I don't understand why?
            Attached Files

            Comment


              #21
              Hello vitaly_p,

              I can't see where you have the print in the code provided to understand the output. If you are wanting to debug why the line is not drawing you would want to put a print inside the area where the line is being drawn to see how frequently that occurs and what the values are when its drawn. If the tag name matched a previously drawn line in the loop then it would just update the existing line.

              Comment


                #22
                Solved!

                It was a problem with Tag of the Lines ("Tag"+CurrentBar) , because Three lines crossed on ONE Candle and all candle has the same Tag and every time Indicator redraw it!​
                Last edited by vitaly_p; 11-14-2022, 06:49 PM.

                Comment


                  #23
                  Hello Jesse

                  I try to insert on the Settings Flag for hide/show text labels on chart. Default is ON. When I turn off - it's OK, but when I turn On again - some different objects from chart (some lines) are hide. Is need to redraw objects on chart?​

                  Comment


                    #24
                    Hello vitaly_p,

                    Yes if you remove the object using RemoveDrawObject you would then have to re draw it if you wanted it displayed again.

                    Comment


                      #25
                      No, I change Brush from current to Transparent

                      if(ShowLabels == false)
                      {
                      Text tmpLabel = null;
                      foreach (Text newlabel in labels)
                      {
                      tmpLabel = newlabel;

                      tmpLabel.TextBrush = Brushes.Transparent;
                      }
                      }​​

                      Comment


                        #26
                        Hello vitaly_p,

                        If you change the color to transparent then it won't be visible. You would have to reset a new color to the object if you wanted it to be visible. If you are trying to hide objects you can just use the IsVisible property.

                        Comment


                          #27
                          Thank you Jesse. I tried but correctly work only last Labels from current day. All labels from previous days work too but when I turn on after hide labels - Indicator show Labels but hide some different other draw objects (some lines). Every time different.

                          foreach (Text newlabel in labels)
                          {
                          if (ShowLabels == false)
                          {
                          newlabel.IsVisible = false;
                          }
                          else
                          {
                          newlabel.IsVisible = true;
                          }
                          }
                          Last edited by vitaly_p; 11-16-2022, 12:04 PM.

                          Comment


                            #28
                            Hello vitaly_p,

                            Unfortunately I cant really understand what you are describing besides that it is not happening consistently.

                            You would likely need to use Prints to better understand how your logic is executed when you toggle the ShowLabels being used in the condition.

                            Comment


                              #29
                              Hello Jesse

                              I have some problem with draw ray who plot dynamically.
                              When I plot ray (or line) with static anchors - it's OK.
                              When I add my indicator on chart and indicator draw current day High or Low on Historical days - I see errors. Starts points of the rays is not from highest or lowest positions, they are more early (1 or more candles ago). When current price in current day go up (or down) and renew current day high or low - ray redraw ok
                              It's problem with different timeframes (in attachment 1 min chart and 30 min chart)
                              I think that problem with counting anchors positions. But I tried draw line from some point to first anchors of this rays - it's ok.
                              Maybe you can help me: how correctly redraw rays when changing High or Low.

                              Part of my code for High:

                              firstAncorGlobexHigh = CurrentBar - barHighGlobex;

                              if(High[0] > currentDayHighGlobex) //dynamical Globex High
                              {
                              barHighGlobex = CurrentBar;
                              isdrawH = true;
                              }​
                              ...
                              if (isdrawH == true) //condition for redraw High ray ONLY if price will be change (NOT EVERY BARS!)
                              {

                              Ray newRay5 = Draw.Ray(this, "C-HighGlobex" + currentDate, false, firstAncorGlobexHigh, currentDayHighGlobex, -1, currentDayHighGlobex, Brushes.White, DashStyleHelper.Solid, widthRaysGlobex );

                              drawings.Add(newRay5);

                              isdrawH = false;
                              }

                              And next question:
                              When I change timeframe - I understand that indicator recount all positions for all drawing objects, but I don't see ALL objects on chart. When I push " Reload ALL historical datas" I see ALL objects. Why?​
                              Attached Files

                              Comment


                                #30
                                Hello vitaly_p,

                                To redraw an object you need to call the same tag name and supply new values. If your script is visually not working right I would suggest adding prints so that you can see how your logic is working in that use case to better understand what may need to change.

                                When you change timeframes you should see that all the historical bars are reprocessed and your logic is re executed. If you are seeing some difference after pressing F5 you would have to determine what part of the logic is happening differently to better understand what's different in those two use cases.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                663 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                376 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                110 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                575 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                580 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X