Page 1 of 1

automatically update My trades list

PostPosted: Wed Apr 11, 2018 1:25 pm
by guangho
My trades list sometimes does not automatically update,the strategy that does not get the latest trades information at run time.

my strategy code:

function HT1(bsk)
local enum=core.host:findTable("trades"):enumerator();
local row=enum:next();
local bb1=0;
local dd1=0;
while row~=nil do
if row.AccountID==Account and row.OfferID==offer then
if row.BS==bsk then bb1=bb1+1 else dd1=dd1+1 end
end
row=enum:next();
end
return bb1,dd1 end

I want use the "refresh" to automatically update My trades list.
How should I write the strategy?

Thank you!

Re: automatically update My trades list

PostPosted: Thu Apr 12, 2018 4:38 am
by Apprentice
Can you provide a complete strategy code?

Re: automatically update My trades list

PostPosted: Sun Apr 29, 2018 1:36 pm
by guangho
Apprentice wrote:Can you provide a complete strategy code?


My code is like this.
Can you help me how to modify,thank you!

function Init()
strategy:name("MA Crossover Strytegy");
strategy.parameters:addString("TF","Time frame","","H1");
strategy.parameters:setFlag("TF",core.FLAG_PERIODS);
strategy.parameters:addString("Account","Account to trade on","","");
strategy.parameters:setFlag("Account",core.FLAG_ACCOUNT);
strategy.parameters:addInteger("FastMA_Period","FastMA_Period","",5);
strategy.parameters:addInteger("SlowMA_Period","SlowMA_Period","",8);
strategy.parameters:addInteger("Amount","Trade Amount in Lots","",1);
strategy.parameters:addInteger("Limit","Limit Order in pips","",30);
strategy.parameters:addInteger("Stop","Stop Order in pips","",30);
end

local Account;
local BaseSize;
local Offer;
local FastMA_Period;
local SlowMA_Period;
local Amount;
local Limit;
local Stop;
local Source;
local first;
local FastMA;
local SlowMA;

function Prepare()
Account=instance.parameters.Account;
BaseSize=core.host:execute("getTradingProperty","baseUnitSize",instance.bid:instrument(),Account);
Offer=core.host:findTable("offers"):find("Instrument",instance.bid:instrument()).OfferID;
FastMA_Period=instance.parameters.FastMA_Period;
SlowMA_Period=instance.parameters.SlowMA_Period;
Amount=instance.parameters.Amount;
Limit=instance.parameters.Limit;
Stop=instance.parameters.Stop;
Source=ExtSubscribe(1,nil,instance.parameters.TF,true,"bar");
first=Source:first();
local name=profile:id().."("..instance.bid:instrument()..")";
instance:name(name);
FastMA=core.indicators:create("MVA",Source.close,FastMA_Period);
SlowMA=core.indicators:create("MVA",Source.close,SlowMA_Period);
end

function ExtUpdate(id,source,period)
if period<first+math.max(FastMA_Period,SlowMA_Period) or id~=1 then return end
FastMA:update(core.UpdateLast);
SlowMA:update(core.UpdateLast);
--My trend map sometimes does not automatically update.
--The strategy that does not get the latest trend map at run time.
--How to automatically update the trend map?
local bb,dd=HT1("B");
--My trades list sometimes does not automatically update.
--The strategy that does not get the latest trades information at run time.
if FastMA.DATA[period]>SlowMA.DATA[period] then
if bb<3 then enter("B") end
if dd>0 then exit("S") end
elseif FastMA.DATA[period]<SlowMA.DATA[period] then
if dd<3 then enter("S") end
if bb>0 then exit("B") end
end
end

function HT1(bsk)--Can I use the "refresh" to automatically update My trades list?
local enum=core.host:findTable("trades"):enumerator();
local row=enum:next();
local bb1=0;
local dd1=0;
while row~=nil do
if row.AccountID==Account and row.OfferID==Offer then
if row.BS==bsk then bb1=bb1+1 else dd1=dd1+1 end
end
row=enum:next();
end
return bb1,dd1 end

function enter(BuySell)
local valuemap=core.valuemap();
valuemap.Command="CreateOrder";
valuemap.OrderType="OM";
valuemap.OfferID=Offer;
valuemap.AcctID=Account;
valuemap.Quantity=Amount*BaseSize;
valuemap.BuySell=BuySell;
valuemap.PegTypeStop="O";
valuemap.PegTypeLimit="O";
if BuySell=="B" then valuemap.PegPriceOffsetPipsStop=-Stop;
valuemap.PegPriceOffsetPipsLimit=Limit;
else valuemap.PegPriceOffsetPipsStop=Stop;
valuemap.PegPriceOffsetPipsLimit=-Limit;
end
executing=true;
--need to write "executing"?
local success,msg=terminal:execute(2000,valuemap);
if not(success) then
executing=false;
--need to write "executing"?
terminal:alertMessage(instance.bid:instrument(),instance.bid[NOW],"Open order failed"..msg,instance.bid:date(NOW));
else terminal:alertMessage(instance.bid:instrument(),instance.bid[NOW],"Open order ok",instance.bid:date(NOW)) end
end

function exit(BuySell)
local valuemap,success,msg;
valuemap=core.valuemap();
if BuySell=="B" then BuySell="S" else BuySell="B" end
valuemap.Command="CreateOrder";
valuemap.OrderType="CM";
valuemap.OfferID=Offer;
valuemap.AcctID=Account;
valuemap.NetQtyFlag="Y";
valuemap.BuySell=BuySell;
executing=true;
--need to write "executing"?
success,msg=terminal:execute(101,valuemap);
if not(success) then
executing=false;
--need to write "executing"?
terminal:alertMessage(instance.bid:instrument(), instance.bid[NOW],"Close order failed"..msg,instance.bid:date(NOW));
end
end

function ExtAsyncOperationFinished(cookie,success,message)
if cookie==2000 and not(success) and Account~="TESTACCT" then
executing=false;
--need to write "executing"?
terminal:alertMessage(instance.bid:instrument(),instance.bid[NOW],"Open order failed"..message,instance.bid:date(NOW));
elseif cookie==2000 and success and Account~="TESTACCT" then
executing=false;
--need to write "executing"?
terminal:alertMessage(instance.bid:instrument(),instance.bid[NOW],"Open order ok"..message,instance.bid:date(NOW));
--There is no hint after the deal.
--How to improve?
end
end

dofile(core.app_path().."\\strategies\\standard\\include\\helper.lua");

Re: automatically update My trades list

PostPosted: Mon Apr 30, 2018 4:11 pm
by Apprentice
Your request is added to the development list under Id Number 4130

Re: automatically update My trades list

PostPosted: Tue May 01, 2018 3:48 pm
by guangho
Apprentice wrote:Your request is added to the development list under Id Number 4130


Thank you for your reply. Can I do what I can do now?

Re: automatically update My trades list

PostPosted: Thu May 03, 2018 3:50 pm
by Apprentice
Try this version.
MACrossoverStrategy.lua
(6.88 KiB) Downloaded 689 times

Re: automatically update My trades list

PostPosted: Thu May 03, 2018 5:39 pm
by guangho
Apprentice wrote:Try this version.
MACrossoverStrategy.lua


Thank you for your reply. I test the effect.

Re: automatically update My trades list

PostPosted: Sat May 05, 2018 12:08 pm
by guangho
Apprentice wrote:Try this version.
MACrossoverStrategy.lua


The strategy test is running normally.

Previous mistake: a trade has been stopped, but the trades list also shows this trade, which leads to the search list and the result is wrong. Then the trade that restarted the software disappeared.

It is not known whether the modification can solve similar problems.