• Get $40 off VIP by signing up for a free account! Sign Up

Looking for flat bar

Bentley

Member
Hi Guys,
I've written some code for finding flat bar which is FlatBar = high == low and signal me when 2 adjacent flatbar difference is 0.01. However, it's a bit of an hit and miss situation... Here is the code... Looking for idea to improve... Thanks
Code:
# This is to find Flat bar of current and previous bar that is difference by 0.01


Declare Lower;
Input Decimal = 2;
Input Diff = 0.01;
Def FlatBar = high == low;
Def FlatBarValue = GetValue(low, FlatBar, 0);
def FlatBarDiff = Round(absValue(FlatBarValue - FlatBarValue[1]),Decimal) == Diff;

Plot FBD = FlatBarDiff;
FBD.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
FBD.SetDefaultColor(GetColor(2));
FBD.SetLineWeight(2);
 
Solution
Your code is looking at the current flatbar and the PREVIOUS flatbar.
And, you're comparing if the lows of the bars are within 1 cent of each other.

What you appear to want is
1. the flatbar CONDITION to be TRUE for currentbar
2. AND the flatbar condition to be true for previousbar

Try this?
Code:
# This is to find Flat bar of current and previous bar that is difference by 0.01
Declare Lower;
Input Decimal = 2;
Input Diff = 0.01;
Def FlatBarCurrent = high == low;
def FlatBarPrevious = high[1] == low[1];

# are flat bars next to each other?
def FlatBarConsecutive = FlatBarCurrent && FlatBarPrevious;
# Are the flat bars 1 cent apart?
def FlatBarDiff = Round(absValue(low- low[1]),Decimal) == Diff;

Plot FBD =if FlatBarConsecutive &&...
Your code is looking at the current flatbar and the PREVIOUS flatbar.
And, you're comparing if the lows of the bars are within 1 cent of each other.

What you appear to want is
1. the flatbar CONDITION to be TRUE for currentbar
2. AND the flatbar condition to be true for previousbar

Try this?
Code:
# This is to find Flat bar of current and previous bar that is difference by 0.01
Declare Lower;
Input Decimal = 2;
Input Diff = 0.01;
Def FlatBarCurrent = high == low;
def FlatBarPrevious = high[1] == low[1];

# are flat bars next to each other?
def FlatBarConsecutive = FlatBarCurrent && FlatBarPrevious;
# Are the flat bars 1 cent apart?
def FlatBarDiff = Round(absValue(low- low[1]),Decimal) == Diff;

Plot FBD =if FlatBarConsecutive && FlatBarDiff  then FlatBarDiff else double.NaN;
FBD.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
FBD.SetDefaultColor(GetColor(2));
FBD.SetLineWeight(2);


I ran this as a scan against daily time frame, and it picked up 230 stocks just now (morning of 10/27/2021, pre-market).

1wBaXUr.png


Here's some of those stocks:

OeaieAh.png



acExmx5.png



56ilBfB.png
 
Solution
@tradecombine ,
Hi there,
Hit it on the nail... totally what I was looking for...

Thought that there's something wrong with my definition of previous period flatbar but just couldn't put my finger how to correctly define them...
Totally wouldn't have think o_O of it if without your help...
Wow, small detail but big differences...
Really learn something new today...
Look obvious until u try it...

Million thanks... 🙏 (y) :)
 

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