tradetollive
New member
can you give an example, if you see the first picture is the closest that i can get to the MTF,Maybe if you smooth the moving averages
can you give an example, if you see the first picture is the closest that i can get to the MTF,Maybe if you smooth the moving averages
i use those too, i need the MTF for bigger time frame, some of the EMA in bigger time frame are very importantIronically, I find myself moving away from moving averages and onto ATR, regression, vwap and pivots seems to have opened up and whole new world for me..
# SwingTrading_R1V3
# R1V1 2011.06.11.23:00 KumoBob
# A very simple method of SwingTrading with Moving average
# R1V2 2011.06.13.09:00 KumoBob
# Added more periods to AverageMode
# R1V3 2011.06.13.15:00 KumoBob
# Added hints and other bells an whistles
declare upper;
#Hint: Three methods are available and provide a very simple method of SwingTrading with Moving Averages. \nThis orignated when I wanted to see what would happen if two moving averages were used on a daily basis with the buy and sell signal always being the highest and lowest of the two averages.\nIt seems to be a fairly good method, but other indicators such as PPS will most likely out perform this method.
#Hint FastMovingAverage: Length of FAST average\nDefault = 5
#Hint SlowMovingAverage: Length of SLOW average\nDefault = 13
#Hint Method: Choose to signal when Price crosses the Fast MA\nor\nChoose to signal when the Fast MA crosses the Slow MA\nor\n "Buy at the Lowest MA and Sell at the Highest MA when Price crosses these curves
#Hint AverageMode: Choose to average by bar or a selectable time period\nThe choices are DAY, 2 DAYS, 3 DAYS, 4 DAYS, WEEK, and MONTH \nDefault = Day
#Hint BubblesOn: Bubbles identify the curve's average length\nDefault = Yes
#Hint ShowPoints: Shows the exact point the signal occured\nDefault = Yes
#Hint ShowArrows: Shows the signal with an arrow\nDefault = Yes
#Hint ShowPlot: Choose to show the curves or hide them
#Hint VerticalDayBreakLinesOn: Choose to place Vertical Lines at Day, Week or Month intervals\nDefault = No
#Hint VerticalLinePeriod: Specifies the interval to plot vertical lines\nDefault = Day
#Hint PriceColorOn: Allows the signal to be seen as Red and Green price bars\nDefault = No
input FastMovingAverage = 5;
input SlowMovingAverage = 13;
Input Method = {"At Fast MA", "MA Cross",Default "Buy at Min MA Sell at Max MA"};
input AverageMode = {"Bar",default DAY, "2 DAYS", "3 DAYS", "4 DAYS", WEEK, MONTH};
input BubblesOn = Yes;
input ShowPlot = Yes;
input ShowPoints = Yes;
input ShowArrows = Yes;
Input PriceColorOn = No;
def Mode;
switch (Method){
case "At Fast MA":
Mode = 1;
case "MA Cross":
Mode = 2;
case "Buy at Min MA Sell at Max MA":
Mode = 3;
}
Input VerticalDayBreakLinesOn = No;
input VerticalLinePeriod = {default DAY, WEEK, MONTH};
def PeriodChoice;
switch (AverageMode){
case "Day":
PeriodChoice = 1;
case "2 DAYS":
PeriodChoice = 2;
case "3 DAYS":
PeriodChoice = 3;
case "4 DAYS":
PeriodChoice = 4;
case WEEK:
PeriodChoice = 7;
case MONTH:
PeriodChoice = 30;
case "Bar":
PeriodChoice = 0;
}
def BarMA1 = Average(close () , FastMovingAverage );
Def Day1MA1 = Average(close (period = "DAY" ), FastMovingAverage );
Def Day2MA1 = Average(close (period = "2 DAYS"), FastMovingAverage );
Def Day3MA1 = Average(close (period = "3 DAYS"), FastMovingAverage );
Def Day4MA1 = Average(close (period = "4 DAYS"), FastMovingAverage );
Def Day7MA1 = Average(close (period = "WEEK" ), FastMovingAverage);
Def Day30MA1 = Average(close (period = "MONTH") , FastMovingAverage);
def BarMA2 = Average(close () , SlowMovingAverage);
Def Day1MA2 = Average(close (period = "DAY" ), SlowMovingAverage);
Def Day2MA2 = Average(close (period = "2 DAYS"), SlowMovingAverage);
Def Day3MA2 = Average(close (period = "3 DAYS"), SlowMovingAverage);
Def Day4MA2 = Average(close (period = "4 DAYS"), SlowMovingAverage);
Def Day7MA2 = Average(close (period = "WEEK" ), SlowMovingAverage);
Def Day30MA2 = Average(close (period = "MONTH") , SlowMovingAverage);
def FMA =
If PeriodChoice == 1 then Day1MA1 else
If PeriodChoice == 2 then Day2MA1 else
If PeriodChoice == 3 then Day3MA1 else
If PeriodChoice == 4 then Day4MA1 else
If PeriodChoice == 7 then Day7MA1 else
If PeriodChoice == 30 then Day30MA1 else BarMA1;
plot FastMA = if !ShowPlot then Double.NaN else FMA;
FastMA.AssignValueColor(if Close > FMA then Color.Green else if Close < FMA then Color.Red else Color.Yellow); AddChartBubble(FastMA && BubblesOn && !IsNaN(close) and IsNaN(close[-1]), FastMA, concat("", FastMovingAverage ), if Close > FMA then Color.Green else if Close < FMA then Color.Red else Color.Yellow); def SMA = If PeriodChoice == 1 then Day1MA2 else If PeriodChoice == 2 then Day2MA2 else If PeriodChoice == 3 then Day3MA2 else If PeriodChoice == 4 then Day4MA2 else If PeriodChoice == 7 then Day7MA2 else If PeriodChoice == 30 then Day30MA2 else BarMA2; plot SlowMA = if !ShowPlot then Double.NaN else SMA; SlowMA.AssignValueColor(if Close > SMA then Color.Green else if Close < SMA then Color.Red else Color.Yellow); AddChartBubble(SlowMA && BubblesOn && !IsNaN(close) and IsNaN(close[-1]), SlowMA, concat("", SlowMovingAverage), if Close > SMA then Color.Green else if Close < SMA then Color.Red else Color.Yellow); #################### def Max = Max(FMA, SMA); def Min = Min(FMA, SMA); def Position = if Close > Max(FMA, SMA) then 2 else if Close < Min(FMA, SMA) then -2 else 0; rec Trend = If Mode == 3 then if Position[1] == 2 && Position[0] <= 0 then -2 else if Position[1] == -2 && Position[0] >= 0 then 2 else
if Position[1] == 0 && Position[0] == 2 then 2 else
if Position[1] == 0 && Position[0] == -2 then -2 else Trend[1]
else If Mode == 1 then if Close > FMA then 2 else -2
else if FMA > SMA then 2 else -2;
AssignPriceColor(if !PriceColorOn then Color.Current else If Trend > 0 then Color.Green else Color.Red);
rec Point = If Mode == 3 then
if Position[1] == 2 && Position[0] <= 0 then Max else if Position[1] == -2 && Position[0] >= 0 then Min else
if Position[1] == 0 && Position[0] == 2 then Max else
if Position[1] == 0 && Position[0] == -2 then Min else Point[1]
else If Mode == 1 then if Close > FMA then Close else Point[1]
else if FMA > SMA then Close else Point[1];
plot SignalPoint = If !ShowPoints then Double.NaN else Point;
SignalPoint.SetLineWeight(1);
SignalPoint.SetPaintingStrategy(PaintingStrategy.Points);
SignalPoint.AssignValueColor(If Trend > 0 then Color.Green else Color.Red);
# ARROWS ROUTINE
# ___
def x_over = Crosses(Trend, 0);
plot up = if ShowArrows && x_over && Trend > 0 then Low else Double.NaN;
up.SetPaintingStrategy(PaintingStrategy.Arrow_up);
up.SetDefaultColor(Color.white);
plot dn = if ShowArrows && x_over && Trend < 0 then High else Double.NaN; dn.SetPaintingStrategy(PaintingStrategy.Arrow_down); dn.SetDefaultColor(Color.white); # Vertical Time Lines # ___ def vert = VerticalLinePeriod == VerticalLinePeriod.Day and getDay() <> getDay()[1] or
VerticalLinePeriod == VerticalLinePeriod.WEEK and getWeek() <> getWeek()[1] or VerticalLinePeriod == VerticalLinePeriod.MONTH and getMonth() <> getMonth()[1];
AddVerticalLine(VerticalDayBreakLinesOn && Vert,
"",
if VerticalLinePeriod == VerticalLinePeriod.day then color.cyan else if VerticalLinePeriod == VerticalLinePeriod.week then Color.Magenta else color.Yellow);# SwingTrading_R1V3
# R1V1 2011.06.11.23:00 KumoBob
# A very simple method of SwingTrading with Moving average
# R1V2 2011.06.13.09:00 KumoBob
# Added more periods to AverageMode
# R1V3 2011.06.13.15:00 KumoBob
# Added hints and other bells an whistles
declare upper;
#Hint: Three methods are available and provide a very simple method of SwingTrading with Moving Averages. \nThis orignated when I wanted to see what would happen if two moving averages were used on a daily basis with the buy and sell signal always being the highest and lowest of the two averages.\nIt seems to be a fairly good method, but other indicators such as PPS will most likely out perform this method.
#Hint FastMovingAverage: Length of FAST average\nDefault = 5
#Hint SlowMovingAverage: Length of SLOW average\nDefault = 13
#Hint Method: Choose to signal when Price crosses the Fast MA\nor\nChoose to signal when the Fast MA crosses the Slow MA\nor\n "Buy at the Lowest MA and Sell at the Highest MA when Price crosses these curves
#Hint AverageMode: Choose to average by bar or a selectable time period\nThe choices are DAY, 2 DAYS, 3 DAYS, 4 DAYS, WEEK, and MONTH \nDefault = Day
#Hint BubblesOn: Bubbles identify the curve's average length\nDefault = Yes
#Hint ShowPoints: Shows the exact point the signal occured\nDefault = Yes
#Hint ShowArrows: Shows the signal with an arrow\nDefault = Yes
#Hint ShowPlot: Choose to show the curves or hide them
#Hint VerticalDayBreakLinesOn: Choose to place Vertical Lines at Day, Week or Month intervals\nDefault = No
#Hint VerticalLinePeriod: Specifies the interval to plot vertical lines\nDefault = Day
#Hint PriceColorOn: Allows the signal to be seen as Red and Green price bars\nDefault = No
input FastMovingAverage = 5;
input SlowMovingAverage = 13;
Input Method = {"At Fast MA", "MA Cross",Default "Buy at Min MA Sell at Max MA"};
input AverageMode = {"Bar",default DAY, "2 DAYS", "3 DAYS", "4 DAYS", WEEK, MONTH};
input BubblesOn = Yes;
input ShowPlot = Yes;
input ShowPoints = Yes;
input ShowArrows = Yes;
Input PriceColorOn = No;
def Mode;
switch (Method){
case "At Fast MA":
Mode = 1;
case "MA Cross":
Mode = 2;
case "Buy at Min MA Sell at Max MA":
Mode = 3;
}
Input VerticalDayBreakLinesOn = No;
input VerticalLinePeriod = {default DAY, WEEK, MONTH};
def PeriodChoice;
switch (AverageMode){
case "Day":
PeriodChoice = 1;
case "2 DAYS":
PeriodChoice = 2;
case "3 DAYS":
PeriodChoice = 3;
case "4 DAYS":
PeriodChoice = 4;
case WEEK:
PeriodChoice = 7;
case MONTH:
PeriodChoice = 30;
case "Bar":
PeriodChoice = 0;
}
def BarMA1 = Average(close () , FastMovingAverage );
Def Day1MA1 = Average(close (period = "DAY" ), FastMovingAverage );
Def Day2MA1 = Average(close (period = "2 DAYS"), FastMovingAverage );
Def Day3MA1 = Average(close (period = "3 DAYS"), FastMovingAverage );
Def Day4MA1 = Average(close (period = "4 DAYS"), FastMovingAverage );
Def Day7MA1 = Average(close (period = "WEEK" ), FastMovingAverage);
Def Day30MA1 = Average(close (period = "MONTH") , FastMovingAverage);
def BarMA2 = Average(close () , SlowMovingAverage);
Def Day1MA2 = Average(close (period = "DAY" ), SlowMovingAverage);
Def Day2MA2 = Average(close (period = "2 DAYS"), SlowMovingAverage);
Def Day3MA2 = Average(close (period = "3 DAYS"), SlowMovingAverage);
Def Day4MA2 = Average(close (period = "4 DAYS"), SlowMovingAverage);
Def Day7MA2 = Average(close (period = "WEEK" ), SlowMovingAverage);
Def Day30MA2 = Average(close (period = "MONTH") , SlowMovingAverage);
def FMA =
If PeriodChoice == 1 then Day1MA1 else
If PeriodChoice == 2 then Day2MA1 else
If PeriodChoice == 3 then Day3MA1 else
If PeriodChoice == 4 then Day4MA1 else
If PeriodChoice == 7 then Day7MA1 else
If PeriodChoice == 30 then Day30MA1 else BarMA1;
plot FastMA = if !ShowPlot then Double.NaN else FMA;
FastMA.AssignValueColor(if Close > FMA then Color.Green else if Close < FMA then Color.Red else Color.Yellow); AddChartBubble(FastMA && BubblesOn && !IsNaN(close) and IsNaN(close[-1]), FastMA, concat("", FastMovingAverage ), if Close > FMA then Color.Green else if Close < FMA then Color.Red else Color.Yellow); def SMA = If PeriodChoice == 1 then Day1MA2 else If PeriodChoice == 2 then Day2MA2 else If PeriodChoice == 3 then Day3MA2 else If PeriodChoice == 4 then Day4MA2 else If PeriodChoice == 7 then Day7MA2 else If PeriodChoice == 30 then Day30MA2 else BarMA2; plot SlowMA = if !ShowPlot then Double.NaN else SMA; SlowMA.AssignValueColor(if Close > SMA then Color.Green else if Close < SMA then Color.Red else Color.Yellow); AddChartBubble(SlowMA && BubblesOn && !IsNaN(close) and IsNaN(close[-1]), SlowMA, concat("", SlowMovingAverage), if Close > SMA then Color.Green else if Close < SMA then Color.Red else Color.Yellow); #################### def Max = Max(FMA, SMA); def Min = Min(FMA, SMA); def Position = if Close > Max(FMA, SMA) then 2 else if Close < Min(FMA, SMA) then -2 else 0; rec Trend = If Mode == 3 then if Position[1] == 2 && Position[0] <= 0 then -2 else if Position[1] == -2 && Position[0] >= 0 then 2 else if Position[1] == 0 && Position[0] == 2 then 2 else if Position[1] == 0 && Position[0] == -2 then -2 else Trend[1] else If Mode == 1 then if Close > FMA then 2 else -2 else if FMA > SMA then 2 else -2;
AssignPriceColor(if !PriceColorOn then Color.Current else If Trend > 0 then Color.Green else Color.Red);
rec Point = If Mode == 3 then
if Position[1] == 2 && Position[0] <= 0 then Max else if Position[1] == -2 && Position[0] >= 0 then Min else
if Position[1] == 0 && Position[0] == 2 then Max else
if Position[1] == 0 && Position[0] == -2 then Min else Point[1]
else If Mode == 1 then if Close > FMA then Close else Point[1]
else if FMA > SMA then Close else Point[1];
plot SignalPoint = If !ShowPoints then Double.NaN else Point;
SignalPoint.SetLineWeight(1);
SignalPoint.SetPaintingStrategy(PaintingStrategy.Points);
SignalPoint.AssignValueColor(If Trend > 0 then Color.Green else Color.Red);
# ARROWS ROUTINE
# ___
def x_over = Crosses(Trend, 0);
plot up = if ShowArrows && x_over && Trend > 0 then Low else Double.NaN;
up.SetPaintingStrategy(PaintingStrategy.Arrow_up);
up.SetDefaultColor(Color.white);
plot dn = if ShowArrows && x_over && Trend < 0 then High else Double.NaN; dn.SetPaintingStrategy(PaintingStrategy.Arrow_down); dn.SetDefaultColor(Color.white); # Vertical Time Lines # ___ def vert = VerticalLinePeriod == VerticalLinePeriod.Day and getDay() <> getDay()[1] or VerticalLinePeriod == VerticalLinePeriod.WEEK and getWeek() <> getWeek()[1] or VerticalLinePeriod == VerticalLinePeriod.MONTH and getMonth() <> getMonth()[1];
AddVerticalLine(VerticalDayBreakLinesOn && Vert, "", if VerticalLinePeriod == VerticalLinePeriod.day then color.cyan else if VerticalLinePeriod == VerticalLinePeriod.week then Color.Magenta else color.Yellow);
Error in this code 94through 97 can this get updated ? thankssomeone can tell me what's wrong with this code
![]()
Code:# SwingTrading_R1V3 # R1V1 2011.06.11.23:00 KumoBob # A very simple method of SwingTrading with Moving average # R1V2 2011.06.13.09:00 KumoBob # Added more periods to AverageMode # R1V3 2011.06.13.15:00 KumoBob # Added hints and other bells an whistles declare upper; #Hint: Three methods are available and provide a very simple method of SwingTrading with Moving Averages. \nThis orignated when I wanted to see what would happen if two moving averages were used on a daily basis with the buy and sell signal always being the highest and lowest of the two averages.\nIt seems to be a fairly good method, but other indicators such as PPS will most likely out perform this method. #Hint FastMovingAverage: Length of FAST average\nDefault = 5 #Hint SlowMovingAverage: Length of SLOW average\nDefault = 13 #Hint Method: Choose to signal when Price crosses the Fast MA\nor\nChoose to signal when the Fast MA crosses the Slow MA\nor\n "Buy at the Lowest MA and Sell at the Highest MA when Price crosses these curves #Hint AverageMode: Choose to average by bar or a selectable time period\nThe choices are DAY, 2 DAYS, 3 DAYS, 4 DAYS, WEEK, and MONTH \nDefault = Day #Hint BubblesOn: Bubbles identify the curve's average length\nDefault = Yes #Hint ShowPoints: Shows the exact point the signal occured\nDefault = Yes #Hint ShowArrows: Shows the signal with an arrow\nDefault = Yes #Hint ShowPlot: Choose to show the curves or hide them #Hint VerticalDayBreakLinesOn: Choose to place Vertical Lines at Day, Week or Month intervals\nDefault = No #Hint VerticalLinePeriod: Specifies the interval to plot vertical lines\nDefault = Day #Hint PriceColorOn: Allows the signal to be seen as Red and Green price bars\nDefault = No input FastMovingAverage = 5; input SlowMovingAverage = 13; Input Method = {"At Fast MA", "MA Cross",Default "Buy at Min MA Sell at Max MA"}; input AverageMode = {"Bar",default DAY, "2 DAYS", "3 DAYS", "4 DAYS", WEEK, MONTH}; input BubblesOn = Yes; input ShowPlot = Yes; input ShowPoints = Yes; input ShowArrows = Yes; Input PriceColorOn = No; def Mode; switch (Method){ case "At Fast MA": Mode = 1; case "MA Cross": Mode = 2; case "Buy at Min MA Sell at Max MA": Mode = 3; } Input VerticalDayBreakLinesOn = No; input VerticalLinePeriod = {default DAY, WEEK, MONTH}; def PeriodChoice; switch (AverageMode){ case "Day": PeriodChoice = 1; case "2 DAYS": PeriodChoice = 2; case "3 DAYS": PeriodChoice = 3; case "4 DAYS": PeriodChoice = 4; case WEEK: PeriodChoice = 7; case MONTH: PeriodChoice = 30; case "Bar": PeriodChoice = 0; } def BarMA1 = Average(close () , FastMovingAverage ); Def Day1MA1 = Average(close (period = "DAY" ), FastMovingAverage ); Def Day2MA1 = Average(close (period = "2 DAYS"), FastMovingAverage ); Def Day3MA1 = Average(close (period = "3 DAYS"), FastMovingAverage ); Def Day4MA1 = Average(close (period = "4 DAYS"), FastMovingAverage ); Def Day7MA1 = Average(close (period = "WEEK" ), FastMovingAverage); Def Day30MA1 = Average(close (period = "MONTH") , FastMovingAverage); def BarMA2 = Average(close () , SlowMovingAverage); Def Day1MA2 = Average(close (period = "DAY" ), SlowMovingAverage); Def Day2MA2 = Average(close (period = "2 DAYS"), SlowMovingAverage); Def Day3MA2 = Average(close (period = "3 DAYS"), SlowMovingAverage); Def Day4MA2 = Average(close (period = "4 DAYS"), SlowMovingAverage); Def Day7MA2 = Average(close (period = "WEEK" ), SlowMovingAverage); Def Day30MA2 = Average(close (period = "MONTH") , SlowMovingAverage); def FMA = If PeriodChoice == 1 then Day1MA1 else If PeriodChoice == 2 then Day2MA1 else If PeriodChoice == 3 then Day3MA1 else If PeriodChoice == 4 then Day4MA1 else If PeriodChoice == 7 then Day7MA1 else If PeriodChoice == 30 then Day30MA1 else BarMA1; plot FastMA = if !ShowPlot then Double.NaN else FMA; FastMA.AssignValueColor(if Close > FMA then Color.Green else if Close < FMA then Color.Red else Color.Yellow); AddChartBubble(FastMA && BubblesOn && !IsNaN(close) and IsNaN(close[-1]), FastMA, concat("", FastMovingAverage ), if Close > FMA then Color.Green else if Close < FMA then Color.Red else Color.Yellow); def SMA = If PeriodChoice == 1 then Day1MA2 else If PeriodChoice == 2 then Day2MA2 else If PeriodChoice == 3 then Day3MA2 else If PeriodChoice == 4 then Day4MA2 else If PeriodChoice == 7 then Day7MA2 else If PeriodChoice == 30 then Day30MA2 else BarMA2; plot SlowMA = if !ShowPlot then Double.NaN else SMA; SlowMA.AssignValueColor(if Close > SMA then Color.Green else if Close < SMA then Color.Red else Color.Yellow); AddChartBubble(SlowMA && BubblesOn && !IsNaN(close) and IsNaN(close[-1]), SlowMA, concat("", SlowMovingAverage), if Close > SMA then Color.Green else if Close < SMA then Color.Red else Color.Yellow); #################### def Max = Max(FMA, SMA); def Min = Min(FMA, SMA); def Position = if Close > Max(FMA, SMA) then 2 else if Close < Min(FMA, SMA) then -2 else 0; rec Trend = If Mode == 3 then if Position[1] == 2 && Position[0] <= 0 then -2 else if Position[1] == -2 && Position[0] >= 0 then 2 else if Position[1] == 0 && Position[0] == 2 then 2 else if Position[1] == 0 && Position[0] == -2 then -2 else Trend[1] else If Mode == 1 then if Close > FMA then 2 else -2 else if FMA > SMA then 2 else -2; AssignPriceColor(if !PriceColorOn then Color.Current else If Trend > 0 then Color.Green else Color.Red); rec Point = If Mode == 3 then if Position[1] == 2 && Position[0] <= 0 then Max else if Position[1] == -2 && Position[0] >= 0 then Min else if Position[1] == 0 && Position[0] == 2 then Max else if Position[1] == 0 && Position[0] == -2 then Min else Point[1] else If Mode == 1 then if Close > FMA then Close else Point[1] else if FMA > SMA then Close else Point[1]; plot SignalPoint = If !ShowPoints then Double.NaN else Point; SignalPoint.SetLineWeight(1); SignalPoint.SetPaintingStrategy(PaintingStrategy.Points); SignalPoint.AssignValueColor(If Trend > 0 then Color.Green else Color.Red); # ARROWS ROUTINE # ___ def x_over = Crosses(Trend, 0); plot up = if ShowArrows && x_over && Trend > 0 then Low else Double.NaN; up.SetPaintingStrategy(PaintingStrategy.Arrow_up); up.SetDefaultColor(Color.white); plot dn = if ShowArrows && x_over && Trend < 0 then High else Double.NaN; dn.SetPaintingStrategy(PaintingStrategy.Arrow_down); dn.SetDefaultColor(Color.white); # Vertical Time Lines # ___ def vert = VerticalLinePeriod == VerticalLinePeriod.Day and getDay() <> getDay()[1] or VerticalLinePeriod == VerticalLinePeriod.WEEK and getWeek() <> getWeek()[1] or VerticalLinePeriod == VerticalLinePeriod.MONTH and getMonth() <> getMonth()[1]; AddVerticalLine(VerticalDayBreakLinesOn && Vert, "", if VerticalLinePeriod == VerticalLinePeriod.day then color.cyan else if VerticalLinePeriod == VerticalLinePeriod.week then Color.Magenta else color.Yellow);# SwingTrading_R1V3 # R1V1 2011.06.11.23:00 KumoBob # A very simple method of SwingTrading with Moving average # R1V2 2011.06.13.09:00 KumoBob # Added more periods to AverageMode # R1V3 2011.06.13.15:00 KumoBob # Added hints and other bells an whistles declare upper; #Hint: Three methods are available and provide a very simple method of SwingTrading with Moving Averages. \nThis orignated when I wanted to see what would happen if two moving averages were used on a daily basis with the buy and sell signal always being the highest and lowest of the two averages.\nIt seems to be a fairly good method, but other indicators such as PPS will most likely out perform this method. #Hint FastMovingAverage: Length of FAST average\nDefault = 5 #Hint SlowMovingAverage: Length of SLOW average\nDefault = 13 #Hint Method: Choose to signal when Price crosses the Fast MA\nor\nChoose to signal when the Fast MA crosses the Slow MA\nor\n "Buy at the Lowest MA and Sell at the Highest MA when Price crosses these curves #Hint AverageMode: Choose to average by bar or a selectable time period\nThe choices are DAY, 2 DAYS, 3 DAYS, 4 DAYS, WEEK, and MONTH \nDefault = Day #Hint BubblesOn: Bubbles identify the curve's average length\nDefault = Yes #Hint ShowPoints: Shows the exact point the signal occured\nDefault = Yes #Hint ShowArrows: Shows the signal with an arrow\nDefault = Yes #Hint ShowPlot: Choose to show the curves or hide them #Hint VerticalDayBreakLinesOn: Choose to place Vertical Lines at Day, Week or Month intervals\nDefault = No #Hint VerticalLinePeriod: Specifies the interval to plot vertical lines\nDefault = Day #Hint PriceColorOn: Allows the signal to be seen as Red and Green price bars\nDefault = No input FastMovingAverage = 5; input SlowMovingAverage = 13; Input Method = {"At Fast MA", "MA Cross",Default "Buy at Min MA Sell at Max MA"}; input AverageMode = {"Bar",default DAY, "2 DAYS", "3 DAYS", "4 DAYS", WEEK, MONTH}; input BubblesOn = Yes; input ShowPlot = Yes; input ShowPoints = Yes; input ShowArrows = Yes; Input PriceColorOn = No; def Mode; switch (Method){ case "At Fast MA": Mode = 1; case "MA Cross": Mode = 2; case "Buy at Min MA Sell at Max MA": Mode = 3; } Input VerticalDayBreakLinesOn = No; input VerticalLinePeriod = {default DAY, WEEK, MONTH}; def PeriodChoice; switch (AverageMode){ case "Day": PeriodChoice = 1; case "2 DAYS": PeriodChoice = 2; case "3 DAYS": PeriodChoice = 3; case "4 DAYS": PeriodChoice = 4; case WEEK: PeriodChoice = 7; case MONTH: PeriodChoice = 30; case "Bar": PeriodChoice = 0; } def BarMA1 = Average(close () , FastMovingAverage ); Def Day1MA1 = Average(close (period = "DAY" ), FastMovingAverage ); Def Day2MA1 = Average(close (period = "2 DAYS"), FastMovingAverage ); Def Day3MA1 = Average(close (period = "3 DAYS"), FastMovingAverage ); Def Day4MA1 = Average(close (period = "4 DAYS"), FastMovingAverage ); Def Day7MA1 = Average(close (period = "WEEK" ), FastMovingAverage); Def Day30MA1 = Average(close (period = "MONTH") , FastMovingAverage); def BarMA2 = Average(close () , SlowMovingAverage); Def Day1MA2 = Average(close (period = "DAY" ), SlowMovingAverage); Def Day2MA2 = Average(close (period = "2 DAYS"), SlowMovingAverage); Def Day3MA2 = Average(close (period = "3 DAYS"), SlowMovingAverage); Def Day4MA2 = Average(close (period = "4 DAYS"), SlowMovingAverage); Def Day7MA2 = Average(close (period = "WEEK" ), SlowMovingAverage); Def Day30MA2 = Average(close (period = "MONTH") , SlowMovingAverage); def FMA = If PeriodChoice == 1 then Day1MA1 else If PeriodChoice == 2 then Day2MA1 else If PeriodChoice == 3 then Day3MA1 else If PeriodChoice == 4 then Day4MA1 else If PeriodChoice == 7 then Day7MA1 else If PeriodChoice == 30 then Day30MA1 else BarMA1; plot FastMA = if !ShowPlot then Double.NaN else FMA; FastMA.AssignValueColor(if Close > FMA then Color.Green else if Close < FMA then Color.Red else Color.Yellow); AddChartBubble(FastMA && BubblesOn && !IsNaN(close) and IsNaN(close[-1]), FastMA, concat("", FastMovingAverage ), if Close > FMA then Color.Green else if Close < FMA then Color.Red else Color.Yellow); def SMA = If PeriodChoice == 1 then Day1MA2 else If PeriodChoice == 2 then Day2MA2 else If PeriodChoice == 3 then Day3MA2 else If PeriodChoice == 4 then Day4MA2 else If PeriodChoice == 7 then Day7MA2 else If PeriodChoice == 30 then Day30MA2 else BarMA2; plot SlowMA = if !ShowPlot then Double.NaN else SMA; SlowMA.AssignValueColor(if Close > SMA then Color.Green else if Close < SMA then Color.Red else Color.Yellow); AddChartBubble(SlowMA && BubblesOn && !IsNaN(close) and IsNaN(close[-1]), SlowMA, concat("", SlowMovingAverage), if Close > SMA then Color.Green else if Close < SMA then Color.Red else Color.Yellow); #################### def Max = Max(FMA, SMA); def Min = Min(FMA, SMA); def Position = if Close > Max(FMA, SMA) then 2 else if Close < Min(FMA, SMA) then -2 else 0; rec Trend = If Mode == 3 then if Position[1] == 2 && Position[0] <= 0 then -2 else if Position[1] == -2 && Position[0] >= 0 then 2 else if Position[1] == 0 && Position[0] == 2 then 2 else if Position[1] == 0 && Position[0] == -2 then -2 else Trend[1] else If Mode == 1 then if Close > FMA then 2 else -2 else if FMA > SMA then 2 else -2; AssignPriceColor(if !PriceColorOn then Color.Current else If Trend > 0 then Color.Green else Color.Red); rec Point = If Mode == 3 then if Position[1] == 2 && Position[0] <= 0 then Max else if Position[1] == -2 && Position[0] >= 0 then Min else if Position[1] == 0 && Position[0] == 2 then Max else if Position[1] == 0 && Position[0] == -2 then Min else Point[1] else If Mode == 1 then if Close > FMA then Close else Point[1] else if FMA > SMA then Close else Point[1]; plot SignalPoint = If !ShowPoints then Double.NaN else Point; SignalPoint.SetLineWeight(1); SignalPoint.SetPaintingStrategy(PaintingStrategy.Points); SignalPoint.AssignValueColor(If Trend > 0 then Color.Green else Color.Red); # ARROWS ROUTINE # ___ def x_over = Crosses(Trend, 0); plot up = if ShowArrows && x_over && Trend > 0 then Low else Double.NaN; up.SetPaintingStrategy(PaintingStrategy.Arrow_up); up.SetDefaultColor(Color.white); plot dn = if ShowArrows && x_over && Trend < 0 then High else Double.NaN; dn.SetPaintingStrategy(PaintingStrategy.Arrow_down); dn.SetDefaultColor(Color.white); # Vertical Time Lines # ___ def vert = VerticalLinePeriod == VerticalLinePeriod.Day and getDay() <> getDay()[1] or VerticalLinePeriod == VerticalLinePeriod.WEEK and getWeek() <> getWeek()[1] or VerticalLinePeriod == VerticalLinePeriod.MONTH and getMonth() <> getMonth()[1]; AddVerticalLine(VerticalDayBreakLinesOn && Vert, "", if VerticalLinePeriod == VerticalLinePeriod.day then color.cyan else if VerticalLinePeriod == VerticalLinePeriod.week then Color.Magenta else color.Yellow);
# SwingTrading_R1V3
# R1V1 2011.06.11.23:00 KumoBob
# A very simple method of SwingTrading with Moving average
# R1V2 2011.06.13.09:00 KumoBob
# Added more periods to AverageMode
# R1V3 2011.06.13.15:00 KumoBob
# Added hints and other bells an whistles
declare upper;
#Hint: Three methods are available and provide a very simple method of SwingTrading with Moving Averages. \nThis orignated when I wanted to see what would happen if two moving averages were used on a daily basis with the buy and sell signal always being the highest and lowest of the two averages.\nIt seems to be a fairly good method, but other indicators such as PPS will most likely out perform this method.
#Hint FastMovingAverage: Length of FAST average\nDefault = 5
#Hint SlowMovingAverage: Length of SLOW average\nDefault = 13
#Hint Method: Choose to signal when Price crosses the Fast MA\nor\nChoose to signal when the Fast MA crosses the Slow MA\nor\n "Buy at the Lowest MA and Sell at the Highest MA when Price crosses these curves
#Hint AverageMode: Choose to average by bar or a selectable time period\nThe choices are DAY, 2 DAYS, 3 DAYS, 4 DAYS, WEEK, and MONTH \nDefault = Day
#Hint BubblesOn: Bubbles identify the curve's average length\nDefault = Yes
#Hint ShowPoints: Shows the exact point the signal occured\nDefault = Yes
#Hint ShowArrows: Shows the signal with an arrow\nDefault = Yes
#Hint ShowPlot: Choose to show the curves or hide them
#Hint VerticalDayBreakLinesOn: Choose to place Vertical Lines at Day, Week or Month intervals\nDefault = No
#Hint VerticalLinePeriod: Specifies the interval to plot vertical lines\nDefault = Day
#Hint PriceColorOn: Allows the signal to be seen as Red and Green price bars\nDefault = No
input FastMovingAverage = 5;
input SlowMovingAverage = 13;
Input Method = {"At Fast MA", "MA Cross",Default "Buy at Min MA Sell at Max MA"};
input AverageMode = {"Bar",default DAY, "2 DAYS", "3 DAYS", "4 DAYS", WEEK, MONTH};
input BubblesOn = Yes;
input ShowPlot = Yes;
input ShowPoints = Yes;
input ShowArrows = Yes;
Input PriceColorOn = No;
def Mode;
switch (Method){
case "At Fast MA":
Mode = 1;
case "MA Cross":
Mode = 2;
case "Buy at Min MA Sell at Max MA":
Mode = 3;
}
def PeriodChoice;
switch (AverageMode){
case "Day":
PeriodChoice = 1;
case "2 DAYS":
PeriodChoice = 2;
case "3 DAYS":
PeriodChoice = 3;
case "4 DAYS":
PeriodChoice = 4;
case WEEK:
PeriodChoice = 7;
case MONTH:
PeriodChoice = 30;
case "Bar":
PeriodChoice = 0;
}
def BarMA1 = Average(close () , FastMovingAverage );
Def Day1MA1 = Average(close (period = "DAY" ), FastMovingAverage );
Def Day2MA1 = Average(close (period = "2 DAYS"), FastMovingAverage );
Def Day3MA1 = Average(close (period = "3 DAYS"), FastMovingAverage );
Def Day4MA1 = Average(close (period = "4 DAYS"), FastMovingAverage );
Def Day7MA1 = Average(close (period = "WEEK" ), FastMovingAverage);
Def Day30MA1 = Average(close (period = "MONTH") , FastMovingAverage);
def BarMA2 = Average(close () , SlowMovingAverage);
Def Day1MA2 = Average(close (period = "DAY" ), SlowMovingAverage);
Def Day2MA2 = Average(close (period = "2 DAYS"), SlowMovingAverage);
Def Day3MA2 = Average(close (period = "3 DAYS"), SlowMovingAverage);
Def Day4MA2 = Average(close (period = "4 DAYS"), SlowMovingAverage);
Def Day7MA2 = Average(close (period = "WEEK" ), SlowMovingAverage);
Def Day30MA2 = Average(close (period = "MONTH") , SlowMovingAverage);
def FMA =
If PeriodChoice == 1 then Day1MA1 else
If PeriodChoice == 2 then Day2MA1 else
If PeriodChoice == 3 then Day3MA1 else
If PeriodChoice == 4 then Day4MA1 else
If PeriodChoice == 7 then Day7MA1 else
If PeriodChoice == 30 then Day30MA1 else BarMA1;
plot FastMA = if !ShowPlot then Double.NaN else FMA;
FastMA.AssignValueColor(if Close > FMA then Color.Green else if Close < FMA then Color.Red else Color.Yellow); AddChartBubble(FastMA && BubblesOn && !IsNaN(close) and IsNaN(close[-1]), FastMA, concat("", FastMovingAverage ), if Close > FMA then Color.Green else if Close < FMA then Color.Red else Color.Yellow); def SMA = If PeriodChoice == 1 then Day1MA2 else If PeriodChoice == 2 then Day2MA2 else If PeriodChoice == 3 then Day3MA2 else If PeriodChoice == 4 then Day4MA2 else If PeriodChoice == 7 then Day7MA2 else If PeriodChoice == 30 then Day30MA2 else BarMA2; plot SlowMA = if !ShowPlot then Double.NaN else SMA; SlowMA.AssignValueColor(if Close > SMA then Color.Green else if Close < SMA then Color.Red else Color.Yellow); AddChartBubble(SlowMA && BubblesOn && !IsNaN(close) and IsNaN(close[-1]), SlowMA, concat("", SlowMovingAverage), if Close > SMA then Color.Green else if Close < SMA then Color.Red else Color.Yellow); def Max = Max(FMA, SMA); def Min = Min(FMA, SMA); def Position = if Close > Max(FMA, SMA) then 2 else if Close < Min(FMA, SMA) then -2 else 0; rec Trend = If Mode == 3 then if Position[1] == 2 && Position[0] <= 0 then -2 else if Position[1] == -2 && Position[0] >= 0 then 2 else
if Position[1] == 0 && Position[0] == 2 then 2 else
if Position[1] == 0 && Position[0] == -2 then -2 else Trend[1]
else If Mode == 1 then if Close > FMA then 2 else -2
else if FMA > SMA then 2 else -2;
AssignPriceColor(if !PriceColorOn then Color.Current else If Trend > 0 then Color.Green else Color.Red);
rec Point = If Mode == 3 then
if Position[1] == 2 && Position[0] <= 0 then Max else if Position[1] == -2 && Position[0] >= 0 then Min else
if Position[1] == 0 && Position[0] == 2 then Max else
if Position[1] == 0 && Position[0] == -2 then Min else Point[1]
else If Mode == 1 then if Close > FMA then Close else Point[1]
else if FMA > SMA then Close else Point[1];
plot SignalPoint = If !ShowPoints then Double.NaN else Point;
SignalPoint.SetLineWeight(1);
SignalPoint.SetPaintingStrategy(PaintingStrategy.Points);
SignalPoint.AssignValueColor(If Trend > 0 then Color.Green else Color.Red);
# ARROWS ROUTINE
# ___
def x_over = Crosses(Trend, 0);
plot up = if ShowArrows && x_over && Trend > 0 then Low else Double.NaN;
up.SetPaintingStrategy(PaintingStrategy.Arrow_up);
up.SetDefaultColor(Color.white);
plot dn = if ShowArrows && x_over && Trend < 0 then High else Double.NaN; dn.SetPaintingStrategy(PaintingStrategy.Arrow_down); dn.SetDefaultColor(Color.white);
# MTF Moving Average
input Period = AggregationPeriod.HOUR;
input AvgType = AverageType.EXPONENTIAL;
input Length = 50;
input priceclose = close;
plot AVG = MovingAverage(AvgType, close(period = Period), Length);
AVG.setdefaultcolor(color.yellow);
AVG.AssignValueColor(if AVG > AVG[1] then Color.GREEN else Color.RED);
Is this possible on thinkorswim maybe someone has posted the code already on here?
For example... 5min moving avg on a 1min chart... If anyone can help that would be nice![]()
# MTF Moving Average
input Period = AggregationPeriod.FIFTEEN_MIN;
input AvgType = AverageType.HULL;
input Length = 20;
input priceclose = close;
plot AVG = MovingAverage(AvgType, close(period = Period), Length);
AVG.SetDefaultColor(Color.YELLOW);
def sState2 = if AVG > AVG[1] then 100 else -100;
AVG.AssignValueColor(if sState2 == 100 then Color.MAGENTA else Color.CYAN);
AVG.SetLineWeight(2);
One of the coding savants here might have a different answer but if nothing else this is where you can just set up a flexible grid with the same stock in both charts, set up the first using the 10 minute chart and the other with the time frame of the moving average you want. Then click the synchronize crosshairs in the settings box. It will show you in both time frames where you are sitting in relation to that MA.I want to apply a moving average from a much higher timeframe onto a 10 minute chart however ToS won't allow a moving average greater than 2000. Is there anyway to bypass this restriction?
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.