Hello @ brawl stars online, you should consider calculating the values for the higher timeframe only when the current bar of the higher timeframe completes. Here's a snippet of how you might modify the Calculate function to ensure proper indexing and checks:
csharp public override void Calculate(int index) { if (index < 4) return;
// Higher timeframe calculations if (UseTF1) { var indexTF1 = barsTF1.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]); if (indexTF1 >= 0 && indexTF1 < barsTF1.Count) // Ensure valid index { double fixTF1 = barsTF1.HighPrices.Maximum(Len2 - 1) - barsTF1.LowPrices.Minimum(Len2 - 1); if (Math.Abs(fixTF1 - 0) < double.Epsilon) fixTF1 = 1;
// Calculate using indexTF1 iSeries1TF1[index] = 100 * (barsTF1.ClosePrices[indexTF1] - (_smaTF1.Result[indexTF1] + ... /* other SMAs for TF1 */) / 10) / fixTF1; // Additional calculations for ST2TF1, ST3TF1, etc. } else { // Handle the case where indexTF1 is out of range } } }
jeffreygrimsley450
28 Mar 2025, 01:40 ( Updated at: 01 Apr 2025, 09:36 )
Hello @ brawl stars online, you should consider calculating the values for the higher timeframe only when the current bar of the higher timeframe completes. Here's a snippet of how you might modify the Calculate function to ensure proper indexing and checks:
csharp
public override void Calculate(int index)
{
if (index < 4)
return;
// Main timeframe calculations
double fix = Bars.HighPrices.Maximum(Len2 - 1) - Bars.LowPrices.Minimum(Len2 - 1);
if (Math.Abs(fix - 0) < double.Epsilon) fix = 1;
iSeries1[index] = 100 * (Bars.ClosePrices[index] - (_sma.Result[index] + ... /* other SMAs */) / 10) / fix;
// Higher timeframe calculations
if (UseTF1)
{
var indexTF1 = barsTF1.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
if (indexTF1 >= 0 && indexTF1 < barsTF1.Count) // Ensure valid index
{
double fixTF1 = barsTF1.HighPrices.Maximum(Len2 - 1) - barsTF1.LowPrices.Minimum(Len2 - 1);
if (Math.Abs(fixTF1 - 0) < double.Epsilon) fixTF1 = 1;
// Calculate using indexTF1
iSeries1TF1[index] = 100 * (barsTF1.ClosePrices[indexTF1] - (_smaTF1.Result[indexTF1] + ... /* other SMAs for TF1 */) / 10) / fixTF1;
// Additional calculations for ST2TF1, ST3TF1, etc.
}
else
{
// Handle the case where indexTF1 is out of range
}
}
}
@jeffreygrimsley450