Using Low of Entry Bar for Stop Loss in a Strategy

silver8ack

New member
I'm trying to use the low of my entry bar as a stop loss in a strategy, but I can't seem to get it to work. Is there any way for a strategy to save the low of the day/bar on entry, and then use that as a stop loss?

Thanks.

Solution
The only way that I know of to do this is to set up an array that maintains the low of the candle:
Code:
``````def entry_condition = if your condition then 1 else 0;
def entry_bar_low = if entry_condition == 1 then LOW else entry_bar_low[1];``````
so that when the entry condition is true the low is captured and then repeated until the next time the entry condition is repeated.

-mashume
The only way that I know of to do this is to set up an array that maintains the low of the candle:
Code:
``````def entry_condition = if your condition then 1 else 0;
def entry_bar_low = if entry_condition == 1 then LOW else entry_bar_low[1];``````
so that when the entry condition is true the low is captured and then repeated until the next time the entry condition is repeated.

-mashume

The only way that I know of to do this is to set up an array that maintains the low of the candle:
Code:
``````def entry_condition = if your condition then 1 else 0;
def entry_bar_low = if entry_condition == 1 then LOW else entry_bar_low[1];``````
so that when the entry condition is true the low is captured and then repeated until the next time the entry condition is repeated.

-mashume
Thanks! I think that will work for me.

Hello,
Would it be possible to create a size calculator risking \$100 per trade (or x dollar amount ) with a Stop Loss at Low of the Day sizing accordingly? Thank you

Last edited:
@WCC you could possibly look at some of the risk calculators on the forum and ask if someone could convert one to calculate from low of day

@WCC you could possibly look at some of the risk calculators on the forum and ask if someone could convert one to calculate from low of day
Thank you Trendr, I will look at that. If someone has an idea how to script it, please add it to the thread.

Thank you trend, i have had check out that one, it sizes you according to the amount of dollars you want to loose on you account. The one i am looking for is an amount of dollar to loose per trade in the trade and size accordingly. for example. XYZ stock i want to enter with a stop at low of the day loosing \$100 on the trade if i stop out. Kinda what Trade Ideas has on the software Brokage Plus set up.

The only way that I know of to do this is to set up an array that maintains the low of the candle:
Code:
``````def entry_condition = if your condition then 1 else 0;
def entry_bar_low = if entry_condition == 1 then LOW else entry_bar_low[1];``````
so that when the entry condition is true the low is captured and then repeated until the next time the entry condition is repeated.

-mashume
This is amazing! Thank you! I don't think anyone has figured this out on the site yet, but is there any way to take the code you did and make it basically into a trailing stop using the low of each new candle? So for example, if I enter into todays candle, the stop loss would be the low of the candle from yesterday. If tomorrow, price increases and close never passes the low from the previous bar, the stop loss is moved up on the indicator. Thanks!

you could perhaps build on the idea above something like this:

Code:
``````input long_trail_by = 0.25;
def entry_condition = if your condition then 1 else 0;
def entry_bar_trail = if entry_condition == 1 then LOW else if LOW < entry_bar_low[1] then LOW else entry_bar_low[1];
plot trail_stop = entry_bar_trail - long_trail_by;``````

The if is a bit more complicated. We keep the first part so that a new entry condition will trigger it at low. Then we ask whether the low from this bar is lower than the entry_bar_trail from the previous bar. if it is, we take the new low, otherwise we keep the entry_bar_trail.

Then we plot some line equal to the entry_bar_trail minus the trail_by value, so that we can see it on the upper chart.

hope that pushes you in the right direction.

-mashume

you could perhaps build on the idea above something like this:

Code:
``````input long_trail_by = 0.25;
def entry_condition = if your condition then 1 else 0;
def entry_bar_trail = if entry_condition == 1 then LOW else if LOW < entry_bar_low[1] then LOW else entry_bar_low[1];
plot trail_stop = entry_bar_trail - long_trail_by;``````

The if is a bit more complicated. We keep the first part so that a new entry condition will trigger it at low. Then we ask whether the low from this bar is lower than the entry_bar_trail from the previous bar. if it is, we take the new low, otherwise we keep the entry_bar_trail.

Then we plot some line equal to the entry_bar_trail minus the trail_by value, so that we can see it on the upper chart.

hope that pushes you in the right direction.

-mashume
Thanks!

Not the exact question you're looking for?

87k+ Posts
279 Online

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?