Working on a Trade Calculator for ThinkorSwim

netarchitech

netarchitech

Well-known member
VIP
@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 :)
 
netarchitech

netarchitech

Well-known member
VIP
@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

RobertPayne

Member
@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/
 
netarchitech

netarchitech

Well-known member
VIP
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.
Understood. I appreciate you taking the time to load the script and verify its' functionality. Thank you :)
 

Similar threads

Top