Multi position ask and bid
Created at 07 Jan 2014, 11:24
Multi position ask and bid
07 Jan 2014, 11:24
I use the following code to calculate the highest number of pips a single position or set of positions goes against a trade. So, if it goes 20 pips against you and then comes back, at the close of the trade I know how far it drew down the account for strategy analysis purposes.
foreach(Position position in Positions) { if (position.TradeType == TradeType.Buy) MaxDrawDown = Math.Max(Math.Round((position.EntryPrice - Symbol.Bid) / Symbol.PipSize, Symbol.Digits), MaxDrawDown); else MaxDrawDown = Math.Max(Math.Round((Symbol.Ask - position.EntryPrice) / Symbol.PipSize, Symbol.Digits), MaxDrawDown); }
it will only work with single currency. because it subtracts from the Symbol.Bid(or Ask) How can I get this o work with multiple currencies there is no bid or ask in the position object. I assume I could use position.symbolcode to get the currency pair but then how do I use that to return the pairs ask and bid?
lec0456
07 Jan 2014, 11:36
Ah, forget it.
you just use:
MarketData.GetSymbol(position.SymbolCode).Bid
Found it in a post...
@lec0456