Need Help

Moderator: admin

Need Help

Postby Tsad94 » Sat Sep 02, 2017 9:53 am

Hello everyone,

First of all i would like to thank all of you for the amazing work.
Second i would like to apologize for my bad english (i'm french).

I 'm not a programmer and i'm just starting to look at some possibilities whith lua, in hopes of developing some strategies.
If anyone could help me with some newbie questions i would much apreciate.

i'm struggling to find how to access indicators data.
I would like to create an indicator that prints on the chart the information we can get from the source in diferent time frames, and an indicator (say BB).

example:

Code: Select all
function Init()
    indicator:name("Test_002");
    indicator:description("Indicator de test");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Indicator);

    indicator.parameters:addGroup("Style");
    indicator.parameters:addColor("clr", "Color", "Color", core.rgb(255, 0, 0));
    indicator.parameters:addInteger("FontSize", "Font size", "", 12);
   
   indicator.parameters:addString("TF", "Time frame", "", "m5");
   indicator.parameters:setFlag("TF", core.FLAG_PERIODS);
   
end

local source, SRCask, SRCbid, TFsource;
local TF;
local font;
local loading;

function Prepare()
   
   source = instance.source;
   SRCask = core.host:execute("getAskPrice");
   SRCbid = core.host:execute("getBidPrice");
   
   -- source info
   BS = source:barSize(-1);
   D = source:date(-1);
   F = source:first(-1);
   GDP = source:getDisplayPrecision(-1);
   GP = source:getPrecision(-1);
   HD = source:hasData(-1);
   I = source:instrument(-1);
   IA = source:isAlive(-1);
   IB = source:isBar(-1);
   IBD = source:isBid(-1);
   N = source:name(-1);
   PS = source:pipSize(-1);
   S = source:serial(-1);
   SZ = source:size(-1);
   T = source:tick(-1);
   TSRCask = SRCask:tick(-1);
   TSRCbid = SRCbid:tick(-1);
   
   
    local name = profile:id() .. "(" .. source:name() .. ")";
    instance:name(name);
    font = core.host:execute("createFont", "Arial", instance.parameters.FontSize, true, false);
   
end

function Update()

   local Text="".. BS .. " barSize, ".. D .. " date, ".. F .. " first, ".. GDP .. " getDisplayPrecision, ".. GP .. " getPrecision, ".. I .. " instrument, ".. N .. " name, ".. PS .. " pipSize, ".. S .. " Serial, ".. SZ .. " size, ".. T .. " tick, ".. TSRCask .. " Ask tick, ".. TSRCbid .. " Bid tick, ";
    core.host:execute("drawLabel1", 1,0, core.CR_RIGHT,10, core.CR_TOP, core.H_Left, core.V_Center, font, instance.parameters.clr,  Text);
   
end


How could i get the same information for other time frames (say D1) in my 5m chart, and for BB indicator (MA and deviations)?? (is it possible??).

Besides the great fxcodebase, could someone advise me on learning programming lua for finance (books or other)?

Thank you in advance for your time and attention.
Tsad94
 
Posts: 2
Joined: Sat Sep 02, 2017 8:48 am

Re: Need Help

Postby Tsad94 » Sun Sep 03, 2017 9:36 am

Hello again everyone,

Maybe my question wasn't clear.
I just want to know how to acces the information.

example of another time frame in 5m chart:

Code: Select all
function Init()
    indicator:name("Test_002");
    indicator:description("Indicator de test");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Indicator);

    indicator.parameters:addGroup("Style");
    indicator.parameters:addColor("clr", "Color", "Color", core.rgb(255, 0, 0));
    indicator.parameters:addInteger("FontSize", "Font size", "", 12);
   
   indicator.parameters:addString("TF", "Time frame", "", "D1");
   indicator.parameters:setFlag("TF", core.FLAG_PERIODS);
   
end

local source, SRCask, SRCbid, TFsource;
local TF;
local font;

function Prepare()

   TF = instance.parameters.TF;
   
   source = instance.source;
   SRCask = core.host:execute("getAskPrice");
   SRCbid = core.host:execute("getBidPrice");
   
   TFsource = core.host:execute("getSyncHistory", source:instrument(), instance.parameters.TF, source:isBid(),  300, 100, 101);
   
   -- This isn't right is it???
   TFBS = TFsource:barSize(-1);
   TFD = TFsource:date(-1);
   TFF = TFsource:first(-1);
   TFGDP = TFsource:getDisplayPrecision(-1);
   TFGP = TFsource:getPrecision(-1);
   TFHD = TFsource:hasData(-1);
   TFI = TFsource:instrument(-1);
   TFIA = TFsource:isAlive(-1);
   TFIB = TFsource:isBar(-1);
   TFIBD = TFsource:isBid(-1);
   TFN = TFsource:name(-1);
   TFPS = TFsource:pipSize(-1);
   TFS = TFsource:serial(-1);
   TFSZ = TFsource:size(-1);
   TFT = TFsource:tick(-1);
   
    local name = profile:id() .. "(" .. source:name() .. ")";
    instance:name(name);
    font = core.host:execute("createFont", "Arial", instance.parameters.FontSize, true, false);
   
end

function Update()
   
   local Text="".. TFBS .. " barSize, ".. TFF .. " first, ".. TFGDP .. " getDisplayPrecision, ".. TFGP .. " getPrecision, ".. TFI .. " instrument, ".. TFN .. " name, ".. TFPS .. " pipSize, ".. TFS .. " Serial, ".. TFSZ .. " size, ";
    core.host:execute("drawLabel1", 2,0, core.CR_RIGHT,27, core.CR_TOP, core.H_Left, core.V_Center, font, instance.parameters.clr,  Text);
   
end

function AsyncOperationFinished(cookie, success, error)

   if cookie == 101
   then
      loading = true;
   elseif cookie == 100
   then
      assert(success, error);
      loading = false;
      instance:updateFrom(0);
   end
   
end



Can someone tell me what's wrong?? and how to access the Bid/Ask??
I know it may sound silly to you guys, but i'm just trying to understand how to access information from diferent time frames and indicators.
At least can someone point me in the right direction? for a newbie it is difficult to understand everything just looking at the wiki or the SDK indicor user guide.
Thank you all for your time.
Tsad94
 
Posts: 2
Joined: Sat Sep 02, 2017 8:48 am

Re: Need Help

Postby PetroIV » Wed Oct 04, 2017 7:06 am

Hello,
I recommend that you look at an example:
http://www.fxcodebase.com/bin/products/ ... story.html

local variable other is different price stream with bar size = source:barSize(). You can change it on "m5" for example. When command getHistory is executed the function AsyncOperationFinished is called. After you can use local variable other.

for example:
Code: Select all
 
       local other_period = core.findDate(other, curr_date, true);
       if other_period ~= -1 then
           H[period] = other.high[other_period];
           L[period] = other.low[other_period];
       end
PetroIV
 
Posts: 24
Joined: Tue Aug 15, 2017 9:45 am


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 7 guests