capture the low (or the high) of the bar preceding the bar in which my AddOrder() is fired

MitchInSF

New member
Ok, I give. I'm tired and I can't figure it out. I would like to capture the low (or the high) of the bar preceding the bar in which my AddOrder() is fired and use that as a stop for said order.

def longEntry = close > open; #simple example
def stopLevel = "the low of the bar prior to the bar in which close > open" <-- how the heck do i capture this?

AddOrder(OrderType.BUY_TO_OPEN, longEntry , close, 2, Color.WHITE, Color.WHITE, "LONG: " + close);

AddOrder(OrderType.SELL_TO_CLOSE, low < stopLevel, close, 2, Color.WHITE, Color.WHITE, "LONG STOP @ " + close + " for " + (close-EntryPrice()) + "pts");
 
Solution
Here you go (y)

https://tos.mx/zEejC7r

FYI The low candle stop loss of the candle will update every time there is a PPS up signal, so it may update while you are in a trade if you get another buy signal.

Cool name btw

## STRATEGY

def ArrowBuy = if PPS()."BuySignal" is true then 1 else 0;
def ArrowBuyExit = if PPS()."SellSignal" is true then 1 else 0;

def Long_Entry = ArrowBuy >= 1;

## RISK MANAGEMENT

def LongStopCriteria = low; #I USE --> low - (2*ticksize());

def LongStopLoss;
def LongLow = if Long_Entry then LongStopCriteria else LongLow[1];
if Long_Entry {
LongStopLoss = LongStopCriteria;
} else if low < LongLow {
LongStopLoss = Double.NaN;
} else {...
Here you go (y)

https://tos.mx/zEejC7r

FYI The low candle stop loss of the candle will update every time there is a PPS up signal, so it may update while you are in a trade if you get another buy signal.

Cool name btw

## STRATEGY

def ArrowBuy = if PPS()."BuySignal" is true then 1 else 0;
def ArrowBuyExit = if PPS()."SellSignal" is true then 1 else 0;

def Long_Entry = ArrowBuy >= 1;

## RISK MANAGEMENT

def LongStopCriteria = low; #I USE --> low - (2*ticksize());

def LongStopLoss;
def LongLow = if Long_Entry then LongStopCriteria else LongLow[1];
if Long_Entry {
LongStopLoss = LongStopCriteria;
} else if low < LongLow {
LongStopLoss = Double.NaN;
} else {
LongStopLoss = LongStopLoss[1];
}
plot EntryLow = LongStopLoss;

EntryLow.setPaintingStrategy(paintingStrategy.DASHES);

def StoppedLong = if low < LongStopLoss[1] then 1 else Double.NaN;



## ORDER EXIT

def Long_Exit = ArrowBuyExit + StoppedLong >= 1;

def GoLong;
if Long_Entry is true {
GoLong = yes;
} else if Long_Exit is true {
GoLong = no;
} else {
GoLong = GoLong[1];
}
plot LongEntry = GoLong and !GoLong[1];

def ExitLong;
if Long_Exit is true {
ExitLong = yes;
} else if Long_Entry is true {
ExitLong = no;
} else {
ExitLong = ExitLong[1];
}
plot LongExit = ExitLong and !ExitLong[1];

LongEntry.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
LongExit.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

LongEntry.SetLineWeight(5);
LongExit.SetLineWeight(5);

LongEntry.SetDefaultColor(Color.GREEN);
LongExit.SetDefaultColor(Color.YELLOW);


AddOrder(OrderType.BUY_TO_OPEN, LongEntry, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "BUY");
AddOrder(OrderType.SELL_TO_CLOSE, LongExit, tickcolor = Color.WHITE, arrowcolor = Color.WHITE, name = "EXIT");
 
Last edited:
Solution

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

Well, Howdy, Mitch! Just saw the update here. Thanks for the idea! Sadly, I need to revisit cuz I tripped on this too late in the evening. Was just saying earlier today that I need 48 hour days.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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