Kindly help me for getting the At the money(ATM) option symbol when the entry conditions are met.
currently it is working the ATM symbol for each bar, but i required the symbol when the entry conditions are met.
kindly suggest the alternate solution for getting the text value like as value when function.
First you are using mutliple timeframe functions incorrectly. You need to read Multiple Time Frame support (especially text in orange boxes). In your code you should be using TimeFrameEXPAND as docs say.
Dear @Tomasz
Thank you for reply, currently i am learning the afl,
The indian market opening time is 091500, i need to get atm symbol value at 09300
can you please help me with the code,
i have tried with time frame expand function as like below, still the value when cant able use it here,
Thank you for support,
Previously i have tried with this option, but while back testing it will take last day symbol only as shown in image, so only i have tried with for loop function.
and also while debugging in afl, it is not showing the strike value, can you help me with the back testing code.
@balakrishnannatesan why did you change the foreign array from close to open there will be no candle starting at 9.30 it will be completed candle hence you need to access the close price any intraday new candle which will be forming will have the open time of 093001?
Also you dont need the setforeign to acces the price field of you custom symbol you can directly access the same through foreign function.
Thank you for your effort, can you please help with exploration value, because still in my system, the trading symbol is same for last 10 days and please find the afl code here.
and it is working fantastic in the chart window ,but i cant able to bactest due to same symbol in the exploration window.
can you please help me to resolve this issue
_Time = 093000;
tn = TimeNum();
dn = DateNum();
newday = dn != Ref( dn, -1 );
CP = Foreign( "BANKNIFTY", "C" );
strikedist = 100;
Plot( C, "Price", colorDefault, styleCandle );
OP_atm = Round( ValueWhen( newDay, CP ) / strikedist ) * strikedist; // Newday Opening Atm
atm = Round( CP / strikedist ) * strikedist; // Current Price Atm
atmattime = ValueWhen( tn == _Time, atm ); // Atm at particular time
SYMBOL = "BANKNIFTY";
CE_Symbol = Symbol + "WK" + atmattime + "CE";
PE_Symbol = Symbol + "WK" + atmattime + "PE";
// Call Option Price for Calculation
iCEC = ValueWhen( tn == _Time, Foreign( Symbol + "WK" + atm + "CE", "C" ) );
iPEC = ValueWhen( tn == _Time, Foreign( Symbol + "WK" + atm + "PE", "C" ) );
_TRACE( "ATM AT NEW DAY OPEN : " + OP_atm );
_TRACE( "ATM AT CLOSE : " + atm );
_TRACE( "ATM AT 9:30 : " + atmattime );
_TRACE( "ATM CE Close : " + iCEC );
_TRACE( "ATM PE Close : " + iPEC );
///Option trading condition for Set No :1
Short_CE_1 = Name() == CE_Symbol;
Short_PE_1 = Name() == PE_Symbol;
ShortPrice_CE_1 = ValueWhen( Short_CE_1, iCEC );
ShortPrice_PE_1 = ValueWhen( Short_PE_1, iPEC );
Cover_CE_1 = TimeNum() >= 151500;
Cover_PE_1 = TimeNum() >= 151500 ;
Short = Short_CE_1 OR Short_PE_1;
Cover = Cover_CE_1 OR Cover_PE_1;
Filter = Short AND TimeNum() == 093000;
AddColumn( iCEC, "Open CE option" );
Premium = iCEC + iPEC;
I have also tried backtest for option symbol but still not succeed.
I think there is no support for backtest with variable symbol on each bar.
In general terms we can't store array of string in memory unless we use matrix of characters and I think still character matrix is not supported in amibroker
I am trying with the following code but as per the analysis window it uses the last option symbol for the whole period which should be different on diff days (ATM Option on each day):
/*
I will buy atm call option when the market open and sell at the last candle open when the market close
I want to backtest this system using amibroker backtester
*/
STRST = 100;
BSMBL = "BANKNIFTY";
EXPIRD = "21818";
TN = TimeNum();
DN = DateNum();
FC = TN==91500;
LC = TN==151500;
Buy = FC;
Sell = LC;
ATMSTRIKE = ValueWhen(Buy, round(O/STRST)*STRST, 1);
CESYM = BSMBL + EXPIRD + NumToStr(ATMSTRIKE, 1.0, False) + "CE";
BuyPrice = ValueWhen(Buy, Foreign(CESYM, "O", False));
SellPrice = IIf(Sell, Foreign(CESYM, "O", False), Null);
Filter = 1;
AddTextColumn(CESYM, "CE SYMBOL", 77);
AddColumn(Buy, "Buy", 1.0);
AddColumn(Sell, "Sell", 1.0);
AddColumn(BuyPrice, "BuyPrice", 1.2);
AddColumn(SellPrice, "SellPrice", 1.2);
You don't need arrays of strings because this is NOT how backtest works at all (you dont' use Foreign!!!)
To backtest multiple symbols you have to PUT ALL those symbols into WATCH LIST (or use "All symbols" Apply To Setting"), then you need to code buy sell rules so CURRENT symbol (one of those in "Apply to" gets traded). You do NOT use Foreign and you should NOT set BuyPrice to Foreign price. That is all wrong.
If you have different rules for different symbols you code this like shown here:
n = Name(); // get the symbol
if( n == "SYMBOL1" )
{
// the "Close" price here is Symbol1 close NO FOREIGN NEEDED
Buy = ...rules for symbol1;
Sell = ...rules for symbol1;
}
if( n == "SYMBOL2" )
{
// the "Close" price here is Symbol2 close NO FOREIGN NEEDED
Buy = ...rules for symbol2;
Sell = ...rules for symbol2;
}