Referencing price array data inside the backtester: the second phase

Dear afl experts, I realize there are more than a few experts here have acknowledged in various posts that price arrays can be exposed inside the backtester; I also know that there is a Trade.GetPrice (i, “H”) c++ / afl member function inside the trade object. But try as I may, I could not get it to work, for example: here are the code snippets I used for testing:

		Other AFL code outside of backtester ....

StaticVarSet ( name() + "High", High ); 
h_ = StaticVarGet ( name() + "High" );
_trace( "High outside of backtester: " + numtostr( h_[2], 1.2) );
		backtester code ....


if ( Status("action") == actionPortfolio )

	_trace( "High inside of backtester: " + numtostr(h_[2], 1.2));
	// etc.,

Here is the debug window:


As can be seen in the picture, the entire price array disappear as soon as the code go pass the line "if (Status("action") == actionPortfolio)". Yes, I am fully aware I can use the Trade.GetPrice ( ) C++ member function object, but the reason for this post is because I have other custom arrays that make use of the price array data and are defined outside of the backtester, but I need to be able to reference these custom arrays inside the backtester, and these custom arrays make use of the price array, but the price array disappear inside the backtester. 1 reason for the use of these custom arrays is so that I can come up with a custom Van Tharp stop loss amount calculation that is based on price data (among other data) a few bars before the trade entry. Now here is my intuitive logic: if the price arrays can easily be seen inside the backtester, then there is no reason for the trade.GetPrice() member function, so somehow I think the price array when attached to a variable was passed by reference and the reference pointer that pointed to these price arrays goes out of the scope inside the backtester. Please help, I have been trying to figure this out for a while. Thanks.

1 Like

You need to put your StaticVarGet() call inside the CBT. That means you won't be able to use the Name() function to retrieve the current symbol, because inside the CBT the current symbol is ~~~EQUITY. Instead you'll most likely get the symbol out of a trade or signal object.


Yes, putting the StaticVarGet() call inside the CBT solves my problem, I just need to use Trade.symbol to get the symbol. Thanks, you guys are great!

Please take a look at the Knowledge Base. It has detailed articles on almost every subject, see this one shows EXACTLY what to do:

Knowledge Base Table of Contents:

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.