[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

@Experts: Export Problem to Excel



PureBytes Links

Trading Reference Links

Currently I try to analyze some patterns. I want to make use of the
FileAppend command and export some
figures like the profit per trade in percent into excel.

Stridsman provided in his book the following code:

{***************************************************************}

Vars: FName(""), TotTr(0), Prof(0), CumProf(1), ETop(1), TopBar(0),
TopInt(0),
BotBar(0), BotInt(0), EBot(1), EDraw(1), TradeStr2("");

If Currentbar = 1 Then Begin
FName="C:\Temp"+LeftStr(GetSymbolName,2)+".csv";
FileDelete(FName);

TradeStr2 = "E Date" + "," + "Position" + "," + "E Price" + "," + "X Date" +
"," + "X Price" + "," + "Profit" + "," + "Cum. prof." + "," + "E-Top" + ","+
"E-Bottom" + "," + "Flat time" + "," + "Run up" + "," + "Drawdown" +
NewLine;
FileAppend(FName, TradeStr2);
End;

TotTr = TotalTrades;
If TotTr > TotTr[1] Then Begin
Prof = 1 + PositionProfit(1)/(EntryPrice(1)*BigPointValue);
CumProf = CumProf * Prof;
ETop = MaxList(ETop,CumProf);
If ETop > ETop[1] Then Begin
TopBar = CurrentBar;
EBot = ETop;
End;
EBot = MinList(EBot, CumProf);
If EBot < EBot[1] Then
BotBar = CurrentBar;
TopInt = CurrentBar - TopBar;
BotInt = CurrentBar - BotBar;
EDraw = CumProf/ETop;
TradeStr2 = NumToStr(EntryDate(1), 0)+ "," + NumToStr(MarketPosition(1),
0)+ "," + NumToStr(EntryPrice(1), 2)+ "," +
NumToStr(ExitDate(1), 0)+ "," + NumToStr(ExitPrice(1), 2)+ "," +
NumToStr((Prof - 1)*100, 2)+ "," +
NumToStr((CumProf - 1)*100, 2)+ "," + NumToStr((ETop - 1)*100, 2) + "," +
NumToStr((EBot - 1)*100, 2) + "," +
NumToStr(TopInt, 0)+ "," + NumToStr(BotInt, 0) + "," +
NumToStr((EDraw - 1)*100, 2)+ NewLine;
FileAppend(FName,TradeStr2);
End;

{***************************************************************************
*}

Indeed, this code works fine considering one entry and exit at a time.
Unfortunately I am working with multiple entries and exits.
For example: two patterns appear in a row. I am exiting each pattern after
five days. I made use of the "total" keyword. The charts and the
Tradestation Srategy Reports look ok:
However the code for the FileAppend will not be executed when applied to
multiple entries.

Does anyone have an idea how to write a code that can calculate for example
the profit per trade in percent if there are multiple entries and exits like
described above?

Any help would be greatly appreciated

dansmo