How to sell the shares that we bought yesterday with IBcontroller?

Greetings everyone!

I bought stock with TWS (Ib.Controller). my code is buy code then save it and make it a sign to sell.

after buying usually wait a while until the signal also appears in intraday. but sometimes a sell signal doesn't appear until the trade ends.

because I turned off my computer, the next day my code did not save the previous day's purchase data and the sell signal could not be executed.

one solution I know of is to use persistent variables if I'm not mistaken, or is there really no need to use persistent variables ? do we need to be stored or can be directly sold if it meets the selling conditions ?

do you all here have any input for me? I also opened a paid service for this problem

Buy = 1; // filed for test
Sell = 1 ;// filed for test


Symbol                = Name();
Open_Position1        = StaticVarGet(Symbol + "Open_Position1");         //Open_Position1
Open_Position2        = StaticVarGet(Symbol + "Open_Position2");         //Open_Position2
Open_Position3        = StaticVarGet(Symbol + "Open_Position3"); 
Open_Position4        = StaticVarGet(Symbol + "Open_Position4");
Open_Position5        = StaticVarGet(Symbol + "Open_Position5");

TotalOf_Trade     	  = StaticVarGet(Symbol + "TotalOf_Trade");   
Win          	      = StaticVarGet(Symbol + "Win");
Loss                  = StaticVarGet(Symbol + "Loss");
Buy_Price             = StaticVarGet(Symbol + "Buy_Price");
Buy_Price2            = StaticVarGet(Symbol + "Buy_Price2");
Buy_Price3            = StaticVarGet(Symbol + "Buy_Price3");


Sell_Price             = StaticVarGet(Symbol + "Sell_Price");
Shares_Holding         = StaticVarGet(Symbol + "Shares_Holding");
Profit_Total           = StaticVarGet(Symbol + "Profit_Total");
Profit_Sesion   	   = StaticVarGet("Profit_Sesion");
Modal_tersedia         = StaticVarGet("Modal_tersedia");
Nilai_SaatIni          = StaticVarGet("Nilai_SaatIni");


if(IsEmpty(Open_Position1)){ // jika nilai posisiopen1 tidak ada maka, 
    Open_Position1 = 0; 
    Buy_Price      = 0;  
    Sell_Price     = 0; 
    TotalOf_Trade  = 0; 
    Win            = 0; 
    Loss           = 0; 
    Profit_Total   = 0; 
    Profit_Sesion  = 0; 
    Shares_Holding = 0; 
    StaticVarSet(Symbol + "Open_Position1",0);
    StaticVarSet(Symbol + "TotalOf_Trade",0);
    StaticVarSet(Symbol + "Win",0);
    StaticVarSet(Symbol + "Loss",0);
    StaticVarSet(Symbol + "Buy_Price",0);
    StaticVarSet(Symbol + "Sell_Price",0);
    StaticVarSet(Symbol + "Profit_Total",0);
    StaticVarSet("Profit_Sesion",0);
    StaticVarSet(Symbol + "Shares_Holding",0);
}

if(IsEmpty(Open_Position2)){
	Open_Position2 = 0;
	Buy_Price2     = 0;
	Sell_Price     = 0;
	TotalOf_Trade  = 1;
	Win            = 0;
	Loss           = 0;
	Profit_Total   = 0;
	Profit_Sesion  = 0;
	Shares_Holding  = 0;
	StaticVarSet(Symbol + "Open_Position2",0);
    StaticVarSet(Symbol + "Win",0);
    StaticVarSet(Symbol + "Loss",0);
    StaticVarSet(Symbol + "Buy_Price2",0);
    StaticVarSet(Symbol + "Sell_Price",0);
    StaticVarSet(Symbol + "Profit_Total",0);
    StaticVarSet("Profit_Sesion",0);
    StaticVarSet(Symbol + "Shares_Holding",0);
    }

if(IsEmpty(Open_Position3)){
	Open_Position3  = 0;
	Buy_Price3      = 0;
	Sell_Price      = 0;
	TotalOf_Trade   = 2;
	Win             = 0;
	Loss            = 0;
	Profit_Total    = 0;
	Profit_Sesion   = 0;
	Shares_Holding  = 0;
	StaticVarSet(Symbol + "Open_Position3",0);
    StaticVarSet(Symbol + "Win",0);
    StaticVarSet(Symbol + "Loss",0);
    StaticVarSet(Symbol + "Buy_Price3",0);
    StaticVarSet(Symbol + "Sell_Price",0);
    StaticVarSet(Symbol + "Profit_Total",0);
    StaticVarSet("Profit_Sesion",0);
    StaticVarSet(Symbol + "Shares_Holding",0);
 }
    
    
Transmit = ParamToggle("Automatic Transmit","OFF|ON",0);
if(Transmit){
   Panggil_IBController = GetTradingInterface("IB"); 
   SetChartBkColor( colorBlue);
}

  Posisi_1 = 1;
if(LastValue(Ref(Buy,-1)) AND Open_Position1==0 AND transmit==1){
  Posisi_1 = 1;
  
  orderid                = Panggil_IBController.PlaceOrder( Name(), "BUY", Posisi_1 , "MKT", 0, 0, "Day", Transmit );
  StaticVarSet(Symbol + "Shares_Holding", Shares_Holding);
  Open_Position1   = 1; 
  StaticVarSet(Symbol + "Open_Position1", 1);
  TotalOf_Trade  = TotalOf_Trade+1;
  StaticVarSet(Symbol + "TotalOf_Trade",TotalOf_Trade);
  Buy_Price = LastValue(C);
  StaticVarSet(Symbol + "Buy_Price",Buy_Price);
}

  Posisi_2 = 2;
if(LastValue(Ref(Buy,-1)) AND Open_Position2==0  AND transmit==1){
  Posisi_2 = 2;
  
  Panggil_IBController.PlaceOrder( Name(), "BUY",Posisi_2, "MKT", 0, 0, "Day", Transmit );
  Shares_Holding = Shares_Holding + Jumlah_saham_ygDibeli2;
  StaticVarSet(Symbol + "Shares_Holding", Shares_Holding);
  Open_Position2   = 1;
  StaticVarSet(Symbol + "Open_Position2", 1);
  TotalOf_Trade  = TotalOf_Trade+1;
  StaticVarSet(Symbol + "TotalOf_Trade",TotalOf_Trade);
  Buy_Price2     = LastValue(C);
  StaticVarSet(Symbol + "Buy_Price2",Buy_Price2);
}

  Posisi_3 = 3;
if(LastValue(Ref(Buy,-1)) AND Open_Position3==0  AND transmit==1){
  Posisi_3 = 3;
  
  Panggil_IBController.PlaceOrder( Name(), "BUY", Posisi_3, "MKT", 0, 0, "Day", Transmit );
  Shares_Holding = Shares_Holding + Jumlah_saham_ygDibeli3;
  StaticVarSet(Symbol + "Shares_Holding", Shares_Holding);
  Open_Position3   = 1;
  StaticVarSet(Symbol + "Open_Position3", 1);
  TotalOf_Trade  = TotalOf_Trade+1;
  StaticVarSet(Symbol + "TotalOf_Trade",TotalOf_Trade);
  Buy_Price3     = LastValue(C);
  StaticVarSet(Symbol + "Buy_Price3",Buy_Price3);
}


if(LastValue(Ref(Sell,-1)) AND (Open_Position1==1 OR Open_Position2==1 OR Open_Position3==1 OR Open_Position4==1 OR Open_Position5==1) AND transmit==1 ){
  
  if( ibc.IsConnected()){
	if( ibc.GetPositionSize( Name() ) > 0 ){
	Panggil_IBController.PlaceOrder( Name(), "SELL", ibc.GetPositionSize( Name() ), "MKT", 0, 0, "Day", Transmit );
  
  StaticVarSet(Symbol + "Shares_Holding", 0);
  Open_Position1 = 0;
  StaticVarSet(Symbol + "Open_Position1", 0);
  Open_Position2 = 0;
  StaticVarSet(Symbol + "Open_Position2", 0);
  Open_Position3 = 0;
  StaticVarSet(Symbol + "Open_Position3", 0);
  Open_Position4 = 0;
  StaticVarSet(Symbol + "Open_Position4", 0);
  Open_Position5 = 0;
  StaticVarSet(Symbol + "Open_Position5", 0);
  
  Sell_Price = LastValue(C);  
  StaticVarSet(Symbol + "Sell_Price",Sell_Price);
  
	if (Sell_Price > (Buy_Price + Buy_Price2 + Buy_Price3 + Buy_Price4 + Buy_Price5) ){
	 Win+=1; 
	 StaticVarSet(Symbol + "Win",Win);
	}
	if (Sell_Price < (Buy_Price + Buy_Price2 + Buy_Price3 + Buy_Price4 + Buy_Price5) ){
	 Loss+=1; 
	 StaticVarSet(Symbol + "Loss",Loss);
	}
	Profit_Total = Profit_Total+(Sell_Price - (Buy_Price + Buy_Price2 + Buy_Price3 + Buy_Price4 + Buy_Price5));
	StaticVarSet(Symbol+"Profit_Total",Profit_Total);
	
	Profit_Sesion = Profit_Sesion+(Sell_Price-(Buy_Price + Buy_Price2 + Buy_Price3 + Buy_Price4 + Buy_Price5));
	StaticVarSet("Profit_Sesion",Profit_Sesion);
}}}