Plotting and deleting horizontal lines programatically  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
darob
Posts: 207
Joined: 20 Nov 2014
Has thanked: 57 times
Been thanked: 32 times

Plotting and deleting horizontal lines programatically

Postby darob » 05 Nov 2016

Hi,
Can you access any other functions via the alert properties of programmatically plotted horizontal lines? For example, instead of firing an alert on a close across I’d like to delete the line.

If not, how does one achieve this with an open-ended quantity of lines (and open-ended quantity of variables)? Hence my interest in the lines' built-in properties (alerts or anything else).

Any other ideas on an approach are most welcome.

Many thanks

darob
Posts: 207
Joined: 20 Nov 2014
Has thanked: 57 times
Been thanked: 32 times

Re: Plotting and deleting horizontal lines programatically

Postby darob » 06 Nov 2016

Another approach I've been looking at is removing the lines with a moving average eraser, but I haven't been able to figure out how to access the lines' price property. How is price accessed in ITrendLineObject? Attached screenshot shows the kinds of errors I'm getting. There are others.

Thanks for any help.
Attachments
horiz trendline price property--what is it.png
(22.29 KiB) Downloaded 1132 times

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Plotting and deleting horizontal lines programatically

Postby JoshM » 06 Nov 2016

Another approach I've been looking at is removing the lines with a moving average eraser, but I haven't been able to figure out how to access the lines' price property.
The `PriceValue()` method that you're trying to use here requires a DateTime value that specifies for which date and time the trend line should retrieve its price value. In other words, without such a DateTime value the `PriceValue()` method doesn't know whether it should return the trend line's price for this bar, a previous bar, or some future bar.

If you want the trend line's price for the current bar, you'd use something like:

Code: Select all

myTrendLine.PriceValue(Bars.Time[0]);
Or if you want to know which value the trend line had on the previous bar, then:

Code: Select all

myTrendLine.PriceValue(Bars.Time[1]);
And so on. A description of the different methods and properties of trend lines is given here: MultiCharts .NET trend lines. This article uses more of a tutorial-like approach: how to get the price value of a trend line?.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Plotting and deleting horizontal lines programatically

Postby JoshM » 06 Nov 2016

Can you access any other functions via the alert properties of programmatically plotted horizontal lines? For example, instead of firing an alert on a close across I’d like to delete the line.
Not sure if I fully understand, but the `Alert` property of a trend line can disable the trend line's alerts, set the alerts to fire intra-bar, or set the line's alerts to fire on the close of the bar.
If not, how does one achieve this with an open-ended quantity of lines (and open-ended quantity of variables)? Hence my interest in the lines' built-in properties (alerts or anything else).
I think I don't understand what you're saying here. But regarding one line versus a whole bunch of lines: it doesn't matter, because how we work with a single line is the same as how we work with multiple lines. The only difference is that, when we have a collection of multiple lines, then we'll need to work with each line individually (like, removing each line).

It's not possible in PowerLanguage .NET to enable the alerts of all trend lines in one go or do something else with all trend lines unless you loop over all trend lines on the chart. (But in that case you'd still treat each line as an individual line, and just work with a group of lines that are processed quickly after each other.) Hope this makes sense.

darob
Posts: 207
Joined: 20 Nov 2014
Has thanked: 57 times
Been thanked: 32 times

Re: Plotting and deleting horizontal lines programatically

Postby darob » 06 Nov 2016

Thanks, Josh. Your material is excellent and fills a real void, I was able to use it to develop the automatic placement of trendlines, but I'm having difficulty with the removals. My question about using the alerts properties I'll just drop, I'm probably just barking up the wrong tree, and I'll just focus on the 2nd approach.

Thanks for the DateTime explanation. I've adjusted the code and now I have the opportunity to show you the second error I've been seeing (see attached.) I've found a reference on the subject but don't know how to apply it to the present situation. I've gone back and forth over your material but obviously I'm not getting it.

Again, any kind of further help appreciated.
Attachments
error.png
(16.38 KiB) Downloaded 1129 times
double to bool.png
(100.33 KiB) Downloaded 1129 times

darob
Posts: 207
Joined: 20 Nov 2014
Has thanked: 57 times
Been thanked: 32 times

Re: Plotting and deleting horizontal lines programatically  [SOLVED]

Postby darob » 06 Nov 2016

Eureka. Found an approach that works. Dumped the MA and went back to matching a price variable to the trendline price directly. Very simple and obvious in hindsight. Thanks again Josh for the great resource you've developed.
Attachments
trendline delete.png
(8.16 KiB) Downloaded 1133 times


Return to “MultiCharts .NET”