How to get values from accounts tab and write to csv

If you need an Indicator or Signal developed or translated from other language, please post all Indicator development REQUESTS to this section here.

Moderator: admin

How to get values from accounts tab and write to csv

Postby conjure » Mon Aug 20, 2018 8:53 am

Hi.
I m trying to make a strategy to export
Balance , Equity , Used Mr , Usable Mr %
from Accounts Tab and export it to a .csv using comma,
so i can import it to Google Chart API and make a diagram of my accounts activity.

Can someone help me with the code ?
Can i also add a delay of 5 minutes so i don't end up with a huge file
Can i also store the .csv file to path C:\xampp\htdocs ?
conjure
 
Posts: 90
Joined: Sat Jul 22, 2017 7:27 am

Re: How to get values from accounts tab and write to csv

Postby conjure » Mon Aug 20, 2018 12:29 pm

I found a way...

Code: Select all

function ExtUpdate(id, updatedSource, period)
 
   
       local account = core.host:findTable("accounts"):find("AccountID", Account);

      


file = io.open(instance.parameters.File.. ".csv", "a");

Balance=math.floor(account.Balance)
Equity=math.floor(account.Equity)
Used=math.floor(account.UsedMargin)
Usable=math.floor(getUsableMarginPercent())

    file:write(now);
    file:write(",");
    file:write(Balance);
    file:write(",");
    file:write(Equity);
    file:write(",");
    file:write(Used);
    file:write(",");
    file:write(Usable);
    file:write("\n");

      file:close()



end

function checkAccountRow()
    if mAccountRow == nil then
        mAccountRow = core.host:findTable("accounts"):find("AccountID", mAccount);
    else
        mAccountRow:refresh();
    end
end


function getUsableMarginPercent()
   checkAccountRow();
   return (mAccountRow.UsableMargin / mAccountRow.Equity) * 100;
end


function getUsableMargin()
    checkAccountRow();
    return mAccountRow.UsableMargin;
end


conjure
 
Posts: 90
Joined: Sat Jul 22, 2017 7:27 am


Return to Indicator and Signal Requests

Who is online

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