Working on a Trade Calculator for ThinkorSwim

netarchitech

Well-known member
@RobertPayne I'm sure that there will be a number of uTS scripters looking to take advantage of your very generous offer. Thank you :)

On that note, I was hoping to ask you to take a look at a script I've been working on, when you have a moment. I'm trying to put together a simple trade calculator...

Rich (BB code):
# filename: _TradeCalculator_
# author: netarchitech
# version: 20181105

def priceC = close;
input averageType = AverageType.WILDERS;
input ATRlength = 10; # default length = 14 - can range anywhere from 6 to 21
input ATRmultiplier = 1.50; # default multiplier = 2.0 - can range anywhere from 1.0 to 5.0
def ATR = MovingAverage(averageType, TrueRange(high, close, low), ATRlength);
def avgDailyMovement = (ATR / priceC) * 100;
input profitMultiplier = 3.00;

input AccountEquity = 100000;
input PercentRiskPerTrade = 0.005;
def EquityRiskPerTrade = AccountEquity * PercentRiskPerTrade;

def SharesToBuy = (EquityRiskPerTrade / (avgDailyMovement * ATRmultiplier));
def currentPositionSize = SharesToBuy * priceC;

def stopAmount = avgDailyMovement * ATRmultiplier;
def longSellStop = priceC - stopAmount;
def shortBuyStop = priceC + stopAmount;

def profitTarget = avgDailyMovement * profitMultiplier;
def longSellLimit = priceC + profitTarget;
def shortBuyLimit = priceC - profitTarget;

AddLabel(yes, "Shares to Buy: " + Round(SharesToBuy, 0), CreateColor (255, 255, 255));
AddLabel(yes, "Position Size: " + AsText(currentPositionSize, NumberFormat.TWO_DECIMAL_PLACES), CreateColor (255, 255, 255));

AddLabel(yes, "LONG Sell STOP: " + AsText(longSellStop, NumberFormat.TWO_DECIMAL_PLACES), CreateColor (255, 255, 255));
AddLabel(yes, "LONG Sell LIMIT: " + AsText(longSellLimit, NumberFormat.TWO_DECIMAL_PLACES), CreateColor (255, 255, 255));

AddLabel(yes, "SHORT Buy STOP: " + AsText(shortBuyStop, NumberFormat.TWO_DECIMAL_PLACES), CreateColor (255, 255, 255));
AddLabel(yes, "SHORT Buy LIMIT: " + AsText(shortBuyLimit, NumberFormat.TWO_DECIMAL_PLACES), CreateColor (255, 255, 255));


Any pointers/tips would be much appreciated :)
 
@RobertPayne Thank you for the swift reply. I apologize for the lack of specificity. Essentially, I guess I was hoping to have a second set of eyes desk-check the logic of the script.

Admittedly, when it comes to thinkscripting, I'm more of an editor than a coder. This is one of a few scripts I've written from the ground up. I guess I was thinking this was appropriate to send your way because you mentioned helping those who are "coding their own indicators".

Thanks again :)
 
@RobertPayne Essentially, I guess I was hoping to have a second set of eyes desk-check the logic of the script.

Admittedly, when it comes to thinkscripting, I'm more of an editor than a coder. This is one of a few scripts I've written from the ground up. I guess I was thinking this was appropriate to send your way because you mentioned helping those who are "coding their own indicators".

Thanks again :)

No. I am not interested in proofing scripts or providing my opinion on them. What I said was, "If you are stuck on something, perhaps I can help you figure it out." I loaded your script and it seems to function.

This is the "Tutorial" section of the forum. I am looking to provide assistance that can be beneficial to the community at large by showing how something may be accomplished. Then someone may use that technique in their own scripts.

Here are a couple of examples of what I have in mind.

https://funwiththinkscript.com/count-the-number-of-bars-between-successive-highs/
https://funwiththinkscript.com/adding-space-between-candles/
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
295 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