Join useThinkScript to post your question to a community of 21,000+ developers and traders.
input fastLength = 12;
input slowLength = 26;
input macdLength = 9;
input averageType = AverageType.EXPONENTIAL;
def diff = reference MACD(fastLength, slowLength, macdLength, averageType).Diff;
def lips = reference WilliamsAlligator().Lips;
def teeth = reference WilliamsAlligator().Teeth;
def price = open;
def Closeprice = close;
def sucess = diff crosses above 0 and price > lips;
def exit = price < lips or closeprice < lips;
def Q = 50/(price - teeth);
input digits = 0;
def buyQ = roundup(Q, digits);
AddOrder(OrderType.BUY_TO_OPEN, condition = sucess, open[-1], tradesize = buyQ, Color.GREEN, Color.GREEN, "BUY");
AddOrder(OrderType.SELL_TO_CLOSE, condition = exit, open[-1], tradesize = buyQ, Color.RED, Color.RED, "SELL");
def teeth = reference WilliamsAlligator().Teeth;
def price = open;
def Q = 50/(price - teeth);
input digits = 0;
def buyQ = roundup(Q, digits);
AddOrder(OrderType.BUY_TO_OPEN, condition = sucess, open[-1], tradesize = buyQ, Color.GREEN, Color.GREEN, "BUY");
input tradesize = 50;
AddOrder(OrderType.BUY_TO_OPEN, condition = up, price = open[-1], tradesize, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Long");
AddOrder(OrderType.SELL_TO_CLOSE, condition = down, price = open[-1], tradesize, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Cover");
About the bubbles - currently can't understand how I use it I'll go over this again later and will try to write one for the 'teeth'.@Camus1612
Not working is not a very detailed explanation. I just wrote the syntax using your logic. Are you saying you are getting a syntax error?
Otherwise, is your logic not correct?
When troubleshooting logic, you can put in labels and chart bubbles to see the values of your calculations to determine if what you think you are calculating is what is actually being done.
input risk = 50;
def buyQ = round(risk/price - teeth, 0);
AddOrder(OrderType.BUY_TO_OPEN, condition = success, open[-1] tradesize = buyQ, Color.GREEN, Color.GREEN, "BUY");
AddOrder(OrderType.SELL_TO_CLOSE, condition = exit, open[-1], tradesize = buyQ, Color.RED, Color.RED, "SELL");
Thank you for the comment.@Camus1612 Unfortunately, TOS allows for multiple Buys using AddOrder() but I'm fairly certain that Sell orders close the entire trade regardless of how many shares have been bought... Therefore, you can scale into a simulated trade but you cannot scale out...
@MerryDay Thanks for the kind words...
input tradeSize = 100;
AddOrder(OrderType.BUY_TO_OPEN, IN, open[-1], tradeSize, Color.CYAN, Color.CYAN);
AddOrder(OrderType.SELL_TO_CLOSE, **Idk**, open[-1], tradeSize, Color.MAGENTA, Color.MAGENTA);
input length = 20;
input trendSetup = 3;
def BodyMax = Max(open, close);
def BodyMin = Min(open, close);
def IsEngulfing = BodyMax > BodyMax[1] and
BodyMin < BodyMin[1];
def IsWhite = open < close;
def IsBlack = open > close;
def IsPrevDoji = IsDoji(length)[1];
def Bullish = IsDescending(close, trendSetup)[1] and
(IsBlack[1] or IsPrevDoji) and
IsWhite and
IsEngulfing;
def sell_condition = if Bullish then close else sell_condition[1];
def sell_location = (2/100) * sell_condition;
input tradeSize = 100;
def IN = Bullish;
def OUT = sell_condition - sell_location;
AddOrder(OrderType.BUY_TO_OPEN, IN, open[-1], tradeSize, Color.CYAN, Color.CYAN);
AddOrder(OrderType.Sell_TO_CLOSE, OUT, open[-1], tradeSize, Color.CYAN, Color.CYAN);
plot data = OUT;
data.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
data.SetDefaultColor(Color.YELLOW);
def entryprice = if buycondition then close else entryprice[1];
AddOrder(OrderType.SELL_TO_CLOSE, close >= (entryprice + target) or close <= (entryprice - SL), open[-1], tradeSize, Color.MAGENTA, Color.MAGENTA);
AddOrder(OrderType.SELL_TO_CLOSE, close >= (entryprice + .25) or close <= (entryprice - .10), open[-1], tradeSize, Color.MAGENTA, Color.MAGENTA);
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
thinkScript IDE For ThinkOrSwim | Tutorials | 5 | ||
Thinkorswim Chart Study and Thinkscript Plot Hierarchy | Tutorials | 5 | ||
How to debug ThinkScript | Tutorials | 6 | ||
thinkScript BarNumber() Function Usage and Examples | Tutorials | 7 | ||
Robert Payne offering to help with ThinkScript | Tutorials | 46 |
Start a new thread and receive assistance from our community.
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.
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.