Previous trade P/L

Moderator: admin

Previous trade P/L

Postby cyanidez » Sun Jun 12, 2011 2:05 pm

Hi guys,

Maybe you've had this before... I need to figure out if the previous trade of a strategy was profitable or not... is this too vague or is there any easy way to figure this out?

This then means that I somehow need to look back in time to when the last signal was triggered, then figure out if it exited on a profit or loss... sounds way too complicated? There must be a simpler way.

Oh, and the previous trade will most likely NOT be on the same day as today, so the Closed Trades table probably won't help. I read in it's documentation that it only lists the current day's closed trades.

Thanks, you guys rock!
cyanidez
cyanidez
 
Posts: 52
Joined: Tue Mar 15, 2011 1:10 pm
Location: South Africa

Re: Previous trade P/L

Postby sunshine » Mon Jun 13, 2011 2:57 am

cyanidez wrote:Hi guys,

Maybe you've had this before... I need to figure out if the previous trade of a strategy was profitable or not... is this too vague or is there any easy way to figure this out?

This then means that I somehow need to look back in time to when the last signal was triggered, then figure out if it exited on a profit or loss... sounds way too complicated? There must be a simpler way.


Why not save P/L directly in the code of the strategy at closing a trade? In this case, you'll be able to retrieve the value at any time while the strategy is working.

If this is not suitable for you, there is another way I suppose. You can use FXCM Report API to load history of trading. See the report_balance.lua indicator as an example:
viewtopic.php?f=17&t=3142&start=0&hilit=balance

Hope this will help.
sunshine
 

Re: Previous trade P/L

Postby cyanidez » Mon Jun 13, 2011 3:07 am

sunshine,

Thank you very much for your reply.

The more I think about it, the more I realize that I am probably complicating it for myself... because storing the result in a variable was exactly what I wanted to do, but I somehow wanted to get the previous trade (before the strategy was started) and get it's results...

But this is just making my life difficult. So what I'm going to do is just add a "Previous Trade Result" field to the parameters, where you select "Profit" or "Loss" before starting the strategy for the 1st time, then start the strategy and everything runs from there... updating that variable as the strategy progresses.

So much simpler, thanks for the insights!
cyanidez
cyanidez
 
Posts: 52
Joined: Tue Mar 15, 2011 1:10 pm
Location: South Africa

Re: Previous trade P/L

Postby sunshine » Mon Jun 13, 2011 3:13 am

Update to my previous post.

IndicoreSDK has an extension that provides ability for working with the SQLite DB.

The storage library lets indicator or strategy save some data and then restore it when the indicator (or strategy) is created again.

To use the storage library just put require("storagedb"); into the Prepare() method of your indicator or strategy, and then use the storagedb table.

Documentation for this extension - http://www.fxcodebase.com/documents/Ind ... agedb.html
sunshine
 

Re: Previous trade P/L

Postby cyanidez » Mon Jun 13, 2011 3:46 am

sunshine,

That's amazing, never knew about the database functionality!

Hmmmm.. so many new things I can do with this! My brain is working overtime now hahaha :)

Thanks man, great tip!
cyanidez
cyanidez
 
Posts: 52
Joined: Tue Mar 15, 2011 1:10 pm
Location: South Africa


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 74 guests