Australian (ASX) Stock Market Forum

AmiBroker - CBT Help

Joined
27 November 2017
Posts
1,200
Reactions
1,884
All,

I was hoping that someone could provide assistance in helping with coding up some CBT code so I can trace what Market Regime is in use when Buy Signal is initiate and then once this is working I can leverage of the code to add more data points.

Code located here - https://www.aussiestockforums.com/threads/amibroker-tips-and-tricks.35508/#post-1076776

Statement of Requirements

- BUY is initiated
- Return status of RegimeFilter array to Backtest trade list

RegimeFilter = IIf( VolatileBear, Volatile Bear, IIf( QuietBear, Quiet Bear, IIf( QuietBull, Quiet Bull, IIf( VolatileBull, Volatile Bull, Null))));
I can get the following in the Trade List

upload_2020-6-13_13-31-44.png

But now need to map the correct data into CBT.

Code in main AFL
StaticVarSet( Name() + "Regime Filter ", RegimeFilter );

Code in CBT
for( trade = bo.GetFirstOpenPos(); trade; trade = bo.GetNextOpenPos() )
{
// read Regime Filter values and display as custom metric
symbolRegime = StaticVarGet( trade.Symbol + "Regime Filter" );
trade.AddCustomMetric( "Entry Regime Filter", Lookup( symbolRegime, trade.EntryDateTime ) );
NumTrades++;
}

// iterate through closed trades
for ( trade = bo.GetFirstTrade( ); trade; trade = bo.GetNextTrade( ) )
{
// read Regime Filter values and display as custom metric
symbolRegime = StaticVarGet( trade.Symbol + "Regime Filter" );
trade.AddCustomMetric( "Entry Regime Filter", Lookup( symbolRegime, trade.EntryDateTime ) );
}

Any ideas would be appreciated. Just a push in the right will do, but this is the one area where I am really struggling. The more I play with it I am sure that I can crack it open.

Cheers

Trav
 
OK after a little detour and a slight change in strategy oh and about 6 hours of reading and googling I think I have come up with a solution :eek::eek::eek:

As per above I managed to assign the appropriate type of entry to each trade

Then I found some code in the AmiBroker manual that was designed for counting different stop methods and did a 'macgyver' as per @Warr87 suggestion ;) and managed to sum all types of entries as per below

Columns are All Trades and Long Trades

upload_2020-6-13_19-5-51.png

Code attached free of charge !! :2twocents:2twocents:2twocents :xyxthumbs:xyxthumbs:xyxthumbs (i'm getting addicted to these little emoji's)

I will post over in the new backtesting thread with same info and then we can explore some other information that I uncovered during this process. Don't worry it's not ground breaking but like most things with AmiBroker all the information is there but you have to find it then have a use. For me I read multiple articles but if it doesn't apply to me that day I will just move on. A bit like today when @Skate re-posted some great information about Norgate data that I would have read but dismissed at the time, as I have very limited capacity up stairs

Anyway I digress, I hope the above is useful to you.

EDIT:

You will need the following in the main code

RegimeFilterCBT = IIf(VolatileBear, 1, IIf(QuietBear, 2, IIf (QuietBull, 3, IIf (VolatileBull, 4, Null)))); // Assigns a number to entry regime
StaticVarSet( Name() + "RegimeFilter", RegimeFilterCBT ); // Sets the value of static variable so it can be retrieved in CBT
 

Attachments

  • RegimeCBT.afl
    4 KB · Views: 20
Last edited:
Top