Login Page - Create Account

Support Board


Date/Time: Wed, 15 Jan 2025 17:35:45 +0000



Post From: Persist Variables

[2017-06-29 20:21:06]
User972044 - Posts: 154
As long as you are displaying the values properly using the proper formatting function and formatting specification, persistent variables even without expressly resetting them in a study function, are at 0 when a study is applied to a chart or the Chartbook containing the chart which contains the study, is opened.

I thought the proper formatting might be the cause too so I checked countless times already on what I did. These are the codes that I am using to display values of my persist variables Trade_PosL and Trade_PosS:

SCString Message7;
    
Message7.Format("Buy PositionData Quantity: %d TradeS_OrderQuantity: %d Trade_PosL: %d", PositionData.PositionQuantity, fabs(TradeS.OrderQuantity), Trade_PosL);  
  
sc.AddMessageToLog(Message7, 0);

SCString Message8;
    
Message8.Format("Sell PositionData Quantity: %d TradeS_OrderQuantity: %d Trade_PosS: %d", PositionData.PositionQuantity, fabs(TradeS.OrderQuantity), Trade_PosS);  
  
sc.AddMessageToLog(Message8, 0);   

I know you don't provide Programming help and I am not expecting you to. I am just posting these codes here to show you what I did. I have used the same formatting to display other data and they are all displayed fine except these two persist variables. That's why it's so baffling and I am spending the time to create a support ticket for it. If you see something that's amiss, I would appreciate it if you can point it out. If not, you can just leave them to be.

if (sc.Index == 0)

{

// When there is a full recalculation of the study,

// reset the persistent variables we are using

sc.PersistVars->Integers[0] = 0;

sc.PersistVars->Integers[1] = 0;

sc.PersistVars->Integers[2] = 0;

sc.PersistVars->Integers[3] = 0;

}

This is what I use in my codes to reset the persist variable:

if (sc.Index == 0)
{

Trade_PosL = 0;

Trade_PosS = 0;

}

Very simple codes and they worked fine all last year but for some reason not anymore for this year. I will try your suggestions to see if they work. Hopefully they do and I won't have to post here again.
Date Time Of Last Edit: 2017-06-29 20:23:06