first open price with respect to the initial balance

shakib3585

Active member
VIP
Hello All,

I have been researching to find the "initial balance" for an entire trading session and determine if the type is "small", "medium," or "wide". I finally gathered a code, which I attached in the code section. The only drawback is that it won't be able to determine the type beyond a regular trading session. If you find a solution to determine the type of "initial balance" beyond the regular trading session, then please feel free to post it here.

Thanks

Code:
def firstBarNumber = if GetDay() <> GetDay()[1] then BarNumber() else firstBarNumber[1];

 

#First Bar Info

def high1 = if BarNumber() == firstBarNumber then high(period = aggregationPeriod.thirtY_MIN) else high1[1];

def low1 = if BarNumber() == firstBarNumber then low(period = aggregationPeriod.thirTY_MIN) else low1[1];


#Second Bar Info

def high2 = if BarNumber() == firstBarNumber+1 then high(period = aggregationPeriod.thirtY_MIN) else high2[1];

def low2 = if BarNumber() == firstBarNumber+1 then low(period = aggregationPeriod.thirTY_MIN) else low2[1];

def hi = if high1>=high2 then high1 else high2;
def lo = if low1<=low2 then low1 else low2;

def rangebar = hi - lo;

input length = 10;
input averageType = AverageType.Simple;

def ATR1 = MovingAverage(averageType, TrueRange(high(period=aggregationPeriod.DAY)[1], close(period=aggregationPeriod.DAY)[1], low(period=aggregationPeriod.DAY)[1]), length);


def a = 1.2*ATR1;

def b = ATR1/3;

AddLabel(yes, if rangeBar<b then "IB.Range.type : SMALL" else if rangeBar>a then "IB.Range.type: WIDE "else if isNaN(ATR1)==1 then "IB.Range.type : N/A" else  "IB.Range.type: MEDIUM " , color.CYAN);
 
Last edited:
Hello,

I have attached a scan code that finds the open of the very first bar and compares its position with respect to the initial balance. The code works great, except I see the laptop was working really hard to run the scan. I was wondering if anyone generous could modify this code to make it easier to run. The scan is based on a
Code:
def firstBarNumber = if GetDay() <> GetDay()[1] then BarNumber() else firstBarNumber[1];

def open1 = if BarNumber() == firstBarNumber then open else open1[1];


def high1 = if BarNumber() == firstBarNumber then high else high1[1];

def low1 = if BarNumber() == firstBarNumber then low else low1[1];


def high2 = if BarNumber() == firstBarNumber+1 then high else high2[1];

def low2 = if BarNumber() == firstBarNumber+1 then low else low2[1];

def hi = if high1>=high2 then high1 else high2;
def lo = if low1<=low2 then low1 else low2;

def mrangebar = (hi - lo)/2;

def op = hi - mrangebar;

plot scan = open1<=op;
30 minute aggregation.

Thanks
 

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