Support Board
Date/Time: Sat, 08 Feb 2025 05:59:10 +0000
[Programming Help] - Count set to 0 every tick
View Count: 706
[2020-06-17 09:43:05] |
gfx2trade - Posts: 48 |
Hi, I want to use a counter in my studiy so that the order generation only starts after a few bars. I use a count with ... int periodCount;
and then if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED) {
ServiceLogStr = ""; ServiceLogStr.Format(" # of period since start up : %i", periodCount ); sc.AddMessageToTradeServiceLog(ServiceLogStr, 0); periodCount ++; ServiceLogStr.Format(" # of period since start up : %i", periodCount ); sc.AddMessageToTradeServiceLog(ServiceLogStr, 0); } issue it that periodCount gets reset to 0 a every tick. Therefore it never exceeds 1. Can you please help ? Thks |
[2020-06-17 12:41:53] |
Ackin - Posts: 1865 |
periodCount++; //without space and next Do you use autolooping? If not, you are missing the index in parentheses if (sc.GetBarHasClosedStatus(Index) == BHCS_BAR_HAS_CLOSED) { |
[2020-06-22 15:26:43] |
gfx2trade - Posts: 48 |
hello, thks for helping. I do have sc.AutoLoop = 1;
and ... // ************************************************************************************************************* // Data Processing // ************************************************************************************************************* if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED) { ServiceLogStr = ""; ServiceLogStr.Format(" # of period since start up : %i", periodCount ); sc.AddMessageToTradeServiceLog(ServiceLogStr, 0); periodCount++; ServiceLogStr.Format(" # of period since start up : %i", periodCount ); sc.AddMessageToTradeServiceLog(ServiceLogStr, 0); } if (periodCount < 10) { ServiceLogStr.Format(" Period count is lower than 10 : %i", periodCount ); sc.AddMessageToTradeServiceLog(ServiceLogStr, 0); periodCount++; ServiceLogStr.Format(" After ++ Period count is lower than 10 : %i", periodCount ); sc.AddMessageToTradeServiceLog(ServiceLogStr, 0); IsTradeAllowed = false; sc.AddMessageToTradeServiceLog("-------------------- Pending further market data prior to activation --------------------", 0); // return; } In the end ... result is ... # of period since start up : 0 | 2020-06-22 17:23:01.264 # of period since start up : 1 | 2020-06-22 17:23:01.264 Period count is lower than 10 : 1 | 2020-06-22 17:23:01.264 After ++ Period count is lower than 10 : 2 | 2020-06-22 17:23:01.264 -------------------- Pending further market data prior to activation -------------------- | 2020-06-22 17:23:01.264 Period count is lower than 10 : 1 | 2020-06-22 17:23:01.264 After ++ Period count is lower than 10 : 2 | 2020-06-22 17:23:01.264 -------------------- Pending further market data prior to activation -------------------- | 2020-06-22 17:23:01.264 Period count is lower than 10 : 0 | 2020-06-22 17:23:01.440 After ++ Period count is lower than 10 : 1 | 2020-06-22 17:23:01.440 -------------------- Pending further market data prior to activation -------------------- | 2020-06-22 17:23:01.440 Period count is lower than 10 : 0 | 2020-06-22 17:23:03.258 After ++ Period count is lower than 10 : 1 | 2020-06-22 17:23:03.258 -------------------- Pending further market data prior to activation -------------------- | 2020-06-22 17:23:03.258 Period count is lower than 10 : 0 | 2020-06-22 17:23:03.493 After ++ Period count is lower than 10 : 1 | 2020-06-22 17:23:03.493 -------------------- Pending further market data prior to activation -------------------- | 2020-06-22 17:23:03.493 it is like it is reset to 0 @ eack new tick. definition is ... int periodCount; // Gestion d'un seuil minimum de bar avant activation.
it is outside if (sc.SetDefaults)
if inside, I get the following error message . 'error: 'periodCount' was not declared in this scope' |
[2020-06-22 15:51:03] |
User907968 - Posts: 826 |
it is like it is reset to 0 @ eack new tick.
Each time the function is called, your variable 'periodCount' will be uninitialised i.e. have no value set. Read this to understand when the function is called using automatic looping: Working with ACSIL Arrays and Understanding Looping If you want the variable to retain its value between calls to the function, there are the persistent variable functions available: Persistent Variable Functions |
[2020-06-23 10:41:20] |
gfx2trade - Posts: 48 |
I'll have a look.
|
[2020-06-24 16:09:37] |
gfx2trade - Posts: 48 |
Thks. I could not find in the documentation the persistent variable for boolean. Does it exists ? |
[2020-06-24 17:20:43] |
User907968 - Posts: 826 |
You could use sc.GetPersistentInt false = 0 true = 1 (non-zero) |
[2020-06-25 06:28:38] |
gfx2trade - Posts: 48 |
Nice work around. Does it mean that there is no native solution to keep a boolean value tick after tick ?
|
To post a message in this thread, you need to log in with your Sierra Chart account: