This is simple Highest high and Lowest low strategy.
Buy when break HH+offset
Sell when break LL+offset
Offset = (HH-LL)/2
CODE:
CSS:
#// Copyright by HPotter v2.0 19/09/2022
#// This is simple Highest high and Lowest low strategy.
#// Buy when break HH+offset
#// Sell when break LL+offset
# https://www.tradingview.com/script/CRNp5xev-HHLL-Strategy/
#strategy(title='HHLL', overlay=true)
# Converted and mod by Sam4Cok@Samer800 - 10/2022
input ShowBubble = yes;
input BarColor = no;
input Wicks = no;
input Length = 29;
input maTypeInput = {default "SMA", "EMA", "SMMA", "WMA", "VWMA", "VIDYA"};
input reverse = yes; # 'Trade reverse'
def h = high; def l = low; def c = close;
#vwma(source, length)
script VWMA {
input x = close;
input y = 15;
def VWMA = SimpleMovingAvg(x * volume, y) / SimpleMovingAvg(volume, y);
plot result = VWMA;
}
#VIDYA(source, length)
script VIDYA {
input src = close;
input pds = 29;
def alpha = 2/(pds+1);
def momm = src-src[1];
def m1 = if momm >=0 then momm else 0;
def m2 = if momm >=0 then 0 else -momm;
def k = stdev(src,pds);
def VIDYA;
VIDYA = (alpha*k*src)+(1-alpha*k)* VIDYA[1];
plot return = VIDYA;
}
#ma(src, maLengthInput, maTypeInput) =>
script ma {
input src = close;
input len = 29;
input maTypeInput = "WMA";
def ma = if maTypeInput == "SMA" then SimpleMovingAvg(src, len) else
if maTypeInput == "EMA" then ExpAverage(src, len) else
if maTypeInput == "SMMA" then if isNaN(ma[1]) then Average(src, len) else
(ma[1] * (len-1) + src) / len else
if maTypeInput == "VIDYA" then VIDYA(src, len) else
if maTypeInput == "WMA" then WMA(src, len) else
if maTypeInput == "VWMA" then vwma(src, len) else Double.NaN;
plot return = ma;
}
def xHH = ma(h, Length,maTypeInput);
def xLL = ma(l, Length,maTypeInput);
def movevalue = (xHH - xLL) / 2;
def xHHM = xHH + movevalue;
def xLLM = xLL - movevalue;
def pos; def long;
def possig; def short;
def iff_1 = if (if(Wicks,h,c)) > xHHM[1] then -1 else pos[1];
pos = if (if(wicks,l,c)) < xLLM[1] then 1 else iff_1;
def iff_2 = if reverse and pos == -1 then 1 else pos;
possig = if reverse and pos == 1 then -1 else iff_2;
long = possig == 1 and possig[1] != possig;
short = possig ==-1 and possig[1] != possig;
plot maHigh = xHHM;
maHigh.SetDefaultColor(Color.BLUE);
plot maLow = xLLM;
maLow.SetDefaultColor(Color.BLUE);
plot maHH = xHH;
maHH.SetDefaultColor(Color.DARK_ORANGE);
plot maLL = xLL;
maLL.SetDefaultColor(Color.DARK_ORANGE);
AddChartBubble(ShowBubble and long,l,"L", color.GREEN, no);
AddChartBubble(ShowBubble and short,h,"S", color.RED, yes);
AssignPriceColor(if BarColor then
if possig == -1 then color.RED else
if possig == 1 then color.GREEN else color.GRAY else Color.CURRENT);
#--- End Code