Pinescript Zig-zag without percentage and saving variables

50 Views Asked by At

I'm trying to build the zig-zag indicator which will work without using percentage change.

For this I wrote some code for start line and then I don't know how to do the next zz points for plotting.

This is a code to find the start zag.

var bool startPresent = false

var bool strikedUp = false
var bool strikedDown = false
var int strikedUpIndex = 0
var int strikedDownIndex = 0

freeHigh = high[1] < high[2] and high[2] > high[3]
freeLow = low[1] > low[2] and low[2] < low[3]

//Start Logics
if not startPresent
    if freeHigh and not fUpFound
        fUpPrice := high[2]
        fUpIndex := bar_index[2]
        fUpFound := true
        zigzag := high[2]
    if fUpFound and not fDownFound and freeLow
        fDownPrice := low[2]
        fDownIndex := bar_index[2]
        fDownFound := true
        zigzag := low[2]

    if fUpFound and fDownFound
        startPresent := true
        pointCount := pointCount + 1
        trendUp := false
        trendDown := true

The rules for ZZ next points are (example is for higher high, for lower low will be mirrored):

1, if high > zzHigh and freeHigh 2. Setup new zag firstly on minimum low between new high and previous high 3. Setup new zag right on the new freeHigh

So in that case the script will not build zags when the price (highs or lows) are "inside" the zig-zag high and low. It will plot only when extremums are stroked.

Also for future I want to save in memory last 2 points of highs and 2 points of low of the zig-zag. F.e. save: currentHigh, prevHigh, currentLow, prevLow. I will need it to check are they consecutive higher-higher or lower-lower.

I tried to check for strikeUp with if high[1] > zzHigh and freeHigh

But I don't know how to find the minimum low between this points and plot the zigzag line and get right values of it.

0

There are 0 best solutions below