python – Invalid syntax on “def patternFinder” in my machine learning code


I have been following a few tutorials in order to build machine learning models for forex and Algo trading

I am running into this error below:

def patternFinder():
#Simple Average
avgLine = ((bid+ask)/2)

#This finds the length of the total array for us
x = len(avgLine)-30
#This will be our starting point, allowing us to compare to the
#past 10 % changes. 
y = 11

while y < x:
    
    p1 = percentChange(avgLine(y-10), avgLine(y-9))
    p2 = percentChange(avgLine(y-10), avgLine(y-8))
    p3 = percentChange(avgLine(y-10), avgLine(y-7))
    p4 = percentChange(avgLine(y-10), avgLine(y-6))
    p5 = percentChange(avgLine(y-10), avgLine(y-5))
    p6 = percentChange(avgLine(y-10), avgLine(y-4))
    p7 = percentChange(avgLine(y-10), avgLine(y-3))
    p8 = percentChange(avgLine(y-10), avgLine(y-2))
    p9 = percentChange(avgLine(y-10), avgLine(y-1))
    p10= percentChange(avgLine(y-10), avgLine(y))

    outcomeRange = avgLine(y+20:y+30)
    currentPoint = avgLine(y)

    #function to account for the average of the items in the array
    print( sum(outcomeRange) / len(outcomeRange) ) 

    
    print (currentPoint)
    print (' _______')
    print (p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)
    y+=1
    time.sleep(5555)

Error:

  File "<ipython-input-39-ece27253b81c>", line 4
def patternFinder():
  ^
SyntaxError: invalid syntax

Originally, I had seen someone else run into the same problem on this stackoverflow, I made those adjustments and still run into the same error

Change:

print reduce((lambda x,y:x+y,outcomeRange)/len(outcomeRange))

To:

print( sum(outcomeRange) / len(outcomeRange) )

Anyways, any help in solving this error would be much appreciated. Thank you in advance.

I don’t know if this will help, But I’ll leave all of my current code here at the bottom in case there might be something wrong in an earlier cell:

    import matplotlib
    import matplotlib.pyplot as plt
    import matplotlib.ticker as mticker
    import matplotlib.dates as mdates
    from matplotlib.dates import strpdate2num
    from __future__ import division
    import numpy as np
    import time

def bytespdate2num(fmt, encoding='utf-8'):
    strconverter = strpdate2num(fmt)
    def bytesconverter(b):
        s = b.decode(encoding)
        return strconverter(s)
    return bytesconverter
date,bid,ask = np.loadtxt('GBPUSD1d.txt', unpack=True,
                              delimiter=',',
                              converters={0:bytespdate2num('%Y%m%d%H%M%S')})

def percentchange(startPoint, currentPoint):
    return ((float(currentPoint-startPoint)/startPoint)*100.00

def patternFinder():
    #Simple Average
    avgLine = ((bid+ask)/2)
    
    #This finds the length of the total array for us
    x = len(avgLine)-30
    #This will be our starting point, allowing us to compare to the
    #past 10 % changes. 
    y = 11
    
    while y < x:
        
        p1 = percentChange(avgLine(y-10), avgLine(y-9))
        p2 = percentChange(avgLine(y-10), avgLine(y-8))
        p3 = percentChange(avgLine(y-10), avgLine(y-7))
        p4 = percentChange(avgLine(y-10), avgLine(y-6))
        p5 = percentChange(avgLine(y-10), avgLine(y-5))
        p6 = percentChange(avgLine(y-10), avgLine(y-4))
        p7 = percentChange(avgLine(y-10), avgLine(y-3))
        p8 = percentChange(avgLine(y-10), avgLine(y-2))
        p9 = percentChange(avgLine(y-10), avgLine(y-1))
        p10= percentChange(avgLine(y-10), avgLine(y))

        outcomeRange = avgLine(y+20:y+30)
        currentPoint = avgLine(y)

        #function to account for the average of the items in the array
        print( sum(outcomeRange) / len(outcomeRange) ) 

        
        print (currentPoint)
        print (' _______')
        print (p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)
        y+=1
        time.sleep(5555)