PM High of Day

casperamy

New member
Hello! I have been working on a script/study that plots the current High/Low of the session at 11:30 AM. I am trying to figure out how to generate a label and buy/sell signal if a bar closes above or below the respective plotted line (after 11:30 AM. I have tried a couple of solutions but no luck. If anyone has any input I would appreciate it!

Thanks in advance!

Casper

This is what I have so far:

Ruby:
input RangeBegin = 0930;

input RangeEnd = 1130;

input MarketOpen = 0930;

Def IsRangeActive = if secondstilltime(RangeEnd) > 0 && secondsfromtime(RangeBegin) >= 0 then 1 else 0;

Rec RangeHigh = if RangeHigh[1] == 0 or IsRangeActive[1] == 0 && IsRangeActive == 1 then high else if IsRangeActive && high > RangeHigh[1] then high else RangeHigh[1];

Rec RangeLow = if RangeLow[1] == 0 or IsRangeActive[1] == 0 && IsRangeActive == 1 then low else if IsRangeActive && low < RangeLow[1] then low else RangeLow[1];

plot pmH = RangeHigh;

plot pmL = RangeLow;

Also If possible for some insight on how to have the plots pmH and pmL start at 11:30 am (input Range End). I dont need to see them before that.

Thanks
 
Last edited by a moderator:
Solution
@casperamy
:side note:
'Rec' is no longer required for defining recursive variables, just use 'Def'.

Ruby:
input RangeBegin = 0930;
input RangeEnd = 1130;
input MarketOpen = 0930;

Def IsRangeActive = if secondstilltime(RangeEnd) > 0 && secondsfromtime(RangeBegin) >= 0 then 1 else 0;
Def EOD = 1630;
Def PlotActive = if secondstilltime(EOD) > 0 && secondsfromtime(RangeEnd) >= 0 then 1 else 0;

Def RangeHigh = if RangeHigh[1] == 0 or IsRangeActive[1] == 0 && IsRangeActive == 1 then high else if IsRangeActive && high > RangeHigh[1] then high else RangeHigh[1];

Def RangeLow = if RangeLow[1] == 0 or IsRangeActive[1] == 0 && IsRangeActive == 1 then low else if IsRangeActive && low < RangeLow[1] then low else RangeLow[1];

plot pmH =...
@casperamy
:side note:
'Rec' is no longer required for defining recursive variables, just use 'Def'.

Ruby:
input RangeBegin = 0930;
input RangeEnd = 1130;
input MarketOpen = 0930;

Def IsRangeActive = if secondstilltime(RangeEnd) > 0 && secondsfromtime(RangeBegin) >= 0 then 1 else 0;
Def EOD = 1630;
Def PlotActive = if secondstilltime(EOD) > 0 && secondsfromtime(RangeEnd) >= 0 then 1 else 0;

Def RangeHigh = if RangeHigh[1] == 0 or IsRangeActive[1] == 0 && IsRangeActive == 1 then high else if IsRangeActive && high > RangeHigh[1] then high else RangeHigh[1];

Def RangeLow = if RangeLow[1] == 0 or IsRangeActive[1] == 0 && IsRangeActive == 1 then low else if IsRangeActive && low < RangeLow[1] then low else RangeLow[1];

plot pmH = if PlotActive then RangeHigh else double.nan;
plot pmL = if PlotActive then RangeLow else double.nan;

Def BuySignal;
Def SellSignal;

if !PlotActive {
    BuySignal = 0;
    SellSignal = 0;
}else if PlotActive &&  !BuySignal[1] && close[1] > pmH {
    BuySignal = 1;
    SellSignal = 0;
}else if PlotActive &&  !SellSignal[1] && close[1] < pmL {
    BuySignal = 0;
    SellSignal = 1;
}else{
    BuySignal = BuySignal[1];
    SellSignal = SellSignal[1];
}

AddChartBubble(BuySignal && !BuySignal[1],high,"Buy Signal",Color.Green,yes);
AddChartBubble(SellSignal && !SellSignal[1],low,"Sell Signal",Color.Light_Red,no);

AddLabel(yes,
        if BuySignal then "Buy Signal" else if SellSignal then "Sell Signal" else "Waiting For Signal",
        if BuySignal then Color.Green else if SellSignal then Color.Light_Red else Color.Gray);
 
Solution
@casperamy
:side note:
'Rec' is no longer required for defining recursive variables, just use 'Def'.

Ruby:
input RangeBegin = 0930;
input RangeEnd = 1130;
input MarketOpen = 0930;

Def IsRangeActive = if secondstilltime(RangeEnd) > 0 && secondsfromtime(RangeBegin) >= 0 then 1 else 0;
Def EOD = 1630;
Def PlotActive = if secondstilltime(EOD) > 0 && secondsfromtime(RangeEnd) >= 0 then 1 else 0;

Def RangeHigh = if RangeHigh[1] == 0 or IsRangeActive[1] == 0 && IsRangeActive == 1 then high else if IsRangeActive && high > RangeHigh[1] then high else RangeHigh[1];

Def RangeLow = if RangeLow[1] == 0 or IsRangeActive[1] == 0 && IsRangeActive == 1 then low else if IsRangeActive && low < RangeLow[1] then low else RangeLow[1];

plot pmH = if PlotActive then RangeHigh else double.nan;
plot pmL = if PlotActive then RangeLow else double.nan;

Def BuySignal;
Def SellSignal;

if !PlotActive {
    BuySignal = 0;
    SellSignal = 0;
}else if PlotActive &&  !BuySignal[1] && close[1] > pmH {
    BuySignal = 1;
    SellSignal = 0;
}else if PlotActive &&  !SellSignal[1] && close[1] < pmL {
    BuySignal = 0;
    SellSignal = 1;
}else{
    BuySignal = BuySignal[1];
    SellSignal = SellSignal[1];
}

AddChartBubble(BuySignal && !BuySignal[1],high,"Buy Signal",Color.Green,yes);
AddChartBubble(SellSignal && !SellSignal[1],low,"Sell Signal",Color.Light_Red,no);

AddLabel(yes,
        if BuySignal then "Buy Signal" else if SellSignal then "Sell Signal" else "Waiting For Signal",
        if BuySignal then Color.Green else if SellSignal then Color.Light_Red else Color.Gray);
This is great! Ty!
 

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