- ago
ext_gspc_hist = GetHistory(bars,"^GSPC")
gspc_sma_ = SMA.Series(ext_gspc_hist.Close,60)

CODE:
if (ext_gspc_hist.Close[idx] > gspc_sma_[idx])             {                b_mkt_cond_1_bool = 1;             }


Throws the above error.

The strategy settings are for all data avaiable and GSPC is from 1927 (although OHLC data is availbale from later)

I am running on the Yahoo - Nasdaq dataset which is 4192 symbols.
It plots (PlotHistory(ext_gspc_hist,"GSPC")) fine so I assume the program is picking up the data correctly.

I don't understand why I am getting the error when I run the backtest.

Thank you in advance for any help.
0
814
11 Replies

Reply

Bookmark

Sort
- ago
#1
Can you post the entire code with the line of the runtime error?
0
- ago
#2
Working on adapting code so as to not share all of it. I am not ignoring your request. Each change for me in C# is like passing a kidney stone.

I know you all are not python people but ..........
0
Cone8
 ( 21.65% )
- ago
#3
QUOTE:
I assume the program is picking up the data
Bad assumption. There's no mystery. You can't run 4000 symbols in Yahoo! anymore, not 500, and maybe not even 100. Yahoo! just doesn't support tons of requests like it used to. \

Eugene, we need to work in a rate limiter for Yahoo! - if we can find a sweet spot that works. I'm not an expert on Y!, but this might help get started -
https://developer.yahooinc.com/dsp/api/docs/traffic/info/rate-limits.html
0
- ago
#4
QUOTE:
Working on adapting code so as to not share all of it. I am not ignoring your request.

On second thought, I guess we can skip this step for now. Thanks.

QUOTE:
I don't understand why I am getting the error when I run the backtest.

It's simple. Because the external system does not have the data (like ^GSPC going back to 1927) or, as Cone just suggested, Yahoo is playing dirty tricks on you.
0
Cone8
 ( 21.65% )
- ago
#5
To test and trade large EOD DataSets over 500 symbols, historical watchlists, troublefree and automatic updates, there's no better provider than Norgate Data. https://wealth-lab.com/extension/detail/Norgate

0
- ago
#6
I don't understand something. If I have downloaded the historical yahoo prices.? It turns out I cannot actually use the data?

Does wealthlab itself provide a 4000 + ticker dataset?

Thank you

0
Cone8
 ( 21.65% )
- ago
#7
Sure you can if you've downloaded all the data. The problem is that even if you finally manage to download all those symbols from Yahoo!, you won't be able update them all. Y! will cut you off. That's the reality in 2023 and last year too. And, when WealthLab can't get an update, it starts looking for the update in your list of checked providers. If it can't get the data there, then you're out of luck.

By "wealthlab pro" subscription, I guess you meant "Premium" subscription. Sure you can have a million symbol DataSet if you want... but you're not going to get the data from Y! in 2023.
0
- ago
#8
As per usual can't get anything to work. BEYOND FRUSTRATING. I AM GOING TO KEEP SAYING IT.

Compiles. Does not plot
Gives the following error despite being able to plot a graph.


CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript1 { public class MyStrategy : UserStrategyBase {       public MyStrategy() // This has to have the name of the class above       {          // Parameters go here and the are indexed such as Parameter[0 : ]          AddParameter("ATR_move", ParameterType.Int32, 175, 100, 400, 25); // Parameter index 0          AddParameter("SL", ParameterType.Int32, 10, 2, 10, 1); // Parameter index 1          AddParameter("PT", ParameterType.Int32, 5, 2, 10, 1); // Parameter index 2          AddParameter("SMATar", ParameterType.Int32, 5, 2, 10, 1);                 }                     //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {                    StartIndex = 51;          SMA sma_two_s = SMA.Series(bars.Close, 50);          SMA dolvol_s = SMA.Series(bars.Close * bars.Volume, 30);          PlotTimeSeriesLine(dolvol_s, "Dolvol", "Price", WLColor.Blue);                         } //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.Short)) {             //code your buy conditions here             if (                sma_two_s.CrossesOver(bars.Close,idx)                && bars.Close[idx] > 10.0                && dolvol_s[idx] > 15000000                             )                 {                PlaceTrade(bars, TransactionType.Short, OrderType.Market, 0,"SAM");             }                 } else {             //code your sell conditions here             Position p = LastPosition;             if (idx - p.EntryBar > 10)             {                ClosePosition(p, OrderType.Market, 0,"Time_exit");             } } }       //declare private variables below       SMA dolvol_s;       SMA sma_two_s; } }



0
- ago
#9
Execute Exception (TREE,51) Line 47 - Object reference not set to an instance of an object.
at WealthScript1.MyStrategy.Execute(BarHistory bars, Int32 idx) in :line 47
at WealthLab.Backtest.UserStrategyExecutor.FlushRole(List`1 lst, DateTime dt)
0
- ago
#10
You have a scoping problem with your declarations. Can you see the scoping issue?

You are declaring sma_two_s and dolvol_s to be local so they are only visible to Initialize and no other program block (such as Execute{}). Can you see that?

CODE:
      public override void Initialize(BarHistory bars)       {          StartIndex = 51;          SMA sma_two_s = SMA.Series(bars.Close, 50);          SMA dolvol_s = SMA.Series(bars.Close * bars.Volume, 30);          PlotTimeSeriesLine(dolvol_s, "Dolvol", "Price", WLColor.Blue);       }

I think what you want to do is declare them so they are visible (i.e. as global variables) to all program blocks in MyStrategy. So remove the SMA typedef in the Initialize declarations that defines them as "local" to Initialize. Your code should now look like this:
CODE:
      public override void Initialize(BarHistory bars)       {          StartIndex = 51;          sma_two_s = SMA.Series(bars.Close, 50);          dolvol_s = SMA.Series(bars.Close * bars.Volume, 30);          PlotTimeSeriesLine(dolvol_s, "Dolvol", "Price", WLColor.Blue);       }

And that fixes your problem. Now the compiler is using the declarations for sma_two_s and dolvol_s that you declared in the MyStrategy block instead so they are both global (i.e. visible) to all blocks in MyStrategy.

Scoping is a very important concept in modern OOPs languages (like C#). If this solution isn't obvious to you, then you must ask more questions. The reason the declarations work this way is so you can have many independent copies of "x" (or sma_two_s) with different scopes. The compiler knows to keep all your "x"s separate since they may have been declared by different programmers in the same 100,000 line, multi-blocked program. Happy computing to you.
0
- ago
#11
Thank you!
1

Reply

Bookmark

Sort