• 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

Problem with Ray

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

    Problem with Ray

    Hello,
    I have indicator which draw Rays on swing Highs.
    When High[0] is higher than the Ray I want to change color from green to red. In NT7 this indicator works perfectly, but in NT8 doesn't work even if I changed the code.
    Can you write me, where is problem?
    thank you

    Here is my code in NT8:

    Code:
    protected override void OnBarUpdate()
    		{
    			if (CurrentBar < BarsRequiredToPlot) return;
    			
    			bool SwingHigh = false;
    			SwingHigh = High[4] < High[2] && High[3] <= High[2] && High[1] <= High[2] && High[0] < High[2];
    						 
    			if (SwingHigh) 
                            Draw.Ray(this, "RayHigh" +CurrentBar, false, 2, High[2], 0, High[2], Brushes.LightGreen, DashStyleHelper.Solid, 2);
    			
    			foreach (DrawingTool draw in DrawObjects)
    			{
    				if (draw is DrawingTools.Ray && draw.Tag.StartsWith("RayHigh"))
    				{
    					DrawingTools.Ray tempRay = draw as DrawingTools.Ray;
    					
    					if (High[0] > tempRay.StartAnchor.Price) 					
    						tempRay.Stroke.Brush = Brushes.Red;
    				}
    			}
    		}

    #2
    Originally posted by licovata View Post
    Hello,
    I have indicator which draw Rays on swing Highs.
    When High[0] is higher than the Ray I want to change color from green to red. In NT7 this indicator works perfectly, but in NT8 doesn't work even if I changed the code.
    Can you write me, where is problem?
    thank you

    Here is my code in NT8:

    Code:
    protected override void OnBarUpdate()
    		{
    			if (CurrentBar < BarsRequiredToPlot) return;
    			
    			bool SwingHigh = false;
    			SwingHigh = High[4] < High[2] && High[3] <= High[2] && High[1] <= High[2] && High[0] < High[2];
    						 
    			if (SwingHigh) 
                            Draw.Ray(this, "RayHigh" +CurrentBar, false, 2, High[2], 0, High[2], Brushes.LightGreen, DashStyleHelper.Solid, 2);
    			
    			foreach (DrawingTool draw in DrawObjects)
    			{
    				if (draw is DrawingTools.Ray && draw.Tag.StartsWith("RayHigh"))
    				{
    					DrawingTools.Ray tempRay = draw as DrawingTools.Ray;
    					
    					if (High[0] > tempRay.StartAnchor.Price) 					
    						tempRay.Stroke.Brush = Brushes.Red;
    				}
    			}
    		}
    You have defined tempRay inside a loop, so tempRay goes out of scope when you leave the loop, so anything done to it is irrelevant.

    You will need to create a temporary list of the identifiers for objects to modify, then modify them outside the loop, by using the identifiers, because you cannot modify objects in a list that you are parsing with any kind of loop.

    Comment


      #3
      Hello licovata,

      Thanks for your post.

      In testing your code I noticed that DrawObjects.Count is not being correctly updated when the indicator loads historically. The foreach loop then would never run or run after some point having missed many previously drawn rays. I have reported this as a bug and will update this thread when I have further information.
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        Hello i have a question which perhaps relates to this for Draw.Ray.
        The indicator performs similar function in that it draws lines at swing highs and lows and stores in a collection to be managed. When it comes to RemoveDrawObject i reference the tag as stored in the collection which uses CurrentBar as part of the identifier. In NT7 this works no problem but in testing in N8 the lines are not removed when they should be (on certain condition tests). So i wanted to see if this is related.
        thanks

        Comment


          #5
          Hello soulfx,

          Thanks for your post.

          You can test this with a print statement of the DrawObjects.Count value while counting the objects you've drawn to see if it matches up with the objects that do or do not get removed.
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Hello,

            I am trying currently to put in print statements around this but may need to isolate the code i ported from N7 to N8 of which there is no code breaking changes to note in this area of the code.

            Can you clarify if you want me to test this to see for myself if Removeobjects works? or are you saying it may be a bug related to the below or you arent sure. Also this indicator does process historical bars for prior swings and draws lines from those that may or may not be removed as the indicator is loaded depending on the price location of the swing. Is this related to the below?

            For the record here on other items i have submitted detailed information and then ninja says is logged and will be fixed - the last beta 8 i then had to test it and the same detailed bug i pointed out had to be put back in as a bug. All this to say i do not want to presume anything here as even if i point out the problem it doesnt always seem to get tested. This is time consuming to test and write these up and the back and forth and for subtle details to be overlooked.

            thanks

            Comment


              #7
              Hello soulfx,

              Thanks for your reply.

              From your post it sounded like you had a situation where you suspected this DrawObjects.Count may be related to the RemoveDrawObjects. I do not know if they are related and was suggesting that since you have a repeatable condition that some print statements may help to further understand.

              If so then I would ask if you can reduce your code down to allow us then to replicate here on a simplified version or provide some further descriptions of the situation.

              Beta testing is all about finding the bugs and fixing them and we very much appreciate your help (and all other beta testers). We are trying very hard to find and fix everything as quickly as we can. If we've missed something it was not intentional.
              Paul H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by vpzdcv, Today, 02:31 AM
              0 responses
              3 views
              0 likes
              Last Post vpzdcv
              by vpzdcv
               
              Started by YevhenShynkarenko, Today, 01:22 AM
              0 responses
              7 views
              0 likes
              Last Post YevhenShynkarenko  
              Started by ttodua, Today, 12:52 AM
              0 responses
              4 views
              0 likes
              Last Post ttodua
              by ttodua
               
              Started by ttodua, Today, 12:50 AM
              0 responses
              2 views
              0 likes
              Last Post ttodua
              by ttodua
               
              Started by mulshah, Yesterday, 11:12 PM
              0 responses
              3 views
              0 likes
              Last Post mulshah
              by mulshah
               
              Working...
              X