Compilation error. Line 23: mismatched character 'i' expecting '='
Line 23 is
if (close > MA_200 and close < MA_10 and !is_long and !is_short)
from the // Check if long buy condition is met block.
Any help in understanding what I'm getting wrong would be awesome. It's fun learning pine but it has got strange errors.
Code: Select all
// @version=5
// Define strategy input parameters
input MA_length_10 = 10
input MA_length_200 = 200
input stop_loss_percent = 10
// Define strategy variables
var float balance = 100000
var float fee_rate = 0.0026 // Kraken fee rate
var float stop_loss_price
var bool is_long = false
var bool is_short = false
// Define strategy plots
plot long_plot
plot short_plot
// Calculate moving averages
var float MA_10 = sma(close, MA_length_10)
var float MA_200 = sma(close, MA_length_200)
// Check if long buy condition is met
if (close > MA_200 and close < MA_10 and !is_long and !is_short)
{
// Set long stop loss price
stop_loss_price = (1 - stop_loss_percent/100) * close
// Open long position
is_long = true
balance -= balance * fee_rate
long_plot = 1
}
// Check if long sell condition is met
if ((close > MA_10 or close < stop_loss_price) and is_long)
{
// Close long position
is_long = false
balance += balance * fee_rate
long_plot = 0
}
// Check if long position should be held
if (is_long and close < MA_200 and close > MA_10)
{
// Check for red candle that closes below preceding green candle
if (close < open and close[1] > open[1])
{
// Close long position
is_long = false
balance += balance * fee_rate
long_plot = 0
}
}
// Check if short sell condition is met
if (close < MA_200 and close > MA_10 and !is_long and !is_short)
{
// Set short stop loss price
stop_loss_price = (1 + stop_loss_percent/100) * close
// Open short position
is_short = true
balance -= balance * fee_rate
short_plot = 1
}
// Check if short buy condition is met
if ((close < MA_10 or close > stop_loss_price) and is_short)
{
// Close short position
is_short = false
balance += balance * fee_rate
short_plot = 0
}
// Check if short position should be held
if (is_short and close > MA_200 and close < MA_10)
{
// Check for green candle that closes above preceding red candle
if (close > open and close[1] < open[1])
{
// Close short position
is_short = false
balance += balance * fee_rate
short_plot = 0
}
}
// Calculate final balance
strategy.entry("Profit").profit = balance - 100000