Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
937 views
in Technique[技术] by (71.8m points)

pine script - strategy.exit sells the wrong entry even with my specific entry id

I am buying up to 2 orders at the same time. Both of them have their own Entry ID. For each Entry I save the stock price so that I can put my own logic when to sell. For some reason those sells with specific sells are not working. Here some trade results:

enter image description here

and also my code:

var price_buy_1 = 0.0
var price_buy_2 = 0.0

enter_signal = crossover(macdLine, signalLine)

if (enter_signal and price_buy_1 == 0.0)
    strategy.entry("buy", strategy.long, qty=1, comment="buy1")
    price_buy_1 := close

else if (enter_signal  and price_buy_1 != 0.0 and price_buy_2 == 0.0)
    strategy.entry("buy2", strategy.long, qty=1, comment="buy2")
    price_buy_2 := close

rsi_sell_trigger =  rsi_normal > 70 and close > price_buy_1 * (1 + ((profit - 2)/100)) and histLine[1] > histLine and price_buy_1 != 0.0
profit_sell_trigger = close > price_buy_1 * (1 + ((profit)/100)) and (histLine[1] > histLine or rsi_normal[1] > rsi_normal) and price_buy_1 != 0.0 

if (rsi_sell_trigger or profit_sell_trigger)
    price_buy_1 := 0.0
    strategy.close("buy",  comment = "Profit Sell", when = profit_sell_trigger)
    strategy.close("buy",  comment = "Max RSI Sell", when = rsi_sell_trigger)

rsi_sell_trigger2 =  rsi_normal > 70 and close > price_buy_2 * (1 + ((profit - 2)/100)) and histLine[1] > histLine and price_buy_2 != 0.0
profit_sell_trigger2 = close > price_buy_2 * (1 + ((profit)/100)) and (histLine[1] > histLine or rsi_normal[1] > rsi_normal) and price_buy_2 != 0.0 

if (rsi_sell_trigger2 or profit_sell_trigger2)
    price_buy_2 := 0.0
    strategy.close("buy2",  comment = "Profit Sell 2", when = profit_sell_trigger2)
    strategy.close("buy2",  comment = "Max RSI Sell 2", when = rsi_sell_trigger2)
question from:https://stackoverflow.com/questions/65853985/strategy-exit-sells-the-wrong-entry-even-with-my-specific-entry-id

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...