class BBand(Indicator): # Set the default initialization. The first one is executed. def initialize(self): self.options = [12, 2] self.displays = ["UP", "MA", "DN"] # It generates indicators that is used internally. The first one is executed. def declare_using(self): self.ind1 = NAverage(self, self.options[0], None, ("NAverage", "MA")) self.ind2 = StdDev(self, self.options[0], None, ("StdDev", "__BBand_StdDev")) # The computation is executed each time data is added or changed. def calculating(self): factor = self.options[1] self.ind1.calculate() self.ind2.calculate() ma = self.lines["MA"] dev = self.lines["__BBand_StdDev"] self.lines["UP"] = ma + dev * factor self.lines["DN"] = ma - dev * factor
class RSI(Indicator): # Set the default initialization. The first one is executed. def initialize(self): self.options = [12, 9] self.inputs = ["C"] self.displays = ["RSI", "RSI_MA"] # It generates indicators that is used internally. The first one is executed. def declare_using(self): self.ind1 = NAverage(self, self.options[1], "RSI") # The computation is executed each time data is added or changed. def calculating(self): length = self.options[0] up_sum = 0 dn_sum = 0 for index in range(length): old_value = self.lines[self.inputs[0], index+1] new_value = self.lines[self.inputs[0], index+0] amount = new_value - old_value if amount >= 0: up_sum += amount else: dn_sum += abs(amount) self.lines["RSI"] = up_sum / (up_sum + dn_sum) * 100.0 self.ind1.calculate() self.lines["RSI_MA"] = self.ind1.lines["NAverage"]
class ATR(Indicator): # Set the default initialization. The first one is executed. def initialize(self): self.options = [14] self.displays = ["ATR"] # It generates indicators that is used internally. The first one is executed. def declare_using(self): self.ind1 = TrueRange(self, None, None,("TrueRange", "__ATR_TR")) self.ind2 = NAverage(self, self.options[0], "__ATR_TR", ("NAverage", "ATR")) # The computation is executed each time data is added or changed. def calculating(self): self.ind1.calculate() self.ind2.calculate()
class Envelope(Indicator): # Set the default initialization. The first one is executed. def initialize(self): self.options = [12, 2] self.displays = ["UP", "MA", "DN"] # It generates indicators that is used internally. The first one is executed. def declare_using(self): self.ind1 = NAverage(self, self.options[0], None, ("NAverage", "MA")) # The computation is executed each time data is added or changed. def calculating(self): factor = self.options[2] self.ind1.calculate() self.lines["UP"] = self.lines["MA"] + self.lines["MA"] * factor / 100.0 self.lines["DN"] = self.lines["MA"] - self.lines["MA"] * factor / 100.0
class CCI(Indicator): # Set the default initialization. The first one is executed. def initialize(self): self.options = [12] self.displays = ["CCI"] # It generates indicators that is used internally. The first one is executed. def declare_using(self): self.ind1 = NAverage(self, self.options[0], "MID", ("NAverage", "AMID")) self.ind2 = NAverage(self, self.options[0], "INTERVAL", ("NAverage", "AINTERVAL")) # The computation is executed each time data is added or changed. def calculating(self): self.lines["MID"] = (self.lines["H"] + self.lines["L"] + self.lines["C"]) / 3.0 self.ind1.calculate() self.lines["INTERVAL"] = self.lines["MID"] - self.lines["AMID"] self.ind2.calculate() self.lines["CCI"] = self.lines["INTERVAL"] / (0.015 * self.lines["AINTERVAL"])
class StdDev(Indicator): # Set the default initialization. The first one is executed. def initialize(self): self.options = [10] self.inputs = ["C"] self.displays = ["StdDev"] # It generates indicators that is used internally. The first one is executed. def declare_using(self): self.ind1 = NAverage(self, self.options[0], self.inputs[0]) # The computation is executed each time data is added or changed. def calculating(self): length = self.options[0] linename = self.inputs[0] self.ind1.calculate() ma = self.ind1.lines["NAverage"] sum = 0 for index in range(length): sum += (ma - self.lines[linename, index])**2 self.lines["StdDev"] = sqrt(sum / length)
class MA3(Indicator): # Set the default initialization. The first one is executed. def initialize(self): self.options = [10, 20, 60] self.inputs = ["C"] self.displays = ["MA1", "MA2", "MA3"] # It generates indicators that is used internally. The first one is executed. def declare_using(self): self.ind1 = NAverage(self, self.options[0], self.inputs[0]) self.ind2 = NAverage(self, self.options[1], self.inputs[0]) self.ind3 = NAverage(self, self.options[2], self.inputs[0]) # The computation is executed each time data is added or changed. def calculating(self): self.ind1.calculate() self.ind2.calculate() self.ind3.calculate() self.lines["MA1"] = self.ind1.lines["NAverage"] self.lines["MA2"] = self.ind2.lines["NAverage"] self.lines["MA3"] = self.ind3.lines["NAverage"]
def declare_using(self): self.ind1 = TrueRange(self, None, None,("TrueRange", "__ATR_TR")) self.ind2 = NAverage(self, self.options[0], "__ATR_TR", ("NAverage", "ATR"))
def declare_using(self): self.ind1 = NAverage(self, self.options[0], "MID", ("NAverage", "AMID")) self.ind2 = NAverage(self, self.options[0], "INTERVAL", ("NAverage", "AINTERVAL"))
def declare_using(self): self.ind1 = NAverage(self, self.options[0], self.inputs[0])
def declare_using(self): self.ind1 = NAverage(self, self.options[0], None, ("NAverage", "MA")) self.ind2 = StdDev(self, self.options[0], None, ("StdDev", "__BBand_StdDev"))
def declare_using(self): self.ind1 = NAverage(self, self.options[0], None, ("NAverage", "MA"))
def declare_using(self): self.ind1 = NAverage(self, self.options[1], "RSI")