Tutorial 205 Part 2 | Converting tutorial 173 to a function

  • 2 months ago
This tutorial demonstrates how to convert tutorial 173 into a function, and how to call the function.
Transcript
00:00Okay, so the second tutorial program I want to demonstrate how to convert into a function
00:05is tutorial 173. As I said, if you're a GoldPass member, you can already look at this for Q&A 50,
00:13but I'm just going to do it again for those who are not GoldPass members or who would like to
00:19see a little bit more information. As you can see, the original tutorial aims to show when there's a
00:24trend up and a trend down, as you can see in this graph. So let's go to the original program,
00:31which is tutorial 173. As you'll see, we've got several inputs, and then we're calculating,
00:38is it an uptrend or a downtrend? And we're also calculating the supertrend value. So let's have
00:45a look at as a function. A lot of the inputs I've changed into numeric simple, so they will be
00:52actually input values that will input into the function. So ATRLength, ATRmult, AVHILO, etc, etc.
01:02And then the only one that's slightly different is we need to have a value which we're going to
01:07return for the supertrend value. And I'll show you how we do that. Again, a lot of the syntax
01:17is pretty much identical to the original program. But what we're doing is we're returning
01:25into tutorial 173 function, the name of this function, the direction. And the direction is
01:31something that we calculate in both programs. Let's have a look. Just go down. This is the
01:37original indicator, and you can see that direction is something that we're calculating there.
01:43So let's go back to the function. So we're returning the direction in the name of the
01:48function. We're also returning a value for supertrend. And as I've said, that is going to be
01:54put into O supertrend, which I have set up here as a numeric reference. So that is the function.
02:07Again, pretty similar to the original program. And you can watch this and type it in if you like,
02:15or there is a download available. But what we also need is something to call the function.
02:21So we're simply going to put in the values we need into the function. And again, you can see
02:29what those are if you just go to the top of the function, what they all mean. But we put those
02:35values into the function. And then we have a value here, which you could make a variable,
02:40I've just used value two, that is going to return whether it's an uptrend or a downtrend. So value
02:47one is whether it's up or down. So if value one is negative, then we plot value two, which is
02:52the supertrend value, but we give it a specific color. And again, if value one, in other words,
02:59the trend going up is one, then we plot the same value, but we plot it a different color.
03:05And what I've done is on the original chart, I've applied the original program.
03:10And I've also applied the program calling the function. And I've just made the lines
03:16very different thicknesses. So you can see that we are getting the same values. And of course,
03:22the inputs are the same. Okay, so hopefully, that might be useful for you. And if you wish
03:30to download it, you may do so. If you're a GoldPass member, look at Q&A 50, which is more
03:36or less, or I think it is identical, just slightly different naming convention. Okay, thank you very
03:42much.

Recommended