Manta, Ecuador
Site Administrator Developer Swing Trader
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,398 since Jun 2009
Thanks Given: 33,173
Thanks Received: 101,537
|
Hi guys,
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.
Anyone care to help me with this?
Mike
|