Does Order Matter?

a1cturner

Well-known member
Does order matter when defining studies? Does timeframe matter? For example: def MACD = if MACDDiff1Min > 0 and MACDDiff10Min > 0 then 1 else 0; Does it matter if I put all my 1 minute studies before the 10 minute studies etc? Does the type of study matter? For Example: def Study = if 5EMA > 12 EMA and MACDDiff > 0 and RSI > 70 then 1 else 0; Do certain types of studies need to go first?

I'm sure this sounds like a dumb question but I am working on a study and everything works great except one parameter. I am trying to paint the candles green if I get a "buy signal" but only if VIX EMA is Bearish and vice versa to paint them red if I get a sell signal and VIX EMA is bullish. I still want to see the buy and sell signals but want to be aware if VIX is trending in the wrong direction so I want to paint those candles orange if I get a buy signal and VIX is trending up and vice versa if I get a sell signal and VIX is trending down.

The VIX comparison works perfect by itself but is not working when I pair it with the other indicators.

Before you ask, yes I am aware of repainting.

This is what I have. I get the green, red, cyan, and grey candles but never an orange candle.

FYI the only 1 minute indicator is the TSIShort in the study below.

Code:
#BUY CALL and PUT
def BuyCallTimeRest = StartDay and EndSignal;
def BuyCall1Min = TSIShort>0;
def BuyCall10Min = EMA1>EMA2 and EMA3>EMA4 and MACDDiff>=MACDDiff[1];
def BuyCall = BuyCallTimeRest and BuyCall1Min and BuyCall10Min and CompareEMA1<CompareEMA2;

def BuyPutTimeRest = StartDay and EndSignal;
def BuyPut1Min = TSIShort<0;
def BuyPut10Min = EMA1<EMA2 and EMA3<EMA4 and MACDDiff<=MACDDiff[1];
def BuyPut = BuyPutTimeRest and BuyPut1Min and BuyPut10Min and CompareEMA1>CompareEMA2;

#BUY CALL and PUT
def BuyCallXTimeRest = StartDay and EndSignal;
def BuyCallX1Min = TSIShort>0;
def BuyCallX10Min = EMA1>EMA2 and EMA3>EMA4 and MACDDiff>=0 and CompareEMA1>CompareEMA2;
def BuyCallX = BuyCallTimeRest and BuyCall1Min and BuyCall10Min;

def BuyPutXTimeRest = StartDay and EndSignal;
def BuyPutX1Min = TSIShort<0;
def BuyPutX10Min = EMA1<EMA2 and EMA3<EMA4 and MACDDiff<=0 and CompareEMA1<CompareEMA2;
def BuyPutX = BuyPutTimeRest and BuyPut1Min and BuyPut10Min;

#SELL CALL AND PUT
def SellCallTimeRest = StartDay and EndStop;
def SellCall1Min = TSIShort crosses below 0;
def SellCall10Min = MACDDiff crosses below MACDDiff[1];
def SellCall = SellCallTimeRest and SellCall1Min or SellCall10Min;

def SellPutTimeRest = StartDay and EndStop;
def SellPut1Min = TSIShort crosses above 0;
def SellPut10Min = MACDDiff crosses below MACDDiff[1];
def SellPut = SellPutTimeRest and SellPut1Min or SellPut10Min;

AssignPriceColor(if BuyCall then color.dark_green else if BuyCallX then color.orange else if BuyPut then color.dark_red else if BuyPutX then color.orange else if SellPut or SellCall then color.cyan else color.gray);
 
Last edited:
Solution
Does order matter when defining studies? Does timeframe matter? For example: def MACD = if MACDDiff1Min > 0 and MACDDiff10Min > 0 then 1 else 0; Does it matter if I put all my 1 minute studies before the 10 minute studies etc? Does the type of study matter? For Example: def Study = if 5EMA > 12 EMA and MACDDiff > 0 and RSI > 70 then 1 else 0; Do certain types of studies need to go first?

I'm sure this sounds like a dumb question but I am working on a study and everything works great except one parameter. I am trying to paint the candles green if I get a "buy signal" but only if VIX EMA is Bearish and vice versa to paint them red if I get a sell signal and VIX EMA is bullish. I still want to see the buy and sell signals but want to...
Does order matter when defining studies? Does timeframe matter? For example: def MACD = if MACDDiff1Min > 0 and MACDDiff10Min > 0 then 1 else 0; Does it matter if I put all my 1 minute studies before the 10 minute studies etc? Does the type of study matter? For Example: def Study = if 5EMA > 12 EMA and MACDDiff > 0 and RSI > 70 then 1 else 0; Do certain types of studies need to go first?

I'm sure this sounds like a dumb question but I am working on a study and everything works great except one parameter. I am trying to paint the candles green if I get a "buy signal" but only if VIX EMA is Bearish and vice versa to paint them red if I get a sell signal and VIX EMA is bullish. I still want to see the buy and sell signals but want to be aware if VIX is trending in the wrong direction so I want to paint those candles orange if I get a buy signal and VIX is trending up and vice versa if I get a sell signal and VIX is trending down.

The VIX comparison works perfect by itself but is not working when I pair it with the other indicators.

Before you ask, yes I am aware of repainting.

This is what I have. I get the green, red, cyan, and grey candles but never an orange candle.

FYI the only 1 minute indicator is the TSIShort in the study below.

Code:
#BUY CALL and PUT
def BuyCallTimeRest = StartDay and EndSignal;
def BuyCall1Min = TSIShort>0;
def BuyCall10Min = EMA1>EMA2 and EMA3>EMA4 and MACDDiff>=MACDDiff[1];
def BuyCall = BuyCallTimeRest and BuyCall1Min and BuyCall10Min and CompareEMA1<CompareEMA2;

def BuyPutTimeRest = StartDay and EndSignal;
def BuyPut1Min = TSIShort<0;
def BuyPut10Min = EMA1<EMA2 and EMA3<EMA4 and MACDDiff<=MACDDiff[1];
def BuyPut = BuyPutTimeRest and BuyPut1Min and BuyPut10Min and CompareEMA1>CompareEMA2;

#BUY CALL and PUT
def BuyCallXTimeRest = StartDay and EndSignal;
def BuyCallX1Min = TSIShort>0;
def BuyCallX10Min = EMA1>EMA2 and EMA3>EMA4 and MACDDiff>=0 and CompareEMA1>CompareEMA2;
def BuyCallX = BuyCallTimeRest and BuyCall1Min and BuyCall10Min;

def BuyPutXTimeRest = StartDay and EndSignal;
def BuyPutX1Min = TSIShort<0;
def BuyPutX10Min = EMA1<EMA2 and EMA3<EMA4 and MACDDiff<=0 and CompareEMA1<CompareEMA2;
def BuyPutX = BuyPutTimeRest and BuyPut1Min and BuyPut10Min;

#SELL CALL AND PUT
def SellCallTimeRest = StartDay and EndStop;
def SellCall1Min = TSIShort crosses below 0;
def SellCall10Min = MACDDiff crosses below MACDDiff[1];
def SellCall = SellCallTimeRest and SellCall1Min or SellCall10Min;

def SellPutTimeRest = StartDay and EndStop;
def SellPut1Min = TSIShort crosses above 0;
def SellPut10Min = MACDDiff crosses below MACDDiff[1];
def SellPut = SellPutTimeRest and SellPut1Min or SellPut10Min;

AssignPriceColor(if BuyCall then color.dark_green else if BuyCallX then color.orange else if BuyPut then color.dark_red else if BuyPutX then color.orange else if SellPut or SellCall then color.cyan else color.gray);

i don't think the order matters,
BUT it can cause issues when conditions of different time frames are put into 1 formula.

def MACD = if MACDDiff1Min > 0 and MACDDiff10Min > 0 then 1 else 0;

try separating all conditions, that use 2nd agg, into their own formulas. then combine their output variables.

def diff1min = if MACDDiff1Min > 0 then 1 else 0;
def diff10min = if macDDiff10Min > 0 then 1 else 0;
def MACD = if diff1min and diff10min then 1 else 0;
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
376 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

What are the benefits of VIP Membership?
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.
Back
Top