finding newest positive trade?

Section for discussions related to indicators, use of indicators, and building of trading stategies using indicators.

Moderator: admin

finding newest positive trade?

Postby lalala987 » Mon Mar 11, 2013 7:57 am

Dear all

I'd like to find the close price of the newest positive trade i have closed.
I understand, that i have to work with something like:

core.host:findTable("closed trades"):find(.......

the "close-price" would therefore be the newest entry in the closed trade table, where "PL" > 0.

any help would be appreciated
best regards!
lalala987
 
Posts: 28
Joined: Wed Jan 02, 2013 5:31 pm

Re: finding newest positive trade?

Postby lalala987 » Tue Mar 12, 2013 5:58 am

Dear all

I think, i have found a solution. Is there a more efficient way?

Code: Select all
function lastpositivetrade()
   local enum2, row2={},{};
   enum2 = core.host:findTable("closed trades"):enumerator();
    row2 = enum2:next();

   while row2 ~=nil do
     if row2.PL>0 then
    storage1=row2.Close;
     end;
     row2=enum2:next();
    end
return storage1
end


the returnvalue "storage1" will be handed to the trading rule of my strategy, like:

dummy code:
Code: Select all
if ((S_SOURCE.open[period]>storage1) then
Buy();


so i'd buy, if the current price is higher than the last positive trade.

best regards
lalala987
 
Posts: 28
Joined: Wed Jan 02, 2013 5:31 pm

Re: finding newest positive trade?

Postby Ekaterina » Wed Mar 13, 2013 7:35 pm

Hi lalala987,

Is there a more efficient way?


It the best way actually.
The only one issue is here. Closed Trades table keeps data only one day, which means that if the last trade was yesterday and reconnect comes today, the table could possibly be empty. A kind of workaround will be the following: to track a closing of the trade by events and put prices in the persistent storage. So if a trade wasn't found in the table, then search in the persistent storage.

Best regards,
Ekaterina
Ekaterina
 

Re: finding newest positive trade?

Postby lalala987 » Thu Mar 14, 2013 5:05 am

ok, tnx!

Closed Trades table keeps data only one day, which means that if the last trade was yesterday and reconnect comes today, the table could possibly be empty.


Does that mean, if i let trade a strategy using lastpositivetrade(), the "closed trades" table will be flushed at 00:00 and the table is empty? Or will the "cloded trades" table be only flushed when i reconnect with the client?

best regards
Stefan
lalala987
 
Posts: 28
Joined: Wed Jan 02, 2013 5:31 pm

Re: finding newest positive trade?

Postby Ekaterina » Fri Mar 15, 2013 6:47 am

Hi Stefan,

Does that mean, if i let trade a strategy using lastpositivetrade(), the "closed trades" table will be flushed at 00:00 and the table is empty?


No, it won't be flashed at 00:00, but I wouldn't rely that all data between sessions will be saved. It is most likely, that it will be cleaned when reconnect occurs.

Best regards,
Ekaterina
Ekaterina
 


Return to Discussions

Who is online

Users browsing this forum: No registered users and 18 guests