Login Page - Create Account

Support Board


Date/Time: Sun, 24 Nov 2024 08:54:54 +0000



Post From: Delta on DOM

[2024-06-22 16:26:01]
R108limbs - Posts: 6
Hello, its been a while but I've managed to find some time to create a script for my requested function. The values are calculating correctly but I'm not sure why they're not getting printed into the actual DOM column. Do you think you could diagnose the problem? Thanks.


#include "sierrachart.h"

SCDLLName("DeltaInDOMColumnExample")

struct CumulativeDeltaData
{
int cumulativeDelta;
int lastTradeIndex;
};

SCSFExport scsf_DeltaInDOMColumnExample(SCStudyInterfaceRef sc)
{
if (sc.SetDefaults)
{
sc.GraphName = "Delta in DOM Column Example";
sc.MaintainVolumeAtPriceData = 1;
sc.AutoLoop = 1;
return;
}

static CumulativeDeltaData cdData;
if (sc.IsFullRecalculation)
{
cdData.cumulativeDelta = 0;
cdData.lastTradeIndex = 0;
}

// Calculate CD
int newTradesIndex = sc.VolumeAtPriceForBars->GetNumberOfBars() - 1;
for (int barIndex = cdData.lastTradeIndex; barIndex <= newTradesIndex; ++barIndex)
{
if (barIndex < 0 || barIndex >= sc.ArraySize)
continue;

int VAPSizeAtBarIndex = sc.VolumeAtPriceForBars->GetSizeAtBarIndex(barIndex);
for (int VAPIndex = 0; VAPIndex < VAPSizeAtBarIndex; ++VAPIndex)
{
const s_VolumeAtPriceV2* p_VolumeAtPrice = NULL;
if (!sc.VolumeAtPriceForBars->GetVAPElementAtIndex(barIndex, VAPIndex, &p_VolumeAtPrice))
break;

if (p_VolumeAtPrice)
{
cdData.cumulativeDelta += (p_VolumeAtPrice->BidVolume - p_VolumeAtPrice->AskVolume);
}
}
}

cdData.lastTradeIndex = newTradesIndex;

// Debug
SCString debugText;
debugText.Format("Cumulative Delta: %d", cdData.cumulativeDelta);
sc.AddMessageToLog(debugText, 0);

// CD in column
SCString text;
text.Format("%d", cdData.cumulativeDelta);

s_UseTool tool;
tool.Clear();
tool.ChartNumber = sc.ChartNumber;
tool.DrawingType = DRAWING_TEXT;
tool.AddAsUserDrawnDrawing = 1;
tool.UseRelativeVerticalValues = 1;
tool.BeginDateTime = sc.BaseDateTimeIn[sc.ArraySize - 1]; // Use the last bar's datetime
tool.Text = text;
tool.Color = RGB(255, 0, 0); // Red color for visibility
tool.FontSize = 12;
tool.FontBold = true;
tool.Region = 0;
tool.TextAlignment = DT_CENTER | DT_VCENTER; // Center text
tool.AddMethod = UTAM_ADD_OR_ADJUST;

int leftCoordinate = sc.GetDOMColumnLeftCoordinate(n_ACSIL::DOM_COLUMN_GENERAL_PURPOSE_1);
int rightCoordinate = sc.GetDOMColumnRightCoordinate(n_ACSIL::DOM_COLUMN_GENERAL_PURPOSE_1);
int middleCoordinate = (leftCoordinate + rightCoordinate) / 2;

tool.BeginValue = 0;
tool.BeginDateTime = middleCoordinate; // Set the horizontal position

sc.UseTool(tool);
sc.AddMessageToLog("Text drawing tool was used to draw the delta.", 0);
}