Alert on Open

Questions about MultiCharts and user contributed studies.
wall richard
Posts: 60
Joined: 28 Dec 2007
Has thanked: 9 times
Been thanked: 1 time

Alert on Open

Postby wall richard » 14 Jul 2012

I need to audio alert when an Open condition is met. Usually EL audio alerts are triggered when a Close meets a condition.

Richard

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Alert on Open

Postby bowlesj3 » 14 Jul 2012

I am assuming your study is set to update on every tick.
I am assuming your study is set to not bypass duplicate ticks at the same price.
I assume your bars have been filled out (meaning you are processing this code during "LastBarOnChart". If true then put this code in the LastBarOnChart section.

Code: Select all

IntrabarPersist TimePrev(0), {Use IntrabarPersist to ensure the next tick does not change it}

If time = 0930 then {this is your opening time}
begin
if time > PrevTime then {If true this is the first tick of the bar}
begin
PrevTime = time; {Make sure your code only executes once}
{This code will execute}
end;
end;
Study this link to debug it to make sure it works and to fix it if it does not.
viewtopic.php?f=16&t=10397

wall richard
Posts: 60
Joined: 28 Dec 2007
Has thanked: 9 times
Been thanked: 1 time

Re: Alert on Open

Postby wall richard » 14 Jul 2012

Thanks John,

I am looking for an audio alert on Open to make a decision in trading on a discretionary basis. This alert is generated by comparing O[0] and previous bar data. I often trade with range bars and it isn't possible to trade on the Close because C doesn't occur until the next bar.

I prefer to use the PlaySound command ==> .wav file. This alert will give me a "go" - "no go" assist in making my decision to trade. I prefer to keep this all relatively simple. Assuming this is a workable idea it should be easy to code. Simple "Up" or "Down" audio alerts are adequate.

A source of .wav files would also be appreciated. Also, I would be interested in others experience in non fixed indicator alerts.

Richard Wall

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Alert on Open

Postby bowlesj3 » 14 Jul 2012

.wav files is the easy part.

I either use the ones in this directory
C:\WINDOWS\Media

or

I create my own in my own voice using Audacity because you can cut and paste.
http://audacity.sourceforge.net/

wall richard
Posts: 60
Joined: 28 Dec 2007
Has thanked: 9 times
Been thanked: 1 time

Re: Alert on Open

Postby wall richard » 14 Jul 2012

About 1990 I first had TS. I remember they had several audio alerts. If they are not copy righted and some one has these files I would appreciate it if you would send them to me.

Thanks

Richard Wall

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

Re: Alert on Open

Postby JoshM » 17 Jul 2012

About 1990 I first had TS. I remember they had several audio alerts. If they are not copy righted and some one has these files I would appreciate it if you would send them to me.
Alternatively, you can use the AT&T labs tool for making your own sound files.

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

Re: Alert on Open

Postby Henry MultiСharts » 17 Jul 2012

I need to audio alert when an Open condition is met. Usually EL audio alerts are triggered when a Close meets a condition.

Richard
Hello Richard,

Have you tried to generate an alert when the opening tick of the bar is received?

Code: Select all

if barstatus=0 then PlaySound

wall richard
Posts: 60
Joined: 28 Dec 2007
Has thanked: 9 times
Been thanked: 1 time

Re: Alert on Open

Postby wall richard » 22 Jul 2012

Henry,

Yes, it works very well.

Thanks.

Richard

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Alert on Open

Postby bowlesj3 » 22 Jul 2012

Code: Select all

barstatus=0
There use to be a bug in "barstatus=0". Did anyone create a bug tracker entry for this bug? Has it been fixed? This is why I test the previous time which also works but never fails. As far as I know barstatus=2 has no bug and barstatus=1 also has no bug.

Code: Select all

If time > TimePrev then
begin
TimePrev = time;
{Your code to be executed on the first tick of the bar}
end;

If time_s > TimePrev then
begin
TimePrev = time_s;
{Your code to be executed on the first tick of the bar}
end;

wall richard
Posts: 60
Joined: 28 Dec 2007
Has thanked: 9 times
Been thanked: 1 time

Re: Alert on Open

Postby wall richard » 22 Jul 2012

See viewtopic.php?f=1&t=10110. Intermittent problem?

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Alert on Open

Postby bowlesj3 » 23 Jul 2012

Yes it is intermittent, It actually it occurs fairly often and I could write a script to get some stats on it using the date code to test the status in the bracketed code above.

It was reported about 4 years ago by drawr (can't remember the spelling).

Maybe if it is still out there I should put together a script to create some numbers to show how bad it is and create a PM entry. Okay I just created a ToDo for it but I will search to see if it has been reported already. If someone wants to put it in the PM system ahead of me feel free but let me know.

It really should be fixed since the date code requires a variable be set up and a move statement too (two extra statements that really should not be required of the programmer).

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

Re: Alert on Open

Postby Henry MultiСharts » 24 Jul 2012

There use to be a bug in "barstatus=0".
Hello Bowlesj3,

Please describe what exact issue with "barstatus=0" you are referring to.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Alert on Open

Postby bowlesj3 » 24 Jul 2012

Hi Henry,

What happens is the first tick of the bar comes through with barstatus=1 rather than barstatus=0. Knowing this it then becomes very easy to test for by using the above date code that without fail detects the first tick of the bar. None of my code has the barstatus=0 test so I do not remember if it appears on 1 minute bars or 10 second bars. Probably both. I just remember seeing it and changing it to the date test to resolve the issue it was creating.

Thanks,
John.

wall richard
Posts: 60
Joined: 28 Dec 2007
Has thanked: 9 times
Been thanked: 1 time

Re: Alert on Open

Postby wall richard » 24 Jul 2012

Along with playing an audio alert on the opening tick I need to execute a trade at the opening of the bar. I am trying to use a stop or limit order to execute at the open. Here is a small snippet of code for an always in signal. It will not compile - perhaps it's due to the barstatus=0 problem.

If MP < 1 AND (Value2 > Value2[1]) AND barstatus=0 then buy 1 share at open stop;
If MP > 0 AND (Value2 < Value2[1]) AND barstatus=0 then sellshort i share at Open stop;

It's my understanding that stop and limit orders may be executed anywhere they are triggered within a bar. I do not wish to wait until the next bar to execute an order.

Thanks,

Richard

wall richard
Posts: 60
Joined: 28 Dec 2007
Has thanked: 9 times
Been thanked: 1 time

Re: Alert on Open

Postby wall richard » 24 Jul 2012

As a point of clarification. Setstoploss will execute within a bar automatically. Placeorder macros, while not automated, allow discretionary orders to be placed within a bar.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Alert on Open

Postby bowlesj3 » 25 Jul 2012

I have not done stats on the barstatus=0 problem but I am going to guess that 5 come trough daily on the 10 second bars. Maybe 1 or 2 every day on the 1 minute bars. Again I could be off by a fair bit but I know it does not happen every 4th time. It is not that bad.

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

Re: Alert on Open

Postby Henry MultiСharts » 25 Jul 2012

Along with playing an audio alert on the opening tick I need to execute a trade at the opening of the bar. I am trying to use a stop or limit order to execute at the open. Here is a small snippet of code for an always in signal. It will not compile - perhaps it's due to the barstatus=0 problem.

If MP < 1 AND (Value2 > Value2[1]) AND barstatus=0 then buy 1 share at open stop;
If MP > 0 AND (Value2 < Value2[1]) AND barstatus=0 then sellshort i share at Open stop;

It's my understanding that stop and limit orders may be executed anywhere they are triggered within a bar. I do not wish to wait until the next bar to execute an order.

Thanks,

Richard
Hello Richard,

That is not possible to check conditions and send the order on the same tick.
You need to specify in the code when the order should be sent.

Code: Select all

If MP < 1 AND (Value2 > Value2[1]) AND barstatus=0 then buy 1 share next bar at open stop;
If MP > 0 AND (Value2 < Value2[1]) AND barstatus=0 then sellshort i share next bar at Open stop;
In order to send the order on the opening tick of the bar-it should be generated on the closing tick of the previous bar.

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

Re: Alert on Open

Postby Henry MultiСharts » 25 Jul 2012

I have not done stats on the barstatus=0 problem but I am going to guess that 5 come trough daily on the 10 second bars. Maybe 1 or 2 every day on the 1 minute bars. Again I could be off by a fair bit but I know it does not happen every 4th time. It is not that bad.
Bowlesj3, there were no problems reported regarding Barstatus=0. Please provide a workspace and test signal with problem description for conducting further investigation in our environment.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Alert on Open

Postby bowlesj3 » 25 Jul 2012

Bowlesj3, there were no problems reported regarding Barstatus=0.
Clarification. This problem has (absolutely for sure) been reported 2 times (about 4 years ago). However it has not been reported in the Bug Tracker. I have already put it on my todo list to report it officially in the bug tracker. I will create a test script (about 4 lines of code) to prove it exists along with some printed output. In my case the problem occurred on the E-Mini "ES" symbol. I do not know what symbol Dwar reported it on but it could probably be found in a search. When I reported it Dwar commented on the post to confirm my findings.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Alert on Open

Postby bowlesj3 » 30 Jul 2012

Hi all,

I am finally following up on my Saturday todo list for programming (a little behind). I have created this test for the 1 minute bars which I will be running today. I set the ErrorCnt to -1 too bypass the first occurance of "LastBarOnChart" since I am not sure if it will properly work the first time through until the TimePrev variable is set. I am only running ES (the S&P 500 futures contract) since that is all I do. If this code appears to have no bugs and the problem appears again as it did roughly 4 years ago then I will create the PM entry. I will also create a special thread to try and get others to test other symbols so the MC-Team will get a better feel for how bad the problem is (does it effect all symbols or just some or it is Just IB).

If anyone wants to try the code out now in its original untested state you can cut and paste it from below (faster than dealing with a zip file). Note that I have the alert=y setting in place. If the alert is driving you crazy you can set it to N. If I do create a special thread for this problem to get others to test I may have a slightly revised test script in that thread. I already see one change to make.

Note: I will also create one of these for the 10 second bars once I am happy with the script.


Thats it for now. Time to focus on trading. Must stay focused. Focus is very important.

Thanks,
John

Code: Select all

Inputs: PlayAlert("Y");

Variables:
Intrabarpersist ErrorCnt(-1),
LogPath(""),
PrintFile(""),
Intrabarpersist TimePrev(0);

If currentbar = 1 then
begin
LogPath = "C:\";
PrintFile = LogPath + "A_BarStatusZeroTest.txt";
end;

If lastbaronchart then
begin
if time > TimePrev then
begin
TimePrev = time;
if BarStatus > 0 then
begin
ErrorCnt = ErrorCnt + 1;
if ErrorCnt > 0 then
begin
Print(File(PrintFile),
"Error: BarStatus > 0 during the first tick of the bar. " ,
"Time=",
Time, " " ,
"BarStatus=",
BarStatus, " " ,
"ErrorCnt=",
ErrorCnt, " " ,
" ");
if PlayAlert = "Y" then
Alert("Error: BarStatus > 0. Time=" + numtostr(time,0) + " Cnt=" + NumToStr(ErrorCnt,0));
end;
end;
end;
end;

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Alert on Open

Postby bowlesj3 » 30 Jul 2012

Related to my question above "Has the barstatus=0 bug been fixed?", it appears that it may have been. The 1 minute bar test ran fine (none of the old bug). I will run it tomorrow on 10 second bars to see if it runs okay there.

wall richard
Posts: 60
Joined: 28 Dec 2007
Has thanked: 9 times
Been thanked: 1 time

Re: Alert on Open

Postby wall richard » 30 Jul 2012

John,

Thank you for your opinions on this issue and the work you did to settle the controversy.

Rick

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Alert on Open

Postby bowlesj3 » 31 Jul 2012

Your welcome guys. Assuming the problem has been fixed (as it appears to be) I am betting if all the MC_Team programmers were asked, one of them would remember fixing this bug but it never properly got back to us so those of us who experienced the bug before had no option but keep using our work around. This issue points out the good thing about the bug tracker (PM system). Specifically we get email notices now when things are fixed or we can just go in and check if we are not on the email list.

Here is the seconds bar version if anyone is interested. Take note that it has a method of outlining the If statements which simulates the lineup of VBA and some of the better languages. I just wish I had thought of it when I first wrote all my EL code. It looks better with the editor since you can see the larger indent. The rules is the actual End; statement immediately above the comment is the one tied in with the If statement in the comment (comment being lined up with the If statement itself).

Code: Select all

Inputs: PlayAlert("Y");

Variables:
Intrabarpersist ErrorCnt(-1),
LogPath(""),
PrintFile(""),
Intrabarpersist TimePrev(0);

If currentbar = 1 then
begin
LogPath = "C:\";
PrintFile = LogPath + "A_BarStatusZeroTest_Sec.txt";
Print(File(PrintFile),"Just making sure the print file is out there. CurrentDate=" + numtostr(currentdate,0));
end;

If lastbaronchart_s then
begin
if time_s > TimePrev then
begin
TimePrev = time_s;
if BarStatus > 0 then
begin
ErrorCnt = ErrorCnt + 1;
if ErrorCnt > 0 then
begin
Print(File(PrintFile),
"Error: BarStatus > 0 during the first tick of the bar. " ,
"Time_s=",
Time_s, " " ,
"BarStatus=",
BarStatus, " " ,
"ErrorCnt=",
ErrorCnt, " " ,
" ");
if PlayAlert = "Y" then
Alert("Error: BarStatus > 0. Time_s=" + numtostr(time_s,0) + " Cnt=" + NumToStr(ErrorCnt,0));
end;
{END: if ErrorCnt > 0 then}
end;
{END: if BarStatus > 0 then}
end;
{END: if time_s > TimePrev then}
end;
{END: If lastbaronchart_s then}

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Alert on Open

Postby bowlesj3 » 02 Aug 2012

I think it is confirmed now that the BarStatus = 0 bug is fixed because I ran both of the test scripts for a full day and no errors were found. As I said earlier, 3/4 years ago I would get maybe 4 to 6 errors in a day but I found the work around and focused my attention elsewhere. I seem to remember I found the problem during the missing ticks problem which seems to be largely fixed so maybe this problem was fixed at the same time.

Triage
Posts: 28
Joined: 12 Mar 2012
Has thanked: 2 times
Been thanked: 3 times

Re: Alert on Open

Postby Triage » 02 Aug 2012

Bowlesj3, what version of MC are you running on?
I think it is confirmed now that the BarStatus = 0 bug is fixed because I ran both of the test scripts for a full day and no errors were found. As I said earlier, 3/4 years ago I would get maybe 4 to 6 errors in a day but I found the work around and focused my attention elsewhere. I seem to remember I found the problem during the missing ticks problem which seems to be largely fixed so maybe this problem was fixed at the same time.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Alert on Open

Postby bowlesj3 » 03 Aug 2012

7.4 build 4953

Triage
Posts: 28
Joined: 12 Mar 2012
Has thanked: 2 times
Been thanked: 3 times

Re: Alert on Open

Postby Triage » 03 Aug 2012

That's strange because we are using the latest version of MC 8.0, and I'm almost sure now some of the intermittent trade issues we experienced are from the skipped ticks problem.

In your tests, are you sending the orders to the broker as well with either SA or AA auto trading mode? Or are the tests just with live data and no order execution to the broker?

Thanks again for the detailing of this problem in the post.
7.4 build 4953

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Alert on Open

Postby bowlesj3 » 04 Aug 2012

Hi,

No, I do not have MC do any execution.

The best thing to do is pop my code above into your chart and leave it there for a week maybe. If you find a problem let us know. The barstatus=0 can not escape undetected if this code is running. However it just occurred to me that maybe the barstatus=0 problem is specific to certain studies for MC related technical reasons. If that is the case the obvious thing to do is to insert my code directly into the study you suspect has this problem. For sure if you insert it directly before your BarStatus=0 test you will find out if BarStatus=0 is your problem or not. After having done this, if you still have the problem and it is not barstatus=0 then having done this will have the benefit of getting you started on writing a series of traps to find it (see link below if needed) rather than always assuming it is barstatus=0 and never resolving the issue (just like I always assumed barstatus=0 was unfixed and kept writing the above logic in place of it).
viewtopic.php?f=16&t=10397


John


Return to “MultiCharts”