#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_StartTimeForAllowedTimeRange = sc.Input[0];
SCInputRef Input_EndTimeForAllowedTimeRange = sc.Input[1];
SCInputRef Input_LongSignalSelection = sc.Input[2];
SCInputRef Input_ShortSignalSelection = sc.Input[3];
SCInputRef Input_CurrentTime = sc.Input[4];
SCInputRef Input_240StnAngle = sc.Input[5];
SCInputRef Input_DayStnValue = sc.Input[6];
SCInputRef Input_720StnValue = sc.Input[7];
SCInputRef Input_720DayAtrValue = sc.Input[8];
SCInputRef Input_720WeekAtrValue = sc.Input[9];
SCInputRef Input_DayDayAtrValue = sc.Input[10];
SCInputRef Input_DayWeekAtrValue = sc.Input[11];
SCInputRef Input_60TickValue = sc.Input[12];
SCInputRef Input_240TickValue = sc.Input[13];
SCInputRef Input_DayTickValue = sc.Input[14];
/////////////////////////////////////////
if (sc.SetDefaults)
{
sc.GraphName = "Spreadsheet Test 1";
sc.AutoLoop = 0;
Input_StartTimeForAllowedTimeRange.Name = "Start Time For Allowed Time Range";
Input_StartTimeForAllowedTimeRange.SetTime(HMS_TIME(21, 00, 00));
Input_EndTimeForAllowedTimeRange.Name = "End Time For Allowed Time Range";
Input_EndTimeForAllowedTimeRange.SetTime(HMS_TIME(15, 00, 00));
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";
Input_240StnAngle.SetChartStudySubgraphValues(17, 74, 0);
Input_DayStnValue.Name = "Day STN";
Input_DayStnValue.SetChartStudySubgraphValues(17, 73, 0);
Input_720StnValue.Name = "720 STN";
Input_720StnValue.SetChartStudySubgraphValues(17, 75, 0);
Input_720DayAtrValue.Name = "720 Day Atr";
Input_720DayAtrValue.SetChartStudySubgraphValues(17, 76, 0);
Input_720WeekAtrValue.Name = "720 Week Atr";
Input_720WeekAtrValue.SetChartStudySubgraphValues(17, 77, 0);
Input_DayDayAtrValue.Name = "Day Day Atr";
Input_DayDayAtrValue.SetChartStudySubgraphValues(17, 78, 0);
Input_DayWeekAtrValue.Name = "Day Week Atr";
Input_DayWeekAtrValue.SetChartStudySubgraphValues(17, 79, 0);
Input_60TickValue.Name = "Day Day Atr";
Input_60TickValue.SetChartStudySubgraphValues(17, 80, 0);
Input_240TickValue.Name = "240 Tick";
Input_240TickValue.SetChartStudySubgraphValues(17, 81, 0);
Input_DayTickValue.Name = "240 Tick";
Input_DayTickValue.SetChartStudySubgraphValues(17, 82, 0);
////////////////////////////////////////////////////////////////////////////
Input_CurrentTime.Name = "Current Timme";
Subgraph_FormulaResult.Name = "Formula Result";
Subgraph_FormulaResult.DrawZeros = true;
return;
}
//creating current time output
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);
float dayHighClose = sc.BaseData[SC_HIGH][sc.Index];
float dayLowClose = sc.BaseData[SC_LOW][sc.Index];
/// log low value
char lowLogMessage[64];
snprintf(lowLogMessage, sizeof(lowLogMessage), "Low of day: %f", dayLowClose);
sc.AddMessageToLog(lowLogMessage, 1);
// Log the high value
char highLogMessage[64];
snprintf(highLogMessage, sizeof(highLogMessage), "High of day: %f", dayHighClose);
sc.AddMessageToLog(highLogMessage, 1);
SCString symbol = sc.Symbol;
float currentPrice = sc.Close[sc.Index];
float pirceDiffUp = currentPrice - dayHighClose;
float priceDiffDown = currentPrice - dayLowClose;
float tempPriceDiffUp = 0.0;
float tempPriceDiffDown = 0.0;
//Create arrays for all the inputs
SCFloatArray stn240Array;
sc.GetStudyArrayUsingID(Input_240StnAngle.GetStudyID(), Input_240StnAngle.GetSubgraphIndex(), stn240Array);
SCFloatArray dayStnValArray;
sc.GetStudyArrayUsingID(Input_DayStnValue.GetStudyID(), Input_DayStnValue.GetSubgraphIndex(), dayStnValArray);
SCFloatArray Stn720ValArray;
sc.GetStudyArrayUsingID(Input_720StnValue.GetStudyID(), Input_720StnValue.GetSubgraphIndex(), Stn720ValArray);
SCFloatArray Stn720DayAtrValArray;
sc.GetStudyArrayUsingID(Input_720DayAtrValue.GetStudyID(), Input_720DayAtrValue.GetSubgraphIndex(), Stn720DayAtrValArray);
SCFloatArray Stn720WeekAtrValArray;
sc.GetStudyArrayUsingID(Input_720WeekAtrValue.GetStudyID(), Input_720WeekAtrValue.GetSubgraphIndex(), Stn720WeekAtrValArray);
SCFloatArray DayDayAtrValArray;
sc.GetStudyArrayUsingID(Input_DayDayAtrValue.GetStudyID(), Input_DayDayAtrValue.GetSubgraphIndex(), DayDayAtrValArray);
SCFloatArray DayWeekAtrValArray;
sc.GetStudyArrayUsingID(Input_DayWeekAtrValue.GetStudyID(), Input_DayWeekAtrValue.GetSubgraphIndex(), DayWeekAtrValArray);
SCFloatArray Tick60ValArray;
sc.GetStudyArrayUsingID(Input_60TickValue.GetStudyID(), Input_60TickValue.GetSubgraphIndex(), Tick60ValArray);
SCFloatArray Tick240ValArray;
sc.GetStudyArrayUsingID(Input_240TickValue.GetStudyID(), Input_240TickValue.GetSubgraphIndex(), Tick240ValArray);
SCFloatArray TickDayValArray;
sc.GetStudyArrayUsingID(Input_DayTickValue.GetStudyID(), Input_DayTickValue.GetSubgraphIndex(), TickDayValArray);
// Long Short arrays and Bool
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];
// Calling the spreasheet name and handle. Must be saved to how its saved in the .cpp file extension as collectoin name
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);
tempPriceDiffUp = currentPrice - dayHighClose;
tempPriceDiffDown = currentPrice - dayLowClose;
// Update the spreadsheet with the calculated values
if (LongAlert)
{
sc.SetSheetCellAsDouble(SheetHandle, 3, rowIndex, tempPriceDiffUp);
}
else if (ShortAlert)
{
This query has been addressed here.