Login Page - Create Account

Support Board


Date/Time: Mon, 21 Apr 2025 14:14:20 +0000



Post From: ACSIL Drawings Disappear Upon Chart Reload

[2025-03-08 16:12:04]
Timmseh - Posts: 5
I'm having an issue with my ACSIL code that I can't figure out. When I first build the DLL and add it to my "Studies to Graph" list via the "Add Custom Study" button, the drawings for the pivot points I'm trying to identify show up correctly and as expected. After adding, I can hit "Save All" and exit out of the "Chart Studies" window with no issues. However, if I attempt to hit "Save All" a second time, my pivot marker drawings disappear. They also disappear when attempting to either reload the chart or kick off any chart replay (which would reload the chart).

I'm not sure what is going on that the drawings would show up initially and be correct and only disappear and have the bug appear to manifest on a second reload of the chart. The pertinent parts of the code are as follows:


// Inputs
SCInputRef Input_MinimumValidPivotPeriod = sc.Input[10];
SCInputRef Input_MarkerOffset = sc.Input[13];

// Subgraphs
SCSubgraphRef Subgraph_Ema = sc.Subgraph[0];
SCSubgraphRef Subgraph_Slope = sc.Subgraph[1];
SCSubgraphRef Subgraph_PeriodLength = sc.Subgraph[8];
SCSubgraphRef Subgraph_PivotPoint = sc.Subgraph[9];

// Constants
const int PIVOT_HIGH = 0;
const int PIVOT_LOW = 1;

// Use persistent variables to remember attached order IDs so they can be modified or canceled.
int32_t& CurrentPivotValue = sc.GetPersistentInt(10); // Stores the pivot value (either high or low) for the most recent direction trend
int32_t& CurrentPivotIndex = sc.GetPersistentInt(11); // Stores the index of the pivot value for the most recent direction trend
int32_t& LastPivotValue = sc.GetPersistentInt(12); // Stores the last pivot value for the previous direction trend
int32_t& LastPivotIndex = sc.GetPersistentInt(13); // Stores the last pivot index for the previous direction trend
int32_t& PivotType = sc.GetPersistentInt(14); // Stores the type of pivot that most recently occurred (PIVOT_HIGH or PIVOT_LOW)
int32_t& PivotDrawingNum = sc.GetPersistentInt(15); // Stores the drawing line number of the last pivot drawing in case it needs to be deleted

// Miscellaneous variables and objects
s_UseTool PivotDrawing;

// Initialize pivot tool drawing
PivotDrawing.Clear();
PivotDrawing.ChartNumber = sc.ChartNumber;
PivotDrawing.DrawingType = DRAWING_MARKER;
PivotDrawing.MarkerType = MARKER_DIAMOND;
PivotDrawing.Color = RGB(255,255,0); // Yellow
PivotDrawing.UseBarSpacingForMarkerSize = 1;

// --------------------------------------------------------------------------------
// Set study defaults
// --------------------------------------------------------------------------------
if(sc.SetDefaults)
{
// Set study name and description
sc.GraphName = "N/A for this thread";
sc.StudyDescription = "N/A for this thread";

// Set overarching study defaults based on personal preference
sc.AutoLoop = 1;
sc.AllowOnlyOneTradePerBar = true;
sc.MaximumPositionAllowed = 10;
sc.AllowMultipleEntriesInSameDirection = false;
sc.AllowOppositeEntryWithOpposingPositionOrOrders = false;
sc.SupportAttachedOrdersForTrading = true;
sc.CancelAllOrdersOnEntriesAndReversals = true;
sc.AllowEntryWithWorkingOrders = false;
sc.CancelAllWorkingOrdersOnExit = true;
sc.MaintainTradeStatisticsAndTradesData = true;
sc.GraphRegion = 0;
sc.ScaleRangeType = SCALE_SAMEASREGION;
sc.DisplayStudyName = 0;
sc.DisplayStudyInputValues = 0;

// Input: Set minimum valid pivot period defaults
Input_MinimumValidPivotPeriod.Name = "Minimum Pivot Period";
Input_MinimumValidPivotPeriod.SetInt(4);
Input_MinimumValidPivotPeriod.SetDescription("This input determines the minimum number of bars between pivot points for a pivot point to be valid.");

// Input: Set marker offset defaults
Input_MarkerOffset.Name = "Marker Offset (In Points)";
Input_MarkerOffset.SetInt(20);
Input_MarkerOffset.SetDescription("This input determines the offset of the entry and exit symbols on the chart.");

// Subgraph: Set EMA defaults
Subgraph_Ema.Name = "Exponential Moving Average 1";
Subgraph_Ema.ShortName = "EMA";
Subgraph_Ema.DrawStyle = DRAWSTYLE_LINE;
Subgraph_Ema.PrimaryColor = RGB(255,255,0); // Yellow
Subgraph_Ema.DisplayNameValueInDataLine = 0;

// Subgraph: Set slope defaults
Subgraph_Slope.Name = "Slope 1";
Subgraph_Slope.DrawStyle = DRAWSTYLE_HIDDEN;
Subgraph_Slope.PrimaryColor = RGB(0,192,0); // Darker Green
Subgraph_Slope.SecondaryColor = RGB(192,0,0); // Darker Red
Subgraph_Slope.SecondaryColorUsed = 1; // Allow use of secondary color
Subgraph_Slope.DisplayNameValueInDataLine = 1;

// Subgraph: Set period length defaults
Subgraph_PeriodLength.Name = "Dynamic Period Length";
Subgraph_PeriodLength.ShortName = "Period";
Subgraph_PeriodLength.DrawStyle = DRAWSTYLE_HIDDEN;
Subgraph_PeriodLength.PrimaryColor = RGB(0,192,0); // Darker Green
Subgraph_PeriodLength.SecondaryColor = RGB(192,0,0); // Darker Red
Subgraph_PeriodLength.SecondaryColorUsed = 1; // Allow secondary color usage
Subgraph_PeriodLength.DisplayNameValueInDataLine = 0;

// Subgraph: Set pivot location defaults
Subgraph_PivotPoint.Name = "Pivot Point";
Subgraph_PivotPoint.DrawStyle = DRAWSTYLE_HIDDEN;
Subgraph_PivotPoint.PrimaryColor = RGB(255,255,0); // Yellow
Subgraph_PivotPoint.DisplayNameValueInDataLine = 0;

return;
}

// --------------------------------------------------------------------------------
// Data processing and trade logic
// --------------------------------------------------------------------------------

// Set PeriodLength colors based on input
uint32_t PrimaryColor = RGB(0,192,0);
uint32_t SecondaryColor = RGB(192,0,0);

// Calculate values for all subgraphs
sc.ExponentialMovAvg(sc.BaseData[SC_LAST], Subgraph_Ema, Input_EmaLength.GetInt());
sc.Slope(Subgraph_Ema, Subgraph_Slope);

// --------------------------------------------------------------------------------
// Pivot tracking
// --------------------------------------------------------------------------------
if(sc.GetBarHasClosedStatus(sc.Index) == BHCS_BAR_HAS_CLOSED)
{
// EMA slope continuing to trend upward
if(Subgraph_Slope[sc.Index] >= 0 && Subgraph_Slope[sc.Index-1] >= 0)
{
// Set CurrentPivotValue and CurrentPivotIndex values if they meet the necessary conditions
if(CurrentPivotValue <= sc.BaseData[SC_HIGH][sc.Index])
{
CurrentPivotValue = sc.BaseData[SC_HIGH][sc.Index];
CurrentPivotIndex = sc.Index;
}

// Set data color appropriately
Subgraph_PeriodLength.DataColor[sc.Index] = PrimaryColor;
}
// EMA slope switching from positive to negative
else if(Subgraph_Slope[sc.Index] < 0 && Subgraph_Slope[sc.Index-1] >= 0)
{
// Only calculate new valid pivot point if the upward trend has exceeded the minimum valid pivot value
if(Subgraph_PeriodLength[CurrentPivotIndex] >= Input_MinimumValidPivotPeriod.GetInt())
{
if(PivotType == PIVOT_LOW || (PivotType == PIVOT_HIGH && CurrentPivotValue >= LastPivotValue))
{
// If a new high pivot value has presented itself without an intermediary low pivot value, delete the previous high pivot value and replace it with this one
if(PivotType == PIVOT_HIGH)
{
sc.DeleteACSChartDrawing(sc.ChartNumber, TOOL_DELETE_CHARTDRAWING, PivotDrawingNum);
}

// Set the pivot point subgraph for future tracking
Subgraph_PivotPoint[CurrentPivotIndex] = CurrentPivotValue;

// Change most recent pivot type
PivotType = PIVOT_HIGH;

// Change LastPivotValue and LastPivotIndex values
LastPivotValue = CurrentPivotValue;
LastPivotIndex = CurrentPivotIndex;

// Add pivot indicator drawing to the chart
PivotDrawing.BeginIndex = CurrentPivotIndex;
PivotDrawing.BeginValue = CurrentPivotValue + Input_MarkerOffset.GetInt();
sc.UseTool(PivotDrawing);

// Store PivotDrawing line number
PivotDrawingNum = PivotDrawing.LineNumber;
}
}

// Set new CurrentPivotValue and CurrentPivotIndex values
CurrentPivotValue = sc.BaseData[SC_LOW][sc.Index];
CurrentPivotIndex = sc.Index;

// Set data color appropriately
Subgraph_PeriodLength.DataColor[sc.Index] = SecondaryColor;
}
// EMA slope continuing to trend downward
else if(Subgraph_Slope[sc.Index] < 0 && Subgraph_Slope[sc.Index-1] < 0)
{
// Set CurrentPivotValue and CurrentPivotIndex values if they meet the necessary conditions
if(CurrentPivotValue >= sc.BaseData[SC_LOW][sc.Index])
{
CurrentPivotValue = sc.BaseData[SC_LOW][sc.Index];
CurrentPivotIndex = sc.Index;
}

// Set data color appropriately
Subgraph_PeriodLength.DataColor[sc.Index] = SecondaryColor;
}
// EMA slope switching from negative to positive
else if(Subgraph_Slope[sc.Index] >= 0 && Subgraph_Slope[sc.Index-1] < 0)
{
// Only calculate new valid pivot point if the downward trend has exceeded the minimum valid pivot value
if(Subgraph_PeriodLength[CurrentPivotIndex] >= Input_MinimumValidPivotPeriod.GetInt())
{
if(PivotType == PIVOT_HIGH || (PivotType == PIVOT_LOW && CurrentPivotValue <= LastPivotValue))
{
// If a new low pivot value has presented itself without an intermediary high pivot value, delete the previous low pivot value and replace it with this one
if(PivotType == PIVOT_LOW)
{
sc.DeleteACSChartDrawing(sc.ChartNumber, TOOL_DELETE_CHARTDRAWING, PivotDrawingNum);
}

// Set the pivot point subgraph for future tracking
Subgraph_PivotPoint[CurrentPivotIndex] = CurrentPivotValue;

// Change most recent pivot type
PivotType = PIVOT_LOW;

// Change LastPivotValue and LastPivotIndex values
LastPivotValue = CurrentPivotValue;
LastPivotIndex = CurrentPivotIndex;

// Add pivot indicator drawing to the chart
PivotDrawing.BeginIndex = CurrentPivotIndex;
PivotDrawing.BeginValue = CurrentPivotValue - Input_MarkerOffset.GetInt();
sc.UseTool(PivotDrawing);

// Store PivotDrawing line number
PivotDrawingNum = PivotDrawing.LineNumber;
}
}

// Set new CurrentPivotValue and CurrentPivotIndex values
CurrentPivotValue = sc.BaseData[SC_HIGH][sc.Index];
CurrentPivotIndex = sc.Index;

// Set data color appropriately
Subgraph_PeriodLength.DataColor[sc.Index] = PrimaryColor;
}

// Set the period length to the difference beteween the current and previous pivot points
Subgraph_PeriodLength[sc.Index] = CurrentPivotIndex - LastPivotIndex;
}

It appears that all the calculations and *PivotValue and *PivotIndex values are propagating correctly, even once the drawings disappear. I can put those values into various debug subgraphs and see that their tracking remains even once the PivotDrawing markers are gone. I'm just not sure why the PivotMarker drawings are disappearing on chart reload and not initial study load and any help here would be greatly appreciated. Thanks!
Date Time Of Last Edit: 2025-03-08 16:13:47