Hi there,
I've been trying to create a buy filter that checks if a stock has a higher dollar volume than the position size that I would set. The idea is to avoid buying a stock if the dollar volume is lower than my potential position size, and that the $ amount of the position size would also vary depending on whether my equity goes up or down.
After some searching and reading, I think the only way to do this is to perform some basic calculations on bo.equity to inside the backtester object to work out my position size and compare it to a DollarVolume array that I created.
If that works, I would write an if statement that checks if DollarVolume is greater than my position size. If so it would then run bo.ProcessTradeSignals( bar );
At this stage I'm trying to build the code and seeing if the backtester object can read the DollarVolume array values and Trace it to console, however the DollarVolume array is writing out 0.0 for its values.
Is it possible to get DollarVolume recognised in the backtester object? Or if this isn't the way it's meant to work, I would appreciate being pointed in the right direction.
I've included a simplified version of what I've coded so far for reference.
Thanks
dt = DateTime();
SetOption("MaxOpenPositions", 20);
SetPositionSize(5, spsPercentOfEquity);
DollarVolume = V*C;
Plot(DollarVolume, "dollar Volume", colorLightBlue, styleLine);
SetCustomBacktestProc("");
if( Status( "action" ) == actionPortfolio ) {
bo = GetBacktesterObject();
bo.PreProcess(); // Initialize backtester
for( bar = 0; bar < BarCount; bar++ )
{
_TRACE(NumToStr(bo.Equity) + " " + DateTimeFormat("%Y/%m/%d", dt[bar]) + " " + NumToStr(DollarVolume[bar]));
bo.ProcessTradeSignals( bar );
}
bo.PostProcess();
}
FastMA = MA(C, 50 );
SlowMA = MA(C, 10 );
Buy = Cross(FastMA, SlowMA);
Sell = Cross(SlowMA, FastMA);