Login Page - Create Account

Support Board


Date/Time: Fri, 28 Feb 2025 21:53:02 +0000



Post From: Custom study cause CPU exception

[2021-08-27 07:34:04]
User907968 - Posts: 833
The problem lies here -

    
for (int VAPIndex = 0; VAPIndex <= VAPSizeAtBarIndex-1; VAPIndex++)
{
DeltaCandle += p_VolumeAtPrice->AskVolume - p_VolumeAtPrice->BidVolume;
}

You are dereferencing a null pointer, p_VolumeAtPrice, which is/causes undefined behavior.
Modfiy the for loop similarly to one of the options below.


for (int VAPIndex = 0; VAPIndex < VAPSizeAtBarIndex; VAPIndex++)
{
s_VolumeAtPriceV2* p_VolumeAtPrice = NULL; // set pointer to null on each iteration

sc.VolumeAtPriceForBars->GetVAPElementAtIndex(sc.Index, VAPIndex, &p_VolumeAtPrice); // read volume at price data / set pointer
      
if (p_VolumeAtPrice != NULL) // check for null pointer
DeltaCandle += p_VolumeAtPrice->AskVolume - p_VolumeAtPrice->BidVolume;
}



for (int VAPIndex = 0; VAPIndex < VAPSizeAtBarIndex; VAPIndex++)
{
s_VolumeAtPriceV2* p_VolumeAtPrice = NULL; // set pointer to null on each iteration

if (!sc.VolumeAtPriceForBars->GetVAPElementAtIndex(sc.Index, VAPIndex, &p_VolumeAtPrice)) // read volume at price data / set pointer
continue; // above function returns false on failure to set pointer, in which case loop moves to next iteration without executing code below
      
DeltaCandle += p_VolumeAtPrice->AskVolume - p_VolumeAtPrice->BidVolume;
}