Tutorial 203 | Calculate Volume Ratio in RadarScreen

  • 2 months ago
The standard Volume Ratio indicator does not work in RadarScreen because the EasyLanguage keywords: UpTicks and DownTicks return different values.

Tutorial 203 demonstrates a couple of different approaches to providing Volume Ratios in RadarScreen.

See https://markplex.com/free-tutorials/tutorial-203-calculate-volume-ratio-in-radarscreen/
#tradestation #easylanguage #markplex
Transcript
00:00Hello and welcome to tutorial 203 and a Gold Pass member asked me the question how would you go about
00:09showing the volume ratio on RadarScreen. So first of all let's just have a quick look at
00:16the volume ratio indicator the standard trade station volume ratio indicator and you can see
00:22it here and you and the guts of the calculation occur here. Now the problem with this is that
00:29upticks and downticks work for charts but not for RadarScreen in fact we just right click on that
00:37you'll see that we can go to the all the relevant volume words for trade station and you'll see
00:45for RadarScreen that for example for stock symbols the upticks give you total volume
00:53and the downticks return zero whereas for example on a chart you'll see upticks returns
01:02the shares traded on upticks and downticks the shares traded on downticks. So he wondered the
01:10Gold Pass member how you would go about showing volume ratio on in RadarScreen. So I've got a
01:17couple of ideas of things that you can do here you can see we've got a RadarScreen here I've
01:25created an indicator not dissimilar from the standard indicator and you can see that clearly
01:31those ratios don't work we're just getting hundred hundred hundred but what I've also done
01:37is created a program that is applied to a chart and then the chart sends the value to
01:44RadarScreen. Now obviously this is that has the disadvantage that you need to have a chart open
01:50the same time as the values for RadarScreen if you've got several hundred values in RadarScreen
01:56this is probably a little bit onerous but you'll just see if we look at for example the e-mini and
02:04the sender is applied to this chart and then those values are being returned or sent over here so
02:13that we've got the values on RadarScreen. So let me first of all just run through how the programs
02:21do that so we've got as I say two programs we've got the sender and we've got the receiver so let's
02:26have a look at the sender and essentially what we're doing is creating a global dictionary
02:33and a vector and we create the global dictionary using this syntax because we want the global
02:40dictionary to be shared between the chart and RadarScreen we're setting up a vector and then
02:46we're saying if this is a minute chart minute or tick in fact but this program is designed for
02:52minute charts then we can calculate the values using the standard formula which is total ticks
02:58up ticks plus down ticks bear in mind this is being applied to a chart not to RadarScreen and then
03:05having calculated the values we store them in the vector so if the vector is empty we can store them
03:11using pushback once the vector has got values in it we're going to put them in the position zero
03:16and one having done that we then store the vector in the global dictionary and we do that with the
03:24key being set to get symbol name so the key for this value is going to be the symbol name and
03:31we're going to put it store in that as the value the ratio vector now bear in mind there's nothing
03:36here to make sure that the receiving and the sending charts have the same interval so that's
03:43something that you could potentially add to the program to make it more useful and then we plot
03:48the values so that's the sending indicator what we've also got is a receiving indicator and what
03:55that does again being just down into the one statement we create or initialize the global
04:01dictionary then we have a couple of item changed events first one being item added and another one
04:09being item changed and then we create a new vector which we've called received ratio vector
04:17so what happens if either of these events are fired in other words item added or item changed
04:23then we are we call this update plot method in both cases and in the update plot method what we
04:30do is we say we're looking this for each row applied to radar screen we say if args key is
04:38get symbol name in other words there is some something in the dictionary that has just fired
04:44the events just occurred for the symbol that we're actually plotting in our radar screen then we say
04:51if it contains the symbol name is not false then we're going to say received ratio vector equals
04:58the global dictionary items the name of the symbol as type vector so we we're now getting
05:05the vector that we've just sent from the sending chart into receiving chart and then we're plotting
05:11the two values in the vector and i've just added some extra checks just to make sure there is
05:16actually values in those there are enough values to be able to plot so that essentially is the
05:23program that makes sense to you so that's one way of doing this as i say the big disadvantage is you
05:30have to have a sending chart which is a little bit of a fiddle now the other way is the using
05:37price series provider now if you look at these values carefully you'll notice that they're not
05:43totally synced with each other because the the changes some in the data do not occur exactly
05:51at the same time as the psp that's one of the the disadvantages but this program is most is mainly
05:57designed for radar screen but if you do apply it to chart what you'll find sometimes is there's
06:04because the chart data and the psp are not synchronized together you will see that you'll
06:09get some little errors where for example the the psp finished a millisecond before the end of
06:17chart or vice versa and that could cause discrepancies when comparing values calculated using
06:23the standard train station indicator with this indicator but let's just look at it in terms of
06:29the radar screen and i'll just run through the program a little bit more complicated than the
06:34other program namespaces i put here your system your system dot collections and tts data dot
06:40market data see the inputs there so let's go first of all to the one statement and this is where
06:47we're creating the price series provider if you're not familiar with creating price series provider
06:53the easiest easiest thing is to go into the toolbox double click on price series provider
07:00put in the data that you think is appropriate and having done that go to the designer generator
07:07code copy the code from there into your program but we've i've already created it you'll see
07:13some things here we're looking at data chart type bars so it's a bar chart rather than volume chart
07:20we're using a minute chart the uh the value of the bar interval that is going to be taken from
07:26the radar screen rain data range type bars put in the range bars five times average length because
07:33we need to have a sufficient quantity to be able to calculate accurate values particularly when
07:39we're creating the exponential moving average we're including volume not including ticks yes
07:46we're using real time and then not strictly necessary here but i just like to keep this
07:52code that we can essentially use the time zone of the chart when this is applied to chart the name
08:00psp load true and then we've got an update event standard psp update event so that is what we set
08:08up in the one statement we now can look at the updated event so when the event is updated if it
08:17is a chart then we're going to do something slightly different from if it is radar screen
08:23and the reason that i've done this is simply to try and remove one of the problems that can be
08:29caused by the synchronization unfortunately this creates another problem but the way i did it is
08:35just to check that the the volume was greater than the volume previous time the program worked
08:41otherwise it implies that the either the bar has ended normally or it's the psp has ended just a
08:50little bit before the end of the bar and so this this will smooth out some problems or at least
08:56it's my attempt to do so but if it is radar screen in other words application type equals two then we
09:04set these two variables here psp vol up and psp vol down to be psp.volume up zero square brackets
09:15psp.volume down and if you look in the inputs you'll see that i have made these both intrabar
09:21variables put in a little bit of debugging type print statements which are not necessary for for
09:27the running of the program and then what i do having done that check above i just set the psp
09:33vol up last update equals psp.volume up as type double and similarly for the psp vol down last
09:43update equals psp.volume down so that is where the updates occur now we need to calculate the values
09:51now for a chart what we could do is just use the up ticks and down ticks like we did before and
09:57we're doing that here just by way of example and we're plotting those values in plot one plot two
10:03you'll see though if we go back to radar screen that we don't get anything plotted there again
10:08that's because of the problem i've just described but what we're going to do now is calculate the
10:14values using the psp so as you will have just seen up here in the psp updated event we're setting
10:26the psp vol up and psp vol down to be equal to the psp volume up values so in our calculation
10:36we again do the standard calculation but just using these values rather than using the up ticks
10:42or down ticks we're doing that if this is a chart if it is radar screen we're just going to use psp
10:49volume up and psp volume volume down as you might expect in a more simple simplified program
10:56then to find out the exponential moving average we can use x average what i've also done though
11:03is just a another way of doing this is to just go backwards each time and recalculate
11:11recalculate the moving average so the the x average that's sort of going backwards it's
11:17using previous values this way of doing it is actually going back and redoing the calculation
11:24again i don't think this is necessarily any advantage or one of the other but i just wanted
11:29to to include that code because it might be useful for you and then we plot the bars and what i've
11:34done is make the color slightly different if they're historic bars using the get app info
11:40a real-time calc i'm doing them as white otherwise i'm doing them as yellow and we're
11:46also plotting plot six and that is the exponential moving average calculated using the other way that
11:53i just spoke about and then again we've got some print statement debugging information which we
12:00could just comment out if we if we don't want to and this here bar is that last tick was just
12:09something i was using when i was debugging so hopefully you might find this useful you could
12:15probably if you wanted to type this program in again which is probably quite a good learning
12:21experience if however you'd rather download the programs i will make them available and
12:28if you like this sort of stuff please subscribe to the markplex youtube channel and also the email
12:35list and visit markplex m-a-r-k-p-l-e-x dot com so thank you very much

Recommended