Get price difference between signals

jox51

Member
2019 Donor
So, I have an indicator I am working on that generates buy/sell signals. I am try to calculate the price change or difference between each buy signal and summing the result. I have been racking my brain trying to get this to work. What would be the thinkscript logic to accomplish this. So far i have this below.

bullishpb is the buysignal for example. My logic is that with fold, it will loop through each bar in the chart and if a bullishpb signal is found, then get the value of that close. When I did this, I get a 0.

def bupchg = fold b = 0 to 252 do if bullishpb is true then GetValue(close,-b) else double.nan;


Asking for help. Thank you.
 
So, I have an indicator I am working on that generates buy/sell signals. I am try to calculate the price change or difference between each buy signal and summing the result. I have been racking my brain trying to get this to work. What would be the thinkscript logic to accomplish this. So far i have this below.

bullishpb is the buysignal for example. My logic is that with fold, it will loop through each bar in the chart and if a bullishpb signal is found, then get the value of that close. When I did this, I get a 0.

def bupchg = fold b = 0 to 252 do if bullishpb is true then GetValue(close,-b) else double.nan;


Asking for help. Thank you.
I think this is what you are looking for? The will give you the profit (sum) and percent positive as a label. Enter your sell and buy signals where the UPPER CASE print is. Enter the sell side first.

Code:
################################################################################################
input PandL_Label = Yes;

def orderDir = CompoundValue(1, if  ENTER SELL SIGNAL HERE then 1 else if ENTER BUY SIGNAL HERE then -1 else orderDir[1], 0);
def isOrder = orderDir crosses 0;

def orderCount = CompoundValue(1, if IsNaN(isOrder) then 0 else if isOrder then orderCount[1] + 1 else orderCount[1], 0);

def noBar = IsNaN(open[-1]);

def orderPrice = if isOrder then if noBar then close else open[-1] else orderPrice[1];
def profitLoss = if !isOrder or orderCount == 1
then 0
else if orderDir < 0 then orderPrice[1] - orderPrice
else if orderDir > 0 then orderPrice - orderPrice[1] else 0;
#else if orderDir > 0 then orderPrice[1] - orderPrice
#else if orderDir < 0 then orderPrice - orderPrice[1] else 0;
#def profitLoss = if !isOrder or orderCount == 1 then 0 else orderPrice - orderPrice[1];
def profitLossSum = CompoundValue(1, if IsNaN(isOrder) then 0 else if isOrder then profitLossSum[1] + profitLoss else profitLossSum[1], 0);

def orderWinners = CompoundValue(1, if IsNaN(isOrder) then orderWinners[1] else if orderCount > 1 and profitLoss > 0 then orderWinners[1] + 1 else orderWinners[1], 0);

AddLabel(PandL_Label, "[    Relative Price Oscillator  >", Color.GRAY);
AddLabel(PandL_Label, orderCount + " orders (" + AsPercent(orderWinners / orderCount) + ") | P/L " + AsDollars((profitLossSum / TickSize()) * TickValue()), if profitLossSum > 0 then Color.GREEN else if profitLossSum < 0 then Color.RED else Color.GRAY);
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
418 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top