Die Pivot -Funktionsergebnisse unterscheiden sich von TradingViewPython

Python-Programme
Anonymous
 Die Pivot -Funktionsergebnisse unterscheiden sich von TradingView

Post by Anonymous »

Ich verwende diesen Code, um Drehpunkte zu berechnen. < /p>

Code: Select all

def pivots_low(osc, LBR, LBL):
pivots = []
for i in range(len(osc) - LBR):
pivots.append(0)
pivot = True
if i > LBL:
for j in range(1, LBR + 1):
if osc[i] >= osc[i + j]:
pivot = False
for j in range(1, LBL + 1):
if osc[i] > osc[i - j]:
pivot = False
if pivot is True:
pivots[len(pivots) - 1] = osc[i]
for i in range(LBR):
pivots.append(0)
return pivots
< /code>
Dies gibt ein Array mit 0 zurück, in dem es keine Pivots und den Wert des Drehes gibt, wenn es einen gibt. Download CSV mit Pivot -Punkten), das einzige Mal, dass er genau übereinstimmt, ist, wenn die Lookback nach links und rechts 5 ist. Ansonsten weicht es in der Anzahl der Gesamtdrehzahl und der Position einiger. Verwenden Sie diesen Code, um Pivot Highs zu berechnen: < /p>
def pivots_high(osc, LBR, LBL):
pivots = []
for i in range(len(osc)-LBR):
pivots.append(0)
pivot = True
if i > LBL:
for j in range(1,LBL + 1):
if osc[i] < osc[i-j]:
pivot = False
for j in range(1,LBR + 1):
if osc[i] 
Die Ergebnisse sind unabhängig von den Lookback -Werten perfekt. Aber der Code ist neben dem Vergleich fast genau gleich. < /P>
Was läuft hier falsch? Dies ist Tag 3 von diesem [url=viewtopic.php?t=11587]Problem[/url] und ich kann es einfach nicht beheben < /p>
, um sich zu reproduzieren: < /p>
Lastdaten: < /p>
Full_Data = pd.read_csv(file)
< /code>
Verwenden Sie diese einfache Funktion, um die Übereinstimmungen zwischen berechneten Pivots und TradingView -Pivots zu überprüfen. < /p>
def match_pivs(data, pivs_h, pivs_l): //Data is a DataFrame loaded from tradingview csv
global lblh
global lbrh
global lbll
global lbrl
start = lbrh
if lbrl > lbrh:
start = lbrl
match_h = 0
tot_hd = 0
tot_hp = 0
match_l = 0
tot_ld = 0
tot_lp = 0
for i in range(start, len(data)):
if data['PivHigh'][i] != 0 and pivs_h[i-lbrh] != 0:
match_h += 1
if data['PivLow'][i] != 0 and pivs_l[i-lbrl] != 0:
match_l += 1
if data['PivHigh'][i] != 0:
tot_hd += 1
if data['PivLow'][i] != 0:
tot_ld += 1
if pivs_h[i] != 0:
tot_hp += 1
if pivs_l[i] != 0:
tot_lp += 1
print('PivsLow ' + str(tot_lp))
print('DataLows ' + str(tot_ld))
print('MatchesL ' + str(match_l))
print('PivsHigh ' + str(tot_hp))
print('DataHighs ' + str(tot_hd))
print('MatchesH ' + str(match_h))
< /code>
und um CSV von TradingView zu erhalten: < /p>
//@version=5
indicator("Data Script", overlay=true, max_labels_count=500)

leftLenL = input.int(title="Pivot Low", defval=10, minval=1, inline="Pivot Low", group=lengthGroupTitle)
rightLenL = input.int(title="/", defval=10, minval=1, inline="Pivot Low", group=lengthGroupTitle)
leftLenH = input.int(title="Pivot High", defval=10, minval=1, inline="Pivot High", group=lengthGroupTitle)
rightLenH = input.int(title="/", defval=10, minval=1, inline="Pivot High", group=lengthGroupTitle)
ph = ta.pivothigh(leftLenH, rightLenH)
pl = ta.pivotlow(leftLenL, rightLenL)
if not na(ph)
plth := ph
else
plth := 0.0
if not na(pl)
pltl := pl
else
pltl := 0.0
plot(plth, 'PivHigh')
plot(pltl, 'PivLow')
< /code>
Laden Sie dann einfach CSV mit diesem Skript herunter.pl = pivots_low(Full_Data['low'], lbll, lbrl)
ph = pivots_high(Full_Data['high'], lbrh, lblh)
match_pivs(Full_Data, ph, pl)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post