Welcome to NexusFi: the best trading community on the planet, with over 200,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- discounts are available after registering.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
//@version=5
strategy("Dynamic Range Deviation Entry", overlay=true)
// Define the lookback period for calculating the range
lookback_period = input.int(20, "Lookback Period")
// Calculate the highest high and lowest low over the lookback period
highest_high = ta.highest(high, lookback_period)
lowest_low = ta.lowest(low, lookback_period)
// Define the range of prices to trade within based on the highest high and lowest low
range_low = lowest_low
range_high = highest_high
// Calculate the range width
range_width = range_high - range_low
// Calculate the entry thresholds based on the deviation from the range
entry_deviation_long = input.float(0.04, "Long Entry Deviation")
entry_deviation_short = input.float(0.033, "Short Entry Deviation")
// Place buy and sell orders based on the entry thresholds
strategy.entry("Long", strategy.long, comment="Long Entry", limit=entry_threshold_long)
strategy.entry("Short", strategy.short, comment="Short Entry", limit=entry_threshold_short)
// Close the entire position if it goes against the entry direction
if strategy.position_size != 0 and ((strategy.position_size > 0 and close < range_low) or (strategy.position_size < 0 and close > range_high))
strategy.close("Long", comment="Long Exit")
strategy.close("Short", comment="Short Exit")
// Plot the range and the entry thresholds
plot(range_low, color=color.green, style=plot.style_linebr)
plot(range_high, color=color.red, style=plot.style_linebr)
plot(entry_threshold_long, color=color.green, style=plot.style_circles, linewidth=3)
plot(entry_threshold_short, color=color.red, style=plot.style_circles, linewidth=3)
Can you help answer these questions from other members on NexusFi?