Error: Expected Double using AddOrder()


Category:
0
0

Hi, I am trying to make a very a basic strategy but I am getting a Expected Double Error on my AddOrder(). I am new to this so my apologies if I made a novice mistake.

<pre></pre>
# dependent upon contract traded
def tick_size = .25;
# plot 13EMA
plot short_ema = ExpAverage(close, 13);
short_ema.SetDefaultColor(Color.CYAN);

# plot 200EMA
plot long_ema = ExpAverage(close, 200);
long_ema.SetDefaultColor(Color.BLUE);

# Show signal where macd crosses
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

def Value = MovingAverage(averageType, close, fastLength) – MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);

def Diff = Value – Avg;
def ZeroLine = 0;

def UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
def DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;

# value = fast ; avg = slow
def MACD_bull_cross = if
Value[1] < Avg[1] and # previous fast < previous slow
Value > Avg# and # current fast > current slow
# value > ZeroLine and
# avg > ZeroLine # and both lines are above ZeroLine
then 1 else Double.NaN;

plot macd_up_arrow = MACD_bull_cross;
macd_up_arrow.SetPaintingStrategy(paintingStrategy = PaintingStrategy.BOOLEAN_ARROW_UP);

def MACD_bear_cross = if
Value[1] > Avg[1] and # previous fast < previous slow
Value < Avg # and # current fast > current slow
# value < ZeroLine and
# avg < ZeroLine # and both lines are above ZeroLine
then 1 else Double.NaN;
plot macd_down_arrow = MACD_bear_cross;
macd_down_arrow.SetPaintingStrategy(paintingStrategy = PaintingStrategy.BOOLEAN_ARROW_DOWN);

# adds label in left corner either ‘uptrend’ or ‘downtrend’ depending on emas
AddLabel(yes, if short_ema > long_ema then “Uptrend” else “Downtrend”);

# plot a dot where close price is within 1 tick of 200EMA
# Signal of possible momentum shift or bounce play
plot long_ema_bounce_buy = (close – long_ema) <= 1.25 && (close – long_ema) >= -1.25;

long_ema_bounce_buy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
long_ema_bounce_buy.SetDefaultColor(Color.WHITE);

# LONG ONLY ABOVE 200EMA w/ confirming 13EMA
def buy_to_open_condition = close > long_ema and close[1] > short_ema and close > short_ema;
AddOrder(OrderType.BUY_TO_OPEN, buy_to_open_condition, 1, Color.BLUE);
def sell_to_close_condition = close < close[2];
AddOrder(OrderType.SELL_TO_CLOSE, sell_to_close_condition, 1, Color.ORANGE);

<pre></pre>

Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on June 25, 2019 8:27 pm
294 views
0
Private answer

Please make sure you search the forum before posting a new question. This one has already been asked. The answer I provided was intended to cover every square millimeter of the AddOrder() statement. So your particular issue is addressed as well as many others. Check it out here: https://www.hahn-tech.com/ans/noob-tick-naming-issue/

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on June 26, 2019 12:15 pm