FXCM Forex Trading

TTM Trend indicator

Here you can post and download custom indicators. PLEASE: Do not start topics unless you are posting your own indicator, they will be moved to appropriate section even if you do.

Moderator: admin

TTM Trend indicator

Postby Alexander.Gettinger » Wed May 26, 2010 3:20 am

viewtopic.php?f=27&t=1063&p=2020#p2020

ttm_trend.png


Code: Select all
function Init()
    indicator:name("ttm-trend indicator");
    indicator:description("");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Indicator);
   
    indicator.parameters:addInteger("CompBars", "CompBars", "No description", 6);
end

local CompBars;
local first;
local source = nil;

local open = nil;
local high = nil;
local low = nil;
local close = nil;

local haOpen=nil;
local haClose=nil;
local icolor=nil;

function Prepare()
    CompBars = instance.parameters.CompBars;
    source = instance.source;
    first = source:first()+1;
    local name = profile:id() .. "(" .. source:name() .. ", " .. CompBars .. ")";
    instance:name(name);
    haOpen = instance:addInternalStream(0, 0);
    haClose = instance:addInternalStream(0, 0);
    icolor = instance:addInternalStream(0, 0);
    open = instance:addStream("open", core.Line, name, "open", core.rgb(0, 0, 0), first)
    high = instance:addStream("high", core.Line, name, "high", core.rgb(0, 0, 0), first)
    low = instance:addStream("low", core.Line, name, "low", core.rgb(0, 0, 0), first)
    close = instance:addStream("close", core.Line, name, "close", core.rgb(0, 0, 0), first)
    instance:createCandleGroup("HA", "HA", open, high, low, close);
end

function Update(period, mode)
    if (period>first+CompBars+2) then
     haOpen[period]=(haOpen[period-1]+haClose[period-1])/2.;
     haClose[period]=(source.open[period]+source.close[period]+source.high[period]+source.low[period])/4.;
     if haClose[period]>haOpen[period] then
      icolor[period]=1;
     else
      icolor[period]=-1;
     end
     for i=1,CompBars,1 do
      if haOpen[period]<math.max(haOpen[period-i],haClose[period-i]) and haOpen[period]>=math.min(haOpen[period-i],haClose[period-i]) and haClose[period]<math.max(haOpen[period-i],haClose[period-i]) and haClose[period]>=math.min(haOpen[period-i],haClose[period-i]) then
       icolor[period]=icolor[period-1];
      end
     end
     if icolor[period]>0 then
      open[period]=source.open[period];
      close[period]=source.close[period];
      high[period]=source.high[period];
      low[period]=source.low[period];
     else
      open[period]=source.close[period];
      close[period]=source.open[period];
      high[period]=source.low[period];
      low[period]=source.high[period];
     end
    else
     haOpen[period]=source.open[period];
     haClose[period]=(source.open[period]+source.close[period]+source.high[period]+source.low[period])/4.;
    end
end
Attachments
ttm_trend.lua
(2.49 KiB) Downloaded 606 times
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 2631
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Re: TTM Trend indicator

Postby KBW721 » Wed May 26, 2010 5:58 pm

The TTM Trend is not quite right yet . The concept that it is coded on is this . Look back 6 candles and take the high and the low of them then divide by 2 and if the close of the next candle is above that number it paints it blue and if its below it paints the candle red ...

Thanks for trying Alexander
KBW721
 
Posts: 2
Joined: Tue May 18, 2010 10:26 pm

Re: TTM Trend indicator

Postby Apprentice » Wed Jan 11, 2017 5:52 am

Indicator was revised and updated.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 15819
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia


Return to Custom Indicators

Who is online

Users browsing this forum: Bing [Bot] and 10 guests

cron