Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k 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 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...