Increase Trade Size After Loss Code Help

Questions about MultiCharts and user contributed studies.
mcjohn

Increase Trade Size After Loss Code Help

Postby mcjohn » 17 Apr 2015

Attempting to increase the trade size after a loss using the code below, however, no success. Any help will be greatly appreciated.

Code: Select all

vars:
unitSize(10000),
lastPositionPL(0);

lastPositionPL = Positionprofit(1);

If lastPositionPL < 0 then begin
unitSize = 20000;
End
Else
unitSize = 10000;

//Entry Logic
If BullC = NumBC and BCavg <> 0 then
Buy ("LE") unitSize contracts next bar market;
If BearC = NumBR and BCavg <> 0 then
SellShort ("SE") unitSize contracts next bar market;

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Increase Trade Size After Loss Code Help

Postby TJ » 17 Apr 2015

Attempting to increase the trade size after a loss using the code below, however, no success.
::
What do you mean by "no success"?

No trade?
Wrong size?
Wrong trigger?


Please be more precise, because different problem requires different solutions.

mcjohn

Re: Increase Trade Size After Loss Code Help

Postby mcjohn » 17 Apr 2015

Thank you for the reply. The strategy works as desired; trades enter/exit as expected with the exception of the desired unit size after a losing trade. When there is a losing trade the following trade should have a higher amount, just one cycle.

For example (this is what happens now - incorrectly)

Trade 1: 10,000 units exits with a profit
Trade 2: 10,000 units exits with a profit
Trade 3: 10,000 units exits with a LOSS
Trade 4: 10,000 units exits with a profit (incorrect part, should be 20,000)
Trade 5: 10,000 units exits with a profit

What should occur:

Trade 1: 10,000 units exits with a profit
Trade 2: 10,000 units exits with a profit
Trade 3: 10,000 units exits with a LOSS
Trade 4: 20,000 units exits with a profit
Trade 5: 10,000 units exits with a profit

Thank you for your assistance with this matter.

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: Increase Trade Size After Loss Code Help

Postby tony » 17 Apr 2015

Attempting to increase the trade size after a loss using the code below, however, no success. Any help will be greatly appreciated.

Code: Select all

vars:
unitSize(10000),
lastPositionPL(0);

lastPositionPL = Positionprofit(1);

If lastPositionPL < 0 then begin
unitSize = 20000;
End
Else
unitSize = 10000;

//Entry Logic
If BullC = NumBC and BCavg <> 0 then
Buy ("LE") unitSize contracts next bar market;
If BearC = NumBR and BCavg <> 0 then
SellShort ("SE") unitSize contracts next bar market;
Problem is you are not holding a value of unitsize. The way your code is written if lastpositionPL < 0 then begin, meaning proceed with the rest of the script calculations. You need to hold that value when lastpositionPL < 0 to something like

if lastpositionPL < 0 then unitsize = 20000;

You may need to also add

if lastpositionPL >= 0 then unitsize = 10000;

This way unitsize is held based on the prior position profit value.

mcjohn

Re: Increase Trade Size After Loss Code Help

Postby mcjohn » 17 Apr 2015

Thank you for your reply. I really appreciate the assistance. Your code suggestion did help as it increases the size from 10,000 to 20,000. However, it only works after 2 consecutive losses, not the desired one. I am using PositionProfit(1), is there some other way to capture the previous closed trade's P/L?
size-increase.gif
(42.34 KiB) Downloaded 686 times

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: Increase Trade Size After Loss Code Help

Postby tony » 17 Apr 2015

I'm not sure I follow what is happening. After one loss, size increases from 10000 to 20000 or are you saying after two consecutive losses that is when size increases? Positionprofit(1) should show the position profit of the last closed position. At the bottom of your script write print(positionprofit(1)); and after a trade exits, see in the output tab on PLE what the value prints for positionprofit(1). Try it on the next trade and see what it shows.

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: Increase Trade Size After Loss Code Help

Postby tony » 17 Apr 2015

You can clean it up and get rid of the variable as well and use

if positionprofit(1) < 1 then unitsize = 20000;

if positionprofit(1) >= 0 then unitsize = 10000;

and when you declare the variable change it to unitsize (0),


Return to “MultiCharts”