Fractal Pivots Indicator - Need help adding signal

MP432

Member
Code:
input numBars = 5;
input showLines = yes;
input ShowZigZag = no;
input showValues = yes;
input ShowSignals = no;
input showBarNumbers = no;
input ShowLastPivotTracer = no;
input TrendResistanceStart = 0;
input TrendResistanceEnd = 0;
input TrendSupportStart = 0;
input TrendSupportEnd = 0;

def UserSetResistance = TrendResistanceStart > 0 and TrendResistanceEnd > 0;
def UserSetSupport = TrendSupportStart > 0 and TrendSupportEnd > 0;
def currentHigh = high;
def currentLow = low;
def currentBar = BarNumber();
def PH;
def PL;
def isHigherThanNextBars = fold i = 1 to numBars + 1 with p = 1
while p do currentHigh > GetValue(high, -i);
PH = if UserSetResistance and ( currentBar == TrendResistanceStart or currentBar == TrendResistanceEnd ) then currentHigh else if !UserSetResistance and (currentBar > numBars and currentHigh == Highest(currentHigh, numBars) and isHigherThanNextBars) then currentHigh else Double.NaN;
def isLowerThanNextBars = fold j = 1 to numBars + 1 with q = 1
while q do currentLow < GetValue(low, -j);
PL = if UserSetSupport and ( currentBar == TrendSupportStart or currentBar == TrendSupportEnd ) then currentLow else if !UserSetSupport and (currentBar > numBars and currentLow == Lowest(currentLow, numBars) and isLowerThanNextBars) then currentLow else Double.NaN;
rec PHBar = if UserSetResistance then TrendResistanceEnd else if !IsNaN(PH) then currentBar else PHBar[1];
rec PLBar = if UserSetSupport then TrendSupportEnd else if !IsNaN(PL) then currentBar else PLBar[1];
rec PHL = if !IsNaN(PH) then PH else PHL[1];
rec priorPHBar = if UserSetResistance then TrendResistanceStart else if PHL != PHL[1] then PHBar[1] else priorPHBar[1];
rec PLL = if !IsNaN(PL) then PL else PLL[1];
rec priorPLBar = if UserSetSupport then TrendSupportStart else if PLL != PLL[1] then PLBar[1] else priorPLBar[1];
def isFinalTwoHighPivots = currentBar >= HighestAll(priorPHBar);
def isFinalTwoLowPivots = currentBar >= HighestAll(priorPLBar);
def ResistanceFinishOffset = if isFinalTwoHighPivots then currentBar - PHBar else 0;
def ResistanceStartOffset = if isFinalTwoHighPivots then currentBar - priorPHBar else 0;
def ResistanceSlope = (GetValue(PH, ResistanceFinishOffset) - GetValue(PH, ResistanceStartOffset)) / (PHBar - priorPHBar);
def SupportFinishOffset = if isFinalTwoLowPivots then currentBar - PLBar else 0;
def SupportStartOffset = if isFinalTwoLowPivots then currentBar - priorPLBar else 0;
def SupportSlope = (GetValue(PL, SupportFinishOffset) - GetValue(PL, SupportStartOffset)) / (PLBar - priorPLBar);
rec ResistanceExtend = if currentBar == HighestAll(PHBar) then 1 else ResistanceExtend[1];
rec SupportExtend = if currentBar == HighestAll(PLBar) then 1 else SupportExtend[1];

plot pivotHigh = if
#isFinalTwoHighPivots
ph>0 then PH else Double.NaN;
plot pivotHighLine = if PHL > 0 and isFinalTwoHighPivots then PHL else Double.NaN;

plot ResistanceLine = pivotHigh;
plot ResistanceExtension = if ResistanceExtend then (currentBar - PHBar) * ResistanceSlope + PHL else Double.NaN;
plot pivotLow = if
#isFinalTwoLowPivots
pl>0 then PL else Double.NaN;
plot pivotLowLine = if PLL > 0 and isFinalTwoLowPivots then PLL else Double.NaN;
plot SupportLine = pivotLow;
plot SupportExtension = if SupportExtend then (currentBar - PLBar) * SupportSlope + PLL else Double.NaN;
plot BN = currentBar;
plot PivotDot = if !IsNaN(pivotHigh) then pivotHigh else if !IsNaN(pivotLow) then pivotLow else Double.NaN;
plot BisectLine = if !isNaN(pivotHigh) then pivotHigh else if !isNaN(pivotLow) then pivotLow else double.NaN;
pivotHigh.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
pivotHigh.SetHiding(!showValues);
PivotHigh.SetDefaultColor(Color.Dark_gray);
pivotLow.SetDefaultColor(Color.Dark_gray);
pivotLow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
pivotLow.SetHiding(!showValues);

ResistanceLine.EnableApproximation();
ResistanceLine.SetDefaultColor(GetColor(7));
ResistanceLine.SetStyle(Curve.SHORT_DASH);
ResistanceExtension.SetStyle(Curve.SHORT_DASH);
ResistanceExtension.SetDefaultColor(GetColor(7));
SupportLine.EnableApproximation();
SupportLine.SetDefaultColor(GetColor(7));
SupportLine.SetStyle(Curve.SHORT_DASH);
SupportExtension.SetDefaultColor(GetColor(7));
SupportExtension.SetStyle(Curve.SHORT_DASH);
pivotHighLine.SetPaintingStrategy(PaintingStrategy.DASHES);
pivotHighLine.SetHiding(!showLines);
pivotLowLine.SetPaintingStrategy(PaintingStrategy.DASHES);
pivotLowLine.SetHiding(!showLines);
BisectLine.EnableApproximation();
BisectLine.SetLineWeight(2);
BisectLine.Sethiding(!ShowZigZag);
BisectLine.setDefaultColor(Color.Dark_Gray);
PivotDot.SetDefaultColor(GetColor(7));
PivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);
PivotDot.SetLineWeight(3);
BN.SetDefaultColor(GetColor(0));
BN.SetHiding(!showBarNumbers);
BN.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);





Hello All,

I'd Like to simply have a signal where there is an indication of The current pivot high being less than the previous pivot high, and less than the pivot high before that. Vice versa for the the Lows.

example:
Pivothigh[0] < Pivothigh[1] and Pivothigh[0] < Pivothigh[2].

PivotLow[0] > PivotLow[1] and Pivotlow[0] > Pivotlow[2].


For some reason I am hitting a wall trying to simply put an arrow on when these conditions are met.
Any help would be appreciated.
 

Attachments

  • Screenshot 2024-10-22 133245.png
    Screenshot 2024-10-22 133245.png
    24.3 KB · Views: 19
Solution
Without testing, try the following logic:

Ruby:
plot downArrow = Pivothigh < Pivothigh[1] and Pivothigh[1] < Pivothigh[2];
downArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN));

plot upArrow = PivotLow > PivotLow[1] and Pivotlow[1] > Pivotlow[2];
upArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP));

Note that the [0] is implicit, but use it if you're more comfortable having it as a reference...
Without testing, try the following logic:

Ruby:
plot downArrow = Pivothigh < Pivothigh[1] and Pivothigh[1] < Pivothigh[2];
downArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN));

plot upArrow = PivotLow > PivotLow[1] and Pivotlow[1] > Pivotlow[2];
upArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP));

Note that the [0] is implicit, but use it if you're more comfortable having it as a reference...
 
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
214 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