Multi time-frame chart labels on 5 min chart


Category:
0
0

Hello,

I am trying to add chart labels for multiple time-frame(15 min, 30 min, hour) on a 5 minute chart. The labels appear only for 5 min and 15 min after I comment out the code for 30 min and 1 hour. If I do not comment out the code for 30 min and 1 hour then it does not even show labels for 5 min and 15 min. Please see attachment for details. I have the following code.

#5 min chart
input Period5 = aggregationPeriod.FIVE_MIN;
def GreenCandle5 = Close(period = Period5) > Open(period = Period5);
AddLabel(yes, “X5” , ( if GreenCandle5 == 1 then color.CYAN else color.YELLOW) );
AddLabel(yes, “||”, Color.VIOLET);

#15 min chart
input Period15 = aggregationPeriod.FIFTEEN_MIN;
def GreenCandle15 = Close(period = Period15) > Open(period = Period15);
AddLabel(yes, “X15” , ( if GreenCandle15 == 1 then color.CYAN else color.YELLOW) );
AddLabel(yes, “||”, Color.VIOLET);

#30 min chart
#input Period30 = aggregationPeriod.THIRTY_MIN;
#def GreenCandle30 = Close(period = Period30) > Open(period #= Period30);
#AddLabel(yes, “X30” , ( if GreenCandle30 == 1 then color.#CYAN else color.YELLOW) );
#AddLabel(yes, “||”, Color.VIOLET);

#1 Hour chart
#input Periodhour = aggregationPeriod.HOUR;
#def GreenCandlehour = Close(period = Periodhour) > Open(period = Periodhour);
#AddLabel(yes, “XHour” , ( if GreenCandlehour == 1 then #color.CYAN else color.YELLOW) );
#AddLabel(yes, “||”, Color.VIOLET);

Attachments:
Marked as spam
Posted by (Questions: 7, Answers: 8)
Asked on October 24, 2018 1:55 pm
634 views
0
Private answer

I tested this as thoroughly as I could and you are correct. I could not find a cause. I did find that it’s only the thirty min time frame causing the error. You can substitute “AggregationPeriod.FIFTEEN_MIN” in place of “AggregationPeriod.THIRTY_MIN” and the hourly label will work.

When chart studies do not plot, be sure to check the upper left hand corner for an error message. See attached screenshots for detail. There is an exclamation mark inside a circle. Click that whenever you see to get a list of problems generated for that chart.

In this case it tells us that “Two different secondary periods cannot be used within a signal variable”. However it is perfectly clear you code does NOT break this rule. The platform is misinterpreting things.

I recommend you submit this to TDA support for analysis.

In your code there are some minor issues with style. You have gotten the capitalization rules backwards. User defined inputs and variables should always begin with lowercase. System constants and methods should always begin with a capital letter. The data objects for chart data always begin with a lowercase letter (open, high, low, close, volume). Whenever you are not sure just look at the examples provided by Thinkorswim in their language reference: http://toslc.thinkorswim.com/center/reference/thinkScript/Constants/AggregationPeriod/AggregationPeriod-FIFTEEN-MIN.html

Here is a cleaned up version of your code that corrects all of these style issues:


input period5 = AggregationPeriod.FIVE_MIN;
input period15 = AggregationPeriod.FIFTEEN_MIN;
input period30 = AggregationPeriod.THIRTY_MIN;
input periodHour = AggregationPeriod.HOUR;
#5 min chart
def greenCandle5 = close(period = period5) > open(period = period5);
AddLabel(yes, “X5”, if greenCandle5 then color.CYAN else color.YELLOW);
AddLabel(yes, “||”, color.VIOLET);
#15 min chart
def greenCandle15 = close(period = period15) > open(period = period15);
AddLabel(yes, “X15”, if greenCandle15 then color.CYAN else color.YELLOW);
AddLabel(yes, “||”, color.VIOLET);
#30 min chart
def greenCandle30 = close(period = period30) > open(period = period30);
AddLabel(yes, “X30”, if greenCandle30 then color.CYAN else color.YELLOW);
AddLabel(yes, “||”, color.VIOLET);
#1 Hour chart
def greenCandlehour = close(period = periodHour) > open(period = periodHour);
AddLabel(yes, “XHour”, if greenCandlehour then color.CYAN else color.YELLOW);
AddLabel(yes, “||”, color.VIOLET);

In closing I will leave you with a few more tips. Always place your inputs at the very top of your code, grouped together as you see here. When testing if a variable is true, there is no need to use “= 1”. Notice that I only need to say: if greenCandle5and I did not need to say: if greenCandle5 = 1

Those changes don’t make the code work. But it makes it easier to read and maintain. It’s something in the platforum that is broken. The code should work fine.

Good luck!

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on October 24, 2018 2:54 pm
0

Thanks a lot for looking into it! I have the code as below that you suggested but no labels appear after I add the code for hourly time frame.

input period5 = AggregationPeriod.FIVE_MIN;
input period15 = AggregationPeriod.FIFTEEN_MIN;
input periodHour = AggregationPeriod.HOUR;

#5 min chart
def greenCandle5 = close(period = period5) > open(period = period5);
AddLabel(yes, “X5”, if greenCandle5 then color.CYAN else color.YELLOW);
AddLabel(yes, “||”, color.VIOLET);

#15 min chart
def greenCandle15 = close(period = period15) > open(period = period15);
AddLabel(yes, “X15”, if greenCandle15 then color.CYAN else color.YELLOW);
AddLabel(yes, “||”, color.VIOLET);

#1 Hour chart
def greenCandlehour = close(period = periodHour) > open(period = periodHour);
AddLabel(yes, “XHour”, if greenCandlehour then color.CYAN else color.YELLOW);
AddLabel(yes, “||”, color.VIOLET);

( at October 25, 2018 9:04 am)
0

I did not indicate the changes to the code would make it work. In fact I explicitly stated that these changes would NOT make it work.

Quote: “Those changes don’t make the code work.”

The changes I made were to correct errors in your style of coding. This is so that you can submit this to Thinkorswim and the developers that assist you will see that you have VERY clean code.

I also clarified the source of the problem: “It’s something in the platform that is broken. The code should work fine.”

This means that the problem is inside the platform itself. There is nothing wrong with that code. It should work but does not. Which means the problem is inside the platform itself. Your only course of action here is to submit this to Thinkorswim support.

( at October 25, 2018 10:16 am)
0

And yes, I did notice you tried to apply this without including the 30 min time frame label. Yesterday it was working when I included the 1 hour time frame. Today it is not. This only further confirm something inside Thinkorswim is broken.

( at October 25, 2018 10:34 am)
0

Thank you! I have sent the code to TDA support as to why it’s not working as expected.

( at October 26, 2018 7:42 am)