This thread is locked. For the newest As Good As It Gets chart setup:
As a scalp trader I'm always interested in the direction at opening especially the direction of the second candle (Bar). With not much to do today since it's a holiday I have been working on an indicator that only shows direction on the second bar. This works well on 30 minutes or less?
Here is the code:
##AsGood_OpeningSecondBarTrend
##Charles Ricks 1/16/23
##NOTE: TimeFrame Frame should not be less than current chart aggregation period.
##As with any indicator it is good to have another confirming indicator as well.
input timeFrame = {default MIN, FIVE_MIN, FIFTEEN_MIN, Thirty_MIN};
def cap = GetAggregationPeriod();
def yyyyMmDd = GetYYYYMMDD();
def periodIndx;
switch (timeFrame) {
case MIN:
periodIndx = yyyyMmDd;
case FIVE_MIN:
periodIndx = Floor((DaysFromDate(first(yyyyMmDd)) + GetDayOfWeek(first(yyyyMmDd))) / 7);
case FIFTEEN_MIN:
periodIndx = RoundDown(yyyyMmDd / 100, 0);
case THIRTY_MIN:
periodIndx = RoundDown(yyyyMmDd / 100, 0);
}
def isPeriodRolled = compoundValue(1, periodIndx != periodIndx[1], yes);
def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;
if (isPeriodRolled) {
volumeSum = volume;
volumeVwapSum = volume * vwap;
volumeVwap2Sum = volume * Sqr(vwap);
} else {
volumeSum = compoundValue(1, volumeSum[1] + volume, volume);
volumeVwapSum = compoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap);
volumeVwap2Sum = compoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap));
}
def price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));
def GetDayVar = GetDay();
def BarCountVar = if GetDay() != GetDay()[1] then 1 else BarCountVar[1] + 1;
#####################
##trend logic
def TrendDirection = if BarCountVar == 1 and price[78] - price[2] < 0 then -1 else if BarCountVar == 1 and price[78] - price[2] >= 0 then 1 else TrendDirection[1];
def NewDayTrendChange = if BarCountVar == 2 and TrendDirection == 1 and price[1] >= price[2] then 1 else if BarCountVar == 2 and TrendDirection == 1 and price[1] < price[2] then -2 else if BarCountVar == 2 and TrendDirection == -1 and price[1] >= price[2] then 2 else if BarCountVar == 2 and TrendDirection == -1 and price[1] < price[2] then -1 else NewDayTrendChange[1];
def BarTwoTest = BarCountVar == 2;
def ExitBarCount = BarCountVar == 77;
def EntryLongPrice = if BarTwoTest and (NewDayTrendChange == -2 or NewDayTrendChange == 1) then open else if ExitBarCount then Double.NaN else EntryLongPrice[1];
def longstate = if EntryLongPrice != EntryLongPrice[1] then EntryLongPrice else longstate[1];
def EntryShortPrice = if BarTwoTest and (NewDayTrendChange == -1 or NewDayTrendChange == 2) then open else if ExitBarCount then Double.NaN else EntryShortPrice[1];
def shortstate = if EntryShortPrice != EntryShortPrice[1] then EntryShortPrice else shortstate[1];
plot EntryLongPlot = BarTwoTest and EntryLongPrice;
EntryLongPlot.SetDefaultColor(Color.CYAN);
EntryLongPlot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
EntryLongPlot.SetLineWeight(4);
plot EntryShortPlot = BarTwoTest and EntryShortPrice;
EntryShortPlot.SetDefaultColor(Color.CYAN);
EntryShortPlot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
EntryShortPlot.SetLineWeight(4);
##End Code
Last edited by a moderator: