简体   繁体   中英

Pinescript alert for strategy.exit

I am having a problem in tradingview, pinescript.

I am stuck at a point, I have converted my strategy into study for alerts. Buy and Sell alerts are converted into alerts but the main problem is, I cannot convert strategy.exit code in study with alert condition. Is there a way I can convert this also in alert?

Below is my code:

//@version=4
strategy("My Strategy", overlay=true)

strategy.entry("Buy", strategy.long, when=crossover(sma(close, 14), sma(close, 28)), comment="Buy")
strategy.exit("Buy", trail_points=100, loss=100, comment="Exit")

strategy.entry("Sell", strategy.short, when=crossover(sma(close, 14), sma(close, 28)), comment="Sell")
strategy.exit("Sell", trail_points=100, loss=100, comment="Exit")

loss = When price comes 100 ticks away from the trigger buy/sell in loss, then exit condition comes. So loss is fixed at 100.

trail_points = When price comes, 100 ticks positive from the buy/sell order, then at the closing of candle, the exit condition comes. Profit is variable at candle close, but trigger at 100.

Can these two exit strategies be given in alert condition? I am not able to convert this whole strategy in alert.

you'll have to keep track of your position and stop losses in variables. (isLong, isShort, stopPrice, etc etc) then update then based on your entry and exit conditions. for the trailing stop you'll have to update it every candle and check if its hit on every candle. When you have everything tracked as variables properly, then you can call alertcondition as desired.

maybe this article can help: https://marketscripters.com/pine-script-strategy-vs-study/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM