bramdc 6 posts msg #114904 - Ignore bramdc | 
8/16/2013 1:56:57 AM
  Dear all, 
 
 I came across an interesting indicator, namely the 'TAT' indicator, combining MACD and parabolic SAR,
 
 anyone having good skills to translate this to stockfetcher?
 
 I have pasted the code here below:
 
 thanks!
 
 -------------------------------------------
 indicator TAT;
 input
   macd_fast_period = 12,
   macd_slow_period = 26,
   macd_signal_period = 9,
   sar_step = 0.02,
   sar_maximum = 0.2,
   tat_macd_multiplier = 66.67,
   tat_sar_multiplier = 6.67,
   tat_signal_period = 12,
   overbought_level = 1,
   oversold_level = -1;
 draw
   tat_main("TAT", solid_line, green),
   tat_sig("TAT Signal", solid_line, red),
   ob("Overbought level", dash_line, white),
   os("Oversold level", dash_line, white),
   zero("Zero", dash_line, white);
 vars
   islong(bool),
   af(number),
   extreme(number),
   s(number),
   sar(series),
   i(number),
   macd_main(series),
   macd_sig(series),
   tat_sar(number),
   tat_macd(number);
 
 begin
   if macd_fast_period < 1 or macd_slow_period < 1 or macd_signal_period < 1 or tat_signal_period < 1 or back(close) < front(close) then
     return;
 
   macd_main := ema(close, macd_fast_period) - ema(close, macd_slow_period);
   macd_sig := ema(macd_main, macd_signal_period);
 
   islong := true;
   af := sar_step;
   extreme := high[front(close)];
   s := low[front(close)];
   sar[front(close)] := s;
   for i := front(close) + 1 to back(close) do begin
     s := s + af * (extreme - s);
     if islong then
       if low[i] < s then begin
         islong := false;
         af := sar_step;
         s := extreme;
         extreme := low[i];
       end else begin
         if extreme < high[i] then begin
           extreme := high[i];
           af := af + sar_step;
           if af > sar_maximum then
             af := sar_maximum;
         end;
       end
     else
       if high[i] > s then begin
         islong := true;
         af := sar_step;
         s := extreme;
         extreme := high[i];
       end else begin
         if extreme > low[i] then begin
           extreme := low[i];
           af := af + sar_step;
           if af > sar_maximum then
             af := sar_maximum;
         end;
       end;
     sar[i] := s;
   end;
 
   for i := front(close) to back(close) do begin
     tat_sar := 0;
     tat_macd := 0;
     if sar[i] <> 0 then
       tat_sar := (close[i] - sar[i]) / sar[i];
     if close[i] <> 0 then
       tat_macd := (macd_main[i] - macd_sig[i])/ close[i];
     tat_main[i] := 50*(tat_sar*tat_sar_multiplier + tat_macd*tat_macd_multiplier);
     zero[i] := 0;
     ob[i] := overbought_level;
     os[i] := oversold_level;
   end;
   tat_sig := ema(tat_main, tat_signal_period);  
 end.
 
  |