Page 1 of 1

marketposition skips stop alert

Posted: Jun 26 2017
by Stormy
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;

Re: marketposition skips stop alert

Posted: Jun 26 2017
by TJ
Please see post #1 and post #2
viewtopic.php?t=11713

Re: marketposition skips stop alert

Posted: Jun 28 2017
by JoshM
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.

Re: marketposition skips stop alert

Posted: Jul 10 2017
by Stormy
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]

Re: marketposition skips stop alert

Posted: Jul 11 2017
by TJ
What is your chart resolution?

Re: marketposition skips stop alert

Posted: Jul 11 2017
by Stormy
15 minutes

Re: marketposition skips stop alert

Posted: Jul 11 2017
by Stormy
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);