Automatically fill watchlist with top 60 symbols from Exploration

I do screen for the Highest Gainers with three explorations for 1, 3 and 6 months with daily EOD data and export them as a csv-file with the Amibroker batch. So far, I then selected the top 60 symbols from each exploration and added them manually to one watchlist. I was looking into a few variations to automate this, either before or after the csv-export. In the end it seemed the easiest by reading the top 60 directly from the csv-file.

For the csv-reading exploration I use the settings “Current” and “1 recent bar(s)” (do not run it with “All symbols”). Set symbol “MSFT” as current symbol, it is not in the csv-files.

As a beginner, it took me quite a while to get it done, but I am not so happy with the code. So I ask you for some advice on how I can improve it, especially this issue:

  1. How to solve the case of a csv-file with less than 60 symbols in a simple way?

I need to check this, because if the csv-file has less than 60 symbols, the exploration will add the current symbol to the watchlist, even if it is not part of the top 60 symbols.
My current solutions reads the csv-file twice. First to count the symbols and then it uses this in the second reading to read the symbols and write them into the watchlist.

Testdata 1: "test_10symbols.csv"

Ticker,Date/Time,Close,%Change,Current Currency Vol.,ADR%(20),FullName,Sector,Industry,Rank(%Change)
SBNY,18.01.2024,1.28,2033.33,1136417,1007.23,Signature Bank Common Stock,Finance,Major Banks,1
ACON,18.01.2024,3.11,1270.04,649679,30.11,Aclarion Inc. Common Stock,Technology,Retail: Computer Software & Peripheral ,2
RNAZ,18.01.2024,1.09,522.86,3882907,22.54,TransCode Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,3
POL,18.01.2024,6.39,399.22,1411551,59.67,Polished Inc. Common Stock,Consumer Discretionary,Other Specialty Stores,4
LBPH,18.01.2024,23.69,394.57,12515427,13.50,Longboard Pharmaceuticals Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,5
SWVL,18.01.2024,4.13,358.89,797503,25.42,Swvl Holdings Corp Class A Common Shares,Finance,Business Services,6
SMFL,18.01.2024,1.64,242.65,1485441,30.79,Smart for Life Inc. Common Stock,Consumer Staples,Farming/Seeds/Milling,7
ZJYL,18.01.2024,105.15,209.26,1619310,49.51,,Undefined,Undefined,8
NKTX,18.01.2024,8.51,187.50,16840440,18.95,Nkarta Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,9
NEXI,18.01.2024,8.37,169.13,1732590,28.24,NexImmune Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,10

Testdata 2: "test_249symbols.csv"

Ticker,Date/Time,Close,%Change,Current Currency Vol.,ADR%(20),FullName,Sector,Industry,Rank(%Change)
SBNY,18.01.2024,1.28,2033.33,1136417,1007.23,Signature Bank Common Stock,Finance,Major Banks,1
ACON,18.01.2024,3.11,1270.04,649679,30.11,Aclarion Inc. Common Stock,Technology,Retail: Computer Software & Peripheral ,2
RNAZ,18.01.2024,1.09,522.86,3882907,22.54,TransCode Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,3
POL,18.01.2024,6.39,399.22,1411551,59.67,Polished Inc. Common Stock,Consumer Discretionary,Other Specialty Stores,4
LBPH,18.01.2024,23.69,394.57,12515427,13.50,Longboard Pharmaceuticals Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,5
SWVL,18.01.2024,4.13,358.89,797503,25.42,Swvl Holdings Corp Class A Common Shares,Finance,Business Services,6
SMFL,18.01.2024,1.64,242.65,1485441,30.79,Smart for Life Inc. Common Stock,Consumer Staples,Farming/Seeds/Milling,7
ZJYL,18.01.2024,105.15,209.26,1619310,49.51,,Undefined,Undefined,8
NKTX,18.01.2024,8.51,187.50,16840440,18.95,Nkarta Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,9
NEXI,18.01.2024,8.37,169.13,1732590,28.24,NexImmune Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,10
IVVD,18.01.2024,4.44,161.18,2493504,11.12,Invivyd Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,11
MCAF,18.01.2024,19.45,146.20,1283700,41.46,Mountain Crest Acquisition Corp. IV Common Stock,Industrials,Consumer Electronics/Appliances,12
CGEN,18.01.2024,1.93,144.30,2379690,12.27,Compugen Ltd. Ordinary Shares,Health Care,Biotechnology: Biological Products (No ,13
HLP,18.01.2024,3.00,141.94,1606200,27.26,,Undefined,Undefined,14
PRAX,18.01.2024,38.91,137.98,6147780,14.54,Praxis Precision Medicines Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,15
ALAR,18.01.2024,10.12,129.48,3098744,14.31,Alarum Technologies Ltd. American Depositary Share,Technology,Computer Software: Prepackaged Software,16
CYTK,18.01.2024,82.74,119.59,210722224,11.41,Cytokinetics Incorporated Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,17
ADAG,18.01.2024,3.37,103.01,1355414,20.45,Adagene Inc. American Depositary Shares,Health Care,Biotechnology: Pharmaceutical Preparati,18
MIGI,18.01.2024,2.25,97.37,1453725,28.81,Mawson Infrastructure Group Inc. Common Stock,Finance,Investment Bankers/Brokers/Service,19
UP,18.01.2024,3.65,93.12,3152505,24.39,Wheels Up Experience Inc. Class A Common Stock,Industrials,Aerospace,20
INO,18.01.2024,0.72,84.62,3620304,14.02,Inovio Pharmaceuticals Inc. Common Stock,Health Care,Biotechnology: Biological Products (No ,21
IMNM,18.01.2024,13.48,81.18,5371780,9.26,Immunome Inc. Common Stock,Health Care,Medicinal Chemicals and Botanical Produ,22
LQDA,18.01.2024,13.34,78.34,24025340,7.81,Liquidia Corporation Common Stock,Health Care,Biotechnology: Biological Products (No ,23
ADTH,18.01.2024,2.25,73.08,833850,14.07,AdTheorent Holding Company Inc. Common Stock,Consumer Discretionary,Advertising,24
NAMS,18.01.2024,17.60,70.71,2474560,9.77,NewAmsterdam Pharma Company N.V. Ordinary Shares,n/a,n/a,25
GCT,18.01.2024,22.16,70.46,83897760,13.37,GigaCloud Technology Inc Class A Ordinary Shares,Consumer Discretionary,Catalog/Specialty Distribution,26
NGM,18.01.2024,1.33,66.46,544103,15.03,NGM Biopharmaceuticals Inc. Common Stock,Health Care,Biotechnology: Biological Products (No ,27
IGMS,18.01.2024,10.36,66.29,4491060,11.42,IGM Biosciences Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,28
FUSN,18.01.2024,8.94,61.66,9713310,11.16,Fusion Pharmaceuticals Inc. Common Shares,Health Care,Pharmaceuticals and Biotechnology,29
CXDO,18.01.2024,5.46,60.12,933114,11.42,Crexendo Inc. Common Stock,Telecommunications,Telecommunications Equipment,30
NPCE,18.01.2024,13.25,59.83,2852725,10.16,Neuropace Inc. Common Stock,Health Care,Medical Specialities,31
WGS,18.01.2024,3.26,59.80,1016468,17.26,GeneDx Holdings Corp. Class A Common Stock,Technology,Retail: Computer Software & Peripheral ,32
ESOA,18.01.2024,5.75,59.72,524400,7.54,Energy Services of America Corporation Common Stock,Industrials,Water Sewer Pipeline Comm & Power Line ,33
ZIM,18.01.2024,13.72,59.35,82796088,9.80,ZIM Integrated Shipping Services Ltd. Ordinary Shares,Consumer Discretionary,Marine Transportation,34
AUVI,18.01.2024,2.82,59.32,2367954,24.40,Applied UV Inc. Common Stock,n/a,n/a,35
ANNX,18.01.2024,4.33,58.61,5487842,11.53,Annexon Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,36
SSNT,18.01.2024,13.64,58.05,2370632,17.56,SilverSun Technologies Inc. Common Stock,Technology,Computer Software: Prepackaged Software,37
DAVE,18.01.2024,11.95,56.82,1641930,7.41,Dave Inc. Class A Common Stock,Technology,Retail: Computer Software & Peripheral ,38
LPCN,18.01.2024,4.01,55.79,2532716,9.93,Lipocine Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,39
SLDB,18.01.2024,7.51,55.49,2918386,16.11,Solid Biosciences Inc. Common Stock,Health Care,Biotechnology: Biological Products (No ,40
ALT,18.01.2024,10.79,54.58,70510488,12.72,Altimmune Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,41
IMPP,18.01.2024,3.33,53.46,4589073,9.01,Imperial Petroleum Inc. Common Shares,Consumer Discretionary,Marine Transportation,42
SYRS,18.01.2024,6.63,52.76,1204671,12.02,Syros Pharmaceuticals Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,43
KROS,18.01.2024,51.86,52.53,13530274,7.25,Keros Therapeutics Inc. Common Stock,Health Care,Medicinal Chemicals and Botanical Produ,44
GLYC,18.01.2024,3.06,51.49,1116288,11.92,GlycoMimetics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,45
SGHT,18.01.2024,5.21,51.01,1580714,10.47,Sight Sciences Inc. Common Stock,Health Care,Medical Specialities,46
QSG,18.01.2024,2.39,50.31,1372099,18.32,QuantaSing Group Limited American Depositary Shares,Real Estate,Other Consumer Services,47
HOWL,18.01.2024,4.47,50.00,710730,11.88,Werewolf Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,48
TNYA,18.01.2024,3.19,49.77,1238677,9.27,Tenaya Therapeutics Inc. Common Stock,Health Care,Medicinal Chemicals and Botanical Produ,49
GAU,18.01.2024,0.94,49.21,535236,7.65,Galiano Gold Inc.,n/a,n/a,50
REAX,18.01.2024,2.23,47.68,1930957,9.16,The Real Brokerage Inc. Common Shares,n/a,n/a,51
ACET,18.01.2024,2.44,47.29,1296095,15.63,Adicet Bio Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,52
MPTI,18.01.2024,40.94,46.21,2210760,11.33,M-tron Industries Inc. Common Stock,n/a,n/a,53
AGLE,18.01.2024,21.78,45.69,2305762,10.88,Aeglea BioTherapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,54
MREO,18.01.2024,2.97,45.59,8402130,8.34,Mereo BioPharma Group plc American Depositary Shares,Health Care,Biotechnology: Pharmaceutical Preparati,55
HMST,18.01.2024,14.59,45.46,7850879,6.02,HomeStreet Inc. Common Stock,Finance,Banks,56
STIM,18.01.2024,3.20,45.45,524160,13.51,Neuronetics Inc. Common Stock,Health Care,Managed Health Care,57
GRTS,18.01.2024,2.74,44.21,10229516,12.23,Gritstone bio Inc. Common Stock,Health Care,Biotechnology: Biological Products (No ,58
VTSI,18.01.2024,11.90,44.07,1664810,7.42,VirTra Inc. Common Stock,Consumer Discretionary,Military/Government/Technical,59
SIDU,18.01.2024,8.58,43.00,2904330,38.90,Sidus Space Inc. Class A Common Stock,n/a,n/a,60
FATE,18.01.2024,4.33,42.90,13932641,10.79,Fate Therapeutics Inc. Common Stock,Health Care,Biotechnology: Biological Products (No ,61
FULC,18.01.2024,7.07,42.54,4647111,6.96,Fulcrum Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,62
MAIA,18.01.2024,1.26,42.37,881118,13.64,MAIA Biotechnology Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,63
EPIX,18.01.2024,8.57,42.12,2123646,10.62,ESSA Pharma Inc. Common Stock,Health Care,Pharmaceuticals and Biotechnology,64
CELU,18.01.2024,0.29,40.98,27271686,16.57,Celularity Inc. Class A Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,65
IPSC,18.01.2024,3.86,40.36,536926,10.61,Century Therapeutics Inc. Common Stock,Health Care,Medicinal Chemicals and Botanical Produ,66
SANA,18.01.2024,5.65,39.85,16083290,15.01,Sana Biotechnology Inc. Common Stock,Health Care,Medicinal Chemicals and Botanical Produ,67
CDIO,18.01.2024,2.32,39.76,2936656,17.97,Cardio Diagnostics Holdings Inc. Common stock,Health Care,Biotechnology: Commercial Physical & Bi,68
YRD,18.01.2024,4.02,39.58,577674,8.64,Yiren Digital Ltd. American Depositary Shares each representing two ordinary shares,Finance,Diversified Financial Services,69
KOPN,18.01.2024,2.07,38.93,1537803,9.15,Kopin Corporation Common Stock,Industrials,Industrial Machinery/Components,70
GTHX,18.01.2024,3.54,38.82,5934456,10.73,G1 Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,71
OCGN,18.01.2024,0.52,38.61,860185,10.36,Ocugen Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,72
YMAB,18.01.2024,9.68,38.29,3122768,9.52,Y-mAbs Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,73
ATAI,18.01.2024,1.77,38.28,1936026,11.28,ATAI Life Sciences N.V. Common Shares,Health Care,Biotechnology: Pharmaceutical Preparati,74
DRIO,18.01.2024,2.47,37.99,1119157,10.02,DarioHealth Corp. Common Stock,Health Care,Medical/Dental Instruments,75
OMGA,18.01.2024,3.58,37.69,2403612,15.01,Omega Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,76
VRCA,18.01.2024,5.76,37.14,1144512,8.59,Verrica Pharmaceuticals Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,77
ARDX,18.01.2024,8.04,36.97,60026640,6.98,Ardelyx Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,78
OSCR,18.01.2024,11.03,36.68,35058856,6.74,Oscar Health Inc. Class A Common Stock,Finance,Accident &Health Insurance,79
APGE,18.01.2024,32.19,36.28,5224437,7.46,,Undefined,Undefined,80
VSTM,18.01.2024,10.39,36.17,1357973,6.79,Verastem Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,81
DYN,18.01.2024,16.21,35.54,17670520,11.44,Dyne Therapeutics Inc. Common Stock,Health Care,Medicinal Chemicals and Botanical Produ,82
OMER,18.01.2024,3.87,34.84,3842523,11.68,Omeros Corporation Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,83
PACI,01.12.2023,14.50,34.51,508936,17.48,PROOF Acquisition Corp I Class A Common Stock,Industrials,Consumer Electronics/Appliances,84
EWTX,18.01.2024,9.69,33.66,9738450,10.57,Edgewise Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,85
AMRN,18.01.2024,1.09,32.93,1075939,7.93,Amarin Corporation plc,Health Care,Biotechnology: Pharmaceutical Preparati,86
RVSN,18.01.2024,1.66,32.80,1030030,20.65,Rail Vision Ltd. Ordinary Share,n/a,n/a,87
DRCT,18.01.2024,11.29,32.67,2400254,15.27,Direct Digital Holdings Inc. Class A Common Stock,Consumer Discretionary,Advertising,88
SCOR,18.01.2024,19.10,32.64,622660,10.08,comScore Inc. Common Stock,Finance,Business Services,89
METC,18.01.2024,19.99,32.56,21355316,7.00,Ramaco Resources Inc. Common Stock,Energy,Coal Mining,90
ESTA,18.01.2024,36.13,31.96,14307480,7.62,Establishment Labs Holdings Inc. Common Shares,Industrials,Industrial Specialties,91
WRAP,18.01.2024,3.40,31.78,2646900,11.09,Wrap Technologies Inc. Common Stock,Industrials,Industrial Machinery/Components,92
PBYI,18.01.2024,5.12,31.28,2818048,7.67,Puma Biotechnology Inc Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,93
ABSI,18.01.2024,3.62,31.16,3453480,15.37,Absci Corporation Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,94
ANIX,18.01.2024,4.93,29.74,2322523,6.73,Anixa Biosciences Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,95
LXEO,18.01.2024,15.07,29.47,6477086,14.48,,Undefined,Undefined,96
MRSN,18.01.2024,2.63,29.31,3705713,10.58,Mersana Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,97
AUTL,18.01.2024,6.32,28.98,8175552,8.58,Autolus Therapeutics plc American Depositary Share,Health Care,Biotechnology: Biological Products (No ,98
RNA,18.01.2024,10.43,28.77,6588631,6.99,Avidity Biosciences Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,99
CLRB,18.01.2024,3.54,27.34,2592342,10.95,Cellectar Biosciences Inc.  Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,100
WLGS,18.01.2024,0.70,27.27,899220,21.85,,Undefined,Undefined,101
MGTX,18.01.2024,6.02,27.27,812098,7.21,MeiraGTx Holdings plc Ordinary Shares,Health Care,Biotechnology: Biological Products (No ,102
ANY,18.01.2024,1.77,26.43,1919919,20.42,Sphere 3D Corp. Common Shares,n/a,n/a,103
LYRA,18.01.2024,5.09,26.30,2407061,8.78,Lyra Therapeutics Inc. Common Stock,Health Care,Medicinal Chemicals and Botanical Produ,104
CRGX,18.01.2024,20.50,26.04,2201700,12.23,,Undefined,Undefined,105
ACRX,18.01.2024,0.97,25.84,591035,10.01,AcelRx Pharmaceuticals Inc. Common Stock,Health Care,Medicinal Chemicals and Botanical Produ,106
STTK,18.01.2024,8.47,25.78,3324206,12.01,Shattuck Labs Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,107
HYLN,18.01.2024,0.88,24.89,1165282,12.81,Hyliion Holdings Corp. Class A Common Stock,Consumer Discretionary,Auto Parts:O.E.M.,108
SATS,18.01.2024,17.22,24.51,46760908,8.82,EchoStar  Corporation Common Stock,Technology,Radio And Television Broadcasting And C,109
SERA,18.01.2024,5.98,24.07,1154140,12.10,Sera Prognostics Inc. Class A Common Stock,Health Care,Precision Instruments,110
SMMT,18.01.2024,3.31,23.97,7702701,9.57,Summit Therapeutics Inc. Common Stock,Health Care,Medicinal Chemicals and Botanical Produ,111
OGI,18.01.2024,1.68,23.53,1695792,8.52,Organigram Holdings Inc. Common Shares,Health Care,Pharmaceuticals and Biotechnology,112
SILK,18.01.2024,13.18,23.18,9131104,6.79,Silk Road Medical Inc. Common Stock,Health Care,Medical/Dental Instruments,113
SLN,18.01.2024,19.03,23.09,26577298,6.76,Silence Therapeutics Plc American Depository Share,Health Care,Biotechnology: Pharmaceutical Preparati,114
ARQT,18.01.2024,3.27,22.47,8892111,13.37,Arcutis Biotherapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,115
APLS,18.01.2024,63.88,22.36,120995112,6.50,Apellis Pharmaceuticals Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,116
SELB,12.01.2024,0.84,22.35,573930,10.62,Selecta Biosciences Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,117
AMPX,18.01.2024,4.55,22.31,1643005,12.55,Amprius Technologies Inc. Common Stock,Industrials,Electrical Products,118
ABOS,18.01.2024,3.68,22.26,1431520,8.56,Acumen Pharmaceuticals Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,119
AKBA,18.01.2024,1.40,21.74,2707600,6.98,Akebia Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,120
AQST,18.01.2024,2.48,21.57,2401384,9.09,Aquestive Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,121
APEI,18.01.2024,11.18,21.52,2765932,7.78,American Public Education Inc. Common Stock,Real Estate,Other Consumer Services,122
ESPR,18.01.2024,2.15,21.47,26699346,13.20,Esperion Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,123
CLPT,18.01.2024,7.65,20.66,830025,6.09,ClearPoint Neuro Inc. Common Stock,Health Care,Medical/Dental Instruments,124
TTOO,18.01.2024,4.50,20.64,501300,16.38,T2 Biosystems Inc. Common Stock,Health Care,Biotechnology: In Vitro & In Vivo Diagn,125
TELA,18.01.2024,6.95,20.24,1050840,6.39,TELA Bio Inc. Common Stock,Health Care,Biotechnology: Electromedical & Electro,126
REKR,18.01.2024,3.46,20.14,2954148,8.03,Rekor Systems Inc. Common Stock,Technology,EDP Services,127
VZLA,18.01.2024,1.38,20.00,1826706,6.38,Vizsla Silver Corp. Common Shares,n/a,n/a,128
VXRT,18.01.2024,0.79,19.70,2152592,9.78,Vaxart Inc Common Stock,Health Care,Biotechnology: Biological Products (No ,129
BARK,18.01.2024,0.91,19.69,787877,8.66,BARK Inc. Class A Common Stock,Consumer Discretionary,Department/Specialty Retail Stores,130
KPLT,18.01.2024,11.32,19.44,527652,9.56,Katapult Holdings Inc. Common Stock,Technology,EDP Services,131
ENTA,18.01.2024,11.62,19.30,3644032,7.25,Enanta Pharmaceuticals Inc. Common Stock,Health Care,Biotechnology: In Vitro & In Vivo Diagn,132
BCYC,18.01.2024,17.74,18.42,6441394,6.35,Bicycle Therapeutics plc American Depositary Shares,Health Care,Biotechnology: Pharmaceutical Preparati,133
MCRB,18.01.2024,1.23,18.27,7319361,12.92,Seres Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,134
KALV,18.01.2024,12.46,18.22,2815960,6.37,KalVista Pharmaceuticals Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,135
HRTX,18.01.2024,2.09,18.08,4440205,9.89,Heron Therapeutics Inc. Common Stock,Health Care,Medicinal Chemicals and Botanical Produ,136
INBX,18.01.2024,32.76,17.71,14827175,7.23,Inhibrx Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,137
ALLO,18.01.2024,3.20,17.65,8479040,9.13,Allogene Therapeutics Inc. Common Stock,Health Care,Biotechnology: Biological Products (No ,138
SGMT,18.01.2024,6.46,16.40,549100,16.18,,Undefined,Undefined,139
ATXS,18.01.2024,7.11,16.18,1766835,9.11,Astria Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,140
AGFY,18.01.2024,1.37,16.10,101399728,14.97,Agrify Corporation Common Stock,Consumer Discretionary,Military/Government/Technical,141
IMTX,18.01.2024,11.34,15.95,27985986,6.25,Immatics N.V. Ordinary Shares,Health Care,Biotechnology: Biological Products (No ,142
ARWR,18.01.2024,33.16,15.78,49773160,6.10,Arrowhead Pharmaceuticals Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,143
AEVA,18.01.2024,0.93,15.53,1821033,13.95,Aeva Technologies Inc. Common Stock,Consumer Discretionary,Auto Parts:O.E.M.,144
ACXP,18.01.2024,4.00,15.27,1110800,8.94,Acurx Pharmaceuticals Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,145
SLNO,18.01.2024,43.57,15.17,6513715,6.07,Soleno Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,146
BLFS,18.01.2024,17.03,15.07,9356282,6.74,BioLife Solutions Inc. Common Stock,Health Care,Medical/Dental Instruments,147
CTMX,18.01.2024,1.68,15.07,711648,6.42,CytomX Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,148
ATHA,18.01.2024,2.78,14.40,598534,9.89,Athira Pharma Inc. Common Stock,Health Care,Medicinal Chemicals and Botanical Produ,149
LCUT,18.01.2024,7.12,14.29,739056,7.61,Lifetime Brands Inc. Common Stock,Consumer Discretionary,Home Furnishings,150
XERS,18.01.2024,2.48,14.29,5986224,7.16,Xeris Biopharma Holdings Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,151
CURV,18.01.2024,5.92,14.07,821104,9.74,Torrid Holdings Inc. Common Stock,Consumer Discretionary,Clothing/Shoe/Accessory Stores,152
ARCT,18.01.2024,32.27,13.83,8457967,6.37,Arcturus Therapeutics Holdings Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,153
MGNX,18.01.2024,10.75,13.76,11361675,6.30,MacroGenics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,154
BWAY,18.01.2024,6.24,13.45,501696,8.15,BrainsWay Ltd. American Depositary Shares,Health Care,Medical/Dental Instruments,155
DCTH,18.01.2024,3.84,13.27,886272,7.29,Delcath Systems Inc. Common Stock,Health Care,Medical Specialities,156
ICU,18.01.2024,0.60,13.21,1870140,10.31,SeaStar Medical Holding Corporation Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,157
VLCN,18.01.2024,0.10,12.90,649236,25.47,Volcon Inc. Common stock,n/a,n/a,158
SCLX,18.01.2024,1.53,12.50,1389546,13.19,Scilex Holding Company Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,159
CRBP,18.01.2024,6.92,12.34,783344,9.25,Corbus Pharmaceuticals Holdings Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,160
EYPT,18.01.2024,22.86,12.33,19561302,8.29,EyePoint Pharmaceuticals Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,161
NKTR,18.01.2024,0.55,12.24,576620,8.53,Nektar Therapeutics  Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,162
FGEN,18.01.2024,0.80,11.97,901610,13.23,FibroGen Inc Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,163
RSI,18.01.2024,4.86,11.72,11851596,6.70,Rush Street Interactive Inc. Class A Common Stock,Consumer Discretionary,Services-Misc. Amusement & Recreation,164
PTN,18.01.2024,2.92,11.45,663716,16.02,Palatin Technologies Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,165
OPRT,18.01.2024,3.56,11.44,2939985,7.16,Oportun Financial Corporation Common Stock,Finance,Finance Companies,166
LFCR,18.01.2024,6.67,11.35,645656,6.23,Lifecore Biomedical Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,167
DIBS,18.01.2024,4.99,11.25,938561,7.17,1stdibs.com Inc. Common Stock,Consumer Discretionary,Diversified Commercial Services,168
PLBY,18.01.2024,0.97,11.15,1259518,17.81,PLBY Group Inc. Common Stock,Consumer Discretionary,Recreational Games/Products/Toys,169
NOTV,18.01.2024,3.44,10.97,1609232,8.98,Inotiv Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,170
ORN,18.01.2024,5.13,9.85,518130,6.09,Orion Group Holdings Inc. Common,Industrials,Oilfield Services/Equipment,171
HOTH,18.01.2024,1.37,9.60,2236662,10.19,Hoth Therapeutics Inc. Common Stock,Health Care,Medicinal Chemicals and Botanical Produ,172
MRNS,18.01.2024,9.74,9.56,4519360,6.25,Marinus Pharmaceuticals Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,173
MOR,18.01.2024,10.24,9.28,15441920,6.19,MorphoSys AG American Depositary Shares,Health Care,Biotechnology: Pharmaceutical Preparati,174
ACRS,18.01.2024,1.18,9.26,2032550,12.05,Aclaris Therapeutics Inc. Common Stock,Health Care,Biotechnology: Commercial Physical & Bi,175
BLND,18.01.2024,2.27,9.13,2356714,8.21,Blend Labs Inc. Class A Common Stock,Technology,EDP Services,176
CUTR,18.01.2024,3.03,8.99,6294825,17.44,Cutera Inc. Common Stock,Health Care,Biotechnology: Electromedical & Electro,177
CVRX,18.01.2024,26.69,8.98,2983942,7.24,CVRx Inc. Common Stock,Health Care,Biotechnology: Electromedical & Electro,178
VKTX,18.01.2024,20.94,8.78,50124080,6.83,Viking Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,179
ML,18.01.2024,51.11,8.74,11407752,8.67,MoneyLion Inc. Class A Common Stock,Technology,Retail: Computer Software & Peripheral ,180
HITI,18.01.2024,1.76,8.64,521840,6.07,High Tide Inc. Common Shares,n/a,n/a,181
VIRC,18.01.2024,10.93,8.54,2998099,8.12,Virco Manufacturing Corporation Common Stock,Industrials,Industrial Specialties,182
LPTX,18.01.2024,3.20,8.47,851200,12.93,Leap Therapeutics Inc. Common Stock,Health Care,Biotechnology: Biological Products (No ,183
DOGZ,18.01.2024,3.33,8.47,670329,28.19,Dogness (International) Corporation Class A Common Stock,Consumer Discretionary,Miscellaneous manufacturing industries,184
ACCD,18.01.2024,11.88,8.39,10715760,6.85,Accolade Inc. Common Stock,Technology,Interactive Media,185
ZKH,18.01.2024,16.73,7.94,794675,6.67,,Undefined,Undefined,186
CCCC,18.01.2024,6.01,7.71,25974018,14.44,C4 Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,187
ANVS,18.01.2024,11.61,7.50,1451250,14.91,Annovis Bio Inc. Common Stock,Health Care,Medicinal Chemicals and Botanical Produ,188
ASPI,18.01.2024,1.94,7.18,801220,7.17,ASP Isotopes Inc. Common Stock,Industrials,Industrial Specialties,189
TCRX,18.01.2024,5.26,7.13,592802,6.74,TScan Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,190
BFLY,18.01.2024,1.06,7.07,1010286,10.72,Butterfly Network Inc. Class A Common Stock,Health Care,Biotechnology: Electromedical & Electro,191
ADCT,18.01.2024,1.83,7.02,925614,13.47,ADC Therapeutics SA Common Shares,Health Care,Biotechnology: Pharmaceutical Preparati,192
IMAB,18.01.2024,1.62,6.95,683307,11.70,I-MAB American Depositary Shares,Health Care,Biotechnology: Pharmaceutical Preparati,193
STRO,18.01.2024,4.11,6.75,2029929,9.84,Sutro Biopharma Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,194
PSNL,18.01.2024,1.62,6.58,530388,14.06,Personalis Inc. Common Stock,Health Care,Biotechnology: In Vitro & In Vivo Diagn,195
OPT,18.01.2024,2.76,6.56,514188,8.32,Opthea Limited American Depositary Shares,Health Care,Biotechnology: Pharmaceutical Preparati,196
XFOR,18.01.2024,0.76,6.55,625388,8.24,X4 Pharmaceuticals Inc. Common Stock,Health Care,Biotechnology: Biological Products (No ,197
CMPS,18.01.2024,8.13,6.55,4929219,8.74,COMPASS Pathways Plc American Depository Shares,Health Care,Biotechnology: Pharmaceutical Preparati,198
SMID,18.01.2024,38.23,6.43,569627,6.36,Smith-Midland Corporation Common Stock,Industrials,Building Materials,199
SURG,18.01.2024,5.70,6.34,14061900,8.32,SurgePays Inc. Common Stock,Technology,Computer Software: Prepackaged Software,200
MNMD,18.01.2024,3.63,6.14,1483944,6.89,Mind Medicine (MindMed) Inc. Common Shares,Health Care,Pharmaceuticals and Biotechnology,201
TNGX,18.01.2024,10.95,5.80,51609540,6.88,Tango Therapeutics Inc.,Health Care,Biotechnology: Pharmaceutical Preparati,202
ATRA,18.01.2024,0.73,5.80,1292319,15.35,Atara Biotherapeutics Inc. Common Stock,Health Care,Biotechnology: Biological Products (No ,203
NVCR,18.01.2024,14.50,5.76,89660752,7.42,NovoCure Limited Ordinary Shares,Health Care,Medical/Dental Instruments,204
KYMR,18.01.2024,27.20,5.59,22336640,7.75,Kymera Therapeutics Inc. Common Stock,Health Care,Medicinal Chemicals and Botanical Produ,205
RVPH,18.01.2024,4.07,5.44,1300365,8.04,Reviva Pharmaceuticals Holdings Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,206
TRDA,18.01.2024,14.99,4.97,541139,8.91,Entrada Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,207
ADVM,18.01.2024,0.85,4.94,3570595,8.37,Adverum Biotechnologies Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,208
LAB,18.01.2024,2.29,4.57,4105283,9.82,Standard BioTools Inc. Common Stock,Industrials,Biotechnology: Laboratory Analytical In,209
HNST,18.01.2024,2.87,4.36,1242136,6.45,The Honest Company Inc. Common Stock,Basic Materials,Paper,210
CHRS,18.01.2024,2.40,4.35,7339681,11.05,Coherus BioSciences Inc. Common Stock,Health Care,Biotechnology: Biological Products (No ,211
VRDN,18.01.2024,20.14,3.92,57749436,6.18,Viridian Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,212
PRQR,18.01.2024,2.12,3.92,3170884,10.29,ProQR Therapeutics N.V. Ordinary Shares,Health Care,Biotechnology: Pharmaceutical Preparati,213
VRNA,18.01.2024,17.18,3.81,8066010,6.25,Verona Pharma plc American Depositary Share,Health Care,Biotechnology: Pharmaceutical Preparati,214
WVE,18.01.2024,4.75,3.71,1890975,6.21,Wave Life Sciences Ltd. Ordinary Shares,Health Care,Biotechnology: Pharmaceutical Preparati,215
SUPV,18.01.2024,3.93,3.69,3980697,6.96,Grupo Supervielle S.A. American Depositary Shares each Representing five Class B shares,Finance,Commercial Banks,216
TLS,18.01.2024,3.97,3.66,1610629,7.06,Telos Corporation Common Stock,Technology,EDP Services,217
LQR,18.01.2024,2.62,3.56,3145572,26.65,LQR House Inc.,Undefined,Undefined,218
CDMO,18.01.2024,6.11,3.21,4746859,7.68,Avid Bioservices Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,219
INZY,18.01.2024,4.21,3.19,1406561,6.35,Inozyme Pharma Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,220
RXRX,18.01.2024,9.89,3.02,70540424,9.64,Recursion Pharmaceuticals Inc. Class A Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,221
COMP,18.01.2024,3.09,3.00,8148948,7.94,Compass Inc. Class A Common Stock,Technology,EDP Services,222
MXCT,18.01.2024,5.22,2.96,2627748,6.11,MaxCyte Inc. Common Stock,Health Care,Biotechnology: Electromedical & Electro,223
ELTK,18.01.2024,16.08,2.88,1887792,8.19,Eltek Ltd. Ordinary Shares,Industrials,Electrical Products,224
BCAB,18.01.2024,2.08,2.46,700960,11.41,BioAtla Inc. Common Stock,Health Care,Medicinal Chemicals and Botanical Produ,225
OCUL,18.01.2024,3.93,2.34,3913101,7.98,Ocular Therapeutix Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,226
CAN,18.01.2024,1.84,2.22,24158096,18.08,Canaan Inc. American Depositary Shares,Technology,Semiconductors,227
RILY,18.01.2024,21.45,2.05,18037306,8.50,B. Riley Financial Inc. Common Stock,Finance,Investment Managers,228
EXAI,18.01.2024,6.01,2.04,3251410,7.94,Exscientia Plc American Depositary Shares,Health Care,Biotechnology: Biological Products (No ,229
SDIG,18.01.2024,5.08,2.01,4920488,20.05,Stronghold Digital Mining Inc. Class A Common Stock,Finance,Investment Bankers/Brokers/Service,230
IOVA,18.01.2024,7.94,1.79,46639560,9.05,Iovance Biotherapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,231
NINE,18.01.2024,2.30,1.77,1624260,9.61,Nine Energy Service Inc. Common Stock,Industrials,Oilfield Services/Equipment,232
TVTX,18.01.2024,8.88,1.72,11247408,6.78,Travere Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,233
ALDX,18.01.2024,3.04,1.67,1687808,7.24,Aldeyra Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,234
AKYA,18.01.2024,4.88,1.67,801784,8.09,Akoya BioSciences Inc. Common Stock,Health Care,Medical Specialities,235
CRGE,18.01.2024,0.12,1.67,1183937,25.54,Charge Enterprises Inc. Common Stock,Telecommunications,Telecommunications Equipment,236
GLUE,18.01.2024,5.12,1.59,580608,12.07,Monte Rosa Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,237
TUP,18.01.2024,2.00,1.52,2026400,8.60,Tupperware Brands Corporation Common Stock,Industrials,Plastic Products,238
RIGL,18.01.2024,1.34,1.52,822760,8.02,Rigel Pharmaceuticals Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,239
FDMT,18.01.2024,17.05,1.25,5346880,6.12,4D Molecular Therapeutics Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,240
CIFR,18.01.2024,2.63,1.15,16423299,13.38,Cipher Mining Inc. Common Stock,Finance,Investment Bankers/Brokers/Service,241
ALIM,18.01.2024,3.89,1.04,1557167,6.70,Alimera Sciences Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,242
TGL,18.01.2024,0.10,0.98,3626713,14.18,Treasure Global Inc. Common Stock,Technology,Retail: Computer Software & Peripheral ,243
GRPN,18.01.2024,11.82,0.85,12549294,6.73,Groupon Inc. Common Stock,Consumer Discretionary,Advertising,244
UEIC,18.01.2024,8.19,0.49,696150,6.06,Universal Electronics Inc. Common Stock,Industrials,Consumer Electronics/Appliances,245
KOD,18.01.2024,3.07,0.33,994680,8.23,Kodiak Sciences Inc Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,246
BMEA,18.01.2024,14.18,0.28,9239688,8.13,Biomea Fusion Inc. Common Stock,Health Care,Biotechnology: Pharmaceutical Preparati,247

Exploration Code (running this will add symbols to the watchlist "test"):

/* Read_Top60_tickers_from_csv.afl
Description: 	Reads a csv-file from exploration and loads the Top xx symbols into a watchlist.
Author: 		RioL
*/

/* Update Log
----------
YYYY-MM-DD
2024-01-21	RioL	First draft. Tried a few things with the rank column, which failed, in the end I found a solution with
					while and break by reading only the top 60 symbols. Of course this requires the file to be ranked.
*/

//////////////////////////////////////////////////////////////////////////////////////
// variables

//source csv file (tickers a in column one, the file has one header line)
AB_Temp			= "C:\\Program Files\\AmiBroker\\MyFiles\\_Temp";	// part 1 of the path (I use this as temporary folder for all my AmiBroker results 
path 			= AB_Temp + "\\BG_Ma10NotExtended";					// part 2 of the path
//filename		= "test_249symbols.csv";					// filename of the csv-file
filename		= "test_10symbols.csv";					// just for testing

//target watchlist
//NOTE: This code does NOT clear the list beforehand! Do it with the AmiBroker Batch. (Optional include some code in this afl.)
ToWlName = "test";

//Read the first XX symbols in the csv-file.
TopXX = 60;


//////////////////////////////////////////////////////////////////////////////////////
// preparation

//define watchlists
ToWlNum = CategoryFind(ToWlName, categoryWatchlist);


//////////////////////////////////////////////////////////////////////////////////////
// read csv-file to count symbols 
// (Without this, the exploration writes the current symbol also in the watchlist, if the csv-file has less symbols than the variable "TopXX".)


//open csv file
filepath = path + "\\" + filename;
fh = fopen(filepath, "r" );

// prep file position for loop
if( fh ) 
{ 	
	for(i = 0; i < 1; i++)
	CL = fgets(fh);
}
else 
{ 
   Error("ERROR: file can not be open"); 
} 

// read csv-file to count symbols
if( fh ) 
{ 
	symbolCounter	= 0;
	
	while( ! feof( fh ) ) 
	{ 
	  //read line
	  line = fgets( fh );
	  _TRACE( line );
	  
	  //extract first column from line
	  symbol = StrExtract( line, 0);
	  
	  //add symbol to watchlist
	  symbolCounter = IIf(symbol == "", symbolCounter, symbolCounter +1);
	}

	fclose( fh ); 
} 
else 
{ 
   Error("ERROR: file can not be open"); 
} 

//////////////////////////////////////////////////////////////////////////////////////
// reading the symbols and adding the Top xx to the watchlist

// adapt counter, if the csv file has less symbols than the variable TopXX is looking for
lineCounterMax = IIf ( symbolCounter > TopXX, TopXX, symbolCounter);

//open csv file
filepath = path + "\\" + filename;
fh = fopen(filepath, "r" );

// prep file position for loop
if( fh ) 
{ 	
	for(i = 0; i < 1; i++)
	CL = fgets(fh);
}
else 
{ 
   Error("ERROR: file can not be open"); 
} 

// reading the symbols and adding the Top xx to the watchlist
if( fh ) 
{ 
	lineCounter 	= 0;
	
	while( lineCounter < lineCounterMax )
	{ 
	  //read line
	  line = fgets( fh );
	  _TRACE( line );
	  lineCounter++;
	  
	  //extract first column from line
	  symbol = StrExtract( line, 0);
	  
	  //add symbol to watchlist
	  CategoryAddSymbol(symbol, categoryWatchlist, ToWlNum);

	  // break at step 61  
	  if( lineCounter == lineCounterMax )
		{ 
		  break; 
		} 
		  printf("Step " +lineCounter ); 

	  //dummy = 1; // just to place a breakpoint for debugging

	}

	fclose( fh ); 
} 
else 
{ 
   Error("ERROR: file can not be open"); 
} 

//////////////////////////////////////////////////////////////////////////////////////
// end of code
//////////////////////////////////////////////////////////////////////////////////////
1 Like

General purpose ranking
https://www.amibroker.com/guide/afl/staticvargenerateranks.html

Use StaticVarGenerateRanks function to create ranking and then use Strfind in if Statement to check if Symbol is part of top ranked symbol list returned by StaticVarGetRankedSymbols( "top", "ValuesToSort", sdt ) in order to CategoryaddSymbol to Watchlist.

2 Likes

Thanks @fxshrat.

I reread the article and also searched for another thread in which I had read, that it might be necessary to use "pad and align", which should be used with care. Back then I was under the impression, that it is nearly impossible to ensure perfect data with my Yahoo import, so I dismissed the
StaticVarGenerateRanks function.

Might this be an issue with your solution for my use case?

This was the other thread:

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.