Pivot Confirmation with Trading Levels

N

Nick

Active member
2019 Donor
VIP
Another fav of mine is swing waves gotta try it.. This post dot hi/lo
dots but does not work on moble.
Code:
# Trading Analysis Swing Waves
# Version 1.0.1
# 4/20/2015
#
# Author: Brian Strong ([email protected])
# MicroQuant
#

input MajorLeftStr = 13;
input MajorRightStr = 13;
input MinorLeftStr = 5;
input MinorRightStr = 5;
input SwingTickOffset = 2;
input AlertsOn = yes;

# This indicator must be applied to a bar interval larger than 5 ticks.

def offset = TickSize() * (HighestAll(high) - LowestAll(low)) * SwingTickOffset;

#Calculate Major Swings
def pivotH = if high > Highest(high[1], MajorLeftStr) and high > Highest(high[-MajorRightStr], MajorRightStr) then 1 else 0;
def pValH = if pivotH then high + offset else Double.NaN;
def pivotL = if low < Lowest(low[1], MajorLeftStr) and low < Lowest(low[-MajorRightStr], MajorRightStr) then 1 else 0;
def pValL = if pivotL then low - offset else Double.NaN;

#Plot Major Swings
plot MajorSwHigh = pValH;
MajorSwHigh.setpaintingStrategy(paintingStrategy.POINTS);
MajorSwHigh.setLineWeight(5);
MajorSwHigh.setdefaultColor(Color.BLUE);
plot MajorSwLow = pValL;
MajorSwLow.setpaintingStrategy(paintingStrategy.POINTS);
MajorSwLow.setLineWeight(5);
MajorSwLow.setdefaultColor(Color.BLUE);
Hi @J007RMC , i tried to do a scan for majorswing low but not getting any results? Is there something i am not doing correct? thanks
 
G

generic

New member
@J007RMC Have you tried altering the code for short entries?
 
J007RMC

J007RMC

Well-known member
2019 Donor
VIP
No bud sounds like a great idea. I have to say though run it on a 2 min chart
 
G

generic

New member
Heres the code for short entries if anyone is intereseted

Code:
input n = 5;#hint n: For pivot and standard deviation
input addAtPercentStDev = 75;#hint addAtPercentStDev: Add at this percent of standard deviation below previous low
input initialLots = 4;#hint initialLots: Set to preference
input lotsToAdd = 2;#hint lotsToAdd: Number of lots to add on a pull back
input stDevMult = 2.0;#hint stDevMult: trail stop multiplier
input labels = no;

def openingLots = Max(4, initialLots);
def addedlots = Max(2, lotsToAdd);
AddLabel(initialLots < openingLots, " Error: Initial lots must be 4 or more ", Color.Cyan);
AddLabel(lotsToAdd < addedLots, " Error: Lots to add must be 2 or more ", Color.Cyan);
def h = high;
def l = low;
def c = close;
def nan = Double.NaN;
def tick = TickSize();
def x = BarNumber();
def stDev = CompoundValue(1, StDev(c, n), nan);
def hh = h == Highest(h, n);
def LPx = if hh then x else nan;
def LP_low = if !IsNaN(LPx) then l else LP_Low[1];
def LP_High = if !IsNaN(LPx) then h else LP_High[1];
def confirmation_count = if hh then 0 else
if c crosses below LP_Low
then confirmation_count[1] + 1
else confirmation_count[1];
def confirmationX = if confirmation_count crosses above 0
then x else nan;
def confirmed = confirmation_count crosses above 0;

def ro;
def stc;
def trail;
def retrace;
if confirmed {
ro = Round((c - (LP_High - c) / (openingLots - 2)) / tick, 0) * tick;
stc = LP_High;
trail = LP_High;
retrace = LP_High;
}else{
ro = CompoundValue(1, ro[1], nan);
stc = stc[1];
trail = Round(Min(trail[1], h[1] + stDev[1] * stDevMult) / tick, 0) * tick;
retrace = Round(Min(retrace[1], h[1] + StDev[1] * addAtPercentStDev / 100) / tick, 0) * tick;
}

def ro_reached = if confirmed then 0 else
if l < ro then 1 else ro_reached[1];
def added = if confirmed then 0 else
if h crosses above retrace then 1 else added[1];
def trail_hit = if confirmed then 0 else
if c > trail then 1 else trail_hit[1];
def stop_hit = if confirmed then 0 else
if h > stc then 1 else stop_hit[1];


plot
PivotConfirmed = confirmed;
PivotConfirmed.SetDefaultColor(Color.Light_Red);
PivotConfirmed.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

plot
BuyToOpen = if confirmed then c else nan;
BuyToOpen.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BuyToOpen.SetDefaultColor(Color.Light_Green);

plot
SellToClose = if !stop_hit or stop_hit crosses above 0 then stc else nan;
SellToClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
SellToClose.SetDefaultColor(Color.RED);

plot
TrailingStop = if ! trail_hit or trail_hit crosses above 0 then trail else nan;
TrailingStop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TrailingStop.SetDefaultColor(Color.Pink);

plot
Add = if !added or added crosses above 0 then retrace else nan;
Add.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Add.SetDefaultColor(Color.Dark_Green);

plot
RiskOut = if !ro_reached or ro_reached crosses above 0 then ro else nan;
RiskOut.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
RiskOut.SetDefaultColor(CreateColor(215, 215, 215));

AddLabel(labels and BuyToOpen, " BTO "+ openingLots +" = " + BuyToOpen + " ", Color.Light_Green);
Addlabel(labels and BuyToOpen, " ", CreateColor(0, 0, 0));
AddLabel(labels and ro_reached and Add, " Add "+ addedlots +" at = " + Add + " ", Color.Dark_Green);
AddLabel(labels and ro_reached and Add, " ", CreateColor(0, 0, 0));
AddLabel(labels and RiskOut, " Sell " + (openingLots - 2) + " = " + ro + " ", CreateColor(215, 215, 215));
AddLabel(labels and RiskOut, " ", CreateColor(0, 0, 0));
AddLabel(labels and ro_reached and TrailingStop, " Sell "+(1+addedLots-1)+" at = "+trail+" ", Color.Pink);
Addlabel(labels and ro_reached and TrailingStop, " ", CreateColor(0, 0, 0));
AddLabel(labels and SellToClose, " Sell All = " + stc + " ", Color.Red);
Addlabel(labels and SellToClose, " ", CreateColor(0, 0, 0));

#f/ Pivot Confirmation With Trading Levels
 
F

FOTM_8888

Member
VIP
Another fav of mine is swing waves gotta try it.. This post dot hi/lo
dots but does not work on moble.
Code:
# Trading Analysis Swing Waves
# Version 1.0.1
# 4/20/2015
#
# Author: Brian Strong ([email protected])
# MicroQuant
#

input MajorLeftStr = 13;
input MajorRightStr = 13;
input MinorLeftStr = 5;
input MinorRightStr = 5;
input SwingTickOffset = 2;
input AlertsOn = yes;

# This indicator must be applied to a bar interval larger than 5 ticks.

def offset = TickSize() * (HighestAll(high) - LowestAll(low)) * SwingTickOffset;

#Calculate Major Swings
def pivotH = if high > Highest(high[1], MajorLeftStr) and high > Highest(high[-MajorRightStr], MajorRightStr) then 1 else 0;
def pValH = if pivotH then high + offset else Double.NaN;
def pivotL = if low < Lowest(low[1], MajorLeftStr) and low < Lowest(low[-MajorRightStr], MajorRightStr) then 1 else 0;
def pValL = if pivotL then low - offset else Double.NaN;

#Plot Major Swings
plot MajorSwHigh = pValH;
MajorSwHigh.setpaintingStrategy(paintingStrategy.POINTS);
MajorSwHigh.setLineWeight(5);
MajorSwHigh.setdefaultColor(Color.BLUE);
plot MajorSwLow = pValL;
MajorSwLow.setpaintingStrategy(paintingStrategy.POINTS);
MajorSwLow.setLineWeight(5);
MajorSwLow.setdefaultColor(Color.BLUE);
thank you for sharing this awesome indicator.. can you do us a favor, and try to add buy order and exit order like a strategy for us to do a back testing please. thank you very much!
 
J007RMC

J007RMC

Well-known member
2019 Donor
VIP
thank you for sharing this awesome indicator.. can you do us a favor, and try to add buy order and exit order like a strategy for us to do a back testing please. thank you very much!
If I could but I'm not a coder.

Thanks
 
J007RMC

J007RMC

Well-known member
2019 Donor
VIP
A great example of running the swing indicator is BA although I did not trade it. The 15 min chart caught the swing high just before the open.
 
Last edited:
J007RMC

J007RMC

Well-known member
2019 Donor
VIP
@generic Great work thank you. Can you add alarms
 
Last edited:
G

generic

New member
@J007RMC
For long,
Alert(confirmed or l crosses below stc, "", Alert.Bar, Sound.Ding);

For short,
Alert(confirmed or h crosses above stc, "", Alert.Bar, Sound.Ding);
 
J007RMC

J007RMC

Well-known member
2019 Donor
VIP
@J007RMC
For long,
Alert(confirmed or l crosses below stc, "", Alert.Bar, Sound.Ding);

For short,
Alert(confirmed or h crosses above stc, "", Alert.Bar, Sound.Ding);
Thank you very much
 
J007RMC

J007RMC

Well-known member
2019 Donor
VIP
Hi I ran the alerts today all shorts no switch over alerts to buy at open I think I have everything correctly entered...shorts work great
 
G

generic

New member
@J007RMC For the long entry alerts you need to put them into the original code you posted and short alerts into the post I made. Is this what you did? Lmk if that is what you did and the alerts aren't working. I didn't combine the long and short code into 1 since I was too lazy but if that's something you want then I can do that later tonight.
 
J007RMC

J007RMC

Well-known member
2019 Donor
VIP
I understand now thanks. I came across a strategy posted on site that looks pretty good I will test it tomorrow in conjunction with the short wave.
Ben wrote the code to buy every 3rd candle above below the 9 SMA I continue to use the short wave.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2017-2020
#

input price = close;
input length = 9;
input displace = 0;

def AvgExp = ExpAverage(price[-displace], length);

def condition1 = close[3] crosses above AvgExp;
def condition2 = close > AvgExp;

def buy = condition1 and condition2;
def sell = close crosses below AvgExp;

AddOrder(OrderType.BUY_TO_OPEN, condition = buy, price = close,1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Long");
AddOrder(OrderType.SELL_TO_CLOSE, condition = sell, price = close,1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Cover");
 
J007RMC

J007RMC

Well-known member
2019 Donor
VIP
@J007RMC For the long entry alerts you need to put them into the original code you posted and short alerts into the post I made. Is this what you did? Lmk if that is what you did and the alerts aren't working. I didn't combine the long and short code into 1 since I was too lazy but if that's something you want then I can do that later tonight.
Everything is working as designed thank you again.
 

Similar threads

Top