I've got a function (get_score) that uses variables from other functions(self.__sma) in the same class.
My question: How can I access these variables from the get_score function? (error: global name is not defined).
Also, i heard that using global variables causes a shitstorm(just based from what I read on here). Thanks in advance.
Here is some code:
testlist = ['TREE', 'HAPPY']
Class MyStrategy(strategy.BacktestingStrategy):
def __init__(self, feed, instrument):
super(MyStrategy, self).__init__(feed, 1000)
self.__position = [] #None
self.__instrument = instrument
self.setUseAdjustedValues(True)
self.__prices = feed[instrument].getPriceDataSeries()
self.__sma = ma.SMA(feed[instrument].getPriceDataSeries(), smaPeriod)
def get_score(self,banana)
fruit_lover= self.__sma
return fruit_lover + banana
def onBars(self, bars):
for x in bars.getInstruments():
list_large = {}
for y in testlist:
list_large.update({y : self.get_score(5)})
get_scoreshould get / return a score, not set some variables. Along with that point,{y : self.get_score(5)}is settingytoNone