# hull_ashi_revs_strat_00
#https://usethinkscript.com/threads/create-this-custom-strategy.15686/
#Indicator Forums Questions
#Create This Custom Strategy
#eviholdings Jun 17, 2023
#I'm looking for a TOS script to do the following. Who can write this for me?
#1. Take available funds from an TOS account
#2. If TSLA has a HULL moving average with settings of price of close, length of 26 (moves positive).
#and Hieken Ashi turns positive. Then buy however many shares of TSLA you can buy with cash available.
#3. If TSLA has a HULL moving average with settings of price of close, length of 26 (moves NEGATIVE).
#and Hieken Ashi turns NEGATIVE. Then SELL however many shares of TSLA we hold and go to cash.
#4. Repeat the process.
def na = Double.NaN;
def bn = BarNumber();
#---------------------
# hull avg
def price = close;
input ma1_len = 26;
input ma1_type = AverageType.HULL;
def ma1 = MovingAverage(ma1_type, price, ma1_len);
input show_lines = yes;
plot z1 = if show_lines then ma1 else na;
z1.SetDefaultColor(GetColor(1));
#z1.setlineweight(1);
z1.HideBubble();
#-----------------
# ashi
#stockcharts - ashi
#https://school.stockcharts.com/doku.php?id=chart_analysis:heikin_ashi
# 1. The Heikin-Ashi Close is simply an average of the open,
# high, low and close for the current period.
def HA_Close = (open + high + low + close) / 4;
#2. The Heikin-Ashi Open is the average of the prior Heikin-Ashi
#candlestick open plus the close of the prior Heikin-Ashi candlestick.
def HA_Open = (HA_Open[1] + HA_Close[1]) / 2;
#3. The Heikin-Ashi High is the maximum of three data points:
#the current period's high, the current Heikin-Ashi
#candlestick open or the current Heikin-Ashi candlestick close.
#HA_High = Maximum of the High(0), HA-Open(0) or HA-Close(0)
def HA_High = Max(high, Max(HA_Open, HA_Close));
#4. The Heikin-Ashi low is the minimum of three data points:
#the current period's low, the current Heikin-Ashi
#candlestick open or the current Heikin-Ashi candlestick close.
#HA-Low = Minimum of the Low(0), HA-Open(0) or HA-Close(0)
def HA_Low = Min(low, Min(HA_Open, HA_Close));
#----------------------
def long_buy = (ma1 > ma1[1]) and (HA_Close[1] < HA_Open[1]) and (HA_Close > HA_Open);
def long_sell = (ma1 < ma1[1]) and (HA_Close[1] > HA_Open[1]) and (HA_Close < HA_Open);
def size = 1;
AddOrder(OrderType.BUY_TO_OPEN, long_buy , open[-1], size, color.green, color.green, name = "Open" );
AddOrder(OrderType.SELL_TO_CLOSE, long_sell, open[-1], size, color.red, color.red, name = "close" );
#