- ago
I'm tring to create a model combine two history scale (daily and minute), and it raises my an eror: "execute exeption (symbol,2) index was out of range. must be non-negative and less than size of the collction (parameter index)".


this is the code in the prior loop, where i created the daily scale (the model setting is on minutes) :

CODE:
//create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) { DailyBarsT = new BarHistory("day",HistoryScale.Daily); DailyBarsT = BarHistoryCompressor.ToDaily(bars); DailyBars1 = new BarHistory("daily", HistoryScale.Daily); DailyBars1 = BarHistorySynchronizer.Synchronize(DailyBarsT, bars); indicator1 = new ROC(DailyBars1.Close,1); StartIndex = 2; }



thanks!
0
403
10 Replies

Reply

Bookmark

Sort
Glitch8
 ( 12.10% )
- ago
#1
The code you provided compiles and runs fine for me. If you want help with an error you need to provide the full code, otherwise it's impossible to guess what is going on.
CODE:
using Quantacula.Backtest; using System; using Quantacula.Core; using Quantacula.Indicators; using System.Drawing; using System.Collections.Generic; namespace Quantacula { public class MyModel1 : UserModelBase {       private BarHistory DailyBarsT;       private BarHistory DailyBars1;       private ROC indicator1;           public override void Initialize(BarHistory bars)       {          DailyBarsT = new BarHistory("day", HistoryScale.Daily);          DailyBarsT = BarHistoryCompressor.ToDaily(bars);          DailyBars1 = new BarHistory("daily", HistoryScale.Daily);          DailyBars1 = BarHistorySynchronizer.Synchronize(DailyBarsT, bars);          indicator1 = new ROC(DailyBars1.Close, 1);          StartIndex = 2;       } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } } //declare private variables below } }
0
- ago
#2
this is the full code:

CODE:
using Quantacula.Backtest; using System; using Quantacula.Core; using Quantacula.Indicators; using System.Drawing; using System.Collections.Generic; namespace Quantacula { public class MyModel2 : UserModelBase {       private BarHistory DailyBarsT;       private BarHistory DailyBars1;       private ROC indicator1;     //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {     DailyBarsT = new BarHistory("day",HistoryScale.Daily);          DailyBarsT = BarHistoryCompressor.ToDaily(bars);          DailyBars1 = new BarHistory("daily", HistoryScale.Daily);          DailyBars1 = BarHistorySynchronizer.Synchronize(DailyBarsT, bars);          indicator1 = new ROC(DailyBars1.Close,1);              StartIndex = 2; } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) {          if ((!HasOpenPosition(bars, PositionType.Long)) && (!HasOpenPosition(bars, PositionType.Short)))          {             Position = true;          }          else          {             Position = false;          }          if (indicator1[idx - 1] > 0)          {             GreenOrRed = true;          }          else          {             GreenOrRed = false;          } //open position condition //above green          if (bars.IsFirstBarOfDay(idx))          {             if (bars.Open[idx] > (DailyBars1.Close[idx - 1] + (DailyBars1.Close[idx - 1] / 100) * 2) && bars.Open[idx] < (DailyBars1.Close[idx - 1] + (DailyBars1.Close[idx - 1] / 100) * 6) && GreenOrRed)             {                GapAboveGreen = bars.Open[idx] - DailyBars1.Close[idx - 1];                PlaceTrade(bars, TransactionType.Short, OrderType.Market, 0, 0);             }             AboveGreen = true;          }          //below green          if (bars.IsFirstBarOfDay(idx))          {             if (bars.Open[idx] < (DailyBars1.Open[idx - 1] + (DailyBars1.Open[idx - 1] / 100) * 2) && bars.Open[idx] > (DailyBars1.Open[idx - 1] + (DailyBars1.Open[idx - 1] / 100) * 6) && GreenOrRed)             {                GapBelowGreen = DailyBars1.Open[idx-1] - bars.Open[idx];                PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, 0);             }             BelowGreen = true;          }          // above red          if (bars.IsFirstBarOfDay(idx))          {             if (bars.Open[idx] > (DailyBars1.Open[idx - 1] + (DailyBars1.Open[idx - 1] / 100) * 2) && bars.Open[idx] < (DailyBars1.Open[idx - 1] + (DailyBars1.Open[idx - 1] / 100) * 6) && GreenOrRed == false)             {                GapAboveRed = bars.Open[idx] - DailyBars1.Open[idx-1];                PlaceTrade(bars, TransactionType.Short, OrderType.Market, 0, 0);             }             AboveRed = true;          }          //below red          if (bars.IsFirstBarOfDay(idx))          {             if (bars.Open[idx] < (DailyBars1.Close[idx - 1] + (DailyBars1.Close[idx - 1] / 100) * 2) && bars.Open[idx] > (DailyBars1.Close[idx - 1] + (DailyBars1.Close[idx - 1] / 100) * 6) && GreenOrRed == false)             {                GapBlowRed = DailyBars1.Close[idx-1] - bars.Open[idx];                PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, 0);             }             BelowRed = true;          }         //close position condition        if(AboveGreen)        {             if (bars.Open[idx] < (DailyBars1.Close[idx - 1] + ((GapBelowGreen / 100) * 80)))             {                PlaceTrade(bars, TransactionType.Cover, OrderType.Market, 0, 0);                AboveGreen = false;             }                     }     else if (BelowGreen)        {             if (bars.Open[idx] > (DailyBars1.Open[idx - 1] - (( GapBelowGreen / 100) * 80)))             {                PlaceTrade(bars, TransactionType.Sell, OrderType.Market, 0, 0);                BelowGreen = false;             }        }     else if (AboveRed)    {             if (bars.Open[idx] < (DailyBars1.Open[idx - 1] + (( GapAboveRed / 100) * 80)))             {                PlaceTrade(bars, TransactionType.Cover, OrderType.Market, 0, 0);                AboveRed = false;             }        }     else if (BelowRed)    {             if (bars.Open[idx] > (DailyBars1.Close[idx - 1] - (( GapBlowRed / 100) * 80)))             {                PlaceTrade(bars, TransactionType.Sell, OrderType.Market, 0, 0);                BelowRed = false;             }        }       }       //declare private variables below       private bool Position;     private bool AboveGreen;     private bool BelowGreen;     private bool AboveRed;     private bool BelowRed;       private bool GreenOrRed;       private double GapAboveGreen;     private double GapBelowGreen;     private double GapAboveRed;     private double GapBlowRed;    } }
0
Glitch8
 ( 12.10% )
- ago
#3
I'm not getting any errors. I ran this on a few single symbols, and then the WealthData Dow 30. What data are you running this on and what is the backtest range?
0
- ago
#4
back test range- 5 days
i tried to run this on AlphaVantage, but also tried QS and Yahoofinance

0
Glitch8
 ( 12.10% )
- ago
#5
5 days?? what scale were you using?
0
- ago
#6
I using 1 min scale, its on 5 days because i want to minimize data errors and know if my code working. then i will buy some data sources to optimize and full backtest
0
- ago
#7
Do you have any idea what could be the source of the problem?
It raises me another error now, maybe it helps to understand ..


0
Glitch8
 ( 12.10% )
- ago
#8
QData and WealthData do not offer intraday data. I guess that leaves AlphaVantage, which has serious limitations. Can you intraday charts for the symbols you are trying to backtest?
0
- ago
#9
It worked for me on a simple model I just created, but it still raises me the error even though it ran.
which data source do you recommend me to use?
0
Glitch8
 ( 12.10% )
- ago
#10
I would say IQFeed but we made so many improvements to the IQFeed adapter during the time after QS development stopped. If you have access to any ASCII intraday data that could be a source for QS.
0

Reply

Bookmark

Sort