Symbol Specific Parameters Stored in File to be used by Chart plotting AFL

Background Info:

I have custom developed my own Trailing Stop that uses parameters like the following:

  • Entry Price
  • Date of Entry
  • Market Type
  • Profit Target
  • Initial Risk
  • Expected Duration
  • etc...

I then calculate and plot my trailing stops on charts only for those symbols where "Date of Entry" is set - in other words I have an active open trade.
The same Chart for other symbols does not plot stops as there is no active trade (ie. no "Date of Entry" is present).

For example, I can plot trailing stops for Commonwealth Bank of Australia by setting a profit target of 5ATR. Using exactly the same chart, but for ANZ bank for example, I could set a target of 8ATR and plot the chart and calculated stops.

The Problem:

How to store Symbol specific parameters into an external file, rather than being programmed into AFL plotting the chart. The external file would then be "read" by the chart's AFL and trailing stops would be plotted for symbols if the required parameters have been set.

In essence, I am looking for an easy way for a chart to read external file like CSV file and use symbol specific parameters in order to calculate and plot trailing stops.

**Quick and Dirty Solution **

One way to achieve above is to use data fields already defined by Amibroker symbol files to store parameters rather that use them for their original intent.

For example, let's assume that I do not need to use Alias and Address fields for my trading. I could "trick the system" and store "Entry Price" into Alias and "Date of Entry" into Address. Then use string operations to determine values contained in these two fields and use those values as parameters for calculating and plotting my trailing stops.

The advantage of this solution is that no significant amount of AFL programming is required and overall process is very simple. It achieves exactly what I want at the expense of eliminating standard use of Alias and Address fields.

Is there a BETTER Solution

Is there a better solution that does not require massive amount of programming, but achieves the same outcome?

Any ideas?

Thank you.

1 Like

Well, after all, I have resolved my own question by using an external file with parameters.

Sorry to have bothered the forum with my initial question, but since I asked the question already, here is a solution that I thought some people may want to use. This one provides more flexibility than "tricking the system" described above.

// Get Active Trades Params
file = "F:\AdminZ\Documents\ActiveTrades.csv"; // change this to real location of your data file

// Set initial values to variables
EntryPrice =Target = 0;
fh = fopen( file, "r" );
if( fh )
while( ! feof( fh ) )
line = fgets( fh );
// get the ticker symbol from the file
ticker = StrExtract( line, 0 );

     // check if ticker matches current symbol name
     if ( Name() == ticker )
         // read data from lines of text
         EntryDate = StrToDateTime( StrExtract( line, 1 ) );
         EntryPrice = StrToNum( StrExtract( line, 2) );
         Target = StrToNum( StrExtract( line, 3 ) );

 fclose( fh );

Error( "ERROR: file can not be open" );

Thank you ...


1 Like

A similar issue was discussed in this other thread. The solution in that case was to use the persistence feature of StaticVars.

Beppe, thank you very much,

the alternative solution you pointed out is also an elegant solution.
I appreciate very much for taking the time to reply to my question.

Kind Regards,