dandy
Pine Script Rookie
Pine Script Rookie
Posts: 2
Joined: September 29th, 2020

How to add limit buy/sell in strategy

Hi there!

Happy to be a new member of the forum. I've followed the course and I am quite new to this.

I understand how an entry signal works when the signal to enter is buying/selling when one indicator crosses the other for example..

But what if I want to trail a limit order that is triggered when the price is hit? For example how would I trail a limit sell that is x ticks above a 50sma? The entry is not based on what an indicator does, rather it is triggered when price hits a parameter in relation to the price of the indicator.

Thanks in advance!

Brad

User avatar
Matthew
Site Admin
Site Admin
Posts: 92
Joined: July 1st, 2020
Location: Australia
Contact: Website Facebook Twitter TradingView Profile

Re: How to add limit buy/sell in strategy

Hi Dandy!

This is not something I have time to try to help you write, but what you need to do is get your SMA price and add X ticks to that price and then input that value into your strategy.exit()'s "stop" parameter.

Here's what the documentation says:
stop (float) An optional parameter. Stop loss (requires a specific price). If it is specified, a stop order is placed to exit market position at the specified price (or worse). Priority of the parameter 'stop' is higher than priority of the parameter 'loss' ('stop' is used instead of 'loss', if its value is not 'NaN'). The default value is 'NaN'.

Return to “Request Scripts”