• Happy Independence Day! Take $40 off VIP Membership with code JULY4. Sign up here.

Profit Calculator


New member
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


Staff member
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.


New member
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:


New member
@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