Display close from most recent PPS signal


0
0

I have a simple PPS column indicator I pieced together that will change colors dependent of which signal is currently  triggered. I use it in multiple columns each with a different timeframe to get a decent idea of the overall trend…what I can’t seem to figure out is how to get the price of the security when the study was triggered to display in the box rather than just the current close. I have already tried to create a counter and use that in ‘close[x]’ but apparently the ‘x’ must be a constant. Is there even a way to do this? Here is the code i am using:

def sell = PPS().”SellSignal”;
def buy = PPS().”buySignal”;

rec PriceAtBuy = if BarNumber() == 1 then close else if !IsNaN(buy[0]) then open[0] else PriceAtBuy[1];
rec PriceAtSell = if BarNumber() == 1 then close else if !IsNaN(sell[0]) then open[0] else PriceAtSell[1];

rec trigger = if PriceAtBuy <> PriceAtBuy[1] then -1 else if PriceAtSell <> PriceAtSell[1] then 1 else trigger[1];
#def BuyPrice = if trigger == -1 then PriceAtBuy else Double.NaN;

#def SellPrice = if trigger == 1 then PriceAtSell else Double.NaN;

AddLabel(yes, close, if trigger == -1 then color.black else color.white);
AssignBackgroundColor(if trigger == -1 then Color.uptick else Color.downtick);

I only take credit for piecing it together from other code I have found online…Any help is appreciated!

RESOLVED
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on September 6, 2018 2:19 pm
191 views
0

Due to the context of this post it will be moved out of the “Alerts and Notifications” topic and into the “Watch Lists” topic. I will also change the title of the question to more accurately describe the context of the question. This will make it easier for the rest of our visitors to search for and find this question and it’s solution. When I change that title it will also change the URL. So the original link to the post will no longer work.

The new question title will be: “Display close from most recent PPS signal”

( at September 6, 2018 4:48 pm)
0
Private answer

I decided to replace your code with my own version from scratch. The code you provided reads the open price at the buy/sell signal instead of the close price. The AddLabel() statement does not make use of those values anyway. You have the value set to the current close.

Writing it from scratch allowed me to focus on the most efficient way to complete the goal.

Here is the code for the watchlist column. Screenshot below shows the result.

def buy = !IsNaN(PPS().”buySignal”);
def sell = !IsNaN(PPS().”SellSignal”);
rec closeAtBuy = if buy then close else closeAtBuy[1];
rec closeAtSell = if sell then close else closeAtSell[1];
rec state = if buy then 1 else if sell then -1 else state[1];
plot data = if state == 1 then closeAtBuy else if state == -1 then closeAtSell else 0;
data.AssignValueColor(if state == 1 or state == -1 then Color.BLACK else Color.WHITE);
AssignBackGroundColor(if state == 1 then Color.GREEN else if state == -1 then Color.RED else Color.CURRENT);

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on September 7, 2018 10:20 am
0

I was just using the close in the label as a sort-or place holder until I knew how to achieve what I was looking for, but your code is much cleaner than what I had pieced together. Now that I read your code, it makes sense that rec would save that particular piece of data and not get rewritten on each close like I had thought. Thank you for helping with this, I really appreciate it!

( at September 7, 2018 4:41 pm)