Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I am trying to create a small bit of code that will calculate the % Profitable (win %) of all trades taken by a signal over a certain period.
Let's keep the first example simple. I just want to calculate the win % for the trades taken so far today (since midnight).
I know we have the PercentProfit reserved word, but that seems worthless here as it is for the entire series length. So then I look at the PosTradeProfit reserved word, which returns a numerical value indicating the profit (or loss if negative) of the specified trade.
With PosTradeProfit, we need to pass the PosAgo (number of positions ago, 0=open), and the TradeNumber within that position.
For my strategy, each position can have up-to 10 trades associated with it.
So far, I am thinking that I need to track:
- Current number of "positions" initiated (trades taken, but relates to PosAgo) -- rollover at midnight
- Number of trades taken within each position, tracked on a per-position basis -- I think we can use PosTradeCount for this, as it returns the number of entries within a position
And then I would create a loop and increment the PosTradeProfit(PosAgo, TradeNumber) first by the most recent position, then by each trade within that position, and so forth.
I would then come back with the total number of profitable trades, and the total number of all trades, and can do the math from there.
Complete dataseries length (chart history) = 30 days
I want to know what the win % was for yesterday. After I get the routine written, I will want to be able to calculate the win % for the last 'x' trades or last 'x' days.
That is what I am after. Needs to be done in the signal so I can use the information in the signal itself.