Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Backtesting problem with GetBars

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Strategy Backtesting problem with GetBars

    Hello everybody,
    I noticed a very strange behavior of the getbars function during the backtest, (in reality it works very well)​
    this is my function

    protected double ValoreMassimoRange()
    {
    double MassimoRange = 0;
    try
    {

    if (Time[0].TimeOfDay >= Calcolo_Range_Fino.TimeOfDay)
    {
    WriteToFile("Start date " + Calcolo_Range_Da.TimeOfDay.ToString(), @"C:\temp" + Instrument.FullName + ".log");
    WriteToFile("End date " + Calcolo_Range_Fino.TimeOfDay.ToString(), @"C:\temp" + Instrument.FullName + ".log");
    int BarraInizio = Bars.GetBar(Calcolo_Range_Da);
    WriteToFile("Index Start " + BarraInizio.ToString(), @"C:\temp" + Instrument.FullName + ".log");
    int BarraFine = Bars.GetBar(Calcolo_Range_Fino);
    WriteToFile("Index End " + BarraFine.ToString(), @"C:\temp" + Instrument.FullName + ".log");
    int barrafine = CurrentBar - BarraFine;
    int barrainizio = CurrentBar - BarraInizio;
    int barre = BarraFine - BarraInizio + 1;
    MassimoRange = MAX(High, barre)[barrafine];
    }

    }
    catch (Exception e)
    {
    return MassimoRange;
    }
    return MassimoRange;
    }​

    The problem is that StartBar and EndBar i got always the same index

    This is a part of log result of WriteToFile:

    Start date 15:30:00
    End date 15:45:00
    Index Start 1308 (int BarraInizio = Bars.GetBar(Calcolo_Range_Da)
    Index End 1308​ (int BarraFine = Bars.GetBar(Calcolo_Range_Fino)


    Could you help me to find a solution?

    Best regards

    #2
    Hello termi_80,

    Bars represents the primary series, this could relate to the series used. What series is the primary?

    Comment


      #3
      I solved the problem, thanks the same

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      21 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      30 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      50 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Working...
      X