condition on add order

fat_tony

New member
I'm working on backtesting and I am having some trouble. I want to add a bubble on the chart that shows my entry and exits but only when the trade is first enterd. The issue I am having is I want to set up a flag so they when an order is added it will set the flag = 1. Is there any way to do this?

basically
def flag = if add order == yes then 1 else 0
 
@fat_tony Yes, you can use AddChartBubble() with the same conditional logic used in AddOrder()... Just place the AddChartBubble() call directly below your AddOrder()...
Sorry for hijacking this thread. I have a similar question on AddChartBubble and AddOrder.

I have BUY_AUTO and SELL_AUTO orders in my strategy. I also have SELL_TO_CLOSE and BUY_TO_CLOSE stop loss orders. Bubbles are used to display all the possible stop losses. The issue I'm having is that if the strategy is in a good BUY position, that is current price > Entryprice, my short order stop loss bubble is showing up, which makes sense because a short stop loss order logic is when current price > Entryprice. I would prefer only long order stop loss bubble to show up, if applicable. Is there a way to check if the strategy is currently in a BUY or SELL position, that way if it's in a BUY position, only long stop loss bubbles will show up, if SELL position, only short stop loss bubles will show up? Thanks!
 
@pine You could setup a "state" logic variable structure that sets the state to 1 for Long entries, -1 for Short entries, or 0 when no trade is active and have it update after every iteration of the Strategy... Then you would monitor the states previous or current value, similar to state[1] or state, to identify the current state before taking any AddOrder() actions... It would essentially become another conditional criteria for AddOrder()... That's what popped into my head upon reading your post...
 
@pine You could setup a "state" logic variable structure that sets the state to 1 for Long entries, -1 for Short entries, or 0 when no trade is active and have it update after every iteration of the Strategy... Then you would monitor the states previous or current value, similar to state[1] or state, to identify the current state before taking any AddOrder() actions... It would essentially become another conditional criteria for AddOrder()... That's what popped into my head upon reading your post...
Currently I have

AUTO_BUY
AUTO_SELL

then

SELL_TO_CLOSE
BUY_TO_CLOSE

I assume that once either AUTO_BUY and AUTO_SELL order is hit, you're in position, and if the SELL_TO_CLOSE or BUY_TO_CLOSE condition is met, they will show up.

Sorry for my ignorance, could you guide me on how to set this "state" logic up?
 
@pine You are correct... I'm sure you've also reviewed the StopLoss Strategies that come with TOS as well for ideas... If not, give them a review... Good luck...

There should be more than a few "state" logic examples coded into scripts here in the forums... I can't point you to one right now but if you can't find one I might have time later...
 

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
242 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