Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Hide line if touch price

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

    Hide line if touch price

    Hello everyone

    The task was to implement the display of the line from the previous day, if the price did not touch it, hide _ delete the line if touched

    I ask for help with the logics and correct syntax.

    The code

    // example condition doji bar & day is not today
    If (Close [0] == Open [0] && Time [0] .Day! = DateTime.Now.Day)
    {

    // Draw.Ray.

    }

    #2
    You will want to make use of the RemoveDrawObject() method.

    If you're doing something that occurs daily, or once per session, I'd suggest you either use sessionIterator, or you create your own counter that gets updated daily, and use that as a string tag. That way, you can pass that string tag to RemoveDrawObject for deletion once your condition occurs.

    Comment


      #3
      The above is assuming you are drawing a line with a drawing object, like Draw.Line().

      If you are using a Plot, you could set the plot to transparent once it is touched.

      Comment


        #4
        I need help with the logic or a concrete example of how to implement this or where is it implemented

        Comment


          #5
          I am looking for Way to realize - or indicator that will show daily lows and highs on the chart that were not broken by the price,

          thank you in advance

          Comment


            #6
            Here is an example of doing this. There are probably a million ways to accomplish the same thing, and probably in a more efficient way.

            Also of note, is that I used the CrossAbove()/CrossBelow() methods, which I have always found suspect. When I had the need for the "crossing functionality" in the past, I would write my own, which was to compare the position of the current and past bars to detect a crossing of something.

            But the basic flow of the script, is to at the beginning of the session, store the session count, store the open bar, and reset the flag crossing to false.

            Then on each bar, check if the bar has crossed either the prior day's high or low. If so, set that flag to true.

            The day's high is then draw(by default the prior day's high/low is drawn on every bar).

            But... if the flag has been set(prior day's high/low crossed), remove that line. So it appears as if it has been erased.

            Also of note, it was not specified if the line should remain through subsequent days if not crossed? This indie operates only on a comparison of the prior day. If wanting the line to persist until it is crossed, the values would need to be stored in an array/list, and checked for crossing(doing this is not complicated).

            Pic shows the prior high/low, and comparison how the the line is removed.
            Attached Files

            Comment


              #7
              Click image for larger version

Name:	2021-03-21_204807.gif
Views:	414
Size:	79.1 KB
ID:	1147691

              Comment


                #8
                attachments are acting up
                Attached Files

                Comment


                  #9

                  forrestang thank you very much!

                  Comment


                    #10
                    Originally posted by forrestang View Post

                    Also of note, it was not specified if the line should remain through subsequent days if not crossed? This indie operates only on a comparison of the prior day. If wanting the line to persist until it is crossed, the values would need to be stored in an array/list, and checked for crossing(doing this is not complicated).

                    Pic shows the prior high/low, and comparison how the the line is removed.
                    Yes, according to the idea, the line should be up until the price overshot it, if the price crossed it, then there should be no line at the reverse crossing.

                    I also have a problem with arrays, I'm just learning, and it's very hard to find examples of what I need to see with my eyes and understand how it works with my head

                    Comment


                      #11
                      Originally posted by memonolog View Post

                      Yes, according to the idea, the line should be up until the price overshot it, if the price crossed it, then there should be no line at the reverse crossing.

                      I also have a problem with arrays, I'm just learning, and it's very hard to find examples of what I need to see with my eyes and understand how it works with my head
                      if you have time, please help me with an example of how to implement this,
                      thanks in advance .

                      Comment


                        #12
                        Do you expect the lines to be capable of being different colors(high vs low), or does it matter for your use-case?

                        Comment


                          #13
                          Originally posted by forrestang View Post
                          Do you expect the lines to be capable of being different colors(high vs low), or does it matter for your use-case?
                          keeping different colors would be preferable

                          as in your first option

                          Comment


                            #14
                            For this example, I have used a multi-dimensional List, and created it with a constructor. For more info, search something like, "C# List," or "C# constructor," or "C# mutli-dimensional List". DotNetPerls usually has good examples.

                            You can see the constructor, which defines the List, and it is named "HighLoInfo," this contains a definition for the list. The actual Variable name of the list is called "HiLoList," which can be declared AFTER creating this constructor definition.

                            Just a note, if you don't need a multi-dimensional list(for future scripts), you can create lists easily that only have one dimension, and do not require construction definitions. Also, instead of creating a multi-dimensional list which has a bit of complexity, you can create multiple lists, and just ensure that you always initialize, add to, and delete from them the same way, and this is another option.

                            The multi-dimensional list contains 3 variables, that include the Bar the High/Low was made on, the Price of that High/Low and the Type, which is +1 or -1 for High/Low.

                            Also, in this case, because the lines will persist, I thout it just looks better to actually draw the line from the high low where it was made. To accomplish this, we calculate our own daily/high Lows, which is then stored in our List. This is different than the other script, where we use the built in indicator to get the prior High/Low values. This takes place in the following code:
                            Code:
                            //Initialyze Daily Captures
                            if( Bars.IsFirstBarOfSession ) //Daily Open
                            {
                              //Resetting Daily Highs/Lows/Open on Daily Open bar
                              openBar =CurrentBar; highBar =CurrentBar; lowBar =CurrentBar;
                              openPrice =Open[0]; highPrice =High[0]; lowPrice =Low[0];
                            
                              sessionCnt++; //increment session Count
                            }
                            
                            //Checking if New Daily High/Low is made, if so, store that Price and Bar
                            if( High[0] > highPrice )
                            {
                              highBar =CurrentBar;   highPrice =High[0];
                            }
                            if( Low[0] < lowPrice )
                            {
                              lowBar =CurrentBar;    lowPrice =Low[0];
                            }

                            Next, we iterate over our list, and draw the lines, based on the list information. We then remove a list item, in the case that the line is crossed. Of note, I iterated twice, which may be redundant, but I didn't structure things as efficiently as I should to do this in one loop. Also of note, is that we are iterating over the loop BACKWARDS, because we are removing items from the list, otherwise, you may get an issue with iterating over something recently removed.

                            Also of note, I added a variable called "deleteLine." This variable is used to COMPLETELY remove the line if it is crossed. If it does NOT, then simply STOP drawing the line(which is redrawn on each bar), and it shows WHERE on the chart the line was crossed. You can see the attached image, the difference when this bool is set to true.

                            This should be a UserInput, so I'll leave that to you to add.
                            Attached Files
                            Last edited by forrestang; 03-25-2021, 11:19 AM.

                            Comment


                              #15
                              Originally posted by forrestang View Post
                              For this example, I have used a multi-dimensional List, and created it with a constructor. For more info, search something like, "C# List," or "C# constructor," or "C# mutli-dimensional List". DotNetPerls usually has good examples.

                              You can see the constructor, which defines the List, and it is named "HighLoInfo," this contains a definition for the list. The actual Variable name of the list is called "HiLoList," which can be declared AFTER creating this constructor definition.

                              Just a note, if you don't need a multi-dimensional list(for future scripts), you can create lists easily that only have one dimension, and do not require construction definitions. Also, instead of creating a multi-dimensional list which has a bit of complexity, you can create multiple lists, and just ensure that you always initialize, add to, and delete from them the same way, and this is another option.

                              The multi-dimensional list contains 3 variables, that include the Bar the High/Low was made on, the Price of that High/Low and the Type, which is +1 or -1 for High/Low.

                              Also, in this case, because the lines will persist, I thout it just looks better to actually draw the line from the high low where it was made. To accomplish this, we calculate our own daily/high Lows, which is then stored in our List. This is different than the other script, where we use the built in indicator to get the prior High/Low values. This takes place in the following code:
                              Code:
                              //Initialyze Daily Captures
                              if( Bars.IsFirstBarOfSession ) //Daily Open
                              {
                              //Resetting Daily Highs/Lows/Open on Daily Open bar
                              openBar =CurrentBar; highBar =CurrentBar; lowBar =CurrentBar;
                              openPrice =Open[0]; highPrice =High[0]; lowPrice =Low[0];
                              
                              sessionCnt++; //increment session Count
                              }
                              
                              //Checking if New Daily High/Low is made, if so, store that Price and Bar
                              if( High[0] > highPrice )
                              {
                              highBar =CurrentBar; highPrice =High[0];
                              }
                              if( Low[0] < lowPrice )
                              {
                              lowBar =CurrentBar; lowPrice =Low[0];
                              }

                              Next, we iterate over our list, and draw the lines, based on the list information. We then remove a list item, in the case that the line is crossed. Of note, I iterated twice, which may be redundant, but I didn't structure things as efficiently as I should to do this in one loop. Also of note, is that we are iterating over the loop BACKWARDS, because we are removing items from the list, otherwise, you may get an issue with iterating over something recently removed.

                              Also of note, I added a variable called "deleteLine." This variable is used to COMPLETELY remove the line if it is crossed. If it does NOT, then simply STOP drawing the line(which is redrawn on each bar), and it shows WHERE on the chart the line was crossed. You can see the attached image, the difference when this bool is set to true.

                              This should be a UserInput, so I'll leave that to you to add.
                              Thank you very much for the work done and the time spent, now I will know how this can be implemented.
                              Thank you!

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              627 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              359 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              562 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              567 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X