Specific Time Colored Candle


Category:
0
0

Hi Pete,

I have the following code which makes 2PM-230PM Candles yellow. My purpose is to see the candles between 2-230PM with specific color which is fulfilled when I am on 15 and 30 TF but not in lower than 15min TF. Another thing is I want to also see the 730-800AM candles with a specific color in 1 to 30 min TFs.

2-I tried to add two studies with two different times (2-230 &730-800) but I am getting error ” multiple studies are trying to manipulate color of the same bar” Your help is appreciated.

input OpenTime = 1400;
input Durationmin = 15;

def secondsPassed = secondsFromTime(OpenTime);
def durationSec = Durationmin * 60;

def CandleBlue = secondsPassed >= 0 and secondsPassed <= durationSec;

AssignPriceColor(if candleblue then color.yelloW else color.CURRENT);

Marked as spam
Posted by (Questions: 49, Answers: 62)
Asked on September 22, 2019 12:00 am
154 views
0
I am moving this question out of the "Frequently Asked Questions" topic and into the "Chart Studies" topic.
( at September 22, 2019 8:23 am)
0
Private answer

So you have two hurdles here. One is that you found you cannot add two different chart studies that each try to color the candles. So you need to combine them into a signal study. There is no way around that.

The second hurdle is that you only want the candles colored when specific time frames are selected on the chart. For this, you add a line of code that checks the currently selected time frame on the chart and compares that to your targeted time frame.

For example, this line of code creates a variable named restrictTimeFrames. It gets the currently selected time frame on the chart and checks if it is equal to 15 min or 30 min.

def restrictTimeFrames = GetAggregationPeriod() == AggregationPeriod.FIFTEEN_MIN or GetAggregationPeriod() == AggregationPeriod.THIRTY_MIN;

This is a true/false result that can be added to your statement that applies the candle colors:

AssignPriceColor(if restrictTimeFrames and candleBlue then color.YELLOW else color.CURRENT);

For the other scenario, where you want it to only work for the 1 min through the 30 time frame. You will do something very similar, but in order to cover a wider range of time frames we can use greater-than/less-than to reduce the size and complexity of the code:

def restrictTimeFrames = GetAggregationPeriod() >= AggregationPeriod.MIN and GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN;

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on September 22, 2019 8:36 am
0
Thank you so much Pete. I did not have to change anything for the first scenario except the inclusion of def restricted time frames and assign price color code lines. For the second scenario, I had to change the input duration to 29 min for the code to work perfectly for 1 through 30 min. I don't know why but it works fine. here is the code. # THIS CODE PAINTS THE CANDLEs WHITE STARTING 730 AM TO 8 AM WITH WHITE COLOR FOR 1 MIN THROUGH 30 MIN TFS. input OpenTime = 0730; input Durationmin = 29; def secondsPassed = secondsFromTime(OpenTime); def durationSec = Durationmin * 60; def CandleBlue = secondsPassed >= 0 and secondsPassed = AggregationPeriod.MIN and GetAggregationPeriod()
( at September 22, 2019 8:57 pm)