Please help me implement ticker-specific variables in AFL

#1
Hello,

I have a long-only simple moving average crossover strategy with one added constraint; trades should take place only when the ticker price is in the specified range. I calculate the trading ranges for different tickers in the morning before the trading session at NSE opens. For eg. in the attached picture, I want to enter a trade only when Asianpaint price is between 437 and 440 (these values are specific to Asianpaint). I have written following AFL to implement the strategy.
------------------------
SetBarsRequired(sbrAll,sbrAll);
timeperiod = 10;
UpperLimit = 440;
LowerLimit = 437;
Buy = Cross(Close, MA(Close,timeperiod)) AND (Close>LowerLimit) AND (Close<UpperLimit);
SellTemp = Cross(MA(Close,timeperiod),Close) OR (Close>UpperLimit);
Sell = ExRem(SellTemp,Buy);
Short=Cover=0;
-----------------------
Trade Entry Condition:
Enter into a long trade if price crosses above MA and price is in the specified range.
Trade Exit Condition:
Exit the trade If either the price goes below moving average or the price hits the target (i.e. UpperLimit).
----------------------
My Problem: In the above AFL, same price range is shared by all the tickers. But I want to define different trading ranges for different tickers.

P.S. On a more general note, I haven't been able to figure out how to define variables/parameters in AFL that can take different values for different tickers. Any pointers in this direction on this will be very appreciated.

Love for all.
 

Attachments

Similar threads

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?