MultiTimeFrame Price Action
Here's Pinto's MTF study, I'd say it looks pretty cool. Have at it ...
Here's Pinto's MTF study, I'd say it looks pretty cool. Have at it ...
Code:
# MultiTimeFrame Price Action
# Mar/17/2014
# [email protected]
declare lower;
###################################
#### Price Channel
###################################
input PriceChannelLength = 12;
def UpperChannel = Highest(high[1], PriceChannelLength);
def LowerChannel = Lowest( low[1], PriceChannelLength);
plot above = UpperChannel;
plot below = LowerChannel;
above.AssignValueColor(color.dark_gray);
below.AssignValueColor(color.dark_gray);
###################################
#### Aggregations
###################################
def AP = GetAggregationPeriod();
def weekly = AP >= AggregationPeriod.WEEK;
def daily = AP >= AggregationPeriod.DAY;
def FourHours = AP >= AggregationPeriod.FOUR_HOURS;
def hour = AP >= AggregationPeriod.HOUR;
def halfhour = AP >= AggregationPeriod.THIRTY_MIN;
def FifteenMin = AP >= AggregationPeriod.FIFTEEN_MIN;
def TenMin = AP >= AggregationPeriod.TEN_MIN;
def FiveMin = AP >= AggregationPeriod.FIVE_MIN;
def ThreeMin = AP >= AggregationPeriod.THREE_MIN;
def Min = AP >= AggregationPeriod.MIN;
def cMIN1 = close(period = "1 MIN" );
def cMIN3 = close(period = "3 MIN" );
def cMIN5 = close(period = "5 MIN" );
def cMIN10 = close(period = "10 MIN" );
def cMIN15 = close(period = "15 MIN" );
def cMIN30 = close(period = "30 MIN" );
def cHOUR1 = close(period = "1 HOUR" );
def cHOURS4 = close(period = "4 HOURS");
def cDAY = close(period = "DAY" );
def cWEEK = close(period = "WEEK" );
###################################
#### Time Frames
###################################
input plotLevels = {default "automatic", "manual"};
input _1_MIN_ = yes;
input _3_MIN_ = yes;
input _5_MIN_ = yes;
input _10_MIN_ = yes;
input _15_MIN_ = yes;
input _30_MIN_ = yes;
input _1_HOUR_ = yes;
input _4_HOURS_ = yes;
input _DAY_ = yes;
input _WEEK_ = yes;
def _1_MIN;
def _3_MIN;
def _5_MIN;
def _10_MIN;
def _15_MIN;
def _30_MIN;
def _1_HOUR;
def _4_HOURS;
def _DAY;
def _WEEK;
if plotLevels == plotLevels.manual then {
_1_MIN = _1_MIN_;
_3_MIN = _3_MIN_;
_5_MIN = _5_MIN_;
_10_MIN = _10_MIN_;
_15_MIN = _15_MIN_;
_30_MIN = _30_MIN_;
_1_HOUR = _1_HOUR_;
_4_HOURS = _4_HOURS_;
_DAY = _DAY_;
_WEEK = _WEEK_;
} else {
_1_MIN = _1_MIN_;
_3_MIN = _3_MIN_;
_5_MIN = _5_MIN_;
_10_MIN = _10_MIN_;
_15_MIN = _15_MIN_;
_30_MIN = if ThreeMin then _30_MIN_ else no;
_1_HOUR = if FiveMin then _1_HOUR_ else no;
_4_HOURS = if FifteenMin then _4_HOURS_ else no;
_DAY = if halfhour then _DAY_ else no;
_WEEK = if hour then _WEEK_ else no;
}
def MIN1;
def MIN3;
def MIN5;
def MIN10;
def MIN15;
def MIN30;
def HOUR1;
def HOURS4;
def DAY;
def WEEK;
if weekly then {
MIN1 = 0;
MIN3 = 0;
MIN5 = 0;
MIN10 = 0;
MIN15 = 0;
MIN30 = 0;
HOUR1 = 0;
HOURS4 = 0;
DAY = 0;
WEEK = cWEEK;
} else if daily then {
MIN1 = 0;
MIN3 = 0;
MIN5 = 0;
MIN10 = 0;
MIN15 = 0;
MIN30 = 0;
HOUR1 = 0;
HOURS4 = 0;
DAY = cDAY;
WEEK = cWEEK;
} else if FourHours then {
MIN1 = 0;
MIN3 = 0;
MIN5 = 0;
MIN10 = 0;
MIN15 = 0;
MIN30 = 0;
HOUR1 = 0;
HOURS4 = cHOURS4;
DAY = cDAY;
WEEK = cWEEK;
} else if hour then {
MIN1 = 0;
MIN3 = 0;
MIN5 = 0;
MIN10 = 0;
MIN15 = 0;
MIN30 = 0;
HOUR1 = cHOUR1;
HOURS4 = cHOURS4;
DAY = cDAY;
WEEK = cWEEK;
} else if halfhour then {
MIN1 = 0;
MIN3 = 0;
MIN5 = 0;
MIN10 = 0;
MIN15 = 0;
MIN30 = cMIN30;
HOUR1 = cHOUR1;
HOURS4 = cHOURS4;
DAY = cDAY;
WEEK = cWEEK;
} else if FifteenMin then {
MIN1 = 0;
MIN3 = 0;
MIN5 = 0;
MIN10 = 0;
MIN15 = cMIN15;
MIN30 = cMIN30;
HOUR1 = cHOUR1;
HOURS4 = cHOURS4;
DAY = cDAY;
WEEK = cWEEK;
} else if TenMin then {
MIN1 = 0;
MIN3 = 0;
MIN5 = 0;
MIN10 = cMIN10;
MIN15 = cMIN15;
MIN30 = cMIN30;
HOUR1 = cHOUR1;
HOURS4 = cHOURS4;
DAY = cDAY;
WEEK = cWEEK;
} else if FiveMin then {
MIN1 = 0;
MIN3 = 0;
MIN5 = cMIN5;
MIN10 = cMIN10;
MIN15 = cMIN15;
MIN30 = cMIN30;
HOUR1 = cHOUR1;
HOURS4 = cHOURS4;
DAY = cDAY;
WEEK = cWEEK;
} else if ThreeMin then {
MIN1 = 0;
MIN3 = cMIN3;
MIN5 = cMIN5;
MIN10 = cMIN10;
MIN15 = cMIN15;
MIN30 = cMIN30;
HOUR1 = cHOUR1;
HOURS4 = cHOURS4;
DAY = cDAY;
WEEK = cWEEK;
} else {
MIN1 = cMIN1;
MIN3 = cMIN3;
MIN5 = cMIN5;
MIN10 = cMIN10;
MIN15 = cMIN15;
MIN30 = cMIN30;
HOUR1 = cHOUR1;
HOURS4 = cHOURS4;
DAY = cDAY;
WEEK = cWEEK;
}
plot highlight;
plot AP_ = close;
plot AP0 = if _1_MIN and MIN1 then MIN1[1] else Double.NaN;
plot AP1 = if _3_MIN and MIN3 then MIN3[1] else Double.NaN;
plot AP2 = if _5_MIN and MIN5 then MIN5[1] else Double.NaN;
plot AP3 = if _10_MIN and MIN10 then MIN10[1] else Double.NaN;
plot AP4 = if _15_MIN and MIN15 then MIN15[1] else Double.NaN;
plot AP5 = if _30_MIN and MIN30 then MIN30[1] else Double.NaN;
plot AP6 = if _1_HOUR and HOUR1 then HOUR1[1] else Double.NaN;
plot AP7 = if _4_HOURS and HOURS4 then HOURS4[1] else Double.NaN;
plot AP8 = if _DAY and DAY then DAY[1] else Double.NaN;
plot AP9 = if _WEEK and WEEK then WEEK[1] else Double.NaN;
def allUP;
def allDN;
if weekly then {
allUP =
(1)
and (AP_ > AP_[1])
;
allDN =
(1)
and (AP_ < AP_[1])
;
} else if daily then {
allUP =
(1)
and (if _WEEK then AP_ > AP9 else AP_ > AP_[1])
;
allDN =
(1)
and (if _WEEK then AP_ < AP9 else AP_ < AP_[1])
;
} else if FourHours {
allUP =
(1)
and (if _DAY then AP_ > AP8 else AP_ > AP_[1])
and (if _WEEK then AP_ > AP9 else 1)
;
allDN =
(1)
and (if _DAY then AP_ < AP8 else AP_ < AP_[1])
and (if _WEEK then AP_ < AP9 else 1)
;
} else if hour then {
allUP =
(1)
and (if _4_HOURS then AP_ > AP7 else AP_ > AP_[1])
and (if _DAY then AP_ > AP8 else 1)
and (if _WEEK then AP_ > AP9 else 1)
;
allDN =
(1)
and (if _4_HOURS then AP_ < AP7 else AP_ < AP_[1])
and (if _DAY then AP_ < AP8 else 1)
and (if _WEEK then AP_ < AP9 else 1)
;
} else if halfhour then {
allUP =
(1)
and (if _1_HOUR then AP_ > AP6 else AP_ > AP_[1])
and (if _4_HOURS then AP_ > AP7 else 1)
and (if _DAY then AP_ > AP8 else 1)
and (if _WEEK then AP_ > AP9 else 1)
;
allDN =
(1)
and (if _1_HOUR then AP_ < AP6 else AP_ < AP_[1])
and (if _4_HOURS then AP_ < AP7 else 1)
and (if _DAY then AP_ < AP8 else 1)
and (if _WEEK then AP_ < AP9 else 1)
;
} else if FifteenMin {
allUP =
(1)
and (if _30_MIN then AP_ > AP5 else AP_ > AP_[1])
and (if _1_HOUR then AP_ > AP6 else 1)
and (if _4_HOURS then AP_ > AP7 else 1)
and (if _DAY then AP_ > AP8 else 1)
and (if _WEEK then AP_ > AP9 else 1)
;
allDN =
(1)
and (if _30_MIN then AP_ < AP5 else AP_ < AP_[1])
and (if _1_HOUR then AP_ < AP6 else 1)
and (if _4_HOURS then AP_ < AP7 else 1)
and (if _DAY then AP_ < AP8 else 1)
and (if _WEEK then AP_ < AP9 else 1)
;
} else if TenMin then {
allUP =
(1)
and (1)
and (if _15_MIN then AP_ > AP4 else AP_ > AP_[1])
and (if _30_MIN then AP_ > AP5 else 1)
and (if _1_HOUR then AP_ > AP6 else 1)
and (if _4_HOURS then AP_ > AP7 else 1)
and (if _DAY then AP_ > AP8 else 1)
and (if _WEEK then AP_ > AP9 else 1)
;
allDN =
(1)
and (1)
and (if _15_MIN then AP_ < AP4 else AP_ < AP_[1])
and (if _30_MIN then AP_ < AP5 else 1)
and (if _1_HOUR then AP_ < AP6 else 1)
and (if _4_HOURS then AP_ < AP7 else 1)
and (if _DAY then AP_ < AP8 else 1)
and (if _WEEK then AP_ < AP9 else 1)
;
} else if FiveMin then {
allUP =
(1)
and (if _10_MIN then AP_ > AP3 else AP_ > AP_[1])
and (if _15_MIN then AP_ > AP4 else 1)
and (if _30_MIN then AP_ > AP5 else 1)
and (if _1_HOUR then AP_ > AP6 else 1)
and (if _4_HOURS then AP_ > AP7 else 1)
and (if _DAY then AP_ > AP8 else 1)
and (if _WEEK then AP_ > AP9 else 1)
;
allDN =
(1)
and (if _10_MIN then AP_ < AP3 else AP_ < AP_[1])
and (if _15_MIN then AP_ < AP4 else 1)
and (if _30_MIN then AP_ < AP5 else 1)
and (if _1_HOUR then AP_ < AP6 else 1)
and (if _4_HOURS then AP_ < AP7 else 1)
and (if _DAY then AP_ < AP8 else 1)
and (if _WEEK then AP_ < AP9 else 1)
;
} else if ThreeMin then {
allUP =
(1)
and (if _5_MIN then AP_ > AP3 else AP_ > AP_[1])
and (if _10_MIN then AP_ > AP3 else 1)
and (if _15_MIN then AP_ > AP4 else 1)
and (if _30_MIN then AP_ > AP5 else 1)
and (if _1_HOUR then AP_ > AP6 else 1)
and (if _4_HOURS then AP_ > AP7 else 1)
and (if _DAY then AP_ > AP8 else 1)
and (if _WEEK then AP_ > AP9 else 1)
;
allDN =
(1)
and (if _5_MIN then AP_ < AP3 else AP_ < AP_[1])
and (if _10_MIN then AP_ < AP3 else 1)
and (if _15_MIN then AP_ < AP4 else 1)
and (if _30_MIN then AP_ < AP5 else 1)
and (if _1_HOUR then AP_ < AP6 else 1)
and (if _4_HOURS then AP_ < AP7 else 1)
and (if _DAY then AP_ < AP8 else 1)
and (if _WEEK then AP_ < AP9 else 1)
;
} else {
allUP =
(1)
and (if _3_MIN then AP_ > AP1 else AP_ > AP_[1])
and (if _5_MIN then AP_ > AP2 else 1)
and (if _10_MIN then AP_ > AP3 else 1)
and (if _15_MIN then AP_ > AP4 else 1)
and (if _30_MIN then AP_ > AP5 else 1)
and (if _1_HOUR then AP_ > AP6 else 1)
and (if _4_HOURS then AP_ > AP7 else 1)
and (if _DAY then AP_ > AP8 else 1)
and (if _WEEK then AP_ > AP9 else 1)
;
allDN =
(1)
and (if _3_MIN then AP_ < AP1 else AP_ < AP_[1])
and (if _5_MIN then AP_ < AP2 else 1)
and (if _10_MIN then AP_ < AP3 else 1)
and (if _15_MIN then AP_ < AP4 else 1)
and (if _30_MIN then AP_ < AP5 else 1)
and (if _1_HOUR then AP_ < AP6 else 1)
and (if _4_HOURS then AP_ < AP7 else 1)
and (if _DAY then AP_ < AP8 else 1)
and (if _WEEK then AP_ < AP9 else 1)
;
}
def Bull = if isNaN(allUP) then 0 else if allUp and high > UpperChannel[1] then 1 else 0;
def Bear = if isNaN(allDN) then 0 else if allDN and low < LowerChannel[1] then 1 else 0;
#plot BULLsignal = if BULL then low else Double.NaN;
#BULLsignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#BULLsignal.AssignValueColor(Color.MAGENTA);
#BULLsignal.SetLineWeight(1);
#plot BEARsignal = if BEAR then high else Double.NaN;
#BEARsignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#BEARsignal.AssignValueColor(GlobalColor("LIGHT_BLUE"));
#BEARsignal.SetLineWeight(1);
highlight = if Bull then AP_ else if Bear then AP_ else Double.NaN;
highlight.AssignValueColor(if Bull then Color.MAGENTA else if Bear then CreateColor(0, 175, 255 ) else Color.GRAY);
highlight.SetLineWeight(4);
def AP0d = if AP0 > AP0[1] then 1 else if AP0 < AP0[1] then -1 else AP0d[1];
def AP1d = if AP1 > AP1[1] then 1 else if AP1 < AP1[1] then -1 else AP1d[1];
def AP2d = if AP2 > AP2[1] then 1 else if AP2 < AP2[1] then -1 else AP2d[1];
def AP3d = if AP3 > AP3[1] then 1 else if AP3 < AP3[1] then -1 else AP3d[1];
def AP4d = if AP4 > AP4[1] then 1 else if AP4 < AP4[1] then -1 else AP4d[1];
def AP5d = if AP5 > AP5[1] then 1 else if AP5 < AP5[1] then -1 else AP5d[1];
def AP6d = if AP6 > AP6[1] then 1 else if AP6 < AP6[1] then -1 else AP6d[1];
def AP7d = if AP7 > AP7[1] then 1 else if AP7 < AP7[1] then -1 else AP7d[1];
def AP8d = if AP8 > AP8[1] then 1 else if AP8 < AP8[1] then -1 else AP8d[1];
def AP9d = if AP9 > AP9[1] then 1 else if AP9 < AP9[1] then -1 else AP9d[1];
DefineGlobalColor( "LIGHT_BLUE", CreateColor(0, 175, 255 ));
AP_.AssignValueColor( if AP_> AP_[1] then Color.GREEN else if AP_ < AP_[1] then Color.RED else Color.GRAY);
AP0.AssignValueColor( if AP0d > 0 then CreateColor(50, 255, 50) else if AP0d < 0 then CreateColor(255, 50, 50) else Color.GRAY );
AP1.AssignValueColor( if AP1d > 0 then CreateColor( 0, 255, 0) else if AP1d < 0 then CreateColor(255, 0, 0) else Color.GRAY );
AP2.AssignValueColor( if AP2d > 0 then CreateColor( 0, 235, 0) else if AP2d < 0 then CreateColor(235, 0, 0) else Color.GRAY );
AP3.AssignValueColor( if AP3d > 0 then CreateColor( 0, 215, 0) else if AP3d < 0 then CreateColor(215, 0, 0) else Color.GRAY );
AP4.AssignValueColor( if AP4d > 0 then CreateColor( 0, 195, 0) else if AP4d < 0 then CreateColor(195, 0, 0) else Color.GRAY );
AP5.AssignValueColor( if AP5d > 0 then CreateColor( 0, 175, 0) else if AP5d < 0 then CreateColor(175, 0, 0) else Color.GRAY );
AP6.AssignValueColor( if AP6d > 0 then CreateColor( 0, 155, 0) else if AP6d < 0 then CreateColor(155, 0, 0) else Color.GRAY );
AP7.AssignValueColor( if AP7d > 0 then CreateColor( 0, 135, 0) else if AP7d < 0 then CreateColor(135, 0, 0) else Color.GRAY );
AP8.AssignValueColor( if AP8d > 0 then CreateColor( 0, 115, 0) else if AP8d < 0 then CreateColor(115, 0, 0) else Color.GRAY );
AP9.AssignValueColor( if AP9d > 0 then CreateColor( 0, 95, 0) else if AP9d < 0 then CreateColor( 95, 50, 50) else Color.GRAY );
AP_.SetStyle(Curve.FIRM );
AP0.SetStyle(Curve.SHORT_DASH ); # "1 MIN"
AP1.SetStyle(Curve.SHORT_DASH ); # "3 MIN"
AP2.SetStyle(Curve.SHORT_DASH ); # "5 MIN"
AP3.SetStyle(Curve.SHORT_DASH ); # "10 MIN"
AP4.SetStyle(Curve.MEDIUM_DASH); # "15 MIN"
AP5.SetStyle(Curve.MEDIUM_DASH); # "30 MIN"
AP6.SetStyle(Curve.MEDIUM_DASH); # "1 HOUR"
AP7.SetStyle(Curve.LONG_DASH ); # "4 HOURS"
AP8.SetStyle(Curve.LONG_DASH ); # "DAY"
AP9.SetStyle(Curve.LONG_DASH ); # "WEEK"
Addlabel( _WEEK, "WEEK", if AP9d > 0 then CreateColor( 0, 95, 0) else if AP9d < 0 then CreateColor( 95, 0, 0) else Color.GRAY );
Addlabel( _DAY and DAY > 0, "DAY", if AP8d > 0 then CreateColor( 0, 115, 0) else if AP8d < 0 then CreateColor(115, 0, 0) else Color.GRAY );
Addlabel( _4_HOURS and HOURS4 > 0,"4 HOURS", if AP7d > 0 then CreateColor( 0, 135, 0) else if AP7d < 0 then CreateColor(135, 0, 0) else Color.GRAY );
Addlabel( _1_HOUR and HOUR1 > 0, "1 HOUR", if AP6d > 0 then CreateColor( 0, 155, 0) else if AP6d < 0 then CreateColor(155, 0, 0) else Color.GRAY );
Addlabel( _30_MIN and MIN30 > 0, "30 MIN", if AP5d > 0 then CreateColor( 0, 175, 0) else if AP5d < 0 then CreateColor(175, 0, 0) else Color.GRAY );
Addlabel( MIN15 > 0, "15 MIN", if AP4d > 0 then CreateColor( 0, 195, 0) else if AP4d < 0 then CreateColor(195, 0, 0) else Color.GRAY );
Addlabel( MIN10 > 0, "10 MIN", if AP3d > 0 then CreateColor( 0, 215, 0) else if AP3d < 0 then CreateColor(215, 0, 0) else Color.GRAY );
Addlabel( MIN5 > 0, "5 MIN", if AP2d > 0 then CreateColor( 0, 235, 0) else if AP2d < 0 then CreateColor(235, 0, 0) else Color.GRAY );
Addlabel( MIN3 > 0, "3 MIN", if AP1d > 0 then CreateColor( 0, 255, 0) else if AP1d < 0 then CreateColor(255, 0, 0) else Color.GRAY );
Addlabel( MIN1 > 0, "1 MIN", if AP0d > 0 then CreateColor(50, 255, 50) else if AP0d < 0 then CreateColor(255, 50, 50) else Color.GRAY );
Addlabel( yes, " NOW", if isNaN(allUp) or isNaN(allDN) then Color.GRAY else if allUp then Color.MAGENTA else if allDN then CreateColor(0, 175, 255 ) else Color.GRAY );
AP7.SetLineWeight(2);
AP8.SetLineWeight(3);
AP9.SetLineWeight(4);
AP_.HideBubble();
AP0.HideBubble();
AP1.HideBubble();
AP2.HideBubble();
AP3.HideBubble();
AP4.HideBubble();
AP5.HideBubble();
AP6.HideBubble();
AP7.HideBubble();
AP8.HideBubble();
AP9.HideBubble();
Last edited by a moderator: