Resetting a Once...Begin...End expression  [SOLVED]

Questions about MultiCharts and user contributed studies.
eztraderjr
Posts: 18
Joined: 02 Sep 2012
Has thanked: 5 times

Resetting a Once...Begin...End expression

Postby eztraderjr » 27 Sep 2012

I have an alert that I have set in a scanner window. It works fine as far as the logic for setting off the alert, but controlling when to test this condition is where I am stymied.

What I would like to happen is for the condition to be checked on every tick. (no problem)

If the condition is true, then I would like for it to alert and have the alert window stay open. (no problem)

Once the alert is set, do not test again. (no problem with the Once...Begin...End)

On a new bar, reset the alert to begin checking for the condition again. (cannot make this work without resetting the once, begin, end variable reset and start to check on every tick again.

Perhaps there is another piece of code that would control this better; ie, let me alert only once per bar. I am certainly not an accomplished programmer, but have managed to stumble through a few programs without too many issues (trial and error works great :), but for this issue I can find no solution. Thanks to any who can help.

ez

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

Re: Resetting a Once...Begin...End expression  [SOLVED]

Postby TJ » 27 Sep 2012

try this:

Code: Select all

var:
Intrabarpersist playonce(0);

if condition = true
and playonce <> currentbar then
begin
playonce = currentbar;

{-- put your alert here --}

end;

eztraderjr
Posts: 18
Joined: 02 Sep 2012
Has thanked: 5 times

Re: Resetting a Once...Begin...End expression

Postby eztraderjr » 01 Oct 2012

Thanks TJ. Took a little while but was able to get this to finally work. Plotted out current bar and playonce and found out that it was not working correctly until I changed the playonce variable to Intrabarpersist. Now working on setting time functions to change the volume levels at different points during the day. That is a puzzler as well, but will work a little more on this prior to asking for any assistance.

As for the Intrabarpersist, I had thought this possible to set in the format study settings under properties, but I guess update on every tick must do something else. I have read through most of the easylanguage essentials pdf, but some of the TS settings do differ from MC. Makes for an interesting time trying to figure out what to do. Thanks again for the assistance.

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

Re: Resetting a Once...Begin...End expression

Postby TJ » 01 Oct 2012

Thanks TJ. Took a little while but was able to get this to finally work. Plotted out current bar and playonce and found out that it was not working correctly until I changed the playonce variable to Intrabarpersist. Now working on setting time functions to change the volume levels at different points during the day. That is a puzzler as well, but will work a little more on this prior to asking for any assistance.

As for the Intrabarpersist, I had thought this possible to set in the format study settings under properties, but I guess update on every tick must do something else. I have read through most of the easylanguage essentials pdf, but some of the TS settings do differ from MC. Makes for an interesting time trying to figure out what to do. Thanks again for the assistance.
My mistake, I forgot to include the Intrabarpersist.
I have corrected the code above.
I am glad you have it working.

Good trading to you.


Return to “MultiCharts”