Break Even Stop /Stop Loss

Questions about MultiCharts and user contributed studies.
Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Break Even Stop /Stop Loss

Postby Jonny473 » 19 Jan 2017

I am struggling to find a break even stop for my short positions! My Break even for long works correct, see here:

Code: Select all

Input:
[....]
Afterprofitpercentage1(0.9),
Afterprofitpercentage2(0.1),
averagetruerangelength(14),
Stoplosspercentage(2),

Variables:
[....]
averagerange=averagetruerange(averagetruerangelength);
Stoploss=ENTRYPRICE-(Stoplosspercentage*averagerange);


[....]
if(Close> EntryPrice +Afterprofitpercentage1*averagerange)
then
longLiqPoint = EntryPrice-(Afterprofitpercentage2*averageRange); {BreakEven trade}
begin
sell("MA Corss Exit4") numContracts shares total next bar at longLiqPoint stop;
end;
if Close<Stoploss then sell("MA Corss Exit5") numContracts shares total this bar at close;

For the setting a StopLoss or Break Even as seen above when in a SHORT position, I thought the opposite should work:

Code: Select all

Input:
[....]
Afterprofitpercentage1(0.9),
Afterprofitpercentage2(0.1),
averagetruerangelength(14),
Stoplosspercentage(2),

Variables:
[....]
averagerange=averagetruerange(averagetruerangelength);
Stoploss=ENTRYPRICE+(Stoplosspercentage*averagerange);


[....]
if(Close< EntryPrice -Afterprofitpercentage1*averagerange)
then
shortLiqPoint = EntryPrice+(Afterprofitpercentage2*averageRange); {BreakEven trade}
begin
buytocover("MA Corss Exit4") numContracts shares total next bar at shortLiqPoint stop;
end;
if Close>Stoploss then buytocover("MA Corss Exit5") numContracts shares total this bar at close;
So Stoploss comes into play when price is ABOVE certain threshold. For the breakeven to become valid Close has to be < first. The ShortLiqpoint is defined the opposite from the longliqpoint.
Does anybody know where the mistake in the short Breakeven/SL code is?

User avatar
Angelina MultiСharts
Posts: 260
Joined: 28 Dec 2016
Has thanked: 28 times
Been thanked: 66 times

Re: Break Even Stop /Stop Loss

Postby Angelina MultiСharts » 19 Jan 2017

Hello Jonny473,

Please try adding the following conditions to your script:

Code: Select all

if marketposition=0 then shortLiqPoint = 0;
[....]
if shortLiqPoint<>0 then buytocover("MA Corss Exit4")[ ......]

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Break Even Stop /Stop Loss

Postby Jonny473 » 19 Jan 2017

Hi Angelina,

no does not seem to work!

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

Re: Break Even Stop /Stop Loss

Postby tony » 23 Jan 2017

setbreakeven(); should work. Inside the bracket you put the per contract dollar amount at which point a break even stop is set. Put it at the end of your code and it should work just fine. Only thing worth noting is if you have an OCO order in place or similar orders, when the break even stop is triggered, outstanding orders are cancelled and then resubmitted. So if you rely on line queue with limit orders, you're queue will disappear as those limit orders re cancelled and resubmitted.

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Break Even Stop /Stop Loss

Postby Jonny473 » 23 Jan 2017

Hi Tony, thanks for the response- unfortunately also not working. Could you briefly show in the code how you would do it. Thank you very much!

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

Re: Break Even Stop /Stop Loss

Postby tony » 23 Jan 2017

Say you want a break even stop once a 3 tick profit target is met. Which means once you are 3 ticks in the money based on entry price, whether long or short, then a stop will be generated at entry price. So you would literally just right setbreakeven(n); where n equals the dollar value per contract for 3 ticks. Perhaps I'm misunderstanding though what you want to accomplish.

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Break Even Stop /Stop Loss

Postby Jonny473 » 23 Jan 2017

I get your point but I do not want to use absolute numbers. Furthermore I want to calculate that threshold before the break even becomes valid by using average true range multiplied by x just like in the longliqpoint or shortliqpoint (vice versa) shown above.


Return to “MultiCharts”