Login Page - Create Account

Support Board


Date/Time: Sun, 04 Dec 2022 22:00:02 +0000



[Programming Help] - Buy Alert is trigerred accurately via spreadsheet but not via ASCIL

View Count: 94

[2022-09-28 23:19:40]
kam2001 - Posts: 57
Hi,
i am trying to get refernce to Buy alert in my Ascil code.
My spreadsheet buy alert values changes during the bar time frame so I've set it to 'Alert only once per Bar' and 'Signal only on Bar close' which works perfectly via spreadsheet settings but when i am using this spreadsheet by reference in the code below it triggers my if condition but the alert is still changeable during bar period as bar is not closed yet. I am already using GetBarHasClosedStatus method.
Any suggestions. Thanks

const char *SheetCollectionName = "my-alerts";

const char *SheetName = "Sheet2";

void *SheetHandle = sc.GetSpreadsheetSheetHandleByName(SheetCollectionName, SheetName, false);

SCString CellString;
SCString MessageOut;
double CellValue = 0.0;

int status = sc.GetBarHasClosedStatus(sc.UpdateStartIndex);
if (status == BHCS_BAR_HAS_CLOSED) {
if (SheetHandle == nullptr) {
// sc.AddMessageToLog("No Spreadsheet...", 0);
// some code for no spreadsheet

} else {
if (sc.GetSheetCellAsDouble(SheetHandle, 11, 2, CellValue)) {
if (CellValue > 0.0) {
sc.AddMessageToLog("Bar Has Closed", true);
sc.AddMessageToLog("Show Alert Here", 0);
MessageOut.Format("Cell Value = %f", CellValue);
sc.AddMessageToLog(MessageOut, 0);
sc.Subgraph[0][sc.Index] = 100;
}
}
// some different code for spreadsheet found
}
}

[2022-09-29 08:09:33]
User431178 - Posts: 161
Change this

int status = sc.GetBarHasClosedStatus(sc.UpdateStartIndex);

to

int status = sc.GetBarHasClosedStatus();

[2022-09-29 16:12:33]
kam2001 - Posts: 57
Thanks for looking into it, but making the change as suggested has not worked.
Bar has closed but the cell value is not greater than 0 but it's still going inside 'If statement' and logging message 'Show alert here' as per code changed below.

const char *SheetCollectionName = "my-alerts";

const char *SheetName = "Sheet2";

void *SheetHandle = sc.GetSpreadsheetSheetHandleByName(SheetCollectionName, SheetName, false);

SCString CellString;
SCString MessageOut;
double CellValue = 0.0;

int status = sc.GetBarHasClosedStatus();
if(status == BHCS_BAR_HAS_CLOSED){
if (SheetHandle == nullptr) {
// sc.AddMessageToLog("Nope...", 0);
// some code for no spreadsheet

} else {
if (sc.GetSheetCellAsDouble(SheetHandle, 10, 2, CellValue)) {
if (CellValue > 0.0) {
sc.AddMessageToLog("Bar Has Closed", true);
sc.AddMessageToLog("Show Alert Here", 0);
MessageOut.Format("Cell Value = %f", CellValue);
sc.AddMessageToLog(MessageOut, 0);
sc.Subgraph[0][sc.Index] = 100;
}

// sc.AddMessageToLog(CellString, 0);
// sc.AddMessageToLog(CellString, 0);
}
// some different code for spreadsheet found
}
}

Date Time Of Last Edit: 2022-09-29 16:15:37
[2022-09-29 17:04:35]
User431178 - Posts: 161
Try attaching a debugger and see what the value read from the spreadsheet actually is.
If the logging code block is being executed then the value read must be greater than zero, there is no other explanation.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account