A Re-Painting Heiken MTF Strategy

  • Thread starter YungTraderFromMontana
  • Start date
YungTraderFromMontana

YungTraderFromMontana

Active member
Warning: this indicator/strategy will repaint. Do not use unless you know what you’re doing.

Here is what appears to be a fantastic strategy using a Heiken ashi mtf study.
Right now it seems very solid using an aggregation period of 5 min on the 1 min chart, I'd love to see more good combonations.

Photos





Heiken strategy alone

Code:
input compBarsTTM = 6;
input paintBarsTTM = Yes;

plot TrendUp = Double.NaN;
plot TrendDown = Double.NaN;
# Inputs:

input AA = .1;

# Vars:
def CC;
def zeroLine = 0;
def RE1;
def RE2;
def RE3;
def RE4;
def RE5;
def RE6;
def RE7;
def RE8;
def EMA;

CC = if CC[1] == 0 then .9 else 1 – AA;
EMA = AA * close + CC * EMA[1];
RE1 = CC * EMA + EMA[1];
RE2 = Power(CC, 2) * RE1 + RE1[1];
RE3 = Power(CC, 4) * RE2 + RE2[1];
RE4 = Power(CC, 8) * RE3 + RE3[1];
RE5 = Power(CC, 16) * RE4 + RE4[1];
RE6 = Power(CC, 32) * RE5 + RE5[1];
RE7 = Power(CC, 64) * RE6 + RE6[1];
RE8 = Power(CC, 128) * RE7 + RE7[1];

def EMA_Signal = EMA – AA * RE8;

plot FREMA_LED = if !IsNaN(close) then 1 else Double.NaN;
FREMA_LED.SetPaintingStrategy(PaintingStrategy.POINTS);
FREMA_LED.DefineColor("OverZero", Color.GREEN);
FREMA_LED.DefineColor("Normal", GetColor(7));
FREMA_LED.DefineColor("UnderZero", Color.RED);
FREMA_LED.AssignValueColor(if EMA_Signal > zeroLine then FREMA_LED.Color("OverZero") else if EMA_Signal < zeroLine then FREMA_LED.Color("UnderZero") else FREMA_LED.Color("Normal"));
FREMA_LED.SetLineWeight(5);
FREMA_LED.HideBubble();
FREMA_LED.HideTitle();

declare hide_on_daily;
input Mult = 1.0;
input nATR = 4;
input AvgType = AverageType.HULL;
input paintbars = yes;
def x = close;
def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);
def UP = HL2 + (Mult * ATR);
def DN = HL2 + (-Mult * ATR);
def AG = if x < AG[1] then UP else DN;
input compBars = 6;
plot algotrend = AG;
declare hide_on_daily;
algotrend.AssignValueColor(if x < AG then Color.RED else Color.GREEN);
AssignPriceColor(if paintbars and x < AG

                 then Color.RED

                 else if paintbars and x > AG

                      then Color.GREEN

                      else Color.CURRENT);
#backtesting
def STUP = (x > AG);
def STDN = (x < AG);
plot STUPl = if AG crosses below close then 1 else 0;
plot STDNl = if AG crosses above close then 1 else 0;
def FRUP =(EMA_Signal > zeroLine);
def FRDN =(EMA_Signal < zeroLine);
plot Combo_LED = if !IsNaN(close) then 1 else Double.NaN;
Combo_LED.SetPaintingStrategy(PaintingStrategy.POINTS);
Combo_LED.DefineColor("OverZero", Color.GREEN);
Combo_LED.DefineColor("Normal", GetColor(7)); Combo_LED.DefineColor("UnderZero", Color.RED);
Combo_LED.AssignValueColor(if(STUP is true and FRUP is true and Trendup is true) then Combo_LED.Color("OverZero") else if (STDN is true and FRDN is true and Trenddown is true) then Combo_LED.Color("UnderZero") else Combo_LED.Color("Normal"));
Combo_LED.SetLineWeight(5);
Combo_LED.HideBubble();
Combo_LED.HideTitle();
def v1 = (STUP is true and FRUP is true and Trendup is true) ;
def v3 = (STDN is true and FRDN is true and Trenddown is true);
def va2 = ((STUP is true or FrUP is true) and Trendup is true);
def vb2 = ((STUP is true or Trendup is true) and FRUP is true);
def vc2 = (va2 or vb2 is true);
def va4 = ((STDN is true or FrDN is true) and Trenddown is true);
def vb4 = ((STDN is true or Trenddown is true) and FrDn is true);
def vc4 = (va4 or vb4 is true);
# Bullish Orders
AddOrder(OrderType.BUY_TO_OPEN, condition = v1, price = close, 3000, tickcolor = Color.GREEN, arrowcolor = Color.GREEN);
AddOrder(OrderType.SELL_TO_CLOSE, condition = v3, price = open, 3000, tickcolor = Color.RED, arrowcolor = Color.RED);

# Bearish Orders
AddOrder(OrderType.SELL_TO_OPEN, condition = v3, price = open, 3000, tickcolor = Color.RED, arrowcolor = Color.RED);
AddOrder(OrderType.BUY_TO_CLOSE, condition = v1, price = close, 3000, tickcolor = Color.GREEN, arrowcolor = Color.GREEN);
Shareable Link: https://tos.mx/vPnuFek

Heiken strategy with all of Diazlaz's combo paintbar options
Code:
#Strategy using @Diazlaz combo paintbars study.
declare upper;

#INPUTS
input showLabels = yes;
input PaintBars = yes;
input aggregationPeriod = AggregationPeriod.FIVE_MIN;
input threshold = 1;
input enableHA = yes;
input enableHAMTF = yes;
input displace = 0;

#CORE
DefineGlobalColor("CycleLineColor", Color.RED);
DefineGlobalColor("CyclehistColor", Color.BLUE);
DefineGlobalColor("ZeroLineColor", Color.YELLOW);
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("Neutral", Color.MAGENTA); #Color.YELLOW
DefineGlobalColor("Off", Color.DARK_GRAY);
DefineGlobalColor("On", Color.GREEN);
DefineGlobalColor("Sync1", Color.YELLOW);
DefineGlobalColor("Sync2", Color.CYAN);
DefineGlobalColor("Up", Color.GREEN);
DefineGlobalColor("Down", Color.RED);
DefineGlobalColor("NUp", Color.DARK_GREEN);
DefineGlobalColor("NDown", Color.DARK_RED);
DefineGlobalColor("Neutral", Color.BLUE);
DefineGlobalColor("Neutral2", Color.PLUM);

def h = high;
def l = low;
def o = open;
def c = close;

def h1 = high(period = aggregationPeriod);
def l1 = low(period = aggregationPeriod);
def o1 = open(period = aggregationPeriod);
def c1 = close(period = aggregationPeriod);

def na = Double.NaN;


AddLabel(showLabels, "A trend, momentum and cycle Trading System v2.0", Color.CYAN);

#HeikinAshiCandles
def HA1open;
def HA1high;
def HA1low;
def HA1close;
HA1open = CompoundValue(1, (HA1open[1] + HA1close[1]) / 2, (o[1] + c[1]) / 2);
HA1high = Max(Max(h, HA1open), HA1close[1]);
HA1low = Min(Min(l, HA1open), HA1close[1]);
HA1close = (o + h + l + c) / 4;
def sHA1 = if HA1close > HA1open then 100 else -100;
def sBullish_HA1 = if(enableHA and sHA1 == 100,1,0);
def sBearish_HA1 = enableHA and sHA1 == -100;
AddLabel(showlabels and enableHA, "HA", if IsNan(sHA1) then COLOR.DARK_GRAY else
if sHA1[-displace] > 0 then COLOR.GREEN else
if sHA1[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

#HeikinAshiCandles MTF
def HA2open;
def HA2high;
def HA2low;
def HA2close;
HA2open = CompoundValue(1, (HA2open[1] + HA2close[1]) / 2, (o1[1] + c1[1]) / 2);
HA2high = Max(Max(h1, HA2open), HA2close[1]);
HA2low = Min(Min(l1, HA2open), HA2close[1]);
HA2close = (o1 + h1 + l1 + c1) / 4;
def sHA2 = if HA2close > HA2open then 100 else -100;
def sBullish_HA2 = if(enableHAMTF and sHA2 == 100,1,0);
def sBearish_HA2 = enableHAMTF and sHA2 == -100;
AddLabel(showlabels and enableHAMTF, "HAMTF", if IsNan(sHA2) then COLOR.DARK_GRAY else
if sHA2[-displace] > 0 then COLOR.GREEN else
if sHA2[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

#STATE
def sResults = sHA1 + sHA2;
def sBullish = sBullish_HA1 + sBullish_HA2;
def sBearish = sBearish_HA1 + sBearish_HA2 ;
def bullish = if(sBullish >= threshold,1,0);
def bearish = if(sBearish >= threshold,1,0);
def sState = if bullish then 100 else if bearish then -100 else 0;
def sState2 = if sState != 0 then sState else sState2[1];

#COLORBARS
AssignPriceColor(
if PaintBars then
    if bullish then COLOR.GREEN else if bearish then COLOR.RED
     else
    COLOR.GRAY
else COLOR.CURRENT);

AddLabel(showlabels,
if bullish[-displace] then "LONG" else
if bearish[-displace] then "SHORT"
else "HOLD",
if IsNan(c) then COLOR.DARK_GRAY else
if bullish[-displace] then COLOR.GREEN else
if bearish[-displace] then COLOR.RED
else COLOR.GRAY);

#STRATEGY
def SS = if bullish then 100 else if bearish then -100 else 0;

def sBuy = SS crosses above 0;
def sSell = SS crosses below 0;

AddOrder(OrderType.BUY_AUTO, condition = Sbuy
, price =  open[-1], 100, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "BE");

AddOrder(OrderType.SELL_AUTO, condition = sSell
, price = open[-1], 100, tickcolor = Color.RED, arrowcolor = Color.RED, name = "SE");
#END OF trend, a momentum and a cycle based indicator for ThinkorSwim V2.0
Shareable Link: https://tos.mx/o8vMiDI

In the thread "Request combining 3 indicators into 1", @HighBredCloud suggested adding this into @diazlaz's combo paintbars indicator. Messing around with that indicator I found it to be very powerful on its own.

I'm posting this hoping to get community feedback on how to best utilize this strategy and to look for improvements, I'll be testing this myself. Thanks all.
 
Last edited by a moderator:
J007RMC

J007RMC

Active member
2019 Donor
Warehouse
VIP
Bar counts 1-6,? along with a Heiken Ashi moving avg.

def length = 8;
def HAopen;
def HAhigh;
def HAlow;
def HAclose;
HAopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close) / 2);
HAhigh = Max(high, close[1]);
HAlow = Min(low, close[1]);
HAclose = (HAopen + HAclose[1] + HAlow + close) / 4;
AssignPriceColor(if HAclose > HAopen then Color.GREEN else color.RED);
plot HAMA = Average(HAclose, length);
 
YungTraderFromMontana

YungTraderFromMontana

Active member
@J007RMC yep

As I look into this, seems to work well on all timeframes if you stick to this formula.
timeframe on chart * 5 = ideal aggregation period
example
1min chart - 5 min aggregation
3min chart - 15 min aggregation
5min chart - around 30min aggregation
15min chart - around 1 hour aggregation
edit: as chart timeframe goes higher like 10 min chart and up use a 2-3 times multiplier.

There were some concerns with it being an mtf, just watched futures for an hour and entries and exits are legitimate.
 
D

diazlaz

Well-known member
2019 Donor
VIP
thanks @J007RMC what is your suggestion with the MA? replacement of the price with MA and use the MA value to process signal?
 
YungTraderFromMontana

YungTraderFromMontana

Active member
thanks @J007RMC what is your suggestion with the MA? replacement of the price with MA and use the MA value to process signal?
To be honest I don't think it is possible to improve this strategy. I'm using it on /cl, I never trade futures and I especially wouldn't this far outside hours but It has only signaled 1 losing trade since 7 and I've made 400 a contract. Not to be dramatic but this quite literally seems to be the holy grail. I'm going to trade 100k at market open and I'll keep you guys updated.
 
D

diazlaz

Well-known member
2019 Donor
VIP
To be honest I don't think it is possible to improve this strategy. I'm using it on /cl, I never trade futures and I especially wouldn't this far outside hours but It has only signaled 1 losing trade since 7 and I've made 400 a contract. Not to be dramatic but this quite literally seems to be the holy grail. I'm going to trade 100k at market open and I'll keep you guys updated.
@YungTraderFromMontana, keep us update and be careful.

Sharing a full day of simulations, captured each of the state changes of the trading day here:

In the attachment can see the volatlity of the indicator and condition of the MTF, overall I think it's still viable, with a consistent trading plan in place. Make sure you have a plan when the indicator changes and rules, if you're going to stay in, when you're going to exit (e.g. confirmation candle or not, etc).


This includes one slide for each of the state changes to give you an idea of what you can expect.

Keep us updated.
 
J007RMC

J007RMC

Active member
2019 Donor
Warehouse
VIP
Indeed this study looks great
 
T

Traderday401

New member
I cant get this to work.

Im putting this in

def length = 8;
def HAopen;
def HAhigh;
def HAlow;
def HAclose;
HAopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close) / 2);
HAhigh = Max(high, close[1]);
HAlow = Min(low, close[1]);
HAclose = (HAopen + HAclose[1] + HAlow + close) / 4;
AssignPriceColor(if HAclose > HAopen then Color.GREEN else color.RED);
plot HAMA = Average(HAclose, length);


However its just not picking up, anyone know what I am doing wrong? thanks
 
mc01439

mc01439

Well-known member
2019 Donor
VIP
@YungTraderFromMontana - This does re-paint one bar back at times. Have watched it live now for a number of hours on different futures. This is due to the MTF - will happen no matter what I believe. Still trad-able just need to be aware of the potential.

Be careful with /CL - can move against you very quickly.

In reference to a trend indicator for Diazlaz's combo paintbar options. ADX seems to be very late at times, you may want to try this. Do not remember were I found it but seems to be faster than ADX.

Code:
#Indicates Trending or Chop

input AverageType2 = AverageType.HULL;

def AvgLength     = 13; #TOS default 8

def Lengthchop    = 13;

def Choppy        = 61.8;

def MidLine       = 50;

def Trending      = 38.2;


def AVG = MovingAverage(AverageType = AverageType2, c, AvgLength);

def CIB = ((Log(Sum(TrueRange(h, c, l), Lengthchop) /

             (Highest(if h >= c[1] then h else

             c[1], Lengthchop) -

             Lowest( if l <= c[1] then l else c[1], Lengthchop)))

             / Log(10)) / (Log(Lengthchop) / Log(10))) * 100;

def CI  = CIB;

AddLabel(enableCHOP, if CI > MidLine and CI < 62  then "MILD CHOP " + Round(CI, 0) else if CI >= 61.8 then "STRONG CHOP " + Round(CI, 0) else if CI <= MidLine and CI > 31.8 then " MILD TRENDING " + Round(CI, 0) else "STRONG TRENDING " + Round(CI, 0), if CI > MidLine then Color.YELLOW else Color.CYAN);
 
Last edited:
mc01439

mc01439

Well-known member
2019 Donor
VIP
Example of a re-paint this morning on CL at 9:01AM 1M chart.

Do not rely on the back-test on TOS. Many of the trades you could not of entered on the back-test entry due to re-painting. All of the losing trades you could of entered but many of the winners you would of missed.

@YungTraderFromMontana - Look back on your winners this morning. With many of the trades if the entry was not re-tested you could not of entered at the signal price from what I am seeing.

9:24AM - just observed a three bar re-paint and at 9:24:54 re-painted again on CL 1M chart.

I call these charts - thieves in the night. They look wonderful in every way until you put real money on the line - then it turns on you.

If you are going to trade this, use on the 5M mark and use some type of longer direction indicator and some type of trailing stop. By the way 10:35 just had a 3 bar re-paint on the 1M chart.

 
Last edited:
D

diazlaz

Well-known member
2019 Donor
VIP
@mc01439 thanks for the suggestion. I believe I seen this first from the original Stoplight_Indicator_v2 by BLT.



Good alternative and option to integrate to the CSA project. Arrays of yellow flagged as potential non-trending.
 
horserider

horserider

Well-known member
VIP
If anyone just wants basic version of MTF HA.
Code:
#HeikinAshiCandles MTF
#INPUTS

input aggregationPeriod = AggregationPeriod.FIVE_MIN;

def h1 = high(period = aggregationPeriod);
def l1 = low(period = aggregationPeriod);
def o1 = open(period = aggregationPeriod);
def c1 = close(period = aggregationPeriod);

 #HeikinAshiCandles MTF
def HA2open;
def HA2high;
def HA2low;
def HA2close;
HA2open = CompoundValue(1, (HA2open[1] + HA2close[1]) / 2, (o1[1] + c1[1]) / 2);
HA2high = Max(Max(h1, HA2open), HA2close[1]);
HA2low = Min(Min(l1, HA2open), HA2close[1]);
HA2close = (o1 + h1 + l1 + c1) / 4;
def sHA2 = if HA2close > HA2open then 100 else -100;
def sBullish_HA2 = if( sHA2 == 100,1,0);
def sBearish_HA2 =  sHA2 == -100;

assignPriceColor( if IsNan(sHA2) then COLOR.DARK_GRAY else
if sHA2 > 0 then COLOR.GREEN else
if sHA2 < 0 then COLOR.RED
else COLOR.yellow);
 
YungTraderFromMontana

YungTraderFromMontana

Active member
@diazlaz How did you get this data, I'd love to look at a few stocks and see what contributes to state changes. I'll test things like volume, volatility, etc. For example on /ng I am seeing very few of it and it is 3 bars before max. Most signals are one bar color changes
 
YungTraderFromMontana

YungTraderFromMontana

Active member
Example of a re-paint this morning on CL at 9:01AM 1M chart.

Do not rely on the back-test on TOS. Many of the trades you could not of entered on the back-test entry due to re-painting. All of the losing trades you could of entered but many of the winners you would of missed.

@YungTraderFromMontana - Look back on your winners this morning. With many of the trades if the entry was not re-tested you could not of entered at the signal price from what I am seeing.

9:24AM - just observed a three bar re-paint and at 9:24:54 re-painted again on CL 1M chart.

I call these charts - thieves in the night. They look wonderful in every way until you put real money on the line - then it turns on you.

If you are going to trade this, use on the 5M mark and use some type of longer direction indicator and some type of trailing stop. By the way 10:35 just had a 3 bar re-paint on the 1M chart.

I switched to /ng and am seeing a lot less of it. I still made 400 a contract trading /cl for 5 hours yesterday, I think strategy said I should've made 776 so I lost 376 to the repaint.
 
Last edited:
D

diazlaz

Well-known member
2019 Donor
VIP
How did you get this data, I'd love to look at a few stocks and see what contributes to state changes. I'll test things like volume, volatility, etc. For example on /ng I am seeing very few of it and it is 3 bars before max. Most signals are one bar color changes
Hours of grind work and dedication. Spending 40 to 60 hours a week in back testing and forward testing.

If you have a test case or improvement let me know and will keep it in mind and share back any findings.
 
YungTraderFromMontana

YungTraderFromMontana

Active member
Hours of grind work and dedication. Spending 40 to 60 hours a week in back testing and forward testing.

If you have a test case or improvement let me know and will keep it in mind and share back any findings.
So for the powerpoint you sent me you had to watch it all real time and screenshot? If so I appreciate the dedication.
 
mc01439

mc01439

Well-known member
2019 Donor
VIP
I switched to /ng and am seeing a lot less of it. I still made 400 a contract trading /cl for 5 hours yesterday, I think strategy said I should've made 776 so I lost 376 to the repaint.
YungTraderFromMontana - That is for the best - CL can be very choppy at times. Congratulations on a nice day of trading. That is why I like futures can trade when the U.S. markets are closed for a holiday.

Man I love this business!
 
YungTraderFromMontana

YungTraderFromMontana

Active member
@YungTraderFromMontana - This does re-paint one bar back at times. Have watched it live now for a number of hours on different futures. This is due to the MTF - will happen no matter what I believe. Still trad-able just need to be aware of the potential.

Be careful with /CL - can move against you very quickly.

In reference to a trend indicator for Diazlaz's combo paintbar options. ADX seems to be very late at times, you may want to try this. Do not remember were I found it but seems to be faster than ADX.

Code:
#Indicates Trending or Chop

input AverageType2 = AverageType.HULL;

def AvgLength     = 13; #TOS default 8

def Lengthchop    = 13;

def Choppy        = 61.8;

def MidLine       = 50;

def Trending      = 38.2;


def AVG = MovingAverage(AverageType = AverageType2, c, AvgLength);

def CIB = ((Log(Sum(TrueRange(h, c, l), Lengthchop) /

             (Highest(if h >= c[1] then h else

             c[1], Lengthchop) -

             Lowest( if l <= c[1] then l else c[1], Lengthchop)))

             / Log(10)) / (Log(Lengthchop) / Log(10))) * 100;

def CI  = CIB;

AddLabel(enableCHOP, if CI > MidLine and CI < 62  then "MILD CHOP " + Round(CI, 0) else if CI >= 61.8 then "STRONG CHOP " + Round(CI, 0) else if CI <= MidLine and CI > 31.8 then " MILD TRENDING " + Round(CI, 0) else "STRONG TRENDING " + Round(CI, 0), if CI > MidLine then Color.YELLOW else Color.CYAN);
I've seen it repaint up to five back but it is really rare. I think certain stocks repaint less then others, I'm trying at the moment to determine why.
 
YungTraderFromMontana

YungTraderFromMontana

Active member
Hours of grind work and dedication. Spending 40 to 60 hours a week in back testing and forward testing.

If you have a test case or improvement let me know and will keep it in mind and share back any findings.
As a coder yourself what is the root cause of the repaint in the candles, I know it has to do with the mtf but what discrepancy between the 5 and 1 minute cause it?
 
mc01439

mc01439

Well-known member
2019 Donor
VIP
I've seen it repaint up to five back but it is really rare. I think certain stocks repaint less then others, I'm trying at the moment to determine why.
YungTraderFromMontana - as you more than likely know, the signal engine is driven mainly by the aggregation period that is used in the inputs. If the aggregation period signal changes the strategy signal will change. This is why most re-paints are mid aggregation period. The more the symbol trends the fewer the re-paints.
 

Top