marketposition skips stop alert

Questions about MultiCharts and user contributed studies.
Stormy
Posts: 58
Joined: 08 Nov 2012
Has thanked: 4 times
Been thanked: 3 times

marketposition skips stop alert

Postby Stormy » 26 Jun 2017

Hello,
I have an issue with a stop alert not being triggered. I believe it is because once the stop is hit my marketposition is now 0 so it skips the alert.
I am using the code below and I thought by using marketposition(1) it would base the trigger on my most recent position, but for
some reason marketposition(1) is not solving the issue, any suggestions would be greatly appreciated, I have been working on this one
for a long time.

Thank you,
Mike

Code: Select all

Variables: IntraBarPersist alertAlreadyGiven1(False);
if (CheckAlert = True) then begin
if (alertAlreadyGiven1 = False) and marketposition(1)<0 and close>=level1 then begin
alert("Stop");
alertAlreadyGiven1 = True;
end;
end;
Last edited by Stormy on 26 Jun 2017, edited 1 time in total.

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

Re: marketposition skips stop alert

Postby TJ » 26 Jun 2017

Please see post #1 and post #2
viewtopic.php?t=11713

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: marketposition skips stop alert

Postby JoshM » 28 Jun 2017

Hello,
I have an issue with a stop alert not being triggered. I believe it is because once the stop is hit my marketposition is now 0 so it skips the alert.
I am using the code below and I thought by using marketposition(1) it would base the trigger on my most recent position, but for
some reason marketposition(1) is not solving the issue, any suggestions would be greatly appreciated, I have been working on this one for a long time.
Have you tried using the `Print()` keyword inside your if statement to see when the code triggers? If you use that keyword to print the bar's time and bar number, you might see where the code goes wrong.

By the way, I see that the `level1` variable from your post is not defined in the code snippet. Is it safe to say that this might not be the full code? Perhaps the problem might (partly) be caused by a piece of code that we're currently not looking at.

Stormy
Posts: 58
Joined: 08 Nov 2012
Has thanked: 4 times
Been thanked: 3 times

Re: marketposition skips stop alert

Postby Stormy » 10 Jul 2017

Ok, I have narrowed it to marketposition. Since the stop is being executed first and taking the market position to 0 when the script reaches the "alert' code there is no market position and since the alert must be given if market position is <0 then the alert is not sent.

My issue is that why is MC not picking up my prior marketposition if I have coded marketpostion as a variable and set it to 1 bar back?

MP[1]

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

Re: marketposition skips stop alert

Postby TJ » 11 Jul 2017

What is your chart resolution?

Stormy
Posts: 58
Joined: 08 Nov 2012
Has thanked: 4 times
Been thanked: 3 times

Re: marketposition skips stop alert

Postby Stormy » 11 Jul 2017

15 minutes

Stormy
Posts: 58
Joined: 08 Nov 2012
Has thanked: 4 times
Been thanked: 3 times

Re: marketposition skips stop alert

Postby Stormy » 11 Jul 2017

I have also attempted to use marketposition(1) as suggested in the Multicharts Wiki
where marketposition(1)<0 should return the prior short position value-1 since the stop flattened the position

Usage
MarketPosition(PosBack)
Where:
PosBack - a numerical expression, specifying the position:
0 - open position;
1 - one position back (the last position closed);


Return to “MultiCharts”