AGAIG Opening Second Bar Trend For ThinkOrSwim

Status
Not open for further replies.

csricksdds

Trader Educator
VIP
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:
It will occasionally give both directions especially if there are wicks on either side of the candle - this is usually infrequent however. Look back at several opening days and I don't think you will see it very often. If you are using it for longer than 30 minute charts you will probably get arrows both ways as it is designed for 30 min or less?
 
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
Can we start this at market open 9:30 as now it starts at extended hour?
 
Can we start this at market open 9:30 as now it starts at extended hour?
Good question....I have a better suggestion. Look at my new charting indicators (Indicators are like new cars...things are updated and improved on each model as time progresses). We're always looking for trend direction (i.e. Follow the Money) and my new charting AGAIG_BestTradingChartSetup will show trend and continuing direction with long/short entries (repainting of course the same as life repaints) as they occur. I also show arrows (sometimes overlapping) looking at trend direction from different perspectives. On my BestTradingChartSetup everything is at eye level to make trading as easy to follow as possible.
 
Last edited by a moderator:
Status
Not open for further replies.

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
257 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