Need help tracking high and low of day within strategy

nrok2118

New member
I made a simple moving average crossover strategy that I just realized isn't accurate on my backtest. I have a condition that the daily low must be over yesterdays low for the long, and the daily high must be under yesterdays high for the short. For the current day's low, I simply used "low(period=aggregationPeriod.DAY)" but found out today after Powell's pump and dump (and pump) it entered a trade in real time, but when we took out yesterday's low of day the trade it no longer met the conditions, since for the backtesting its looking at the entire day, not the low at the time of condition.

Long story short, Im not the best at coding and ChatGpt isnt giving me anything that's working, how can I code a variable that captures the lowest price of the day at any given point? I assume I have to do something with time and reset it everyday so it can be used in a backtest.
 
I made a simple moving average crossover strategy that I just realized isn't accurate on my backtest. I have a condition that the daily low must be over yesterdays low for the long, and the daily high must be under yesterdays high for the short. For the current day's low, I simply used "low(period=aggregationPeriod.DAY)" but found out today after Powell's pump and dump (and pump) it entered a trade in real time, but when we took out yesterday's low of day the trade it no longer met the conditions, since for the backtesting its looking at the entire day, not the low at the time of condition.

Long story short, Im not the best at coding and ChatGpt isnt giving me anything that's working, how can I code a variable that captures the lowest price of the day at any given point? I assume I have to do something with time and reset it everyday so it can be used in a backtest.


as long as you use a longer 2nd aggregation for data, that overlaps the current candle, you will have signals repaint, come and go.
you would have to read the previous candle data, from yesterdays 'day' data , to have unchanging data ( yesterday candle has closed, and is not changing)
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

as long as you use a longer 2nd aggregation for data, that overlaps the current candle, you will have signals repaint, come and go.
you would have to read the previous candle data, from yesterdays 'day' data , to have unchanging data ( yesterday candle has closed, and is not changing)
I'm not sure I understand. My problem is I need to find a way to use the lowest/highest point of the current day at the time my strategy has an entry condition intra day. I cant look at the entire day's high/low using the day aggregation which can give missing signals during the back testing.
 
I still can't figure this out. I thought a good work around would be to use the Lowest/Highest function with a length but I get an error? Is there another way to do this?

Code:
def condition = if SecondsFromTime(0930) == 0 && SecondsTillTime(0930) == 0 then barNumber() else 0;
def StartBar = condition;
def Barnumber = if barNumber() == StartBar then 1 else Barnumber[1]+1;

def LOD = lowest(low, barnumber);

I get "Only constants expected here: barnumber CL constant function parameter 'length' at 38:23"
 
I'm not sure I understand. My problem is I need to find a way to use the lowest/highest point of the current day at the time my strategy has an entry condition intra day. I cant look at the entire day's high/low using the day aggregation which can give missing signals during the back testing.

i misunderstood . what i said wasn't quite right.
if you want to compare todays high to other data , the output of that comparison can possibly change , until the day is over.

as time progresses through the current day, there may be bars that set a higher high or lower low, which may trigger your condition. there is no getting around this.
not until the day closes will there be final unchanging values.


here is something similar, compare a signal to a signal from yesterday
https://usethinkscript.com/threads/scan-for-5ema-crossing-previous-day-high-low.14370/#post-119570
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
325 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