Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use stop-limit in Strategy

Tags:

pine-script

I'm trying to place a stop-limit order in my strategy-script but failed to do so.

strategy.entry(id = "Long", long = true, limit=high[1]+10)

I want a market buy order to be placed when the price is above 10 points previous candle. previous candle high - 200 order to be placed if price crosses 210

like image 970
karan barsiwal Avatar asked Oct 16 '25 04:10

karan barsiwal


2 Answers

i just figured it out

strategy.entry(id = "Long", long = true, stop=high[1]+10)

you have to use stop instead of limit for placing a stop-limit order

like image 164
karan barsiwal Avatar answered Oct 19 '25 12:10

karan barsiwal


At PineScript V5, Strategy.entry has some quirks. Setting limit, stop, or both parameters will give you different results.

At least for V5, your answer in fact didn't give you a stop-limit. You get a market order with a simple stop loss at market. If you really want a stop-limit, probably you want to set stop and limit parameters.

Below, some explained examples for each case.


No limit or stop parameters

A simple market order.

strategy.entry(id = "Long", long = true)

limit without stop parameter

A simple Limit order. Placed to be executed when a advantageous price is reached.

strategy.entry(id = "Long", long = true, limit=high[1]+10)

stop without limit parameter

A Stop order. Which is kind of a limit order, but placed in a disadvantageous price.

strategy.entry(id = "Long", long = true, stop=high[1]+10)

Both stop and limit parameters

A market order with stop-limit stop loss.

strategy.entry(id = "Long", long = true, limit=high[1]+10, stop=high[1]+20)

This last one will result in a market order with a trigger for a Stop-Limit order. In other words, it placed and when stop price is reached, a limit order at limit price will be placed. It's possible the order could not be fulfilled.

like image 20
luizv Avatar answered Oct 19 '25 13:10

luizv