Login Page - Create Account

Support Board


Date/Time: Tue, 07 May 2024 01:01:10 +0000



[Programming Help] - ACSIL: write to spreadsheet on a new row for each time

View Count: 588

[2020-08-22 14:15:24]
User420253 - Posts: 4
I have a logic that read a value from one spreadsheet and writes that value to another spreadsheet. However, I need a way to write to a new row for each time (now it overwrites the same cell each time).

Any suggestions to how I can write to a new row (either by a counter) or by looking for the first row with no values?

The value (source and writing) is updated each time a candle closes. Could this be used as counter?


This is my code for reading and writing (for reference):

// Get the value from cell A4 (if it exists) and write to cell B2 in other sheet:
double CellValueA4 = 0.00;
if (sc.GetSheetCellAsDouble(SheetHandle1, 0, 3, CellValueA4))
sc.SetSheetCellAsDouble(SheetHandle2, 1, 1, CellValueA4);

Date Time Of Last Edit: 2020-08-22 16:44:31
[2020-08-22 16:44:16]
User420253 - Posts: 4
I have an IF-function that updates (read and write) the cells every time a candle is closed. So I tried adding a counter to make it increase the row number for each iteration:

int Row = 1;

// IF function when candle closed:
{
// Get the value from cell A4 (if it exists) and write to cell B2 in other sheet:
double CellValueA4 = 0.00;
if (sc.GetSheetCellAsDouble(SheetHandle1, 0, 3, CellValueA4))
sc.SetSheetCellAsDouble(SheetHandle2, 1, 'Row', CellValueA4);

Row = Row + 1;
}

But I get this error when compiling:
warning: multi-character character constant [-Wmultichar]

Any takes?
[2020-08-26 00:11:02]
enemyspy - Posts: 304
This is a few days stale now, but in case you didn't already figure it out. 'Row' is not the int Row variable that you declared at top. It is the multichar constant 'Row' as the warning indicates remove the single quotes.

Also I don't know the Scope for int Row = 1. But in order for that to work it would need to be outside the scope of your study function. Or defined as a persistent variable (explained in acsil docs) or it will keep overwriting to 1 at every update interval.

try this:

//Persistent Int will be held in memory so that you don't have to Use it as a global in your DLL.
int& Row = sc.GetPersistentIntFast(0);
//You can specify different initialisation logic in this if statement if you want.
if (sc.Index == 0){
Row = 1;
}
// IF function when candle closed:

{

// Get the value from cell A4 (if it exists) and write to cell B2 in other sheet:

double CellValueA4 = 0.00;

if (sc.GetSheetCellAsDouble(SheetHandle1, 0, 3, CellValueA4))

sc.SetSheetCellAsDouble(SheetHandle2, 1, Row, CellValueA4);
Row++;

}

Date Time Of Last Edit: 2020-08-26 00:32:41
[2020-08-26 00:29:42]
enemyspy - Posts: 304
Oh actually the row = 1 part needs to be:
//Replace the logic in this if statement to initialize the row counter only when your requirements for intialization are met. Commonly the first index of the base_data/subgraphs as is below presently
if(sc.Index == 0){
Row = 1
}

Date Time Of Last Edit: 2020-08-26 00:30:36

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

Login

Login Page - Create Account