Help on converting Backtesting code to Exploration and vice-versa

Hi
I would really appreciate it if someone could please explain how to convert AFL code written for Backtesting or an Indicator to Exploration, an example of this is,

Buy = 	Low < Ref( Low , -1 ) AND 
Ref( Low , -1) < Ref( BBandBot( Close, 15, 2 ) , -1 ) AND
Ref( CCI( 14 ) , -1 ) < CCI( 14 ) AND 
CCI( 14 ) > -150 AND CCI( 14 )<-70 AND 
Volume > MA(  Volume , 5 ) AND
MFI( 14 ) > Ref( MFI( 14 ) , -1 );

Sell = High >Ref (High,-1) AND
Ref (High,-1) > Ref( BBandTop( Close, 15, 2 ) , -1 ) AND
Ref( CCI( 14 ) , -1 ) > CCI( 14 ) AND 
CCI( 14 ) > 70 AND CCI( 14 )<150 AND 
Volume > MA(  Volume , 5 ) AND
Ref( MFI( 14 ) , -1 ) >MFI( 14 );

Moderator co

I assume this code is either an indicator code or Backtesting code but i would like to use it for Exploration. Can the code be converted or does it need to be rewritten.
Thanks

@andyj there are many ways to Explore your code and Explorations are my personal favorite method of debugging your code. They are very useful to look at the values of the variables you have created.

A very useful read,
https://www.amibroker.com/guide/h_exploration.html

For example in your code if you are looking just for which stocks triggered a Buy or Sell on a basket of stocks in your watch list, run this code.

Buy = 	Low < Ref( Low , -1 ) AND
        Ref( Low , -1 ) < Ref( BBandBot( Close, 15, 2 ) , -1 ) AND
        Ref( CCI( 14 ) , -1 ) < CCI( 14 ) AND
        CCI( 14 ) > -150 AND CCI( 14 ) < -70 AND
        Volume > MA( Volume , 5 ) AND
        MFI( 14 ) > Ref( MFI( 14 ) , -1 );

Sell = High > Ref( High, -1 ) AND
       Ref( High, -1 ) > Ref( BBandTop( Close, 15, 2 ) , -1 ) AND
       Ref( CCI( 14 ) , -1 ) > CCI( 14 ) AND
       CCI( 14 ) > 70 AND CCI( 14 ) < 150 AND
       Volume > MA( Volume , 5 ) AND
       Ref( MFI( 14 ) , -1 ) > MFI( 14 );
       
/////////////////
// Explore
/////////////////
Filter = Buy OR Sell;
AddColumn(Buy, "Buy", 1.0, colorDefault, IIf(Buy, colorLime, colorDefault));
AddColumn(Buy, "Sell", 1.0, colorDefault, IIf(Sell, colorred, colorDefault));

And today on the SP500 I get this type of result (although you can and should look back much further than 1 day),
image

You can further break down your code and use just specific elements of the code to see what they you have created.

1 Like