Data export to file
Data export to file
11 Nov 2012, 19:38
Hello Admin,
Based on your instruction, I wrote a code that export backtest result data to file. I try to add almost all of the columns that available in cAlgo backtest.
Coud you please help me, how can I add more columns like:
- Close Price
- Gross profit
- Pips
I attached the part of the code below that I wrote:
string _ID = _position.Id.ToString();
string _ShortDate = Convert.ToString(Server.Time.Year+"-"+Server.Time.Month);
string _Date = Convert.ToString(Server.Time.Year+"-"+Server.Time.Month+"-"+Server.Time.Day);
string _DayName = Server.Time.DayOfWeek.ToString();
string _EntryTime = _position.EntryTime.ToString();
string _Volume = _position.Volume.ToString();
string _Type = _position.TradeType.ToString();
string _EntryPrice = _position.EntryPrice.ToString();
string _TakeProfit = takeProfit.ToString();
string _StopLoss = stopLoss.ToString();
string _Equity = Account.Equity.ToString();
string _Balance = Account.Balance.ToString();
_fileWriter.WriteLine(_ID+" "+_ShortDate+" "+_Date+" "+_DayName+" "+_EntryTime+" "+_Volume+" "+_Type+" "+_EntryPrice+" "+_TakeProfit+" "+_StopLoss+" "+_Equity+" "+_Balance);
This part of code is in "protected override void OnPositionOpened(Position openedPosition)" section.
Thanks for your help!
Replies
admin
12 Nov 2012, 12:10
Hello,
To get the close price of the last completed bar it would be:
var index = MarketSeries.Close.Count - 1; // the current bar being created
car close = MarketSeries.Close[index - 1]; // the last completed bar's close price
The Gross profit would be _position.GrossProfit
For pips you would need to calculate it according to this:
Sell: Entry price - Ask -- pips = Math.Round((_position.EntryPrice - Symbol.Ask)/Symbol.PipSize, Symbol.Digits);
Buy: Entry price - Bid -- pips = Math.Round((_position.EntryPrice - Symbol.Bid)/Symbol.PipSize, Symbol.Digits);
note that OnPositionOpened the value of gross profit would be minimal maybe you want to add it to OnPositionClosed.
@admin
admin
12 Nov 2012, 12:25
RE:
Hello,Hello Admin,
I solved most of the problem. I've only one open question.
How can I add column: Event (CreatePosition, TakeProfitHit, etc...)
Thanks for your help!
@admin
rkokerti
12 Nov 2012, 11:55
Hello Admin,
I solved most of the problem. I've only one open question.
How can I add column: Event (CreatePosition, TakeProfitHit, etc...)
Thanks for your help!
@rkokerti