Average True Range ATR

Created at 29 Jul 2014, 13:46
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
magnokem's avatar

magnokem

Joined 29.07.2014

Average True Range ATR
29 Jul 2014, 13:46


hey guys, i need your help, how can I add this on ctrader? a huge thank you ...

 

 function Init()
    indicator:name("ATR pips indicator");
    indicator:description("ATR pips indicator");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Indicator);

    indicator.parameters:addGroup("Calculation");
    indicator.parameters:addInteger("Period", "Period", "", 13);
    indicator.parameters:addDouble("Multiplier", "Multiplier", "", 0.7);

    indicator.parameters:addGroup("Style");
    indicator.parameters:addColor("clr", "Color", "Color", core.rgb(255, 128, 0));
    indicator.parameters:addInteger("FontSize", "Font size", "", 20);
    indicator.parameters:addInteger("H_Shift", "Horizontal shift", "", 0);
    indicator.parameters:addInteger("V_Shift", "Vertical shift", "", 50);
end

local first;
local source = nil;
local Period;
local Multiplier;
local ATR;
local font;

function Prepare()
    source = instance.source;
    Period=instance.parameters.Period;
    Multiplier=instance.parameters.Multiplier;
    ATR = core.indicators:create("ATR", source, Period);
    first = source:first()+2;
    local name = profile:id() .. "(" .. source:name() .. ", " .. instance.parameters.Period .. ", " .. instance.parameters.Multiplier .. ")";
    instance:name(name);
    font = core.host:execute("createFont", "Arial", instance.parameters.FontSize, truefalse);
end

function Update(period, mode)
   if (period==source:size()-1) then
    ATR:update(mode);
    
    local Text="" .. math.floor(Multiplier*100) .. "% of ATR (" .. Period .. "):" .. math.ceil(ATR.DATA[period]*Multiplier/source:pipSize()) .. " pips";
    core.host:execute("drawLabel1", 1,instance.parameters.H_Shift, core.CR_RIGHT,instance.parameters.V_Shift, core.CR_TOP, core.H_Left, core.V_Center,
        font, instance.parameters.clr,  Text);

   end 
end


@magnokem
Replies

Spotware
05 Aug 2014, 12:48 ( Updated at: 21 Dec 2023, 09:20 )

Average True Range indicator is a standard indicator you can find it in Indicators menu:


@Spotware