Profit Calculator

bmcgraw393

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
 
BenTen

BenTen

Administrative
Staff
VIP
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.
 
bmcgraw393

bmcgraw393

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

Gabrielx77

Member
@bmcgraw393 Would you be able to share the indicator that's used for your entry and exit signal? Thank you
 
bmcgraw393

bmcgraw393

New member
VIP
@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);
 
bmcgraw393

bmcgraw393

New member
VIP
I am now looking to add a trail stop backtesting function. Do either of you know of any forums that could explain how this is done?
@Gabrielx77 @BenTen
 

Similar threads

Top