XII.4. Programming the indicator.

Listing 1. The ATR indicator
//Comments are set here
////the extern keyword sets the variables that will //be displayed in the settings
of the extern indicator period = 27;
 
//This function is executed at the time of launching our script
function init()
{
//setInitCandles(n) - sets the number of initial candles for // which do not need to be called calc()
         
setInitCandles(2);
 
//setBounds(nline, begin, end) - sets the drawing boundaries //of indicators. Parameters: nline — line number, begin — shift //relative to the beginning, end — shift relative to the end
 
         setBounds(0, 1, 0);
 
         var tr = high[1] - low[1];
         if (tr < high[1] - close) {tr = high[1] - close;}
         if (tr < close - low[1]) {tr = close - low[1];}
         line[0][1] = tr;
}
 
function calc()
{
         var tr = high - low;
         if (tr < high - close[-1]) {tr = high - close[-1];}
         if (tr < close[-1] - low) {tr = close[-1] - low;}
         var alpha = 2 / (period + 1);
         line[0] = alpha * tr + (1 - alpha) * line[0][-1];
}
 

To run this script, do the following steps.

1. Copy the text of the script to the oben buffer.

2. Go to TRANSAQ and select Charts and ATF Scripts in the menu.

3. Click the “Add” button.

4. Enter the name of our script, for example, myatr. We drive in the id, for example, myatrid. In the code field, insert our script from the clipboard.

5. Click the “Check” button to check the syntax and search for errors. If everything is fine, the entry “OK!” will appear in the “Errors” field.

6. Click Ok. The current window will close, and the line “myatr” will be displayed in the ATF Scripts window. So TRANSAQ has registered our script, now it can be used.

7, In the chart window of the instrument, right-click the context menu, select “Add indicator”.

1. Select the “myatr” indicator, click Ok and Ok again. Our indicator with the calculated curve for all displayed candlesticks will be displayed in the window. 2. If you change the indicator text further, then in order for it to work, you need to reopen the indicator window in the chart window of your instrument.

Leave a Reply