RicardoSantos

strategy.direction.all() bug - work around

bug
137
bug
the way to work around the bug for this specific strategy, altho its not as efficient as it would if both orders activation was possible.
สคริปต์โอเพนซอร์ซ

ด้วยจิตวิญญาณของ TradingView อย่างแท้จริง ผู้เขียนสคริปต์นี้ได้เผยแพร่เป็นโอเพนซอร์ส เพื่อให้ผู้ค้าสามารถเข้าใจและตรวจสอบได้ ไชโยให้กับผู้เขียน! คุณสามารถใช้ได้ฟรี แต่การใช้รหัสนี้ซ้ำในสิ่งพิมพ์อยู่ภายใต้กฎระเบียบการใช้งาน คุณสามารถตั้งเป็นรายการโปรดเพื่อใช้บนชาร์ตได้

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมที่ เงื่อนไขการใช้บริการ

ต้องการที่จะใช้สคริปต์นี้บนชาร์ตใช่ไหม?
//@version=2
strategy(title='test', shorttitle='T', overlay=true, initial_capital=100000, currency=currency.USD)
strategy.risk.max_intraday_filled_orders(2)
strategy.risk.allow_entry_in(strategy.direction.all)
trade_size = input(10000.0)
take_profit_in_ticks = input(500)
stop_loss_in_ticks = input(50)
//  ||-----------------------------------------------------------------------------------------------------------------------------------------------------------||
trade_session = input(title='Trade Session:', type=string, defval='0400-1500', confirm=false)
istradingsession = not na(time('1', trade_session))
bgcolor(istradingsession?gray:na)
//  ||-----------------------------------------------------------------------------------------------------------------------------------------------------------||
open_price = change(istradingsession) > 0 ? open : open_price[1]
buy_entry_line = open_price + stop_loss_in_ticks * syminfo.mintick
sel_entry_line = open_price - stop_loss_in_ticks * syminfo.mintick
plot(open_price, color=black)
plot(buy_entry_line, color=lime)
plot(sel_entry_line, color=red)
strategy.entry('buy', long=true, qty=trade_size, when=istradingsession > 0 and close > buy_entry_line)
strategy.entry('sel', long=false, qty=trade_size, when=istradingsession > 0 and close < sel_entry_line)
strategy.exit('exit buy', from_entry='buy', profit=take_profit_in_ticks, loss=stop_loss_in_ticks)
strategy.exit('exit sel', from_entry='sel', profit=take_profit_in_ticks, loss=stop_loss_in_ticks)
strategy.close_all(when=change(istradingsession) < 0)