#study(title = "Smoothed Heiken Ashi Candles", shorttitle="Smoothed Ha Candles", overlay=true)
#translated and modified by BLT 20170804
#v1 - added HACO (HACOLT by S Vervoot) and HACO_Mod (by D Valcu) smoothing options
#version whatever - added orders for strategy testing by Barbaros
input onlyTradeTime = yes;
input startTime = 930;
input stopTime = 1500;
def tradeTime = if onlyTradeTime then SecondsFromTime(startTime) >= 0 and SecondsTillTime(stopTime) >= 0 else yes;
input candleSmoothing = {default HACO, HACO_Mod};
input avg = averageType.EXPONENTIAL;
input len = 8;#=input(10)
def o = movingAverage(avg,open, len);
def c = movingAverage(avg,close, len);
def h = movingAverage(avg,high, len);
def l = movingAverage(avg,low, len);
def HAopen;
def HAclose;
switch(candleSmoothing) {
case HACO:
haOpen = CompoundValue(1, ( (haOpen[1] + (o[1] + h[1] + l[1] + c[1]) /4)/2), open);
haClose = ((((O + H + L + C)/4) + haOpen + Max(H, haOpen) + Min(L, haOpen))/4);
case HACO_Mod:
haOpen = CompoundValue(1, ( (haOpen[1] + (o[1] + h[1] + l[1] + c[1]) /4)/2), open);
haClose = ((o + h + l + c)/4) ;
}
def HAhigh = Max( h, Max( HAopen, HAclose ) );
def HAlow = Min( l, Min( HAopen, HAclose ) );
input len2 = 17;#input(10)
def o2 = movingAverage(avg,HAopen, len2);
def c2 = movingAverage(avg,HAclose, len2);
def h2 = movingAverage(avg,HAhigh, len2);
def l2 = movingAverage(avg,HAlow, len2);
input charttype=chartType.CANDLE;
def o3 = o2;
def h3 = h2;
def l3 = l2;
def c3 = c2;
input nowicks = yes;
def o4 = if o3<c3 then if nowicks then l3 else o3 else double.nan;
def c4 = if o3<c3 then if nowicks then h3 else c3 else double.nan;
def h4 = if o3<c3 then h3 else double.nan;
def l4 = if o3<c3 then l3 else double.nan;
def o5 = if o3 >=c3 then if nowicks then h3 else o3 else double.nan;
def h5 = h3;
def l5 = l3;
def c5 = if o3 >=c3 then if nowicks then l3 else c3 else double.nan;
AddOrder(type = OrderType.BUY_AUTO, tradeSize = 1, condition = !isNaN(c4) and tradeTime);
AddOrder(type = OrderType.SELL_AUTO, tradeSize = 1, condition = !isNaN(c5) and tradeTime);
AddOrder(type = OrderType.SELL_TO_CLOSE, tradeSize = 1, condition = !tradeTime);
AddOrder(type = OrderType.BUY_TO_CLOSE, tradeSize = 1, condition = !tradeTime);