“input tradeSize = 100;” in Dollars instead of Shares?


Category:
0
0

Hello! 
I watched the “Thinkorswim Auto Trade Almost” video. 

The opening script for the Strategy Template is “input tradeSize = 100;” and I believe that was intended to designate the purchase of 100 shares. How can I edit that to designate the purchase of a dollar amount? 

Thanks!

Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on April 8, 2020 8:07 am
253 views
0
Private answer

I have not tested this. But what you would need to do is to take the dollar amount and divide by the current price to arrive at a number of shares that equal that dollar amount. What I am saying is that the dollar amount must be converted to a number of shares or contracts. And this must be a whole number so we must round the value to the nearest whole number.

The AddOrder() statement is the place where this computation is required. Below is a very simplistic example of how you could generate a buy signal using $5,000 as the input, which is then converted to a number of shares in the AddOrder() statement:

input tradeDollars = 5000;
def buySignal = yes;
AddOrder(OrderType.BUY_TO_OPEN, buySignal[-1], close[-1], Round(tradeDollars * close, 0), Color.CYAN, Color.CYAN, "Long Entry");

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on April 8, 2020 12:36 pm