# ma9_buysell_strat_00
def na = double.nan;
def bn = barnumber();
def price = close;
input MA1_len = 9;
input MA1_type = AverageType.simple;
#input MA1_type = AverageType.EXPONENTIAL;
def ma1 = MovingAverage(ma1_type, price, ma1_len);
input MA2_len = 21;
input MA2_type = AverageType.simple;
#input MA2_type = AverageType.EXPONENTIAL;
def ma2 = MovingAverage(ma2_type, price, ma2_len);
#input MA3_len = 41;
#input MA3_type = AverageType.EXPONENTIAL;
#def ma3 = MovingAverage(ma3_type, price, ma3_len);
# -----------------------------------------------------
#def buy = close < Average(close - 0.25, 9);
#def sell = close > Average(close + 0.20, 9) and close > Average(close, 21);
input buy_off1 = 0.25;
input sell_off1 = 0.20;
def buy_sig = ma1 - buy_off1;
def sell_sig_a = ma1 + sell_off1;
def sell_sig_b = ma2;
#def buy = close < buy_sig;
#def sell = close > sell_sig_a and close > sell_sig_b;
# buy, is
def buy = close < buy_sig;
def sell = close > sell_sig_a and close > sell_sig_b;
input show_lines = yes;
plot zb1 = buy_sig;
zb1.SetDefaultColor(Color.green);
#z1.setlineweight(1);
zb1.hidebubble();
zb1.SetHiding(!show_lines);
#plot zs1 = sell_sig_a;
#zs1.SetDefaultColor(Color.magenta);
##zs1.setlineweight(1);
#zs1.hidebubble();
#zs1.SetHiding(!show_lines);
plot zs2 = sell_sig_b;
zs2.SetDefaultColor(Color.magenta);
#zs2.setlineweight(1);
zs2.hidebubble();
zs2.SetHiding(!show_lines);
#==========================================
#def buy2 = close < (ma1-buyoff1);
#def sell2 = close > (ma1+selloff1);
def buysignal = buy;
def sellsignal = sell;
#AddOrder(OrderType.BUY_TO_OPEN, buysignal, name = "Buy", tickcolor = Color.DARK_RED, arrowcolor = Color.RED);
#AddOrder(OrderType.SELL_TO_CLOSE, sellsignal, name = "Sell", tickcolor = Color.GREEN, arrowcolor = Color.GREEN);
#AddOrder(OrderType.BUY_TO_OPEN, buysignal, name = "Buy", tickcolor = Color.green, arrowcolor = Color.green);
#AddOrder(OrderType.SELL_TO_CLOSE, sellsignal, name = "Sell", tickcolor = Color.red, arrowcolor = Color.red);
# rev buy/sell actions
AddOrder(OrderType.BUY_TO_OPEN, sellsignal, name = "buy", tickcolor = Color.GREEN, arrowcolor = Color.GREEN);
AddOrder(OrderType.sell_to_close, buysignal, name = "sell", tickcolor = Color.DARK_RED, arrowcolor = Color.RED);
#