Login Page - Create Account

Support Board


Date/Time: Fri, 18 Oct 2024 06:15:20 +0000



Post From: Custom Study Trade DOM

[2024-07-20 13:16:09]
User357489 - Posts: 68
Hi SC

I'm looking to make a study for the trade Dom that highlights prices where the pulling/stacking column values on the bid and ask have values >=100, with the option for the user to input as many price levels as needed. Please see below my current attempt, with screenshots of the graphic output, however I'm at a loss as to why it's not actually functioning as intended, so seeking some help
#include "sierrachart.h"

SCDLLName("Custom DOM Study");

// Define the study function
SCSFExport scsf_CustomDOMStudy(SCStudyInterfaceRef sc)
{
// Initialization
if (sc.SetDefaults)
{
sc.GraphName = "Custom DOM Highlighting Study";
sc.StudyDescription = "Highlights prices in the DOM based on bid/ask volume conditions in pulling/stacking columns.";
sc.AutoLoop = 1; // Auto-loop enabled

// Define subgraphs for bid and ask highlights
sc.Subgraph[0].Name = "Bid Highlighted Prices";
sc.Subgraph[0].PrimaryColor = RGB(0, 255, 0); // Green for bid
sc.Subgraph[0].DrawStyle = DRAWSTYLE_TEXT; // Use DRAWSTYLE_TEXT to color text
sc.Subgraph[0].LineWidth = 2;

sc.Subgraph[1].Name = "Ask Highlighted Prices";
sc.Subgraph[1].PrimaryColor = RGB(255, 0, 0); // Red for ask
sc.Subgraph[1].DrawStyle = DRAWSTYLE_TEXT; // Use DRAWSTYLE_TEXT to color text
sc.Subgraph[1].LineWidth = 2;

// Input for volume threshold
sc.Input[0].Name = "Volume Threshold";
sc.Input[0].SetInt(100); // Default threshold value

// Input for number of levels to consider
sc.Input[1].Name = "Number of Levels";
sc.Input[1].SetInt(5); // Default number of levels

return;
}

// Main calculation
int threshold = sc.Input[0].GetInt();
int numLevels = sc.Input[1].GetInt();

// Ensure we have market depth data
if (sc.UpdateStartIndex == 0)
{
// Initialize the subgraph to default values
for (int i = 0; i < sc.ArraySize; ++i)
{
sc.Subgraph[0][i] = 0.0;
sc.Subgraph[1][i] = 0.0;
}
}

s_MarketDepthEntry depthEntry;

// Loop through market depth data for ask and bid sides
for (int level = 0; level < numLevels; ++level)
{
// Ask side
if (sc.GetAskMarketDepthEntryAtLevel(depthEntry, level))
{
int askVolume = depthEntry.Quantity;
float askPrice = depthEntry.Price;

// Check if ask volume is greater than or equal to threshold
if (askVolume >= threshold)
{
// Highlight ask price in the subgraph
for (int i = sc.UpdateStartIndex; i < sc.ArraySize; ++i)
{
if (sc.BaseData[SC_LAST][i] == askPrice)
{
sc.Subgraph[1][i] = askPrice; // Highlight ask price
}
}
}
}

// Bid side
if (sc.GetBidMarketDepthEntryAtLevel(depthEntry, level))
{
int bidVolume = depthEntry.Quantity;
float bidPrice = depthEntry.Price;

// Check if bid volume is greater than or equal to threshold
if (bidVolume >= threshold)
{
// Highlight bid price in the subgraph
for (int i = sc.UpdateStartIndex; i < sc.ArraySize; ++i)
{
if (sc.BaseData[SC_LAST][i] == bidPrice)
{
sc.Subgraph[0][i] = bidPrice; // Highlight bid price
}
}
}
}
}
}

Appreciate anyone time and suggestions in advance.
imageimage.png / V - Attached On 2024-07-20 13:14:51 UTC - Size: 48.9 KB - 42 views
imageimage.png / V - Attached On 2024-07-20 13:15:05 UTC - Size: 33.54 KB - 36 views