Alert when price is 6% or less above the ATR Trailning Stop


0
0

I would like to create an alert to occur when the stock price is above the Atr trailing stop and the price is 6% or less

above the Atr trainling stop.

Thanks for your help.

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on September 21, 2018 12:41 am
212 views
0

Would this alert be based on a Chart Study? Or did you have plans of having this alert sent through SMS/Email?

( at September 21, 2018 7:46 am)
0

Alert would be based on a chart study if possible?
I would be happy to just have a line drawn on the chart that is 6% above the ATR trailing stop indicator.
Thanks

( at September 22, 2018 1:17 pm)
0
Private answer

No need for code here. I can do this very simply using the Condition Wizard. (well the alert does require a bit of code writing) I can tell I need to do a video on the Condition Wizard. I get a ton of requests for stuff that folks can easily build on their own. If they only knew how to use it.

Screenshots below show the steps.

Step One

We begin with a new chart study (blank) and click the Add Condition button.

Step Two

From the left side select price–> close, in the middle select “is greater than” and from the right side select study–> ATRTralingStop.

Step Three

Same as Step Two accept for this one we select is less than for the middle section. (in order to get this to work we’ll have to add something to the very end of the code that is generated by the condition wizard.)

Step Four

The fourth screenshot shows the final result listing the two conditions we added in steps 2 and 3. From here we need to switch to the thinkScript editor. So just click on that tab and…. The fifth screenshot shows the tiny bit of text we need to add to the code. Which is nothing more than multiplying the ATRTrailingStop from the final condition by 1.06. Ok? That is 6% above the second ATRTralingStop.

Summary of Steps 1 Through 4

First condition checks that the current close is above the ATRTrailingStop. Second condition checks that the current close is below the ATRTrailingStop TIMES 6%. Got that? So when both conditions are true we have the close above the ATRTrailingStop but less than 6% above it.

Step Five

Style the plot. Screenshot 6 shows the plot settings. Here I am setting it to Boolean Down Arrows at the High. I also increased the line weight to make the arrows appear large.

Complete. The final screenshot shows the results.

The Alert

Now adding the alert is a bit more complicated. You have to know how to write and manipulate code in the thinkScript editor. First we take the existing code that was generated at step 4 and use that to define a plot (this will require you to update the study settings to plot this as a boolean down arrow at the high):

plot alertCondition = close is greater than ATRTrailingStop() and close is less than ATRTrailingStop() * 1.06;

All we need now is the alert statement:

Alert(alertCondition, "Close within ATR Range", Alert.BAR, Sound.Ring);

Just clear out any existing code from the previous steps and replace them with these last two lines.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on September 23, 2018 9:56 am
0
Thanks for your help but I would like to have the daily “LOW” be below the ATRTrailingStop TIMES 6%; not the CLOSE. I changed the ThinkScript Editor to “close is greater than ATRTrailingStop() and LOW is less than ATRTrailingStop() *1.06.” But the down arrow doesn’t appear when the daily LOW is “less than ATRTrailingStop() *1.06. I’m using ATR period of 20 and an ATR factor of 4.0. I have adjusted these variables in the ”Inputs:” fields where the default settings were ”ATR period 5 and ATR factor 3.5” But the Down Arrows are being calculated with the Default ATRtrailing Stop. What should I change to get the Arrow to show when the Daily LOW is Less than the AtrStop * 1.06? Thanks for all your help; Greatly appreciated. I will make a contribution once I get these settings to work as I would like.
( at September 24, 2018 4:12 am)
0

When you modify the settings in the condition wizard it changes the code that gets generated. If you truly are using this:
close is greater than ATRTrailingStop() and LOW is less than ATRTrailingStop() *1.06

Then you have stripped out any changes you thought you made to the input parameters.

This is what it looks like when the Condition Wizard generates the code for those custom parameters, and AFTER the times 1.06 is added to the second condition:

close is greater than ATRTrailingStop(“atr period” = 20, “atr factor” = 4.0) and low is less than ATRTrailingStop(“atr period” = 20, “atr factor” = 4.0) * 1.06

When submitting a request, it is always best to include all the details up front. And regarding “voluntary contributions”. I am very grateful for every contribution, however I did not create this Q&A forum for the purpose of collecting tips. This is our “free option” for receiving custom solutions. The thing that actually pays the bills, and makes all this possible, is the several hundred viewers who have and are submitting custom project requests: https://www.hahn-tech.com/about/

( at September 24, 2018 8:34 am)