I am writing code in pine script and am quite new to pine script. I am using pinescript v5. Following is the code
if high > high[1]
strategy.risk.allow_entry_in(strategy.direction.long)
else if low < low[1]
strategy.risk.allow_entry_in(strategy.direction.short)
Pine script gave me following error / warning.
line 103: Cannot use 'strategy.risk.allow_entry_in' in local scope.;
line 109: Cannot use 'strategy.risk.allow_entry_in' in local scope.;
line 113: Cannot use 'strategy.risk.allow_entry_in' in local scope.
Is there any other way out to disable the trend in specific direction. If it cannot be done then I think this function is quite useless.
Delete IFs and try (not sure if it works):
high_condition = high > high[1]
low_condition = low < low[1]
strategy.risk.allow_entry_in(high_condition ? strategy.direction.long : low_condition ? strategy.direction.short : na)
Also, I'm not sure that "na" value is valid as strategy.risk.allow_entry_in
parameter, and it is possible that both your conditions are true at the same time, so delete IFs and also try this:
high_condition = high > high[1]
low_condition = low < low[1]
both_condition = high_condition and low_condition
strategy.risk.allow_entry_in(both_condition ? strategy.direction.all : high_condition ? strategy.direction.long : low_condition ? strategy.direction.short : na)
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.