Static Variables For Group Of Stocks

Hello All,
I use a strategy for intraday where I need to calculate the scope left for the stock to rise.

This is done with help of static data for group of stocks.

The group of stocks with the same margin have the same static value.

Example: SBIN is 0.25 margin stock and the static data is 1.62,2,62 and 3.62
Similarly Another stock like SUNPHARMA has static data 3.62,4.62,5.62

So when the stock SUNPHARMA is displayed calculations with 3.62,4.62,5.62 is needed and SBI needs 1.62,2,62 and 3.62

How can I store this data on basis of a group of stocks for calculation and how can I read it for each stock during the AFL processing.

  1. Use a Static String Variable

  2. Set this

parameter 'persist'. If it is set to True then static variable will be stored in PersistVars.bin file when AmiBroker is closing and reloaded automatically on next startup, preserving the values of static variables between application runs).

  1. Use and search forum how to implement string with StrExtract()
    As per @Tomasz, that's the fastest and efficient way of getting around string data.
    No spoon feeding here :slight_smile:

You don't need static variables for that. Depending on how much data you have, it can be stored directly in the formula, or it can be imported as artificial ticker or ...dozens of different ways....You can place your data in your formula. You can have different data sets for different symbols and use if-else or switch to pick correct one.

n = Name();

switch( n )
   case "SBIN": data1 = 1.62;
                       data2 = 2.62;
   case "SUNPHARMA":
                       data1 = 3.62;
                       data2 = 4.62;
1 Like

True sir, but most of the times the question is ambiguous and I interpreted at it from a persistent state where reading from a file would be another option.
Nevertheless, your suggestion is an A+