PureBytes Links
Trading Reference Links
|
Position size strategies
I want to implement several strategies to calculate the position size for a
trading system (e.g. "trade the half size after a loss"). So I have to test if
the last trade was a winner or a looser and set the number of contracts to
trade according the test result.
It is easy to write the strategy with the help of the function I_ClosedEquity
in indicators. (See the example "Indicator: PSStrategies" below.)
But there seems to be no way to use the function I_ClosedEquity in systems.
(btw: why ? it can´t be a technical problem !?!)
Do YOU have any suggestion, how to code this task ?
My first attempt to code "trade the half size after a loss" in a system is LATE
one bar:
value1=TotalTrades;
if value1<>value1[1] then
value2=NetProfit+OpenPositionProfit;
if value2<value2[1]
then NoContracts=1
else NoContracts=2;
The second attempt works for backtesting but it is an awkward method:
Use the function I_ClosedEquity in an indicator to write the calculated number
of contracts to a file. Insert the file as data2 and use is from a system.
An other idea: The use of a DLL with which it is possible to exchange data
between studies (indicators and systems). But: I don´t have such a DLL and I
prefer a simple solution for a simple problem.
Here is the indicator example:
{Indicator: PSStrategies
4 PositionSize Strategies:
==========================
--------------------------------------------------------------------
PSStrat Name of Strategy Number of contracts to trade
after a after a
winner looser
--------------------------------------------------------------------
1 "constant contracts" 2 2
2 "double or half" 4 1
3 "half after loss" 2 1
4 "double after loss" 2 4
--------------------------------------------------------------------}
Inputs: PSStrat(1), {choose one of four position size strategies}
DefContr(2); {default number of contracts to trade}
Vars: ActContr(0), {actual (calculated) number of contracts}
CE(0); {closed equity}
CE=I_ClosedEquity;
if CE<>CE[1] then
begin
if PSStrat=1 then
ActContr=DefContr;
if PSStrat=2 then
if CE>CE[1] then ActContr=2*DefContr
else ActContr=0.5*DefContr;
if PSStrat=3 then
if CE>CE[1] then ActContr=DefContr
else ActContr=0.5*DefContr;
if PSStrat=4 then
if CE>CE[1] then ActContr=DefContr
else ActContr=2*DefContr;
end;
{plot ActContr if PSStrat is set to a valid value}
if PSStrat=1 or PSStrat=2 or PSStrat=3 or PSStrat=4
then plot1(ActContr,"ActContr")
else plot2(0,"ActContr");
Best regards,
Ulrich
|