I am creating a strategy that uses two Variable moving averages the 10, and the 50 vma I need some help finishing the code...
Code:
#
# TD Ameritrade IP Company, Inc. (c) 2008-2021
#
input price = close;
input fastlegnth = 10;
input slowlength = 50;
def tmp1 = if price > price[1] then price - price[1] else 0;
def tmp2 = if price[1] > price then price[1] - price else 0;
def d2 = Sum(tmp1, length);
def d4 = Sum(tmp2, length);
def cond = d2 + d4 == 0;
def ad3 = if cond then 0 else (d2 - d4) / (d2 + d4) * 100;
def coeff = 2 / (length + 1) * AbsValue(ad3) / 100;
def asd = CompoundValue("visible data" = coeff * price + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = price
);
plot VMA = asd;
VMA.SetDefaultColor(GetColor(0));
def buy = fastlegnth > slowlegnth ;
def sell = slowlegnth < fastlegnth;
AddOrder(OrderType.BUY_AUTO, fastlegnth crosses above Slowlegnth, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "long");
AddOrder(OrderType.SELL_AUTO, fastlegnth crosses below fastlegnth, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "take profit");
Last edited: