NexusFi: Find Your Edge


Home Menu

 





s_VolumeAtPriceV2* p_VolumeAtPriceAtIndex = 0; ???


Discussion in Sierra Chart

Updated
      Top Posters
    1. looks_one yonatan with 4 posts (2 thanks)
    2. looks_two aslan with 2 posts (1 thanks)
    3. looks_3 Ymmv with 2 posts (1 thanks)
    4. looks_4 supermht with 1 posts (0 thanks)
    1. trending_up 2,490 views
    2. thumb_up 4 thanks given
    3. group 4 followers
    1. forum 9 posts
    2. attach_file 0 attachments




 
Search this Thread

s_VolumeAtPriceV2* p_VolumeAtPriceAtIndex = 0; ???

  #1 (permalink)
 yonatan 
Haifa Israel
 
Experience: Beginner
Platform: sierra chart
Broker: Optimus Trading Group/Rithmic
Trading: es
Posts: 91 since Apr 2012
Thanks Given: 50
Thanks Received: 71

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).


/* Date: 2012-05-21
Version: 1.0
Author: Ymmv

*/

#include "sierrachart.h"
#include "scstudyfunctions.h"
#include <math.h>
SCDLLName("High Volume At Price")

SCSFExport scsf_HighVAP(SCStudyInterfaceRef sc)
{
SCSubgraphRef MaxVAP = sc.Subgraph[0];

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;

MaxVAP.Name = "MaxVAP";
MaxVAP.DrawStyle = DRAWSTYLE_DASH;
MaxVAP.LineWidth = 2;
MaxVAP.PrimaryColor = COLOR_YELLOW;

return;
}

if ((int)sc.VolumeAtPriceForBars->GetNumberOfBars() < sc.ArraySize)
return;

unsigned int MaxVolume = 0;
float MaxVolumePrice = 0;

int Count = sc.VolumeAtPriceForBars->GetSizeAtBarIndex(sc.Index);

for (int ElementIndex = 0; ElementIndex < Count; ElementIndex++)
{
s_VolumeAtPriceV2* p_VolumeAtPriceAtIndex = 0;
sc.VolumeAtPriceForBars->GetVAPElementAtIndex(sc.Index, ElementIndex, &p_VolumeAtPriceAtIndex);

if (p_VolumeAtPriceAtIndex &&
p_VolumeAtPriceAtIndex->Volume > MaxVolume)
{
MaxVolume = p_VolumeAtPriceAtIndex->Volume;
MaxVolumePrice = p_VolumeAtPriceAtIndex->PriceInTicks * sc.TickSize;
}
}

MaxVAP[sc.Index] = MaxVolumePrice;
}

Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
ZombieSqueeze
Platforms and Indicators
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
MC PL editor upgrade
MultiCharts
REcommedations for programming help
Sierra Chart
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
48 thanks
Just another trading journal: PA, Wyckoff & Trends
35 thanks
Tao te Trade: way of the WLD
26 thanks
Bigger Wins or Fewer Losses?
24 thanks
GFIs1 1 DAX trade per day journal
20 thanks
  #3 (permalink)
 supermht 
Naperville IL
 
Experience: Intermediate
Platform: ninjatrader
Broker: NT broker
Trading: NQ ES 6E GC CL
Posts: 962 since Feb 2010
Thanks Given: 1,189
Thanks Received: 661


any change we can get zip file?

Reply With Quote
  #4 (permalink)
 yonatan 
Haifa Israel
 
Experience: Beginner
Platform: sierra chart
Broker: Optimus Trading Group/Rithmic
Trading: es
Posts: 91 since Apr 2012
Thanks Given: 50
Thanks Received: 71


supermht View Post
any change we can get zip file?

The code can be downloaded here:


Started this thread Reply With Quote
Thanked by:
  #5 (permalink)
 yonatan 
Haifa Israel
 
Experience: Beginner
Platform: sierra chart
Broker: Optimus Trading Group/Rithmic
Trading: es
Posts: 91 since Apr 2012
Thanks Given: 50
Thanks Received: 71

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.

Am I walking in the right direction ?

Started this thread Reply With Quote
  #6 (permalink)
 
aslan's Avatar
 aslan 
Madison, WI
 
Experience: Advanced
Platform: ALT
Trading: ES
Posts: 625 since Jan 2010
Thanks Given: 356
Thanks Received: 1,127


yonatan View Post
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).

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

 
Code

 s_VolumeAtPriceV2* p_VolumeAtPriceAtIndex = NULL;

Reply With Quote
  #7 (permalink)
 yonatan 
Haifa Israel
 
Experience: Beginner
Platform: sierra chart
Broker: Optimus Trading Group/Rithmic
Trading: es
Posts: 91 since Apr 2012
Thanks Given: 50
Thanks Received: 71


aslan View Post
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

 
Code

 s_VolumeAtPriceV2* p_VolumeAtPriceAtIndex = NULL;

Yep thanks @aslan i think I just realized this :-)

Started this thread Reply With Quote
  #8 (permalink)
 Ymmv 
Poquoson VA USA
 
Experience: Advanced
Platform: Proprietary
Trading: Futures, Crypto
Posts: 17 since Jun 2010
Thanks Given: 6
Thanks Received: 9


aslan View Post
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

 
Code

 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.

Reply With Quote
Thanked by:
  #9 (permalink)
 
aslan's Avatar
 aslan 
Madison, WI
 
Experience: Advanced
Platform: ALT
Trading: ES
Posts: 625 since Jan 2010
Thanks Given: 356
Thanks Received: 1,127

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.

Reply With Quote
Thanked by:
  #10 (permalink)
 Ymmv 
Poquoson VA USA
 
Experience: Advanced
Platform: Proprietary
Trading: Futures, Crypto
Posts: 17 since Jun 2010
Thanks Given: 6
Thanks Received: 9


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.

Reply With Quote




Last Updated on July 2, 2012


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts