subcommand after SetStopLoss was hit

Questions about MultiCharts and user contributed studies.
User avatar
siscop
Posts: 197
Joined: 09 Jan 2011
Has thanked: 34 times
Been thanked: 29 times

subcommand after SetStopLoss was hit

Postby siscop » 01 Feb 2013

Hi,
Is there a easy possibility to add a command to the code

Code: Select all

variables:
SLHit(false);

SetStopPosition;
SetProfitTarget(ProfitTargetSumme);
SetStopLoss(StoppLossSumme);
so when SetStopLoss is hit that “SLHit” becomes true?
I just want the strategy to pause trading when SLHit becomes true for a defined time.

User avatar
siscop
Posts: 197
Joined: 09 Jan 2011
Has thanked: 34 times
Been thanked: 29 times

Re: subcommand after SetStopLoss was hit

Postby siscop » 01 Feb 2013

I normaly dont ask if a position is open since MC doesnt open a position when one is already open → but doing so should solve my problem...?

right now.

Code: Select all

If condition1 then
buy mengelong shares next bar at Eingangspreis limit;

SetStopPosition;
SetProfitTarget(ProfitTargetSumme);
SetStopLoss(StoppLossSumme);
whenever the SL is hit it keeps on entering another position since the limit entry is hit too.
If I just add the marketposition question it should solve my problem so it wont enter another position after an SL is hit.

Code: Select all

If condition1 and marketposition=0 then //<------------add the marketposition question
buy mengelong shares next bar at Eingangspreis limit;

SetStopPosition;
SetProfitTarget(ProfitTargetSumme);
SetStopLoss(StoppLossSumme);
Or am I going on the wrong way and it still opens a limitposition since marketposition is „0“ whenever the SL is hit? If this is so does someone know a better way?
btw. Intrabarordergeneration is turned off.

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

Re: subcommand after SetStopLoss was hit

Postby Henry MultiСharts » 01 Feb 2013

Hello siscop,
so when SetStopLoss is hit
Do you mean when the order is generated and sent or when the order is filled?
whenever the SL is hit it keeps on entering another position since the limit entry is hit too.
SetStopLoss and SetProfitTarget are generated when there is an open position. As they are not under condition in your code-they are evaluated intra-bar (even if IOG is off).

That is not possible to trace the event of SetStopLoss or SetProfitTarget generation. If you need to assign a value to a variable when one of your exits is generated you need to use begin - end statement.
If you do not want to use IOG but need to put SetStopLoss/SetProfitTarget under condition then you can use RecalcLastBarAfter to make your strategy recalculated and have necessary orders generated.

User avatar
siscop
Posts: 197
Joined: 09 Jan 2011
Has thanked: 34 times
Been thanked: 29 times

Re: subcommand after SetStopLoss was hit

Postby siscop » 01 Feb 2013

My problem was that if I have an open position and a new bar was created and within this new bar the SL was hit then the limitorder was triggered and the position reopened.
I just wanted to know how to avoid the reopening of the position after the SL was hit.
First I thought about a extra variable that would change its value when the SL was hit but how can I code that? That was the time I asked for a subcommand.
Then using the “marketposition=0” within the “if” section of the entry limit order seem to do the job. I have some troubles to test this on a low volume Friday night.

btw. with hit i mean filled ;D

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

Re: subcommand after SetStopLoss was hit

Postby TJ » 01 Feb 2013

InteractiveBrokers has a free demo system. It streams day-old data 24 hrs a day for testing purposes. No registration is required to use this facility.

escamillo
Posts: 203
Joined: 25 Mar 2011
Has thanked: 23 times
Been thanked: 56 times

Re: subcommand after SetStopLoss was hit

Postby escamillo » 02 Feb 2013

I just wanted to know how to avoid the reopening of the position after the SL was hit.
Maybe the Function EntriesToday

Code: Select all

if EntriesToday(date) = 0
as a condition for entry will work for you. it resets to zero each time you turn strategy automation off and then on again (the SA button).

viewtopic.php?f=5&t=12064


Return to “MultiCharts”