Using data of an instrument on another charts

Moderator: admin

Using data of an instrument on another charts

Postby jacklrfx » Mon May 29, 2017 4:41 pm

Hi,
I am trying to create an indicator that plot the price (as a Line) of for example USOIL divided by 20 and USOIL divided by 30 on the chart of the UKOIL (or what you want instruments) and when UKOIL crosses from low to high the line of USOIL/20 then give a red arrow (sell signal), when UKOIL crosses from high to low the line of USOIL/30 then give a green arrow (buy signal)
I have tried but it doesn't work.

Code: Select all
function Init()
    indicator:name("Overlaying Instruments");
    indicator:description("Overlaying Instruments");
    indicator:requiredSource(core.bar);
    indicator:type(core.Indicator);
   
    indicator.parameters:addGroup("Style");
    indicator.parameters:addColor("FirstInstrument_clr", "First Instrument clr", "First Instrument clr", core.rgb(255, 0, 0));   --First Instrument is the instrument that is divided then by a number for example 20

    indicator.parameters:addColor("SecondInstrument_clr", "Second Instrument clr", "Second Instrument clr", core.rgb(0, 255, 0));  --Second Instrument is the instrument ( it is equal to First Instrument) that is divided then by a number for example 30

    --the number for which is divided the First Instrument is always greater than the number for which is divided the Second Instrument   for example  USOIL/20 and USOIL/30
 
    indicator.parameters:addColor("Bclr", "Buy arrow color", "Buy arrow color", core.rgb(0, 255, 0));
    indicator.parameters:addColor("Sclr", "Sell arrow color", "Sell arrow color", core.rgb(255, 0, 0));
    indicator.parameters:addInteger("ArrowSize", "Arrow size", "Arrow size", 10);
   
end

local first;
local source = nil;
local firstinstrument, secondinstrument;
local first = 0;

function Prepare()
    source = instance.source;
    first = source:first() + 1;

    local name = profile:id() .. "(" .. source:name() .. ")";

local offer = core.host:findTable("offers"):find("Instrument", "USOIL"); --here it could be useful to be able to select other instruments that they will be then divided by numbers, and not only USOIL
local bid = offer.Bid;

firstinstrument = instance:addStream("firstinstrument", core.Line, name .. ".firstinstrument", "firstinstrument", instance.parameters.FirstInstrument_clr, bid);
secondinstrument = instance:addStream("secondinstrument", core.Line, name .. ".secondinstrument", "secondinstrument", SecondInstrument_clr, bid);

BSignal = instance:createTextOutput("Buy", "Buy", "Wingdings", instance.parameters.ArrowSize, core.H_Center, core.V_Bottom, instance.parameters.Bclr, 0);
SSignal = instance:createTextOutput("Sell", "Sell", "Wingdings", instance.parameters.ArrowSize, core.H_Center, core.V_Top, instance.parameters.Sclr, 0);

end

-- Indicator calculation routine
function Update(period, mode)
    if period >= first then
      firstinstrument[period]=firstinstrument.price[period];
      secondinstrument[period]=secondinstrument.price[period];
     
     if source.close[period]>firstinstrument[period] then
          SSignal:set(period-1, high[period-1], "\226");
     end
     if source.close[period]< secondinstrument[period] then
         BSignal:set(period-1, low[period-1], "\225");
     end
end


Sorry I am not so very good at it but I am trying to improve my skills.
Thanks for your patience
Attachments
OverLaying Instruments.png
jacklrfx
 
Posts: 63
Joined: Mon Apr 20, 2015 2:40 pm

Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 3 guests