I have a very complicated indicator, but I've boiled down my problem to a simple example.
I want to update a string in the following code and have it preserve its value throughout the various scopes, unless it is being updated,
then I want it to keep the updated value. In order words to work like a double does, but with text:
private string currentDayValue = ""; // Declare the variable at the class level
void OnBarUpdate()
{
if (Time[0].TimeOfDay == new TimeSpan(8, 0, 0))
{
currentDayValue = "Morning value"; // Change the value for morning
}
// Access the currentDayValue based on the set time ranges
if (Time[0].TimeOfDay > new TimeSpan(8, 0, 0) && Time[0].TimeOfDay <= new TimeSpan(12, 0, 0))
{
// Code that needs to remember that the string was set to at 8am is currently "Morning value".
// I can set a double outside the scope and it will retain the value, but strings don't work like that.
// Is there any way to get around this?
}
else if (Time[0].TimeOfDay == new TimeSpan(18, 0, 0))
{
currentDayValue = "Evening value"; // Change the value for evening
}
else if (Time[0].TimeOfDay > new TimeSpan(18, 0, 0) && Time[0].TimeOfDay <= new TimeSpan(22, 0, 0))
{
// Code that needs to remember that the string was set to at 6pm which is "Evening value".
}

Comment