Quick-tip 99 | Moving trendlines using the SHIFT/PgUp PgDn keys

  • last month
A Gold Pass member asked how it would be possible to manually draw trend lines on the chart and then move them a certain distance parallel to their original position, either up or down.

The quick-tip tutorial demonstrates how to detect a new trendline has been drawn. This trendline can be shifted up or down by the user input Jump amount by pressing SHIFT-PgUp or SHIFT-PgDn respectively. The program also changes the color and thickness of the trendline when it is drawn.
Transcript
00:00Hello and welcome to Quick Tip 99. A GoldPass member asked me a question. Having got various
00:07trend lines on his chart, what he wanted to do is by selecting a trend line, let's just
00:13use the arrow pointer, clicking on the trend line and then being able to use the shift
00:19page up key to move the trend line up by a certain amount and the shift page down to make it move
00:27down by a certain amount. So that's what we're going to be looking at in this program. Now there
00:32are a number of situations, for example you can see we already have several trend lines applied
00:38to the chart, so I'm just going to press ctrl r. What we need to be able to do, and you'll notice
00:43colours have changed, we'll look at that when we go through the program, but we need to make sure
00:47that when we first apply the program to the chart that we can access trend lines. So that's working
00:54fine, we can indeed. And what we also need to be able to do is to draw a new trend line. So I'm
01:01just going to select the drawing tools and select a trend line from, for example, there to there.
01:09If we were to use the shift page up you'll see that we can move that particular trend line up
01:15or down. And what we could also do if we went back to drawing is choose the arrow pointer,
01:22choose another trend line, and then move that up or down. And you may be wondering, well how much
01:28is it moving up or down? That's really defined as an input in the study for what I've called
01:35jump. I've set that at five. So let's have a look at the program, which I've added quite a few
01:41comments to try and explain what we're doing. The first thing we've got is a method that processes
01:48trend lines that are already on the chart. And so what that basically does, the trend lines
01:54are already stored by TradeStation in this item here, TradeStation items, and then the category
02:03of the trend line. So what I've done is put that into a vector, list underscore tl, and then what
02:12I've done is gone through all the items that are already on the chart, which are in this drawing
02:18objects that items, and I've set the color to orange. I've added a trend line click event to
02:25them, and I've changed the weight to six. That is the first thing that we need to do, and that
02:31is run when we first apply this to the program. We run the method here, process existing. Having done
02:38that, we then go back and have a look at the next method we've got here. This is what happens when
02:45we add a drawing object to the chart. Initially, I think back in QuickTip 19, this was, whenever
02:53that was, this was not working as it was supposed to, and now it seems to work fine. But what we've
02:59got is an event, which is a drawing object being added to the chart. So we're firing that again,
03:08we're setting up that in the one statement, and what that means is that anytime a drawing object
03:13is added to the chart, then this method will be run. So we're just printing a little bit of
03:20information you can use if you need to, but that's just really for information, and then we're setting
03:28what I've called tlTrendline. It's just a generic trendline I'm going to be using throughout the
03:33program. I'm using that as the trendline that's been added, which we get from the addEvent args,
03:41args, and it's called args.addedObject, and it is a trendline. Then we're setting a clickEvent
03:48to that trendline. We're changing the weight and we're changing the color to cyan. So that is every
03:54time a new event is added to, or a new trendline is added to the chart. So for example, if I add
04:01a new trendline now, let's go trendline, and I'm just going to go here again, you'll see it's added
04:08as a cyan color, and that has also got the clickEvent attached to it. The next one is when
04:16a trendline is clicked, because we've now added the clickEvents to all the trendlines on the chart,
04:21all the trendlines are going to be added. And what we essentially do is store into tlTrendline the
04:27sender as type trendline, in other words, the trendline that has been clicked. We set the
04:33weight to six, and we set the color. But the real guts of the program is this area here. Now what
04:39we're doing is a key up. And in other words, when we release a key, that is when this is fired. But
04:45we only want it to take place if, well, first of all, we need to make sure that the trendline is
04:51not null. We also need to make sure that the tlStartPoint.pointType is a date time point.
05:00I don't know exactly why, but when there are no trendlines on the chart, it seems to indicate
05:06the trendline start point type is a BN point, which causes an error. So we're checking here
05:14that it is a date time point, both for the start point, the end point. And if it is,
05:20then what we go through, we set the start date type point to the current tlStartPoint. We set
05:27the end DTPT to the tlEndPoint as DTPoint. And then we need to decide, are we going to add a
05:35value to it or take it away? Now, you will probably be wondering what these values are here. But when
05:40a particular key is pressed, it generates a particular number. I didn't know these numbers,
05:46but if you print the flags values in this method, you'll find out what the numbers are. And the
05:54number, this number represents the shift. In other words, holding down shift and pressing page up.
06:00This one represents holding down shift and pressing page down. If we're holding page up,
06:08then we add jump to the price and we set the STDTPT price to this new value, the old price
06:16plus the jump, the same for the end. And if it is the down, then what we do, we take, we subtract
06:24from those values, the jump values, and then we set the start point and the end point. And then
06:30just to look at it one more time, the one statement, we have this event when a drawing
06:36object is added. We create the TL, which we use throughout the program. And we also have a
06:43charting host because this is where we have the event where we have the key up. And you'll see
06:48here that what I've done is initially created this in the, using the toolbox and then subsequently
06:56copied the code from the design and generated codes. Just to give you an example of how you
07:01might do this is if you go down here, find charting host, double click, and then with
07:08charting host selected, go to properties. And then in the events, you choose whichever property
07:15you needed. So in our case, we used on key up, double click there, and you'll see that you get
07:22a new method added. So we're not going to be using that. So I'm just going to delete that.
07:27We've already done that. I'm going to delete charting host. Hopefully that might be useful
07:32for you. Please, if you're watching this and you're not subscribed to the Markplex YouTube
07:38channel, then please subscribe. If you're also not subscribed to the email list, then
07:43be grateful if you could join that as well. So thank you.

Recommended