简体   繁体   中英

Error If Else Mismatched input 'if' expecting 'end of line without line continuation'

I've this simply script. This is the first time i code a trading system and I'm not able to get rid of this siply script:

if ((CrossToPlotN > 40) and (CrossToPlotD < -40))
    strategy.entry("Buy", strategy.long)
else if ((CrossToPlotN < -40) and (CrossToPlotD > 40))
    strategy.entry("Sell", strategy.short)
else if (crossunder(CrossToPlotN, CrossToPlotD))
    strategy.close("CloseBuy", strategy.long)
else (crossunder(CrossToPlotD, CrossToPlotD))
    strategy.close("CloseShort", strategy.short)

the error message is: Mismatched input 'if' expecting 'end of line without line continuation'.

strategy.close() does not have a parameter like direction .

This is its signature:

strategy.close(id, when, comment, qty, qty_percent, alert_message) → void

else if (crossunder(CrossToPlotN, CrossToPlotD))
    strategy.close("CloseBuy")
else (crossunder(CrossToPlotD, CrossToPlotD))
    strategy.close("CloseShort")

Secondly, your last statement is an else . You shouldn't pass any conditions to that expression.

var_declarationX = if condition  
      var_decl_then0  
      var_decl_then1  
      …  
      var_decl_thenN  
else if [optional block]  
      var_decl_else0  
      var_decl_else1  
      …  
      var_decl_elseN  
else  
      var_decl_else0  
      var_decl_else1  
      …  
      var_decl_elseN  
      return_expression_else

You either want:

else if (crossunder(CrossToPlotD, CrossToPlotD))
    strategy.close("CloseShort", strategy.short)

Or

else
    strategy.close("CloseShort", strategy.short)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM