Hi I'm building a script in another study to reference the near-term and momentum lines within Market Forecast. Within the larger study their positions (crossed over 40 in last bar, above last bar) help determine the color of a different moving average. I want the aggregation period referenced for both Market Forecast lines to in one of two states depending on the aggregation period being used. If the aggregation period is lower than Day, I want the line referenced to be the 2 hour. If the chart is day or higher I want the line to be whatever period is being used. I am lost.. I'm sure there's a really easy way to do this but I can't figure it out, I'm just too inexperienced can someone help please? This is what I have so far for the nested code.. I didn’t want to paste the whole thing because it’s so long so if anything else is needed please let me know.
Cheers, Misty
thank you, this second aggregation logic is very helpful for the future, even though I can't use it on MarketForecast. Too bad the authors won't fess up lol, maybe I wouldn't either. I'm going through the ADR part of the painting strategy and try to set a new variable for when ADRunder/ADRover is true/false and when either is true, place a dot under the tema line. here is what I have, I appreciate any feedback I know I must be doing this wrong because there's a dot under every bar! Thank you so much for your feedback, I appreciate it! Misty
This is some of the other script where these lines are colored.. if there's an easy way to just adjust it from there that would be even better Thanks for any help! Misty
Code:
input Tema_BVlength = 4;
plot TEMA_BV = TEMA(BaseBuyAvg, Tema_BVlength);
TEMA_BV.SetPaintingStrategy(PaintingStrategy.LINE);
TEMA_BV.AssignValueColor(
if ADRover > ADRunder and ADRover[1] < ADRunder[1] then Color.GREEN
else if MarketForecast().NearTerm > MarketForecast().NearTerm[1] and MarketForecast().NearTerm[1] < 40 and MarketForecast().NearTerm > 40 then Color.YELLOW else Color.DARK_GREEN);
TEMA_BV.SetLineWeight(3);
#TEMA_BV.SetDefaultColor(Color.BLUE);
input Tema_SVlength = 4;
plot TEMA_SV = TEMA(BaseSellAvg, Tema_SVlength);
TEMA_SV.SetPaintingStrategy(PaintingStrategy.LINE);
TEMA_SV.AssignValueColor(
if ADRover < ADRunder and ADRover[1] > ADRunder[1] then Color.RED
else if MarketForecast().NearTerm < MarketForecast().NearTerm[1] and MarketForecast().NearTerm[1] > 40 and MarketForecast().NearTerm < 40 then Color.DARK_ORANGE else Color.DARK_RED);
TEMA_SV.SetLineWeight(3);
If I'm understanding, you want it to aggregate 2 hours for intraday charts, and then for the daily charts, you want to aggregate it with whatever aggregation period is on the chart?
The issue is that the getaggregationPeriod() returns a number, so you can't compare it to aggregationperiod.Four_Hours.
If I'm understanding, you want it to aggregate 2 hours for intraday charts, and then for the daily charts, you want to aggregate it with whatever aggregation period is on the chart?
The issue is that the getaggregationPeriod() returns a number, so you can't compare it to aggregationperiod.Four_Hours.
If I'm understanding, you want it to aggregate 2 hours for intraday charts, and then for the daily charts, you want to aggregate it with whatever aggregation period is on the chart?
The issue is that the getaggregationPeriod() returns a number, so you can't compare it to aggregationperiod.Four_Hours.
Thank you for the input! That's correct, for intraday, I would like the market forecast operators to aggregate on the two hour time frame, but revert to usual on all higher time frames. This is how I changed the code so far, but I can't figure out how to link the referenced studies to the defined variable for the period "test".. also below that is where I'm trying to have them color an average.. I'm unsure how to proceed to make them work with eachother and how to instruct it to define the period properly- "plot momoDay = MFMomentumDAY (period=close_test); returns no such function.. thanks for any help, I'm a real newbie!
Misty
Code:
#############################################################
def aP2 = AggregationPeriod.TWO_HOURS;
def aPD = GetAggregationPeriod();
def currentPeriod = GetAggregationPeriod();
def agg = if currentPeriod < 14400000 then AggregationPeriod.TWO_HOURS else currentPeriod;
def close_test = close(period = agg);
#def close_aPD = close(period = aPD);
def MFMomentumDAY = MarketForecast().Momentum;
def MFNearTerm = reference MarketForecast().NearTerm;
plot momoDay = MFMomentumDAY (period=close_test);
############################################################
#####################################################################
####### Tema on 2 period EMA of Buying and Selling Volume############
input Tema_BVlength = 4;
plot TEMA_BV = TEMA(BaseBuyAvg, Tema_BVlength);
TEMA_BV.SetPaintingStrategy(PaintingStrategy.LINE);
TEMA_BV.AssignValueColor(
if ADRover > ADRunder and ADRover[1] < ADRunder[1] then Color.GREEN
else if MarketForecast().NearTerm > MarketForecast().NearTerm[1] and MarketForecast().NearTerm[1] < 40 and MarketForecast().NearTerm > 40 then Color.YELLOW else Color.DARK_GREEN);
TEMA_BV.SetLineWeight(3);
#TEMA_BV.SetDefaultColor(Color.BLUE);
input Tema_SVlength = 4;
plot TEMA_SV = TEMA(BaseSellAvg, Tema_SVlength);
TEMA_SV.SetPaintingStrategy(PaintingStrategy.LINE);
TEMA_SV.AssignValueColor(
if ADRover < ADRunder and ADRover[1] > ADRunder[1] then Color.RED
else if MarketForecast().NearTerm < MarketForecast().NearTerm[1] and MarketForecast().NearTerm[1] > 40 and MarketForecast().NearTerm < 40 then Color.DARK_ORANGE else Color.DARK_RED);
TEMA_SV.SetLineWeight(3);
####################################################################################
Hi I'm building a script in another study to reference the near-term and momentum lines within Market Forecast. Within the larger study their positions (crossed over 40 in last bar, above last bar) help determine the color of a different moving average. I want the aggregation period referenced for both Market Forecast lines to in one of two states depending on the aggregation period being used. If the aggregation period is lower than Day, I want the line referenced to be the 2 hour. If the chart is day or higher I want the line to be whatever period is being used. I am lost.. I'm sure there's a really easy way to do this but I can't figure it out, I'm just too inexperienced can someone help please? This is what I have so far for the nested code.. I didn’t want to paste the whole thing because it’s so long so if anything else is needed please let me know.
Cheers, Misty
my comments are to help you learn. keep asking questions.
referencing post #1
not sure what you are trying to do.
you can't change the aggregation time for MarketForecast. there aren't any input parameters for it.
the code for it is hidden, so we can't copy it and modify it. https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/M-N/MarketForecast
if you can find another study that mimics what marketforecast does, maybe 2nd agg could be applied to it.
..cant define 2nd aggregation in a script
..there are 2 vars set to same thing, GetAggregationPeriod()
..ref external data in a script, might be redundant , slow. ref it once in main script, then pass on values to script
..the variable being assigned a value from an if-then, doesn't go inside of it. it is put at the start of the expression.
def MFMomentum = if x then y else if k then z else t;
..if you want data from a 2nd aggregation, you need to set the 2nd agg within a price function. then put the price funtion inside of the desired function , like close(). unfortunetely , can't use 2nd agg on MarketForecast().
i would rewrite these rules
. If the aggregation period is lower than Day,
. I want the line referenced to be the 2 hour.
. If the chart is day or higher,
. I want the line to be whatever period is being used.
to look like this
. if the chart agg < day then 2 hour
. if the chart agg >= day then chartagg
then try to create codes for them
Code:
# example code
# ----------------------------------
# get agg of the chart
def chartagg = GetAggregationPeriod();
def chartmin = (chartagg / 1000) / 60;
# use an input to set a variable to desired agg when chart agg is < day
input lowagg = AggregationPeriod.two_hours;
# compare chart agg to day
def lineagg2 = If chartagg < AggregationPeriod.day then lowagg else chartagg;
# calc minutes of the agg
def lineaggmin = (lineagg2/60000);
# example , get price from an agg time
def test1 = open(period = lineagg2);
addlabel(1, "close: " + test1 + " agg: " + lineagg2 + " aggmin: " + lineaggmin, color.yellow);
i left 2nd aggregation formulas in this, although they aren't used
Thank you for the input! That's correct, for intraday, I would like the market forecast operators to aggregate on the two hour time frame, but revert to usual on all higher time frames. This is how I changed the code so far, but I can't figure out how to link the referenced studies to the defined variable for the period "test".. also below that is where I'm trying to have them color an average.. I'm unsure how to proceed to make them work with eachother and how to instruct it to define the period properly- "plot momoDay = MFMomentumDAY (period=close_test); returns no such function.. thanks for any help, I'm a real newbie!
Misty
Code:
#############################################################
def aP2 = AggregationPeriod.TWO_HOURS;
def aPD = GetAggregationPeriod();
def currentPeriod = GetAggregationPeriod();
def agg = if currentPeriod < 14400000 then AggregationPeriod.TWO_HOURS else currentPeriod;
def close_test = close(period = agg);
#def close_aPD = close(period = aPD);
def MFMomentumDAY = MarketForecast().Momentum;
def MFNearTerm = reference MarketForecast().NearTerm;
plot momoDay = MFMomentumDAY (period=close_test);
############################################################
#####################################################################
####### Tema on 2 period EMA of Buying and Selling Volume############
input Tema_BVlength = 4;
plot TEMA_BV = TEMA(BaseBuyAvg, Tema_BVlength);
TEMA_BV.SetPaintingStrategy(PaintingStrategy.LINE);
TEMA_BV.AssignValueColor(
if ADRover > ADRunder and ADRover[1] < ADRunder[1] then Color.GREEN
else if MarketForecast().NearTerm > MarketForecast().NearTerm[1] and MarketForecast().NearTerm[1] < 40 and MarketForecast().NearTerm > 40 then Color.YELLOW else Color.DARK_GREEN);
TEMA_BV.SetLineWeight(3);
#TEMA_BV.SetDefaultColor(Color.BLUE);
input Tema_SVlength = 4;
plot TEMA_SV = TEMA(BaseSellAvg, Tema_SVlength);
TEMA_SV.SetPaintingStrategy(PaintingStrategy.LINE);
TEMA_SV.AssignValueColor(
if ADRover < ADRunder and ADRover[1] > ADRunder[1] then Color.RED
else if MarketForecast().NearTerm < MarketForecast().NearTerm[1] and MarketForecast().NearTerm[1] > 40 and MarketForecast().NearTerm < 40 then Color.DARK_ORANGE else Color.DARK_RED);
TEMA_SV.SetLineWeight(3);
####################################################################################
your code is missing a couple of variables.
i set them = to a couple of averages, just to get something to plot.
regarding the plot color formula, i would pull out marketforecast and set it to a variable before the plot. that will minimize how many times the script makes external references, and make it easier to read.
Code:
def ADRover = average(close, 22);
def ADRunder = average(close, 44);
def mrk_n = MarketForecast().NearTerm;
input Tema_BVlength = 4;
#plot TEMA_BV = TEMA(BaseBuyAvg, Tema_BVlength);
plot TEMA_BV = TEMA(close, Tema_BVlength);
TEMA_BV.SetPaintingStrategy(PaintingStrategy.LINE);
TEMA_BV.SetLineWeight(3);
# TEMA_BV.AssignValueColor(
# if ADRover > ADRunder and ADRover[1] < ADRunder[1] then Color.GREEN else if MarketForecast().NearTerm > MarketForecast().NearTerm[1] and MarketForecast().NearTerm[1] < 40 and MarketForecast().NearTerm > 40 then Color.YELLOW else Color.DARK_GREEN);
TEMA_BV.AssignValueColor(
if ADRover > ADRunder and ADRover[1] < ADRunder[1] then Color.GREEN
else if mrk_n > Mrk_n[1] and mrk_n[1] < 40 and mrk_n > 40 then Color.YELLOW
else Color.DARK_GREEN);
thank you, this second aggregation logic is very helpful for the future, even though I can't use it on MarketForecast. Too bad the authors won't fess up lol, maybe I wouldn't either. I'm going through the ADR part of the painting strategy and try to set a new variable for when ADRunder/ADRover is true/false and when either is true, place a dot under the tema line. here is what I have, I appreciate any feedback I know I must be doing this wrong because there's a dot under every bar! Thank you so much for your feedback, I appreciate it! Misty
also, I'll take a look at your code thank you for rewriting some of my adr stuff, I had some plots for the adr info, it was from a seperate script but since it was custom I couldn't reference it into this code so I smooshed it into the top of this study. ADRover and ADRunder are the percent "ADR%" are over average ADR% (20 length, Day)
its a work in progress but I'm leaving it for now.. I'll leave it up for a while but don't want to share too loudly, I think it's my best tool I don't need anything else for volume really
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.
How do I get started?
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.
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.