automatically update My trades list

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

automatically update My trades list

Postby guangho » Wed Apr 11, 2018 1:25 pm

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!
guangho
 
Posts: 85
Joined: Sat Sep 29, 2012 12:16 pm

Re: automatically update My trades list

Postby Apprentice » Thu Apr 12, 2018 4:38 am

Can you provide a complete strategy code?
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 18958
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: automatically update My trades list

Postby guangho » Sun Apr 29, 2018 1:36 pm

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");
guangho
 
Posts: 85
Joined: Sat Sep 29, 2012 12:16 pm

Re: automatically update My trades list

Postby Apprentice » Mon Apr 30, 2018 4:11 pm

Your request is added to the development list under Id Number 4130
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 18958
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: automatically update My trades list

Postby guangho » Tue May 01, 2018 3:48 pm

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?
guangho
 
Posts: 85
Joined: Sat Sep 29, 2012 12:16 pm

Re: automatically update My trades list

Postby Apprentice » Thu May 03, 2018 3:50 pm

Try this version.
MACrossoverStrategy.lua
(6.88 KiB) Downloaded 312 times
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 18958
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: automatically update My trades list

Postby guangho » Thu May 03, 2018 5:39 pm

Apprentice wrote:Try this version.
MACrossoverStrategy.lua


Thank you for your reply. I test the effect.
guangho
 
Posts: 85
Joined: Sat Sep 29, 2012 12:16 pm

Re: automatically update My trades list

Postby guangho » Sat May 05, 2018 12:08 pm

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.
guangho
 
Posts: 85
Joined: Sat Sep 29, 2012 12:16 pm


Return to Indicator and Signal Requests

Who is online

Users browsing this forum: No registered users and 9 guests