I am writing a strategy to send email of account summary everyday, but it do not work, there are some things wrong.
How can I let it work?
thanks!
- Code: Select all
function Init()
strategy:name("Account infomation");
strategy:description("Account infomation");
strategy.parameters:addGroup("Time frame");
strategy.parameters:addString("TF", "Time frame", "", "D1");
strategy.parameters:setFlag("TF", core.FLAG_PERIODS);
strategy.parameters:addGroup("Account Group");
strategy.parameters:addBoolean("Account", "Account", "Account", true);
strategy.parameters:setFlag("Account", core.FLAG_ACCOUNT);
strategy.parameters:addBoolean("SendEmail", "Send email on signal", "", false);
strategy.parameters:addString("Email", "Email address", "", "");
strategy.parameters:setFlag("Email", core.FLAG_EMAIL);
end
local Account;
local SendEmail;
local Email;
local source;
local AccountID;
local Balance;
local Equity;
local DayPL;
local UsedMargin;
local UsableMargin;
function Prepare()
Account = instance.parameters.Account;
SendEmail = instance.parameters.SendEmail;
Email = instance.parameters.Email;
source = ExtSubscribe(1, nil, instance.parameters.TF, true, "bar");
end
function ExtUpdate()
AccountID = core.host:findTable("accounts"):find("AccountID", Account);
Balance = core.host:findTable("accounts"):find("Balance", Account);
Equity = core.host:findTable("accounts"):find("Equity", Account);
DayPL = core.host:findTable("accounts"):find("DayPL", Account);
UsedMargin = core.host:findTable("accounts"):find("UsedMargin", Account);
UsableMargin = core.host:findTable("accounts"):find("UsableMargin", Account);
-- if myCondition then
-- local UsedMarginrate = 100 * UsedMargin / Balance;
local EmailSubject = "Account ".." infomation ".. os.date();
local EmailMessage =
Account .. infomation .. os.date().."\n\n"
.."AccountName\t".."NetFunds\t".."FloatingFunds\t".."DayPL\t".."UsedMargin\t".."UsableMargin\n"
..AccountID.."\t"..Balance.."\t"..Equity.."\t"..DayPL.."\t"..UsedMargin.."\t"..UsableMargin;
if instance.parameters.SendEmail then
terminal:alertEmail(Email, EmailSubject, EmailMessage);
end
-- end
end
dofile(core.app_path() .. "\\strategies\\standard\\include\\helper.lua");