Repaints ATR Volume Swing Trade

Repaints

StockT8er

Member
VIP
This strategy was set up for swingtrading. As you can see I added EOD, I need to reset each day in order to run it as a DayTrade. Can you help?

Code:
#[email protected]

#positioning
input usetimefilter = yes;
input rthopen = 0930;
input rthclose = 1600;
def RTH = if usetimefilter == yes then if SecondsFromTime(rthopen) >= 0 and
               SecondsTillTime(rthclose) >= 0
            then 1
            else 0 else 1;

input avglength = 14;
input MTaverageType = AverageType.WILDERS;
input ATRLength = 5;
input MTprice = hlc3;
input MTreversalMode = {default ATRpercent, price};
input MTreversalAmount = .5;

##DayATR Value Calculation
def highPrice = FundamentalType.HIGH;
def closePrice = FundamentalType.CLOSE;
def lowPrice = FundamentalType.LOW;
def aggregationPeriod = AggregationPeriod.DAY;
rec AvgTrueRange = MovingAverage(AverageType.SIMPLE, TrueRange(Fundamental (highPrice, period = AggregationPeriod.DAY), Fundamental (closePrice, period = AggregationPeriod.DAY), Fundamental (lowPrice, period = AggregationPeriod.DAY) ), ATRLength);

##############
##ATR percent conversion calculation
rec DayATRReversalValue = MTreversalAmount * (AvgTrueRange / close) * 100;

def mode = if MTreversalMode == MTreversalMode.price then ZigZagTrendSign(price = MTprice, reversalAmount = MTreversalAmount) else ZigZagTrendPercent(price = MTprice, reversalAmount = DayATRReversalValue);
def MTinflection = if MTreversalMode == MTreversalMode.price then if !IsNaN(ZigZagSign(price = MTprice, reversalAmount = MTreversalAmount)) then 1 else 0 else if !IsNaN(ZigZagPercent(price = MTprice, reversalAmount = DayATRReversalValue)) then 1 else 0;
rec MTtrend = if MTinflection == 1 and mode == -1 then 1 else if MTinflection == 1 and mode == 1 then -1 else MTtrend[1];

rec MTupWaveVolume = if MTinflection == 1 and MTtrend == 1 and close > open then volume else if MTinflection == 1 and MTtrend == 1 and close <= open then 0 else if MTtrend == 1 or (MTinflection == 1 and MTtrend == -1 and close >= open) then MTupWaveVolume[1] + volume else 0;
rec MTdownWaveVolume = if MTinflection == 1 and MTtrend == -1 and close < open then volume else if MTinflection == 1 and MTtrend == -1 and close >= open then 0 else if MTtrend == -1 or (MTinflection == 1 and MTtrend == 1 and close <= open) then MTdownWaveVolume[1] + volume else 0;

plot BuySignal = MTinflection[1] and MTdownWaveVolume[2] > 0;
BuySignal.SetDefaultColor(Color.CYAN);
BuySignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BuySignal.SetLineWeight(4);

plot SellSignal = MTinflection[1] and MTupWaveVolume[2] > 0;
SellSignal.SetDefaultColor(Color.MAGENTA);
SellSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SellSignal.SetLineWeight(4);

def Buy_Time = if MTinflection[1] and MTdownWaveVolume[2] > 0 then 1 else 0;

def Buy_Signal = if RTH == 1 > SecondsTillTime(0930) and Buy_Time == 1 then 1 else 0;
def Sell_Signal = if MTinflection[1] and MTupWaveVolume[2] > 0 then 1 else 0;

def EOD =  RTH == 1 > SecondsTillTime(2000);
def orderPrice = open[-1]+((open[-1]+close[-1])/2);

AddOrder(OrderType.BUY_TO_OPEN, RTH and Buy_Signal, price = orderPrice, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "ST_LE");

AddOrder(OrderType.SELL_TO_CLOSE, RTH and Sell_Signal, price = orderPrice, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "ST_SE");

AddOrder(OrderType.SELL_TO_CLOSE, EOD, price = orderPrice, tickcolor = GetColor(9), arrowcolor = GetColor(7), name = "CDS_EOD");

##input MTVolumeAudible_Alert = yes;
def MTVolumeDeviation_Length = 60;
def MTVolumeDeviate = 2;
def MTvolumestdevlength = RelativeVolumeStDev(length = MTVolumeDeviation_Length);
def abovedev = MTvolumestdevlength >= MTVolumeDeviate;
def belowdev = MTvolumestdevlength <= MTVolumeDeviate;

def MTvolumeincrease = volume > volume[1];
def MTvolumedevincrease = MTvolumeincrease and abovedev;
def MTvolumedecrease = volume < volume[1];
def MTvolumedevdecrease = MTvolumedecrease and abovedev;

def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def MTvolumeBuying = V * (C - L) / (H - L);
def MTvolumeSelling = V * (H - C) / (H - L);

input Show_Labels = yes;
AddLabel(Show_Labels, "Buy Vol = " + Round(MTvolumeBuying, 0), if MTvolumeBuying > MTvolumeSelling then Color.GREEN else Color.RED);
AddLabel(Show_Labels, "Sell Vol = " + Round(MTvolumeSelling, 0), if MTvolumeSelling > MTvolumeBuying then Color.GREEN else Color.RED);

Like below example due to market not open yet

RmaV7qC.png
 
Last edited by a moderator:
Solution
This indicator looks so good on charts because it repaints. It erases all the wrong signals and only leaves behind the pretty perfect signals.
read more: https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/

To add long/short bubbles in place of arrows; append this code snippet to the end of your study:
AddChartBubble(BuySignal,low,"Long",Color.GREEN);
AddChartBubble(SellSignal,high,"Short",Color.RED);

To remove arrows
LZPb9yk.png

1. click on the first flask at the top of your window
2. click on the gear, that is to the right of your study
3. under the tab BuySignal, un-click the show plot box
4. under the tab SellSignal, un-click the show plot box
5. if you want to use...
This indicator looks so good on charts because it repaints. It erases all the wrong signals and only leaves behind the pretty perfect signals.
read more: https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/

To add long/short bubbles in place of arrows; append this code snippet to the end of your study:
AddChartBubble(BuySignal,low,"Long",Color.GREEN);
AddChartBubble(SellSignal,high,"Short",Color.RED);

To remove arrows
LZPb9yk.png

1. click on the first flask at the top of your window
2. click on the gear, that is to the right of your study
3. under the tab BuySignal, un-click the show plot box
4. under the tab SellSignal, un-click the show plot box
5. if you want to use these settings as your default on all your charts; click on Save as default
6. click OK

@CASTI1313
 
Last edited by a moderator:
Solution

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