How to get a string of a bar for backtest (Call and Put Option Strike name)

Hello Everyone,
I am using Amibroker version 6.40.0 (64-bit).
Is there any way to get String value of a particular bar for backtesting? In other words I am basically asking for array of strings.
I need this to create symbol name for Call Option Strike and Put Option Strike based on value of Index.
The code below is giving the string value 'To Date' selected for backtesting. If I Backtest one day at a time it is working perfectly, but for more than one day it is taking value of last day only.

SetOption("DisableRuinStop", TRUE );
Entry_Time=093500;

Index="BANKNIFTY";//Underlaying Intrument
SetForeign(Index,1,True); Index_C=C; PDC0=TimeFrameGetPrice("C",inDaily,-1); RestorePriceArrays();

Strike_CE = ceil(Index_C/100)*100+200;//Call option Strike selection
Strike_PE = floor(Index_C/100)*100-200;//Put option Strike selection

Strike_CE = ValueWhen(TimeNum() == Entry_Time, Strike_CE,1);//Call option Strike at the time of taking position. This is required to exit all the positions based on combined profit/loss of all positions.
Strike_PE = ValueWhen(TimeNum() == Entry_Time, Strike_PE,1);//Put option Strike at the time of taking position. This is required to exit all the positions based on combined profit/loss of all positions.

CE_Symbol = "BANKNIFTY22DEC"+Strike_CE+"CE";// Call option symbol. I have trouble on this line. This is giving only string of Last date selected for backtest.
PE_Symbol = "BANKNIFTY22DEC"+Strike_PE+"PE";// Put option symbol. I have trouble on this line. This is giving only string of Last date selected for backtest.

SetForeign(CE_Symbol,1,True); CE_Premium = C; RestorePriceArrays();// Call option Premium 
SetForeign(PE_Symbol,1,True); PE_Premium = C; RestorePriceArrays();// Put option Premium 
Combined_premium= CE_Premium + PE_Premium;//Combined premium of Call option and Put option
Short_Premium = ValueWhen(TimeNum() == Entry_Time,Combined_premium,1);//Combined premium of Call option and Put option at the time of creating short position

Short = TimeNum() == Entry_Time AND (Name() == CE_Symbol OR  Name() == PE_Symbol);//Short Position entry in both Call option strike and Put option Strike
ShortPrice = C;

SL  = Short_Premium + 30;
Target = Short_Premium - 50;

Cover = (Combined_premium > SL OR Combined_premium < Target OR TimeNum() == 151500);//Square off Short Position in both Call option strike and Put option Strike
CoverPrice = C;

maxpos = 2; // maximum number of open positions
SetOption("InitialEquity", 200000 ); // set initial equity = 200K
SetOption( "MaxOpenPositions", maxpos );
SetPositionSize( 25, spsShares ); // number of shares/contracts per trade


Filter = TimeNum() == Entry_Time AND Name() == Index;
AddColumn(Strike_CE,"Strike_CE",1);
AddTextColumn(CE_Symbol,"CE_Symbol");
AddColumn(Strike_PE,"Strike_PE",1);
AddTextColumn(PE_Symbol,"PE_Symbol");

When date range is selected 01-12-2022 to 01-12-2022. The Call Option strike is 43200PE and PE Option strike is 43700CE which are correct as per snap-shot below:
01-12-2022

When date range is selected 02-12-2022 to 02-12-2022. The Call Option strike is 42800PE and PE Option strike is 43300CE which are correct as per snap-shot below:
02-12-2022

When date range is selected 01-12-2022 to 02-12-2022(For 2 days). The Call Option strike is 42800PE and PE Option strike is 43300CE appearing for both days, which is not correct for 01-12-2022 as per snap-shot below:
01_02-12-2022

I am struggling to get this code corrected from many days. I have tried many different ways but still I am not able to figure out.
Please help me to get the strike symbol names correctly. If there is sample code, it will be very helpful.

Thank you.

As far as EXPLORATION is considered,

You need to use AddMultiTextColumn() or better yet AddRow()

https://forum.amibroker.com/search?q=addmultitextcolumn
https://forum.amibroker.com/search?q=addrow

As far as BACKTEST is considered, you should not use SetForeign the way you do.
SetForeign is used to access other symbol data (such as an index), not to "switch" backtested symbol.
Instead you should run your backtest on a WATCH LIST consiting of all options you want to trade (all strike prices) and use SetForeign to access underlying index as explained here:

Then depending on price use Name() to select option to trade

if( Name() == CE_SYMBOL )
{
    ... trade call option 
}

if( Name() == PE_SYMBOL )
{
    ... trade put option 
}

You have to keep in mind that backtester trades CURRENT symbol (or one of the symbols within Watch list / portfolio ), and not what you specify with SetForeign.

Thank you very much Tomasz for pointing out mistakes in my code. With your suggestion I changed the code and now I am able to enter the correct strikes in backtest on each day but still not able to exit the positions as desired.
Short

In below code I am taking short position at 9:35am daily in both Call and Put options types in Strike values based on Index value at 9.35am. Please note Strike value will be different daily. I am getting the correct strikes to enter the positions with code below.
Now I want to cover the both positions based on combined profit/loss of both positions.
But I am not able to figure out how to close both the position based on combined profit/loss of both the positions. Is there any way to achieve this?
If I use Foreign function, I need to symbol name string, but as per my understanding Amibroker stores strings based on last value only. I need the symbol name string based on 9.35am daily because it strike can be different daily. Is there any alternative way to achieve this?

Thank you very much.

SetOption("DisableRuinStop", TRUE );
Entry_Time=093500;

Index="BANKNIFTY";//Underlaying Intrument
SetForeign(Index,1,True); Index_C=C; PDC0=TimeFrameGetPrice("C",inDaily,-1); RestorePriceArrays();

Strike_CE = ceil(Index_C/100)*100+200;//Call option Strike selection
Strike_PE = floor(Index_C/100)*100-200;//Put option Strike selection

Name_Str_Mid=StrMid(Name(),14,5);//Extract the Digit part from Option symbol name. For example it extracts '43200' from Symbol BANKNIFTY22DEC43200PE
Name_Strike =StrToNum(Name_Str_Mid);// Convert to number to compare with index strike
Name_Strike_Type=StrRight(Name(),2);//Extract the Last 2 alphabet from symbol to Get type of option(CE or PE). For example it extracts 'PE' from Symbol BANKNIFTY22DEC43200PE

Short = TimeNum() == Entry_Time AND ((Name_Strike==Strike_CE AND Name_Strike_Type == "CE") OR (Name_Strike==Strike_PE AND Name_Strike_Type == "PE"));//Short Position entry in both Call option strike and Put option Strike
ShortPrice = C;

Cover = (TimeNum() == 151500);//Square off Short Position in both Call option strike and Put option Strike
CoverPrice = C;

maxpos = 2; // maximum number of open positions
SetOption("InitialEquity", 200000 ); // set initial equity = 200K
SetOption( "MaxOpenPositions", maxpos );
SetPositionSize( 25, spsShares ); // number of shares/contracts per trade