Hi - using Rotational Backtester and a portfolio of stocks in a watchlist, how would I buy a symbol (say "AAPL") if all other symbol's have ROC-250<0.
Currently in the AFL below I eliminate all symbols that have ROC-250<0. But I don't know how to buy AAPL if all symbols are negative, regardless of whether AAPL's ps is negative or not.
Thank you
SetBacktestMode(backtestRotational);
mn = Month();
monthendflag = mn != Ref(mn,-1);
ps = ROC(C,250);
xScore = IIf(ps<0, 0, ps+1000); // +1000 to avoid short trades
PositionScore = IIf(monthendflag, xScore, scorenoRotate);
SetBacktestMode(backtestRotational);
mn = Month();
monthendflag = mn != Ref(mn,-1);
ps = ROC(C,250);
xScore = IIf(ps<0 AND Name() != "AAPL", 0, ps+1000); // +1000 to avoid short trades
PositionScore = IIf(monthendflag, xScore, scorenoRotate);
Thanks fxshrat, the man with a plan yet again
I was so busy thinking of elaborate solutions that I overlooked the obvious
Sorry to revisit this - I'm starting to learn custom backtester.
How would this be done in CBT and not with the Name()!="AAPL" code above?
Something like:
Add all xScores to a StaticVar (the original xScore = IIf(ps<0, 0, ps+1000); )
In CBT, if symbol=="AAPL" and StaticVar==0, set PositionScore to 9999999.
You do not need if
statement in CBT.
Static var is set per symbol name already.
So you may do like this
xScore = IIf(ps<0 AND Name() != "AAPL", 0, ps+1000);
StaticVarSet("xScore_"+Name(), xScore);
or like this
if ( Name() == "AAPL" )
xScore = ps+1000;
else
xScore = (ps>0) * (ps+1000);
StaticVarSet("xScore_"+Name(), xScore);
or ...
And then just call static var within CBT.
1 Like
system
Closed
August 18, 2022, 10:32pm
7
This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.