Dear Forum Members,
I am learning AFL programming and progressing gradually. I have been working on my requirement which is mentioned as below:
- Select Future stocks based on Volume & OI data
- Convert the Future stocks to Cash market ( As i wanted to trade on stocks in cash market which has high Volume and OI )
- Categorise and create 2 watchlist,, one for Buy and one for sell based on..
-- Increase in price and Increase in Volume and Increase in OI --- for Buy Watchlist
-- Decrease in Price and Increase in Volume and Increase in OI -- for Sell Watchlist
*Note : STocks once created in watchlist will remain in the watchlist even there is change in V, OI or price
- Take an entry on Buy side only from the stocks in Buy watchlist and Short entry from the stocks that are in Sell watchlost .. as soon as they are listed in the watchlist..
I am using Daily Timeframe for scanning the stocks and sorting them into watchlist.. So far worked up on code is mentioned below
_SECTION_BEGIN("Stocks Screening");
PCP = Param("PCP",0.5,-10,100);
PCV = Param("PCV",5,0,100);
PCO = Param("PCO",1,0,100);
A1 = (C-Ref(C,-1))*100/Ref(C,-1);
A2 = (V - MA(V,20))*100/V ;
A3 = (V-Ref(V,-1))*100/Ref(V,-1);
A4 = (OI - Ref(OI,-1))*100/Ref(OI,-1);
A = C > 100 AND C < 2000;
Buy = (A1 > PCP AND A3 > PCV AND A4 > PCO ) AND A ;
Sell = (A1 < -PCP AND A3 > PCV AND A4 > PCO ) AND A ;
InWatchList( 67 );
Symbol = Name();
Symbol = StrTrim(StrReplace(Name(),"-FUT",""),"",2);
Filter=Buy OR Sell;
AddRankColumn();
AddColumn(Close,"Price",1.1);
AddColumn(A1,"% Change",1.1);
AddColumn(A3,"% V Change",1.0);
AddColumn(A4,"% OI Change",1.0);
AddColumn(Buy,"Buy",1.1);
AddColumn(Sell,"SELL",1.1);
_SECTION_END();
_SECTION_BEGIN("Bullish Stocks");
F1 = Filter = ( Buy ) ;
listnum = 1; // watchlist to use
if ( Status( "stocknum" ) == 0 )
{
oldlist = CategoryGetSymbols( categoryWatchlist, listnum );
Symbol = Name();
Symbol = StrTrim(StrReplace(oldlist,"-FUT",""),"",2);
for ( i = 0; ( sym = StrExtract( Symbol, i ) ) != ""; i++ );
}
if ( LastValue( Cum( Filter AND Status( "barinrange" ) ) ) )
CategoryAddSymbol( Symbol, categoryWatchlist, listnum );
_SECTION_END();
_SECTION_BEGIN("Bearish Stocks");
F2 = Filter = ( Sell ) ;
listnum = 2; // watchlist to use
if ( Status( "stocknum" ) == 0 )
{
oldlist = CategoryGetSymbols( categoryWatchlist, listnum );
for ( i = 0; ( sym = StrExtract( oldlist, i ) ) != ""; i++ );
}
if ( LastValue( Cum( Filter AND Status( "barinrange" ) ) ) )
CategoryAddSymbol( Symbol, categoryWatchlist, listnum );
_SECTION_END();
_SECTION_BEGIN("All Stocks");
F3 = Filter = ( Buy OR Sell ) ;
listnum = 3; // watchlist to use
if ( Status( "stocknum" ) == 0 )
{
oldlist = CategoryGetSymbols( categoryWatchlist, listnum );
Symbol = Name();
Symbol = StrTrim(StrReplace(oldlist,"-FUT",""),"",2);
for ( i = 0; ( sym = StrExtract( oldlist, i ) ) != ""; i++ );
}
if ( LastValue( Cum( Filter AND Status( "barinrange" ) ) ) )
CategoryAddSymbol( Symbol, categoryWatchlist, listnum );
_SECTION_END();
What is achieved so far -
- I am able to scan future stocks based on Price, Volume and OI
- Able to convert them to Cash market stocks
- Able to create 2 different watchlist for Buy and Sell respectively
What I am looking for -
- Place Buy or Sell order for the stocks that are added to the respective watchlist with a definite target %.. and SL %
Issue part:
I do have various algos that actually work on list of stocks which are constant.. but stocks are screened based on the price, volume and oi, the existing algos are failing to generate a fresh signal once the stock is created in the watchlist. Many times, the entries are way before the stocks being listed..
Any suggestion or guidance on the code part is very much appreciated.. Thanks in advance..