I've been trying to solve the errors in strategy.close, and the quantity Long order for nearly a week but failed to figure it out. It works well if only enables a single direction but if enables both directions at the same time, the strategy.close for Short is not showing and not firing. Besides, the Long Order quantity is double than the Short Order quantity.
Any help is appreciated. Thank you.
bool longCond = enableLong ? kagi_L : na and strategy.opentrades == 0
bool shortCond = enableShort ? kagi_S : na and strategy.opentrades == 0
bool longClose = enableLong ? kagi_S : na and strategy.position_size > 0
bool shortClose = enableShort ? kagi_L : na and strategy.position_size < 0
if (longCond)
strategy.entry('Long', strategy.long, alert_message = i_alert_msg_long)
if (longClose)
strategy.close(id='L', comment='Close Long', alert_message = i_alert_msg_closelong)
if (shortCond)
strategy.entry('Short', strategy.short, alert_message = i_alert_msg_short)
if (shortClose)
strategy.close(id='S', comment='Close Short', alert_message = i_alert_msg_closeshort)