Profit Calculator

bmcgraw393

New member
VIP
Does anyone know how to write a script that adds and subtracts the price of candles at specific points?
For instance, I have an indicator that signals a buy and sell point. I want to be able to write a script that will display the percent profit from the buy and sell point. From there, I want the script to add up every buy-sell profit in a certain range (ex the last 5 days). As of now, I make a script and then manually enter a month worth of information into excel to see if the script is profitable; I want to make something that gets around the manual labor.

I have written many programs, but this is one concept that I have yet to discover.

Thanks y'all
 
If you can implement a backtesting strategy for your indicator, you can get the entry and exit points. Then, export it to Google Sheet or Excel and calculate the specific points there.
 

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

Hey Ben,

That's where I am looking for help. For simplicity, let's say my indicator is the HMA. How can I implement a back testing strategy that will grab the price (buy) when the HMA first moves up and the price (sell) when the indicator moves down?
I think something like this would be of great use to everyone if I can get help starting it.

I found a very useful link to do this. I was able to implement it on one of my indicators. https://ryanclouser.com/2019/04/12/Backtesting-with-thinkscript/
 
Last edited by a moderator:
@Gabrielx77 I figured it out! I have been using back testing for a number of different indicators. Below is the fundamental code I use (not my actual indicator just the general idea):

def TradeSize = inset dollar amount / close;
input price = close;
input length = 20;
input displace = 0;

plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];

def earlyBuy = SecondsFromTime(0930) >= 0 and SecondsFromTime(1600) <= 0;
def buy=earlyBuy==1 and HMA>HMA[1] and HMA[1]<HMA[2];
def sell=earlyBuy==0 or HMA<HMA[1];
AddOrder(OrderType.BUY_TO_OPEN,buy, close, TradeSize);
AddOrder(OrderType.SELL_TO_CLOSE,sell, close, TradeSize);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
315 Online
Create Post

Similar threads

Similar threads

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