Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
The following line is taken from a code that was kindly sent to me by @Ymmv.
s_VolumeAtPriceV2* p_VolumeAtPriceAtIndex = 0;
I an breaking my teeth trying to understand this line and will be grateful for any help understanding it ( I am just beginning with ACSIL and C++ and am not a programming expert in general).
Here is the full code and it is working just fine (identifying the price with the max volume within a bar).
I am looking for a function that returns the price with the highest volume within a bar. I am trying to figure out away to get this using the sc.VolumeAtPriceForBars member but any idea will be appreciated.
*/
#include "sierrachart.h"
#include "scstudyfunctions.h"
#include <math.h>
SCDLLName("High Volume At Price")
if (sc.SetDefaults)
{
// During development set this flag to 1, so the DLL can be modified. When development is done, set it to 0 to improve performance.
sc.FreeDLL = 0;
sc.GraphName = "High Volume At Price";
sc.StudyDescription = "Display high volume at price for each bar.";
sc.AutoLoop = 1;
sc.GraphRegion = 0;
sc.ScaleRangeType = SCALE_SAMEASREGION;
sc.MaintainVolumeAtPriceData = 1;
Ok, after reading about pointers here : Pointers - C++ Documentation I think that I am beginning to understand this line.
The "*" symbol is not used here for multiplication but it is used to signify that we are talking about a pointer. * p_VolumeAtPriceAtIndex refers not to the value of p_VolumeAtPriceAtIndex but to the value pointed by p_VolumeAtPriceAtIndex.
This line is the declaration of this pointer and my wild guess is that s_VolumeAtPriceV2 is the variable type.
I still have to fully understand this but it seems like I have clue.
This line is just initializing the ptr to a null value before it gets filled in the subsequent call. It would have been clearer to say
s_VolumeAtPriceV2* p_VolumeAtPriceAtIndex = NULL;
Note that technically C++ does not have a "NULL" type, that's more of a C thing. NULL is not always typesafe therefore the "official" recommendation in C++ is to use 0.
Not that it really matters in practice as it's a bit of a pedantic exercise.
Edit to clarify and add more information (sorry was in an unnecessary rush before):
Stroustrup himself (inventor of C++) plus a few other well known people is where I got the "official" recommendation from (technically there is nothing actually official about it which is why I quote it). See here: Stroustrup: C++ Style and Technique FAQ
The new C++11 has a "nullptr" keyword which serves the purpose of the old NULL in a typesafe way. Right now support for that is highly dependent on your compiler which is why I personally still use 0.
We will have to agree to disagree on the use of NULL. Obviously, using zero can be confusing or questions like this don't come up. If it had been NULL, then the new user can at least figure it out and look it up. It also makes scanning code easier, as searching for zero is going to have a few hits, while NULL is what it is.
If you read the ref, you will see it is talking about type safety (which NULL obviously isn't), but zero is not either. The other point they make is about dealing with pre-standard code (aka really old crap), and while that can be an issue in the really big picture, it is a non-issue for an indicator or anything that people are doing at this level.
Defining another macro for nullptr is a good tradeoff if you want future compatibility.
I don't think we're disagreeing per se because I wasn't trying to make an argument, only to explain the rational behind my personal choice. As I said, it's a bit of a pedantic exercise. I base my choices on what I have learned from other professionals and my own experience but that doesn't mean the other option is wrong. Especially in this case where NULL is very often the exact same thing as 0. Just be consistent.