Hi everyone,
I am vert new to the amibroker coding.
I am trading in Thailand stock market which have about 700 stocks.
Please anyone here suggest me how to code my trading model like this.
Long only, in Thai stocks of about 700 stocks (with “SET” as its index )
Keep invest in the best 15 stocks only when market timing is right (SET index EMA 20 golden cross EMA 100), otherwise no new entry for the remaining cash. The existing position will stay for 20 days( or 1 month holding period)
Upon the market is right …rebalance the portfolio once per month.
My criterias to select all 15 stocks is that
Ranking all stocks in the universe with one indicator (let say ADX) and choose the top best 10% (first 10 percentile) from all stocks in the universe or that is around 70 stocks.
*I don’t know how to code this part !
Then, ranking these selected stocks with another indicator (let say RSI) and select the best 15 stocks (among approximatedly 70 stocks from the first ranking)
*for the second ranking, i know that i can use positionscore function.
Then Rebalance once per month. Any stocks that rank below 15th is sold and replaced with the new one whose rank is 15th or better in order for the portfolio keep having 15 stocks all the time.
Below is my rough coding, just to show you what i am trying to do as a very afl programming novice. Its absolutely need to be corrected a lot.
So could anyone here please suggest me correct my code or show me the right coding for my trading rules.
Thank you in advance.
{//Option
SetOption("InitialEquity" , 1000000);
SetOption("MaxOpenPositions", 15);
SetOption("MinShares", 100);
RoundLotSize = 100;
SetOption("CommissionMode", 1);
SetOption("CommissionAmount", 0.16);
SetTradeDelays(1, 1, 0, 0);
BuyPrice = Open;
SellPrice = Open;
}
{//Signal
index = Foreign( "SET","C", 1);
buyCon1 = MA(index, 20) > MA(index, 100);//Broad index Market Timing
buyCon2 = ???//ranking with ADX, then select the top 70 stocks or the top 10 percentile among all stocks in the universe with highest ADX
Buy = buyCon1// AND buyCon2 ;
Sell = 0; //no sell condition, sell only with applystop function of N bars representing N days.
}
{//Position
SetPositionSize(6.5, spsPercentOfEquity);
PositionScore = RSI();
}
{//Stop
//ApplyStop(3, 1, 20);
ApplyStop(stopTypeNBar, stopModeBars, 20);//20 means 20 trading day is 1 month holding period.
}
Moderator comment: Your post included incorrectly formatted code and I had to fix it. Next time follow the forum rules and make sure your code is properly formatted as instructed in “How to use this site”