Getting error in Backtesting

Hi

I am trying to code a simple strategy and backtest it .
Here is my code


SetBacktestMode( backtestRegularRaw2Multi );
spotprice = IIf( int( C % 100 ) > 50, ( C - C % 100 + 100 ), ( C - C % 100 + 50 ) );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g ,spotprice %g (%.1f%%) {{VALUES}}", O, H, L, C, spotprice, SelectedValue( ROC( C, 1 ) ) ) );
tn = TimeNum();
startTime1 = 92900; // start in HHMMSS format
startTime2 = 102900;
endTime1 = 160000;  // end in HHMMSS format
endTime2 = 150100;
Key = "NIFTY" + ( spotprice ) + "12MAY22" + "CE";
SetForeign(Key ); 
printf("Close="+(C));//Interpretor
Buy1 = Cross( tn, startTime1 );
Buy2 = Cross( tn, startTime2 );
BuyPrice = C;
printf("\n"+"Buy1="+Buy1);//Interpretor
Buy = buy1 OR Buy2 ;
printf("\n"+"Buy="+Buy);//Interpretor
printf("\n"+"BuyPrice"+(BuyPrice));
Sell1 = Cross( tn, endTime1 );
Sell2 = Cross( tn, endTime2 );
Sell = Sell1 OR Sell2; 
SetTradeDelays(1,1,1,1);
SetPositionSize(1,spsShares);
printf("\n"+"BuyPrice2="+(BuyPrice));//Interpretor
//Exploration
Filter= (TimeNum() >092900 AND TimeNum() < 093000 ) OR (TimeNum() >102900 AND TimeNum() < 103000 ) ;
//AddColumn( C, "Close", 1.2, colorRed, colorGreen );
AddtextColumn((key),"Key");
AddColumn(Spotprice,"Spot Price",1.2);
AddColumn(Buy1,"Buy1",1.2);
AddColumn(Buy2,"Buy2",1.2);
AddColumn(Buy,"Buy",1.2);
AddColumn(Buyprice,"Buy Price",1.2);

My Problem is with variable "KEY" .It is taken as a string , but I want to covert it into an array of keys .
When I check 'key' in interpretation value for Key is changing for every bar . But when I backtest or do a exploration it is only taking the lastvalue and its corresponding Buyprice.

What I want : Key should have dynamic spotprice .which is not happening when i did a backtest
image

Please help
baru

see this ADDMULTITEXTCOLUMN instead of AddtextColumn

AFL Function Reference - ADDMULTITEXTCOLUMN (amibroker.com)

Hi

Getting error "Error 5.1st argument of the AddMultiTextColumn() call has incorrect type.The Function expected an array here , but found a string.

Variable "Key" here is dynamic string . I want to move/change it into an array .
cap2

Read the help file properly and use "\n". It is clearly explained there.
If you take shortcut, you will not get result.

I am only using "\n" for printf statement which is for Interpretation .
To my knowledge ADDMultitextcolumn is used for a different pupose ( where we have mutiple text output).

AddTextColumn displays SINGLE TEXT that represents SELECTED VALUE (in Analysis it is end of the analysis period).

It has been said many many times:

@Tomasz

Thank you .

Why am I getiing Lastvalue as Key in backtesting as well when I see variable being dynamic in _TRACE.
why is it not reflecting in the backtest when i can see them changing in the _TRACE .
Please help where I am wrong

No, you are mistaken. If you write
TRACE( "Test " + Close );
then it will also display selected value.

If you concatenate string to ARRAY of numbers, then the result is STRING (single string, not array of strings), and that string shows SELECTED VALUE of array.

Hi

image

I can see them in the Interpretor . Please see the screen shot above with different values that of the backtesting .
Spot price is 16050 , Key @ interpretor = NIFTY1605019MAY22CE --- this is correct and the buy price all are correct here .

image
The first line is at 09:29:29 , the value I selected at the interpretor . Here the values are retrived w.r.t to last key/spot price 15900 Last line in Backtest.

One more thing @Tomasz . My plot is dynamic , it is changing/showing ( retrieving Key/ticker w.r.t main symbol )
Please execute my code you will understand what i am trying to tell you .

Many thanks for your time .

Regards,
Baru

I realised that you will not have symbol data which i am using .
Changed code little bit so that it will work with amazon symbol and its options .

_SECTION_BEGIN("ShortStranglebacktesting");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetBacktestMode( backtestRegularRaw2Multi );

//Spotprice
x =2261.10;
spotprice = IIf(int(x%10)<5,(x- x%10),(x- x%10 +10));
//title with spot price
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g ,spotprice %g (%.1f%%) {{VALUES}}", O, H, L, C, spotprice, SelectedValue( ROC( C, 1 ) ) ) );
tn = TimeNum();
startTime1 = 92900; // start in HHMMSS format
startTime2 = 102900;
endTime1 = 145859;  // end in HHMMSS format
endTime2 = 150100;
//strike key
Key = "AMZN" + "220513"+"CO"+SelectedValue( spotprice ) ;//Please change this if i am wrong , I dont have amazon data with me
SetForeign(Key ); 
printf("Close="+(C));//Interpretor
Buy1 = Cross( tn, startTime1 );
//Buy2 = Cross( tn, startTime2 );
BuyPrice = C;
Plot(C,"strikeprice",colorred,styleCandle);
printf("Buy1="+Buy1);//Interpretor
BuyPrice = ValueWhen(Cross( tn, startTime2 ),C);
//Buy = buy1 OR Buy2 ;
RestorePriceArrays();
SetForeign(Key ); 
Buy =buy1;
BuyPrice = ValueWhen(Cross( tn, startTime2 ),C);
printf("\n"+"Buy="+Buy);//Interpretor
printf("\n"+"BuyPrice"+(BuyPrice));
Sell1 = Cross( tn, endTime2 );
//Sell2 = Cross( tn, endTime2 );
//Sell = Sell1 OR Sell2; 
Sell =Cross( tn, endTime1 );

SellPrice=ValueWhen(Cross( tn, endTime1 ),C);
SetTradeDelays(1,1,1,1);
SetPositionSize(1,spsShares);
printf("\n"+"BuyPrice2="+(BuyPrice));//Interpretor
//RestorePriceArrays();
//Exploration
Filter= (TimeNum() >092900 AND TimeNum() < 093000 ) OR (TimeNum() >102900 AND TimeNum() < 103000 ) OR (TimeNum() >145859 AND TimeNum() <150000 )  ;
//AddColumn( C, "Close", 1.2, colorRed, colorGreen );
AddTextColumn((key),"Key");
AddColumn(Spotprice,"Spot Price",1.2);
AddColumn(Buy1,"Buy1",1.2);
//AddColumn(Buy2,"Buy2",1.2);
AddColumn(Buy,"Buy",1.2);
AddColumn(Sell,"Sell1",1.2);
AddColumn(Buyprice,"Buy Price",1.2);
AddColumn(sellprice,"Sell Price",1.2);

//Cover=TimeNum() > 152000 ;

Many Thanks