#include "sierrachart.h"
SCDLLName("SpreadsheetTest")
static int rowIndex = 1;
SCSFExport scsf_SpreadsheetTest(SCStudyInterfaceRef sc)
{
SCSubgraphRef Subgraph_SignalState = sc.Subgraph[0];
SCSubgraphRef Subgraph_FormulaResult = sc.Subgraph[0];
SCInputRef Input_LongSignalSelection = sc.Input[0];
SCInputRef Input_ShortSignalSelection = sc.Input[1];
SCInputRef Input_240StnAngle = sc.Input[3];
SCInputRef Input_CurrentTime = sc.Input[4];
if (sc.SetDefaults)
{
sc.GraphName = "Spreadsheet Test 1";
sc.AutoLoop = 0;
Input_LongSignalSelection.Name = "Select Long Signal";
Input_LongSignalSelection.SetChartStudySubgraphValues(17, 67, 0);
Input_ShortSignalSelection.Name = "Select Short Signal";
Input_ShortSignalSelection.SetChartStudySubgraphValues(17, 68, 0);
Input_240StnAngle.Name = "240 STN Val";
Input_240StnAngle.SetChartStudySubgraphValues(17, 74, 0);
Input_CurrentTime.Name = "Current Timme";
Subgraph_FormulaResult.Name = "Formula Result";
Subgraph_FormulaResult.DrawZeros = true;
return;
}
int Year, Month, Day, Hour, Minute, Second;
SCDateTime currentDateTime = sc.GetCurrentDateTime();
currentDateTime.GetDateTimeYMDHMS(Year, Month, Day, Hour, Minute, Second);
char formattedDateTime[20];
snprintf(formattedDateTime, sizeof(formattedDateTime), "%04d-%02d-%02d %02d:%02d:%02d",
Year, Month, Day, Hour, Minute, Second);
sc.AddMessageToLog(formattedDateTime, 1);
SCFloatArray stn240Array;
sc.GetStudyArrayUsingID(Input_240StnAngle.GetStudyID(), Input_240StnAngle.GetSubgraphIndex(), stn240Array);
SCFloatArray LongSignalArray;
sc.GetStudyArrayUsingID(Input_LongSignalSelection.GetStudyID(), Input_LongSignalSelection.GetSubgraphIndex(), LongSignalArray);
SCFloatArray ShortSignalArray;
sc.GetStudyArrayUsingID(Input_ShortSignalSelection.GetStudyID(), Input_ShortSignalSelection.GetSubgraphIndex(), ShortSignalArray);
bool LongAlert = LongSignalArray[sc.Index];
bool ShortAlert = ShortSignalArray[sc.Index];
const char* SheetCollectionName = "Test One.scss";
const char* SheetName = "Test One";
void* SheetHandle = sc.GetSpreadsheetSheetHandleByName(SheetCollectionName, SheetName, true);
if ((LongAlert || ShortAlert) && Subgraph_SignalState[sc.Index] == 0)
{
sc.AddMessageToLog("Long Or Signal Condition is TRUE", 1);
sc.SetSheetCellAsDouble(SheetHandle, 7, rowIndex, stn240Array[sc.Index]);
float currentValue;
currentValue = stn240Array[sc.Index];
bool success = sc.SetSheetCellAsDouble(SheetHandle, 7, rowIndex, currentValue);
Subgraph_FormulaResult[sc.Index] = static_cast<float>(currentValue);
if(success && rowIndex > 65535)
{
rowIndex++;
}
if (success)
{
sc.AddMessageToLog("Value written to spreadsheet successfully", 1);
}
else
{
sc.AddMessageToLog("Error writing value to spreadsheet", 1);
}
char logMessage[64];
snprintf(logMessage, sizeof(logMessage), "Current Value: %lf", currentValue);
sc.AddMessageToLog(logMessage, 1);
}
return;
}
/*==========================================================================*/
I am trying to study data relative to my backtest replay and dump data to a spreadsheet when the long short condtion is true. I have the alert condtin built on the the front end of math framwoork UI and essstialy grabing the signal from there. Whcih all works corretly. This is a subgraph i am grabing and trying to dumpo to the spreadhseet 240stnAngle. Whcih also works corectly. All the code compiles and works correctly. I have a log I can dump all the code outcome to to see its functnality exectuion and everything is working correctly. The only issue is when when i start a reply the signal tirggers and dumps a value into column 7, row 2 correctly in the right time but then the next time the alert tirggers it puts the value in the same spot and not sure how to get it to itterate through. So the frist alert will go into 7,2 and then when the next alert triggers, i need to puch the first value to 7,3 and the second one will go into 7,2 and so on? I am not quite sure how to build this iteration?