Buy Low--Sell High --Mental Stoploss Indicator

nordicbeast

New member
Hello.

I have been utilizing DeepSeek, and gone through several iterations to create this custom study. It is intended for scalping stocks on the 1min time frame.

What it does:
Triggers a LONG entry plot when:
  1. Green Candle: close > open (current candle closes higher than it opens).
  2. New High: high > high[1] (current candle’s high exceeds the previous candle’s high).
Triggers a EXIT plot when either of these occurs:
  1. Stop Line Breach: low crosses below low[1] (price breaks below the prior candle’s low).
  2. Red Candle with Lower Low:
    • low < low[1] (current candle’s low is lower than the previous candle’s low).
    • close < open (red candle).
Plots a mental stoploss line:
  • Static Stop Loss:
    • Set at the prior candle’s low (low[1]) when the entry is triggered.
    • Example: If you enter at $100, and the prior candle’s low was $99, the stop is fixed at $99.
  • Stop Updates:
    • Remains active until the trade is exited.
    • Resets to NaN (not a number) after exiting.


What are the remaining issues:
It works like expected: signals are plotted on the chart, mental stoploss lines etc. But, the refresh is not working. I can get new plots on the chart by changing between different tickers, or reapplying studies. Is this a limitation of ToS? I have tried so many different queries for DeepSeek, but we just seem to not be able to solve this challenge.

1744367545057.png

Code:
# SCALPER INDICATOR (TOS-COMPATIBLE REFRESH)
declare once_per_bar;

input showEntries = yes;
input showExits = yes;

# REFRESH TRIGGER (Works on ALL Charts)
def updateTrigger = Close + Volume() + GetTime();  # Valid ToS functions only
plot f = updateTrigger;
f.Hide();

# --- YOUR ORIGINAL STRATEGY LOGIC BELOW ---
def greenCandle = close > open;
def newHigh = high > high[1];
def validEntry = newHigh and greenCandle;

def stopLineBreach = low crosses below low[1];
def redCandleLowerLow = low < low[1] and close < open;

def inPosition;
def stopLevel;

if BarNumber() == 1 {
    inPosition = 0;
    stopLevel = Double.NaN;
} else {
    inPosition = if validEntry and !inPosition[1] then 1
                else if (stopLineBreach or redCandleLowerLow) and inPosition[1] then 0
                else inPosition[1];
               
    stopLevel = if validEntry and !inPosition[1] then low[1]
               else if (stopLineBreach or redCandleLowerLow) and inPosition[1] then Double.NaN
               else stopLevel[1];
}

# VISUAL ELEMENTS
plot EntrySignal = if showEntries and validEntry and !inPosition[1] then low else Double.NaN;
EntrySignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
EntrySignal.SetDefaultColor(Color.WHITE);

plot ExitSignal = if showExits and ((stopLineBreach or redCandleLowerLow) and inPosition[1]) then high else Double.NaN;
ExitSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ExitSignal.SetDefaultColor(Color.CYAN);

plot StopLine = if inPosition then stopLevel else Double.NaN;
StopLine.SetDefaultColor(Color.WHITE);
StopLine.SetStyle(Curve.SHORT_DASH);
 
Last edited by a moderator:
Solution
What are the remaining issues:
It works like expected: signals are plotted on the chart, mental stoploss lines etc. But, the refresh is not working. I can get new plots on the chart by changing between different tickers, or reapplying studies. Is this a limitation of ToS? I have tried so many different queries for DeepSeek, but we just seem to not be able to solve this challenge.

You are correct. Your script relies on Highest High and Lowest Low functions.
These functions were depreciated. They no longer update in real time.


Reduced Functionality of HighestAll --Schwab's response
HighestAll() and all the other Range "All" functions are resource-intensive.
Schwab throttles their use to prevent excess run of resources...
What are the remaining issues:
It works like expected: signals are plotted on the chart, mental stoploss lines etc. But, the refresh is not working. I can get new plots on the chart by changing between different tickers, or reapplying studies. Is this a limitation of ToS? I have tried so many different queries for DeepSeek, but we just seem to not be able to solve this challenge.

You are correct. Your script relies on Highest High and Lowest Low functions.
These functions were depreciated. They no longer update in real time.


Reduced Functionality of HighestAll --Schwab's response
HighestAll() and all the other Range "All" functions are resource-intensive.
Schwab throttles their use to prevent excess run of resources. They will not update or refresh in real time, which will cause your calculations and signals to lag.
https://usethinkscript.com/threads/...-range-lagging-issues-due-to-tos-update.8794/
 
Solution

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

@nordicbeast A potential workaround would be to use Highest(data, length) in place of HighestAll() as the Highest() and Lowest() functions have not been throttled by Schwab - at least not from my findings... There is far less server overhead when using Highest() or Lowest() as the functions are only looking back a smaller number of candles... Perhaps give this a try and get back to us with your results...
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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