thetradingfrog
New member
Hello,
I have a scan that needs to look at 1 minute data and pull a value from the last bar ( 3:59 ) of the last 3 days. I created a simple test using just the close value ( I will have a custom calculation in the final scan).
This results in the first and second values being correct (RTHclose and RTHclose2) but RTHclose3 is the same as RTHclose2. I am not sure the best way to get the last 3.
I created a more complicated version which works correctly when used on a chart but doesn't work in a scan because apparently the HighestAll functions will only look back 1 day worth of 1 minute bars in a scan. Below is the version that will retrieve the correct values on a chart but not a scan.
I would love some help figuring this out as I have been running in circles for several days.
Thanks,
Nathan
I have a scan that needs to look at 1 minute data and pull a value from the last bar ( 3:59 ) of the last 3 days. I created a simple test using just the close value ( I will have a custom calculation in the final scan).
Code:
def RTHclose = If(GetTime() crosses above RegularTradingEnd(GetYYYYMMDD()) - 60000, close, RTHclose[1]);
def RTHclose2 = If(RTHclose != RTHclose[1], RTHclose[1], RTHclose[2]);
def RTHclose3 = if(RTHclose2 != RTHclose2[1], RTHclose2[1], RTHclose[3]);
AddLabel(yes,
"RTHclose: " + RTHclose + ", RTHclose2: " + RTHclose2 + ", RTHclose3: " + RTHclose3,
Color.YELLOW
);
AddChartBubble(
GetTime() crosses above (RegularTradingEnd(GetYYYYMMDD()) - 60000),
high, BarNumber() + " : " + RTHclose2[1],
Color.BLUE, no);
This results in the first and second values being correct (RTHclose and RTHclose2) but RTHclose3 is the same as RTHclose2. I am not sure the best way to get the last 3.
I created a more complicated version which works correctly when used on a chart but doesn't work in a scan because apparently the HighestAll functions will only look back 1 day worth of 1 minute bars in a scan. Below is the version that will retrieve the correct values on a chart but not a scan.
Code:
# Determine if bar is the last of the day #
def isRollover = currentDate != currentDate[1];
def currentDate = GetYYYYMMDD();
def beforeStart = GetTime() < RegularTradingStart(currentDate);
def afterEnd = GetTime() > RegularTradingEnd(currentDate);
def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0;
def lastBarOfDay = if
(afterEnd[-1] == 1 and afterEnd == 0) or
(isRollover[-1] and firstBarOfDay[-1])
then 1
else 0;
# Determine the highest bar number with a proper close indicating it is finished and not just a buffer bar #
def highestFinishedBar = HighestAll(if IsNaN(close) then 0 else BarNumber());
# Checks that the current bar is not the most recent daily last bar #
def notCurrent = BarNumber() != highestFinishedBar and BarNumber() < highestFinishedBar;
# Finds the previous daily last bar #
def last_cond_bn_daily = HighestAll( If(lastBarOfDay and notCurrent, BarNumber(), 0));
# Finds the daily last bar 2 days back #
def last_cond_bn2_daily = HighestAll( If(lastBarOfDay and notCurrent and BarNumber() != last_cond_bn_daily, BarNumber(), 0));
def currentFirstHalf = _customCalculation(condition = conditionFirstHalf, rollOver = break);
# Populate the 1 bar back and 2 bars back values #
def oneBackFirstHalf = GetValue(currentFirstHalf, (BarNumber() - last_cond_bn_daily) );
def twoBackFirstHalf = GetValue(currentFirstHalf, (BarNumber() - last_cond_bn2_daily) );
I would love some help figuring this out as I have been running in circles for several days.
Thanks,
Nathan