Adding PPS Buy Signal indicator to Watchlist


Category:
0
0

Hi everyone, new to ThinkorSwim and to this site. Hoping someone can lend me a hand with this problem.

I am trying to get the PPS Buy and Sell signals in a column in my watchlist and have been able to do so using the code below. The issue is that I run this on the 5 min chart and the signal triggers on and off as the condition for Buy and Sell is being formed. What I would like to do is to only get the notification once the Buy or Sell signal is confirmed on one 5 min candle and that the alert stay on for at least the next five minutes (One candle or two) before it goes away. Is that possible? Thanks in advance!

def buy = !IsNaN(PPS().”BuySignal”);
def sell = !IsNaN(PPS().”SellSignal”);

AddLabel(buy, “Buy Fired”, color.black);
AddLabel(sell, “Sell Fired”, color.black);
AddLabel(!buy and !sell, ” “, color.black);

AssignBackgroundColor(if buy then color.white else if sell then color.white else color.black);

RESOLVED
Marked as spam
Posted by (Questions: 3, Answers: 1)
Asked on April 25, 2020 8:47 pm
690 views
0
Private answer

I moved this out of the "Alert and Notifications" topic and into the "Watch Lists" topic since that is what you are requesting.

I like the code you included because it taught me something new. I did not realize we could add more than one "AddLabel()" statement to a custom watchlist column. In the past I would use only one "AddLabel()" statement and then use the if/then/else logic to dynamically set the text or  value of the label. So thanks for teaching me something. I always love to learn new things.

So if you wanted to modify that to only display the signal after it has locked in and cannot change we need to shift the code to look at the previous bar for the signal instead of the current bar. We do this using something called an index: [1]. If no index is applied, the default index value is zero [0]. Which means the current bar. Taking this concept a bit further, we have the following:

  1. Current bar: buy[0]
  2. Previous bar: buy[1]
  3. The bar before item 2: buy[2]

Next, I will modify the AddLabel() statements from your code to shift them one bar to the left (previous bar):

AddLabel(buy[1], “Buy Fired”, color.black);
AddLabel(sell[1], “Sell Fired”, color.black);
AddLabel(!buy[1] and !sell[1], ” “, color.black);

If you wanted to have the signal persist for several bars after the signal has locked in, we need to have the code look backwards a number of bars. This solution is a bit more complex. I won't take the time to explain this:

AddLabel(Highest(buy[1], 5) > 0, “Buy Fired”, color.black);
AddLabel(Highest(sell[1], 5) > 0, “Sell Fired”, color.black);
AddLabel(Highest(buy[1], 5) < 1 and Highest(sell[1], 5) < 1, ” “, color.black);

This example will look back at the previous 5 bars (excluding the current bar because [1]), and display if any signals were present within that span. What happens if you get a both a buy and a sell within those 5 bars? Well if you need to account for that we need to get much more complex with our solution. That is beyond the scope of what I can cover here in the Q&A forum.

In each of these examples I have only displayed the lines from your code that need to be modified. You will still need to include all the other lines in your code as they are.

Marked as spam
Posted by (Questions: 37, Answers: 4117)
Answered on April 26, 2020 8:25 am