8/23/2018

ACSIL code for getting point of control

this is full code for getting POC (maximum volume) of a bar from a given timeframe. might be good to test the reaction of price to the previous day for instance..


#include "sierrachart.h"
#include <vector>

SCSFExport scsf_POC(SCStudyInterfaceRef sc)
{
if (sc.SetDefaults)
{
sc.GraphName = "Identifying POC Values";
sc.GraphRegion = 0;
sc.Subgraph[0].Name = "POC Value";
sc.Subgraph[1].Name = "POC Price";

sc.MaintainVolumeAtPriceData = 1;

sc.AutoLoop = 1;
sc.FreeDLL = 1;

return;
}

int poc_value = 0; 
float poc_price = 0;
std::vector<int> v_poc_values = {};
std::vector<float> v_poc_prices = {};
const s_VolumeAtPriceV2 *p_volume_at_price = NULL;

int number_of_levels = sc.VolumeAtPriceForBars->GetSizeAtBarIndex(sc.Index);
for (int i = 0; i < number_of_levels; i++)
{
if (!sc.VolumeAtPriceForBars->GetVAPElementAtIndex(sc.Index, i, &p_volume_at_price))
break;

int last_volume_value = p_volume_at_price->Volume;
if (last_volume_value > poc_value)
{
poc_value = last_volume_value;
poc_price = p_volume_at_price->PriceInTicks * sc.TickSize;
v_poc_values.push_back(poc_value);
v_poc_prices.push_back(poc_price);
}
}

sc.Subgraph[0][sc.Index] = (float)poc_value;
sc.Subgraph[1][sc.Index] = (float)poc_price;

//log 
SCString log_prices;
SCString log_values;

if (v_poc_prices.size() != v_poc_values.size())
return;

for (int i = 0; i < v_poc_prices.size(); i++)
{
log_prices.Format("%f", v_poc_prices.at(i));
log_values.Format("%d", v_poc_values.at(i));
}

sc.AddMessageToTradeServiceLog(log_prices, 0); 
sc.AddMessageToTradeServiceLog(log_values, 1);
}

2 comments:

  1. Easier, I think:

    /* Date: 2012-05-21
    Version: 1.0
    Author: Ymmv
    http://www.bigmiketrading.com/sierra-chart-programming/20255-acsil-function-returns-price-highest-volume-within-bar.html
    */

    #include "sierrachart.h"
    #include "scstudyfunctions.h"
    #include
    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;
    }

    ReplyDelete