Audible signals from a script
Author: M635
Creation Date: 4/7/2009 3:50 PM
profile picture

M635

#1
I'm trying to limit the audible signals when running strategys real time. I'm running a three minute time scale and using stop limits from the rules builder bracketed stops. My script is a combination of rules builder and cut and paste. Currently once an entry alert has occured I get audible signals every three minutes after the stop and limit alert signals have been generated.

I went to the user guide and found some code samples that should be able to turn off the 3 minute signals and only signal when a stop or limit condition has been met. I have inserted these in the code and the code compiled and runs but I don't get any signals at all.

The preferances for sound have been turned off, otherwise I still get the 3 minute audible.

Code below:
CODE:
Please log in to see this code.


My codeing skills are improving but I can't seem to get this one to work, all help appreciated.
profile picture

Cone

#2
You need to properly delimit the actions in the conditional block for which they are intended. Also, the main problem is that you put p.EntryBar instead of just bar when comparing to the last bar of the chart. You got it right for the BuyAtMarket, but ...

CODE:
Please log in to see this code.


CODE:
Please log in to see this code.



Here's the whole thing corrected (could be errors since I didn't have all of your code to check) and much more concise with an improvement on treating the AtClose Alert.

CODE:
Please log in to see this code.
profile picture

M635

#3
Cone,
You and Eugene are amazing with the speed of response and your willingness to hold the hands of new users. Keep up the good work!!

Now to the work at hand,

I have integrated the changes from above and am posting the complete code below, first a few comments.
CODE:
Please log in to see this code.


This block is from the rules builder bracketed stops, as I understand it, it kicks in a trailing stop once a certain level of profit is achieved and protects a percentage of those profits as declared in the statement just above it. So basically it sets up a trailing stop that is a factored trail % based on the protection % when a level is hit.

If I've got this wrong please help me to understand.
CODE:
Please log in to see this code.

I am using an indicator from another time period to keep me with the trend. Since this is a day trade strategy I have found trading with the trend is always more profitable than going against it.

One thing I noticed when I ran the revised strategy was I did not get a sell signal for the end of today, and the trade record shows the trade as open. When I run my original code I do get the closing trade for today. I realize you cleaned up the EOD sell statement but why would it not end the last bar of today with a sell. If you look back for earlyer trades they do show sells for EOD.

The thing that is the most difficult for me to understand is you declare the sound alert for the EOD sell but do not make the declaration again for the limit and trailing stop signals. Do these signals use the original declaration form the EOD signal? Will I get a signal for the limit and trail signals when they trigger or when they are sent to the staged order status. I'm wanting the signals for all alerts to sound when they trigger in the strategy and are sent to the order window. Am I thinking correctly here?

Here's the script:
CODE:
Please log in to see this code.


Thanks again!!!
profile picture

M635

#4
OK,
A new day and more to learn.
As per my question above regarding signals sounding only upon alert (initial alert). I am running the strategy and a trade has been alerted and now at 3 minute intervals I get the audible signal. How do I limit this signal to only the initial alert?
profile picture

Cone

#5
QUOTE:
This block is from the rules builder bracketed stops, as I understand it,...
You must have moved it because that snippet does not appear in the block of code in which the Trailing stop is executed. It's not required at all with the use of PlotStops() anyway.

QUOTE:
if (enable[bar] > 50)
The start of the trading loop should be sufficient to make this test redundant.

QUOTE:
If you look back for earlyer trades they do show sells for EOD.
Right, I made the code tradable as explained in the comments: This logic gives you a market order Alert (compatible with trading) if the last bar of the day is also the last bar on the chart.

AtClose signals are for backtesting only and they serve to show that you've closes the position at the close of the day. Of course, the AtMarket order will try to execute when the script is processed at 4:00pm, but since the regular market is "closed", it's unlikely to fill unless you reenter the order for after-hours trading in AT Pro.

QUOTE:
you declare the sound alert for the EOD sell but do not make the declaration again for the limit and trailing stop signals.
Those are "calls", not declarations. ;) Right. The second one is unnecessary; it's redundant. If the idea is to make a sound whenever you have an Alert, you only need to call it once in the exit logic (on the last bar) since the exit logic always creates an Alert for a position since it uses stop and limit orders.
profile picture

M635

#6
Thanks Cone,,I still have some questions, comments and a wish list.

QUOTE:
You must have moved it because that snippet does not appear in the block of code in which the Trailing stop is executed. It's not required at all with the use of PlotStops() anyway.


Here is the block of code copied directly from the Rules builder, I have edited in my slider values and your comment and my question:
CODE:
Please log in to see this code.

Here are the definitions of my sliders lined up with the explanation that appears in the definition box under the Rules selection box in a New Strategy From Rules window.
QUOTE:
(slider.7) Profit Pct: Percentage profit target from entry price.
(slider.8) Stop Pct: Percentage stop loss, e.g., 2 = 2% loss.
(slider.9) Trail Stop Trigger Pct: Percent profit on a MFE basis required to trigger the trailing stop.
(slider.10) Trail Stop Pct: Percentage of profit below most-favorable closing price; e.g., 40 protects 60% of the profit.

I am struggleing with your comment regarding double TStopTrigger block not being required. Would the Bracketed Stop routine still run the same?? I have puzzeled over this for the past hour and still don't get it, am I misunderstanding something? I'll grant you the definition for slider10 takes a little thought to wrap your mind around. What I get from it is that it creates a trailing stop value based on the range of potential max profit experianced since the entry of the trade. Is this correct?

QUOTE:
Those are "calls", not declarations. ;) Right.


Right,, got it,, I'll try and get the jargon as precise as I can:) I'll try,, but can't promise that I wont get my Namespace, Classes, Members, Methods, Blocks, Statements, Declarations, Calls etc. confused again;)
CODE:
Please log in to see this code.

Now for the wish list, how do I keep the straegy from chirpping at me every 3 minutes and only signal me when something has changed?

Thanks!!

Note added:
Sorry for the funky spacing in the code inserts, every time I copy and paste from the code inserts above it strings the code together and blows out the margins.

profile picture

Cone

#7
QUOTE:
I am struggleing with your comment regarding double TStopTrigger block not being required.
Don't struggle, just look. Where is the variable TStopTrigger used? (Answer: Nowhere except to draw a line that doesn't mean anything.) It's in the block of code that executes the SellAtStop signal, whose trigger is the StopPrice variable, not the TStopTrigger. Anyway, now I see that it's not your fault and is extraneous code produced by the Rules Builder, so we'll call that one in to get it fixed.

QUOTE:
Now for the wish list, how do I keep the straegy from chirpping at me every 3 minutes and only signal me when something has changed?
You have to initialize and keep track of the last stop and limit prices, and then conditionally call the SoundAlert method when a change occurs.
profile picture

Cone

#8
Re: TStopTrigger
This one's my misunderstanding. Since the term "trigger" was used in the variable name, I mistook it to mean the trigger price for the trailing stop.

In reality, the TStopTrigger is used to show (on the chart) the price at which the TrailingStop logic will be activated, in other words, where the strategy will switch from using the fixed stop loss to the trailing stop. It's only used for that and could be removed from the code without having any effect.

Long story short - it's okay!

Here's the change for the SoundAlert only if the order has changed or changed price.. just the exit logic change:

CODE:
Please log in to see this code.
profile picture

M635

#9
Thanks Cone!!
I'll integrate this code over the week end. Like the comments you added, it helps a non programer follow the routine and learn!!!

As always your help is greatly appreciated.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).