Calculating trade loss amount per trade and number of losses  [SOLVED]

Questions about MultiCharts and user contributed studies.
KhaosTrader
Posts: 186
Joined: 10 May 2012
Has thanked: 14 times
Been thanked: 11 times

Calculating trade loss amount per trade and number of losses

Postby KhaosTrader » 09 Mar 2013

Hi,

I have a strategy that enters by market order 2 contracts, one with a specific target and one with a trailing stop, both contracts before they hit their target have a hard stop. As my trading starts each day, it counts the number of winners vs losers, as well as how much each position (trade entry consisting of 2 trades) won or lost.

I was able to write a function that calculated the number of entries for a given trading date, however I am not sure how to go about coding the other requirements.. Below is my function.

Code: Select all

Inputs:

ScanDate(numeric);

Variables:
x(0),
vLastEntryTime(0),
vCurrentEntryTime(0),
vPositionProfit(0),
vTotalProfit(0),
vNbrWinningTrades(0),
vNbrLosingTrades(0),
intrabarpersist vNbrEntries(0);

{calculate number of entries}
if entrydate(1) = scandate then begin
vCurrentEntryTime = EntryTime(1);
if vCurrentEntryTime > vLastEntryTime then begin
vNbrEntries = vNbrEntries +1;
end;
vLastEntryTime = vCurrentEntryTime;
end;



{calculate number of wins}
//????????????

{calculate number of losses}
//??????????????????

{calculate win total amount}
//???????????????

_KT_fPOQ = netprofit; // vNbrWinningTrades; // vNbrEntries;

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Calculating trade loss amount per trade and number of lo  [SOLVED]

Postby Henry MultiСharts » 15 Mar 2013

Hello KhaosTrader,

You can get the total number of all completed trades with TotalTrades reserved word.
By checking the closed trades by time you can trace the trades for the last day/session.
If "exitprice- entryprice" is positive then this trade is a winning trade, if negative then it is a losing trade (for long positions, vice versa for short positions).
Similarly netprofit per trades can be calcualted, big point value * (exitprice - entryprice) (for short trades additionally multiply it by -1).

You can contact us directly if you want us to create this logic for you as a custom project.


Return to “MultiCharts”