Difference between 2 bars study for position sizing, is it possible?

Stojanovich1995

New member
To whom it may concern,

I am looking to create an indicator that will allow me to click on (or choose by entering the times of the bars) 2 bars and it will tell me the difference between the highest and lowest price within those bars.

For example, I am trading X stock with a $500/trade risk, I see 2 green bars up, 1 smaller red bar pullback, I want to enter a trade right above the last green bar and I want my stoploss to be at the bottom of the red pullback bar. The difference between the high of the green bar and the low of the red bar will determine how many shares I buy. Let's say the difference is $5, in this case I would buy 100 shares and that's easy, then my first profit target is $5 up (1R) and the final profit target is $10 up (2R). My problem arises when the difference is not that easy, say one bar is at 1013.35 and the other bar is 1006.87, now I have to bust out a calculator and waste time frantically punching in these numbers and then finding my proper position size and my targets. It would be so much nicer if I could just click two bars, it tells me the difference and I'm set to go.

I would appreciate any help or suggestions!
 
Solution
@Stojanovich1995
Unfortunately thinkscript doesn't support clicking on bars, so you will have to enter the start times of the bars and pick High or Low of those bars in the study customizing window for this code.
PSxgIdb.png

xGu1GK9.png

Code:
input Bar_One_Time = 0930;
input Bar_One_Mark = {default High, Low};
input Bar_Two_Time = 1000;
input Bar_Two_Mark = {default Low, High};

def Var1;
switch (Bar_One_Mark) {
case high:
    Var1 = high[1];
case low:
    Var1 = low[1];
}

def Var2;
switch (Bar_Two_Mark) {
case low:
    Var2 = low[1];
case high:
    Var2 = high[1];
}

def Var3 = If secondsFromTime(Bar_One_Time)==(GetAggregationPeriod()/1000) then Var1 else Var3[1];
def Var4 = If...
@Stojanovich1995
Unfortunately thinkscript doesn't support clicking on bars, so you will have to enter the start times of the bars and pick High or Low of those bars in the study customizing window for this code.
PSxgIdb.png

xGu1GK9.png

Code:
input Bar_One_Time = 0930;
input Bar_One_Mark = {default High, Low};
input Bar_Two_Time = 1000;
input Bar_Two_Mark = {default Low, High};

def Var1;
switch (Bar_One_Mark) {
case high:
    Var1 = high[1];
case low:
    Var1 = low[1];
}

def Var2;
switch (Bar_Two_Mark) {
case low:
    Var2 = low[1];
case high:
    Var2 = high[1];
}

def Var3 = If secondsFromTime(Bar_One_Time)==(GetAggregationPeriod()/1000) then Var1 else Var3[1];
def Var4 = If secondsFromTime(Bar_Two_Time)==(GetAggregationPeriod()/1000) then Var2 else Var4[1];
def Var5 = AbsValue(Var3 - Var4);

AddLabel(yes,"Bar 1 "+Bar_One_Mark+": "+Var3,color.WHITE);
AddLabel(yes,"Bar 2 "+Bar_Two_Mark+": "+Var4,color.WHITE);
AddLabel(yes,"Absolute Value of Difference Between Bar 1 "+Bar_One_Mark+" and Bar 2 "+Bar_Two_Mark+": "+Var5, Color.WHITE);
 
Solution

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