I need help writing a simple line of code that I plan to use in a strategy

YungTraderFromMontana

Well-known member
In my strategy I have multiple indicators I'm trying to work into it effectively and noticed that when one signal shows bullish or bearish for 4 strait bars, it is a good time to exit a long or short position. How would that be translated to code, essentially I need code that would coincide with [bearish data is true for the last 4 bars] but in proper format. Simple I know, but for a novice little things like this can take way more time then they need to to solve. I figured I could sleep and hopefully wake up with an answer.
 
Now you've done it. You can't sleep and wake up to an answer. Sleep is over-rated.
Go into that Gold Mine I shared earlier and look at tab #2, i think, and you'll find an education tab.
Start there and come back when you get stuck with code.
It's not that simple, you didn't give enough info. Sorry.
 
low <low[1] .... blah,blah,blah. I am sure there is a way like. [low <low,4] Just off top of my had so may not b correct. Search and you shall find.
should be parenthesis... darn keyboard is failing
 
Let's just use @horserider 's example of low < low[1].

Ruby:
def lowerLow = low < low[1];
def four_in_a_row = Sum(lowerLow, 4) == 4;

AssignPriceColor(if four_in_a_row then Color.MAGENTA else Color.CURRENT);

How this works.

def lowerLow is a boolean that evaluates as either true (this low is lower than the previous one) or false (it's not). Remember, that true = 1 and false = 0. So, add up the last 4 lowerLow's using the Sum() function. If that adds up to 4, then you know that the condition has been true 4 times in a row.

0rXMkyD.png
 

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