Auto Place Buy And Sell Orders In ThinkOrSwim

Hi everybody,
I have a favor to ask and hope someone can help with coding my hard stop strategy for a 1-minute setup.
I am looking for the hard stop coding that can do the following:
1. Look at the 1st bar of every hour (ex: 7 am bar, 8 am bar, etc), go LONG if the price is higher than the high of the 1st bar, or go SHORT if the price lower than the low of the 1st bar.
2. Hard stop will be set to 0.5% of the entry price for either LONG or SHORT, if triggered, trades will switch from LONG -> SHORT, or SHORT -> LONG
3. The trade will close out at the end of the hour (ex: 7:59 am, 8:59 am, etc) and the trade cycle continue from the next hour.
Any help will be greatly appreciated!
Thanks in advance!
Bryan
 

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

I am new to using thinkscript and it might just be that I coded it wrong. My strategy just uses the HULL EMA to make trades and is very simple. on my chart it shows where it would places the trade but no orders are being placed.

Thank you in advance

Code:
plot pHull = MovingAverage(AverageType.HULL, close[0], 12)[-2];
plot cHull = MovingAverage(AverageType.HULL, open[0], 12);

def buy = pHull crosses above cHull;
def sell = pHull crosses below cHull;

# Define the number of contracts and trailing stop loss amount as variables
def numberOfContracts = 1;
def trailingStopAmount = 15;

# Define the volume threshold
def volumeThreshold = 1000;

# Check if volume is above the threshold
def isVolumeValid = volume > volumeThreshold;

# Place a buy order with a trailing stop loss only if volume is above the threshold
AddOrder(OrderType.BUY_AUTO, buy[1] and isVolumeValid, close[0], numberOfContracts, Color.GREEN, Color.GREEN);

# Place a sell order with a trailing stop loss only if volume is above the threshold
AddOrder(OrderType.SELL_AUTO, sell[1] and isVolumeValid, close[0], numberOfContracts, Color.RED, Color.RED);
 
Hi, new here.
I'm trying to play with strategies in ToS but I don't understand why my order is not placed. I feel myself stupid as I don't believe it's an error on ToS side but I can't understand why it does not work.

JavaScript:
def mv = MovAvgExponential(close, 9, 0, no);

AddOrder(OrderType.BUY_TO_OPEN, close crosses above mv, open[-1], 1, name="Buy");
AddOrder(OrderType.SELL_TO_CLOSE, close crosses below mv, open[-1], 1, name="Sell");

AddChartBubble(Yes, high + 10,  close crosses above mv, color.White);

And here how it looks on chart, as you can see there is bubble saying 1 but no order next day...
Vqlo4KY.png


Can someone point me to what Im doing wrong?
Thanks.
 
Ive never felt like I was very good at strategy scripts. So Im starting again, this time with something ive used in the past. Im trying to use a change in the macd hitogram as a trigger for a buy order. However, it wont trigger a buy order. Not sur ewhat Im doing wrong.

Code:
# Define MACD parameters
input fastLength = 12;
input slowLength = 26;
input macdLength = 9;

# Calculate MACD Line and Signal Line
def macdLine = MACD(fastLength, slowLength, macdLength)."Value";
def signalLine = MACD(fastLength, slowLength, macdLength)."Avg";

# Calculate MACD Histogram (difference between MACD Line and Signal Line)
def macdHistogram = macdLine - signalLine;

# Detect a change in MACD Histogram from decreasing to increasing
def decreasingHistogram = macdHistogram < macdHistogram[1]; # Decreasing
def increasingHistogram = macdHistogram > macdHistogram[1]; # Increasing

# Buy signal when histogram goes from decreasing to increasing
def buySignal = decreasingHistogram[1] and increasingHistogram;

# Add buy orders
AddOrder(OrderType.BUY_TO_OPEN, condition = buySignal, name = "Enter Long @");
 
The ToS app is the most robust technical charting and analysis platform available.
The app is used by traders, who are looking to build customized specialized charts to be used as analytical tools to assist in trading decisions.

The ToS app does not support automated trading. There are no auto-trade indicators on the forum.
AddOrder strategies ONLY provide simulated nor real trades.
Executing trades requires manual input from you.

While ToS provides the ability to set up a conditional order:
https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/#post-80482
It still needs to be created manually, and it only executes once. There is no ability for the trading cycle to continue.

There are options outside of ThinkOrSwim for automating trades:
https://usethinkscript.com/threads/outside-auto-trading-solutions-for-thinkorswim.19379/



@samlee @jakin000000 @bkpshah @Kasper777 @firstuser @dominooch
@BAP @TRex50 @AlanChenMB
@ConCac @CyrusCall @bauereri
@matt.mcall111 @JK100 @Trader1M
@mtepera @BlueThunder @Morgmorgan
@Saki1 @Hendrix02 @Gdragon28 @SpaciousO @Nicktoquick @Dmitry @Gradiusr @bitshift
 
Last edited by a moderator:
  • Like
Reactions: BAP

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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