Overall Statistics
Total Orders
287
Average Win
0.17%
Average Loss
-0.11%
Compounding Annual Return
55.246%
Drawdown
4.600%
Expectancy
0.311
Start Equity
1000000
End Equity
1042659.81
Net Profit
4.266%
Sharpe Ratio
2.342
Sortino Ratio
2.468
Probabilistic Sharpe Ratio
65.266%
Loss Rate
49%
Win Rate
51%
Profit-Loss Ratio
1.57
Alpha
0.502
Beta
0.683
Annual Standard Deviation
0.147
Annual Variance
0.022
Information Ratio
4.561
Tracking Error
0.126
Treynor Ratio
0.506
Total Fees
$2185.78
Estimated Strategy Capacity
$930000.00
Lowest Capacity Asset
FLYD 2T
Portfolio Turnover
27.39%
#region imports
from AlgorithmImports import *
#endregion
import os
import glob
import tkinter as tk
from tkinter import filedialog
import chardet
import re
import textwrap

def select_folder():
    root = tk.Tk()
    root.withdraw()
    folder_path = filedialog.askdirectory()
    return folder_path


# Mapping of phrases to their corresponding function names
phrase_mapping = {
    'current-price': 'GetCurrentPrice',
    'moving-average-return': 'SMADayRet',
    'moving-average-price': 'SMA',
    'max-drawdown': 'MaxDD',
    'cumulative-return': 'CumReturn',
    'exponential-moving-average-price': 'EMA',
    'stdev-return': 'STD',
    'rsi': 'RSI'
}

def replace_sort_function(file_path, strategy_number, weight, file_name_without_extension):
    try:
        # Detect encoding
        with open(file_path, 'rb') as file:
            raw_data = file.read()
            encoding = chardet.detect(raw_data)['encoding']

        # Read the content
        with open(file_path, 'r', encoding=encoding) as file:
            content = file.read()

        #Add else
        content = insert_else_statements(content)

        # Process for filter type replacements
        content = process_filter_type_replacements(content, strategy_number, weight)

        # Process for conditional statements replacements
        content = process_conditional_replacements(content)

        content = replace_weighted_asset_with_appendholding(content, strategy_number, weight)

        # Process for IV AH replacements
        content = replace_weight_inverse_volatility(content, strategy_number, weight)

        # Process for AH replacements
        content = replace_asset_with_appendholding(content, strategy_number, weight)


        content = replace_asset_with_appendholding_2(content, strategy_number, weight)

        content = remove_specific_elements(content)

        content = adjust_indentation(content)
        
        content = process_content_def(content)

        content = process_group_filter(content, strategy_number, weight)


        content = modify_weights_based_on_indent(content)

        content = adjust_weights_and_indent_based_on_prefix(content)

        content = adjust_weights_based_on_method_calls(content)

        content = modify_content(content, file_name_without_extension)

        content = replace_none_with_closing_parenthesis(content)


        # Write the changes back
        with open(file_path, 'w', encoding=encoding) as file:
            file.write(content)

    except Exception as e:
        print(f"Error processing file {file_path}: {e}")

def process_filter_type_replacements(content, strategy_number, weight):
    # Define the regex pattern to match the structured code
    pattern = r"""\(\s*filter
\s*\(\s*([a-z-]+)\s*(?:\{\s*:\w+\s*(\d+)\s*\})?\s*\)
\s*\(select-(top|bottom)\s*(\d+)\)
\s*\[\s*((?:\(\s*asset\s*"[^"]+"\s*\)\s*)+)\]\s*\)"""

    # Adjust regex pattern to match assets across multiple lines and spaces
    pattern = re.compile(pattern, re.DOTALL | re.VERBOSE)

    # Find all matches and replace
    new_content = content
    for match in pattern.finditer(new_content):
        filter_type_raw = match.group(1)
        filter_type = phrase_mapping.get(filter_type_raw, filter_type_raw)  # Map the filter type
        window = match.group(2)
        select_type = match.group(3).title()
        number = match.group(4)

        # Modified regex for matching assets
        assets_pattern = r'asset\s*"\s*([^"]+)\s*"'
        assets = re.findall(assets_pattern, match.group(0))
        assets_str = ','.join([f"'{asset}'" for asset in assets])

        replacement = f"Sort(self.algo,'{filter_type}',({assets_str}),{window},{select_type == 'Top'},{number}," + str(strategy_number) + "," + str(weight) + ")"
        new_content = new_content.replace(match.group(0), replacement)

    return new_content

def process_conditional_replacements(content):

    # Updated regex pattern for two assets (possibly with windows), handling multiline and whitespace
    pattern_assets = r"""if\s*\(\s*(<|>|<=|>=)\s*
                    \(\s*([\w-]+)\s*\n?\s*"([^"]+)"\s*(?:\{\s*:window\s*\n?\s*(\d+)\s*\}\s*)?\)\s*
                    \(\s*([\w-]+)\s*\n?\s*"([^"]+)"\s*(?:\{\s*:window\s*\n?\s*(\d+)\s*\}\s*)?\)\s*
                    \)"""

    # Updated regex pattern for one asset (possibly with window) and a number, handling multiline, whitespace, and negative numbers
    pattern_asset_number = r"""if\s*\(\s*(<|>|<=|>=)\s*
                        \(\s*([\w-]+)\s*\n?\s*"([^"]+)"\s*(?:\{\s*:window\s*\n?\s*(\d+)\s*\}\s*)?\)\s*
                        ([-+]?\d+(?:\.\d+)?)\s*\)"""
    
    # Compiling with re.DOTALL and re.VERBOSE
    pattern_assets = re.compile(pattern_assets, re.DOTALL | re.VERBOSE)
    pattern_asset_number = re.compile(pattern_asset_number, re.DOTALL | re.VERBOSE)

    # Find all matches for two assets with two windows and replace
    new_content = content
    for match in pattern_assets.finditer(new_content):
        comparison_operator = match.group(1)
        left_function_raw = match.group(2)
        left_ticker = match.group(3)
        left_window = match.group(4)
        right_function_raw = match.group(5)
        right_ticker = match.group(6)
        right_window = match.group(7)

        left_function = phrase_mapping.get(left_function_raw, left_function_raw)
        right_function = phrase_mapping.get(right_function_raw, right_function_raw)

        replacement = f"if {left_function}(self.algo, '{left_ticker}', {left_window}) {comparison_operator} {right_function}(self.algo, '{right_ticker}', {right_window}):"
        new_content = new_content.replace(match.group(0), replacement)

    # Find all matches for one asset and a number and replace
    for match in pattern_asset_number.finditer(new_content):
        comparison_operator = match.group(1)
        function_raw = match.group(2)
        ticker = match.group(3)
        window = match.group(4)
        number = match.group(5)

        function = phrase_mapping.get(function_raw, function_raw)

        replacement = f"if {function}(self.algo, '{ticker}', {window}) {comparison_operator} {number}:"
        new_content = new_content.replace(match.group(0), replacement)

    return new_content


def replace_asset_with_appendholding(content, strategy_number, weight):
    # Updated Regex pattern to match the asset structure with and without square brackets
    pattern = r"(?:\[\s*)?\(asset\s*\"([^\"]+)\"\s*\)(?:\s*\])?"

    # Compiling the updated regex pattern to handle multiline
    pattern = re.compile(pattern, re.DOTALL | re.VERBOSE)

    # Function to perform the replacement
    def replacement(match):
        ticker = match.group(1)
        return f"AH(self.algo, '{ticker}', {strategy_number}, {weight})"

    # Replace all matches in the content
    new_content = re.sub(pattern, replacement, content)

    return new_content

def replace_asset_with_appendholding_2(content, strategy_number, weight):
    # Regex pattern to match both individual and multiple assets in the format [(asset "SYMBOL") (asset "SYMBOL2")...]
    # Adjusted to not capture whitespace after the optional closing bracket
    pattern = r"""
        (\s*)                                      # Capture leading whitespace for indentation
        \[\s*                                      # Opening bracket with optional whitespace
        (                                          # Start capturing group for one or more asset declarations
            (?:\(\s*asset\s+\"[^\"]+\"\s*\)\s*)+   # Match '(asset "SYMBOL")' with optional spaces, repeat for multiple
        )                                          # End capturing group
        #\s*\]                                      # Closing bracket with optional whitespace
    """
    # Compiling the regex pattern with DOTALL and VERBOSE flags for readability
    pattern = re.compile(pattern, re.DOTALL | re.VERBOSE)

    # Function to perform the replacement
    def replacement(match):
        indentation = match.group(1)  # Capture the indentation
        assets = match.group(2)  # Capture the string with all assets

        # Extract symbols from the captured assets string
        symbols = re.findall(r'\"([^\"]+)\"', assets)

        # Determine format based on the number of symbols
        if len(symbols) == 1:
            # Format without tuple for a single asset
            formatted_assets = f"'{symbols[0]}'"
        else:
            # Format as tuple for multiple assets
            formatted_assets = f"{tuple(symbols)}"

        # Constructs the replacement string with extracted symbols, maintaining the same indentation
        return f"{indentation}AH(self.algo, {formatted_assets}, {strategy_number}, {weight})\n"

    # Replace all matches in the content
    new_content = re.sub(pattern, replacement, content)

    return new_content


def replace_weighted_asset_with_appendholding(content, strategy_number, weight):

    # Enhanced regex pattern to match the asset allocation with optional leading whitespace
    pattern = r"(\s*)\[\(weight-specified((?:\s+\d\.\d\s+\(asset\s+\"[^\"]+\"\))*)\)\]"

    # Compiling the regex pattern to handle multiline and include verbose for whitespace handling
    pattern = re.compile(pattern, re.DOTALL | re.VERBOSE)
    
    # Function to process each match and generate the replacement string with dynamic indentation
    def replacement(match):
        leading_whitespace = match.group(1)  # Capturing the leading whitespace for dynamic indentation
        block_content = match.group(2)  # The content within the weight-specified block

        # Function to format normal assets
        def format_element(element_match):
            weight_factor, ticker = element_match.groups()
            # Adjusting the weight by multiplying with the provided weight and incorporating leading whitespace
            return f"{leading_whitespace}AH(self.algo, '{ticker}', {strategy_number}, {float(weight_factor)}*{weight})"

        # Processing assets within the block
        element_pattern = re.compile(r"(\d\.\d)\s+\(asset\s+\"([^\"]+)\"\)")
        formatted_content = element_pattern.sub(format_element, block_content)

        # Returning the modified content with adjusted weights for each asset, preserving leading whitespace
        return f"{leading_whitespace}[{formatted_content}]"

    # Replacing the content based on the defined patterns
    modified_content = pattern.sub(replacement, content)

    return modified_content

def insert_else_statements(content):
    lines = content.split('\n')
    modified_lines = []
    if_stack = []  # Stack to keep track of 'if' indentation levels

    for i in range(len(lines)):
        line = lines[i]
        modified_lines.append(line)

        # Check if the line contains [(if
        if re.search(r"\s*\(if", line):
            if_indent = re.match(r"\s*", line).group()  # Capture the indentation of the if line
            if_stack.append(if_indent)  # Push the indentation onto the stack

        # Check for the end of an if block (line ending with ] but not with )]
        if if_stack and re.search(r"\]\s*$", line):
        #and not re.search(r"\]\)\s*$", line):
            last_if_indent = if_stack.pop()  # Pop the last unmatched if
            modified_lines.append(last_if_indent + "else:")

        # Check for the special case (line containing )])]
        #if re.search(r"\)\]\)\]\s*$", line):
            # Check if the next line does not end with )])]
            #if i + 1 < len(lines) and not re.search(r"\)\]\)\]\s*$", lines[i + 1]):
               # if if_stack:
                   # last_if_indent = if_stack.pop()
                    #modified_lines.append(last_if_indent + "else:")
                    #if_stack.clear()  # Clear the stack for special case

    return '\n'.join(modified_lines)

def remove_specific_elements(content):
    # Split the content into lines
    lines = content.split('\n')
    modified_lines = []

    for line in lines:
        # Remove all [ and ]
        line = line.replace('[', '').replace(']', '')

        # Remove (group and (weight-equal
        line = line.replace('(group', '').replace('(weight-equal', '')

        # Remove the ( before if
        line = re.sub(r'\(\s*if', 'if', line)

        # Replace double )) with single )
        while '))' in line:
            line = line.replace('))', ')')

        # Remove lines that contain (weight-specified
        if '(weight-specified' in line:
            continue

        if '(asset' in line:
            continue

        # Remove lines that contain only a single ( or )
        if re.match(r'^\s*\(\s*$', line) or re.match(r'^\s*\)\s*$', line):
            continue

        modified_lines.append(line)

    # Second pass: Remove empty lines and lines with only ( or )
    modified_lines = [line for line in modified_lines if line.strip() and not re.match(r'^\s*[\(\)]\s*$', line)]

    # Join the lines back into a single string
    return '\n'.join(modified_lines)


def replace_weight_inverse_volatility(content, strategy_number, weight):
    # Regex pattern to match the entire weight-inverse-volatility structure with flexible whitespace handling
    pattern = r"(\s*)\(\s*weight-inverse-volatility\s+(\d{1,3})\s+\[(.*?)\]\)"
    
    # Compiling the regex pattern to handle multiline and verbose mode
    pattern = re.compile(pattern, re.DOTALL | re.VERBOSE)

    # Function to perform the replacement
    def replacement(match):
        indent = match.group(1)  # Capturing the indentation level from the matched pattern
        period = match.group(2)
        tickers = re.findall(r'\(\s*asset\s*"([^"]+)"\s*\)', match.group(3))

        # Creating the AHIV line with additional indentation
        assets_tuple = ", ".join([f"'{ticker}'" for ticker in tickers])
        additional_indent = '    '  # Assuming 4 spaces for one level of indentation
        ahiv_line = f"{indent}{additional_indent}AHIV(self.algo, ({assets_tuple}), {period}, " + str(strategy_number) + ", " + str(weight) + ")"

        return ahiv_line

    # Applying the replacement to the content
    new_content = re.sub(pattern, replacement, content)
    return new_content


def process_content_def(content):

    # Step 1: Delete (defsymphony and the following quoted text line
    defsymphony_pattern = re.compile(r'^\s*\(\s*defsymphony\s*\n\s*\".*?\"\s*$', re.MULTILINE | re.DOTALL)
    content = re.sub(defsymphony_pattern, '', content)

    qualified_text_pattern = re.compile(r'^(\s*)"(.*?)"(.*?$)', re.MULTILINE)

    def format_qualified_text(text):
        text = re.sub(r'[^\w\s]', '', text)
        text = re.sub(r'\s+', '_', text)
        return text.lower()

    methods = {}
    method_defs = []
    lines = content.split('\n')

    for i in range(len(lines) - 1, -1, -1):
        line = lines[i]
        match = qualified_text_pattern.match(line)
        if match:
            indent, text, _ = match.groups()
            method_name = format_qualified_text(text)
            subcontent = []
            base_indent_level = len(indent)

            j = i + 1
            while j < len(lines):
                line_indent_level = len(lines[j]) - len(lines[j].lstrip(' '))
                # Check if the line is part of the subcontent based on its indentation
                if line_indent_level > base_indent_level:
                    relative_indent = line_indent_level - base_indent_level
                    adjusted_indent = ' ' * (relative_indent - 1) if relative_indent > 0 else ''
                    adjusted_line = adjusted_indent + lines[j].lstrip()
                    subcontent.append(adjusted_line)
                    j += 1
                else:
                    break

            subcontent_str = '\n    '.join(subcontent)

            if method_name not in methods:
                methods[method_name] = subcontent_str
                method_def = f"def {method_name}(self):\n    " + subcontent_str + '\n'
                method_defs.append(method_def)
                lines[i] = f"{indent}self.{method_name}()"
                del lines[i + 1:j]


            else:
                lines[i] = f"{indent}self.{method_name}()"
                del lines[i + 1:j]

    final_content = '\n'.join(lines) + '\n\n' + '\n'.join(method_defs)
    return final_content

def process_group_filter(content, strategy_number, weight):
    pattern = re.compile(r"""
    \(filter\s+                                      # Start of the filter block
    \(\s*(\w+(?:-\w+)*)\s+\{:\s*window\s+(\d+)\}\)\s* # Capture the filter type and window size #issue, only captured 1 - instead of 2-
    \(\s*select-(top|bottom)\s+(\d+)\)           # Capture the select type and number
    ((?:\s*self\.\w+\(\)\s*(?=(?:\n[^s]|$)))*)       # Capture all method calls, allowing for spaces before and after, 
                                                     # ensuring it stops capturing when the next line is either empty, 
                                                     # doesn't contain "self.", or is the end of the string
    """, re.VERBOSE | re.DOTALL)

    def replacement_function(match):

        filter_type = phrase_mapping.get(match.group(1).strip())

        window = match.group(2)
        select_type = match.group(3).capitalize()
        number = match.group(4)
        def_str = match.group(5).strip()

        # Normalize method calls
        def_str_processed = ', '.join(def_str.splitlines())
        def_str_processed = ', '.join([re.sub(r'\s+', ' ', func).strip() for func in def_str_processed.split(',')])

        return f"GroupSort(self.algo,'{filter_type}',({def_str_processed}),{window},{select_type == 'Top'},{number}," + str(strategy_number) + "," + str(weight) + ")"

    new_content = re.sub(pattern, replacement_function, content)

    return new_content

def modify_weights_based_on_indent(content):

    lines = content.split('\n')
    modified_lines = []
    number_indent = None
    current_number = None
    adjusting = False
    
    indent_pattern = r'^\s*'
    number_pattern = r'^\s*([0-9]*\.?[0-9]+)\s*$'
    function_pattern = r'(\w+)\(.*?,\s*(\d+)\)$'
    def_pattern = r'^\s*def (\w+)\(self\):'

    def get_indent_level(line):
        return len(re.match(indent_pattern, line).group())

    def adjust_weight(line, factor):
        match = re.search(function_pattern, line)
        if match:
            parts = line.rsplit(',', 1)
            weight = parts[-1].strip(' )')
            if weight.isdigit():
                new_weight = str(float(weight) * factor)
                new_line = ','.join(parts[:-1]) + ',' + new_weight + ')'
                return new_line
        return line

    for i, line in enumerate(lines):
        number_match = re.match(number_pattern, line)
        if number_match:
            # Reset for a new number
            new_number = float(number_match.group(1))
            if 0 < new_number <= 1:
                current_number = new_number
                number_indent = get_indent_level(line)
                adjusting = True
                continue  # Skip adding this number line to modified_lines

        if adjusting:
            line_indent = get_indent_level(line)
            if line_indent < number_indent:
                adjusting = False  # Stop adjusting if indent level drops

            if adjusting:
                if line.startswith("self."):
                    # Check for the function definition in the next line to reset indent
                    def_search = re.search(def_pattern, lines[i + 1] if i + 1 < len(lines) else "")
                    if def_search:
                        number_indent = get_indent_level(lines[i + 1])
                        continue
                line = adjust_weight(line, current_number)

        modified_lines.append(line)

    return '\n'.join(modified_lines)

def adjust_weights_and_indent_based_on_prefix(content):
    import re

    lines = content.split('\n')
    modified_lines = []

    def adjust_weight_and_indent(line, new_weight, indent):
        # Find the weight and replace it with new_weight
        new_line = re.sub(r'(\d+(\.\d+)?)\)$', f'{new_weight})', line)
        # Adjust the indentation to match the given indent
        return ' ' * indent + new_line.strip()

    i = 0
    while i < len(lines):
        count = 1
        # Strip leading whitespace for the comparison
        while i + count < len(lines) and lines[i].lstrip()[:5] == lines[i + count].lstrip()[:5]:
            count += 1

        if count > 1:
            # Determine the indentation level of the first line in the group
            first_line_indent = len(lines[i]) - len(lines[i].lstrip())
            for j in range(i, i + count):
                weight_match = re.search(r'(\d+(\.\d+)?)\)$', lines[j])
                if weight_match:
                    weight = float(weight_match.group(1))
                    new_weight = str(round(weight / count, 3))
                    modified_lines.append(adjust_weight_and_indent(lines[j], new_weight, first_line_indent))
                else:
                    modified_lines.append(lines[j])
        else:
            modified_lines.append(lines[i])

        i += count

    return '\n'.join(modified_lines)


def adjust_weights_based_on_method_calls(content):
    lines = content.split('\n')
    modified_lines = lines.copy()  # Create a copy of the lines to modify

    # Function to adjust weight and indentation
    def adjust_weight_and_indent(line, new_weight, indent):
        # Find the weight and replace it with new_weight
        new_line = re.sub(r'(\d+(\.\d+)?)\)$', f'{new_weight})', line)
        # Adjust the indentation to match the given indent
        return ' ' * indent + new_line.strip()

    def get_indent_level(line):
        return len(line) - len(line.lstrip())

    def find_method_calls_within_method(start_index):
        """
        Find all method calls within a method starting from the given index.
        Returns a list of method names called within this method, including nested calls.
        """
        method_calls = []
        indent_level = get_indent_level(lines[start_index])
        i = start_index + 1
        while i < len(lines) and get_indent_level(lines[i]) > indent_level:
            call_match = re.search(r'self\.(\w+)\(\)', lines[i])
            if call_match:
                method_calls.append(call_match.group(1))
            i += 1
        return method_calls

    def adjust_method_calls(method_calls, count):
        """
        Adjust the weights for all method calls specified in method_calls list.
        Each call's weight is divided by the count.
        """
        for method_name in set(method_calls):
            def_pattern = r'^\s*def ' + method_name + r'\(self\):'
            for k, line in enumerate(lines):
                if re.match(def_pattern, line):
                    method_indent = get_indent_level(line)
                    method_calls_within = find_method_calls_within_method(k)
                    l = k + 1
                    while l < len(lines) and get_indent_level(lines[l]) > method_indent:
                        weight_match = re.search(r'(\d+(\.\d+)?)\)$', lines[l])
                        if weight_match:
                            weight = float(weight_match.group(1))
                            new_weight = str(round(weight / count, 2))
                            modified_lines[l] = adjust_weight_and_indent(lines[l], new_weight, get_indent_level(lines[l]))
                        # Recursive call for nested method adjustments
                        if lines[l].strip().startswith('self.') and method_calls_within:
                            adjust_method_calls(method_calls_within, count)
                        l += 1
                    break

    i = 0
    while i < len(lines):
        if 'self.' in lines[i] and '(' in lines[i] and ')' in lines[i]:  # Improved check for method calls
            method_calls = find_method_calls_within_method(i - 1)  # Assuming i is on a method call line
            if method_calls:
                adjust_method_calls(method_calls, len(method_calls))
        i += 1

    return '\n'.join(modified_lines)

def adjust_indentation(content):
    lines = content.split('\n')  # Split the content into lines

    for i in range(len(lines)-1):  # Iterate through lines except the last one
        line = lines[i]
        next_line = lines[i+1]

        # Determine the current line's indentation
        current_indent_level = len(line) - len(line.lstrip())
        
        # Determine the next line's intended indentation based on rules
        if line.rstrip().endswith(":"):
            # If current line ends with ":", next line should have +1 indent level
            intended_next_indent_level = current_indent_level + 4  # Assuming 4 spaces per indent level
        elif line.rstrip().endswith(")") and next_line.rstrip().endswith(")"):
            # If both current and next lines end with ")", maintain current indent level
            intended_next_indent_level = current_indent_level
        else:
            continue

        # Adjust the next line's indentation if necessary
        next_line_indent_level = len(next_line) - len(next_line.lstrip())
        if next_line_indent_level != intended_next_indent_level:
            # Re-indent next line according to the intended next indent level
            adjusted_next_line = ' ' * intended_next_indent_level + next_line.lstrip()
            lines[i+1] = adjusted_next_line  # Update the line in the original list

    # Return the adjusted content
    return '\n'.join(lines)

def modify_content(content, file_name_without_extension):
    # Define the new structure to be inserted, using the file name
    new_structure = f"""
    class {file_name_without_extension}Strategy(YellowCatStrat):
        def __init__(self, algo):
            super().__init__()
            self.algo = algo

        def Execute(self):"""

    # Split the original content by lines
    lines = content.split('\n')
    modified_lines = []
    execute_method_found = False

    for line in lines:
        if "{:rebalance-" in line:
            # Replace the target line with the new structure and adjust the flag
            modified_lines.append(new_structure)
            execute_method_found = True  # Indent lines after this
        elif execute_method_found:
            # Increase indent for lines after "def Execute(self):"
            modified_lines.append("    " + line)
        else:
            modified_lines.append(line)

    return '\n'.join(modified_lines)

def replace_none_with_closing_parenthesis(content):
    # Split the content into lines
    lines = content.split('\n')
    modified_lines = []

    for line in lines:
        # Replace ", None)" with ")"
        modified_line = line.replace(", None)", ")")
        modified_lines.append(modified_line)

    # Join the modified lines back into a single string
    return '\n'.join(modified_lines)

def process_files(folder_path):
    strategy_number = 1811  # Starting strategy number
    weight = 1  # Default weight value
    for file_path in glob.glob(os.path.join(folder_path, '*.txt')):
        file_name_without_extension = os.path.splitext(os.path.basename(file_path))[0]
        replace_sort_function(file_path, strategy_number, weight, file_name_without_extension)
        print(f"Processed: {file_path}")
        strategy_number += 1  # Increment strategy number for each file

folder_path = select_folder()
process_files(folder_path)
#region imports
from AlgorithmImports import *
#endregion
import os
import re

def extract_stock_symbols(project_dir):
    # Create a set to store unique stock symbols
    symbols_set = set()

    # Traverse through all subdirectories in the project directory
    for root, dirs, files in os.walk(project_dir):
        for file in files:
            if file.endswith(".py"):
                file_path = os.path.join(root, file)
                with open(file_path, "r") as f:
                    content = f.read()
                    # Extract stock symbols from the file content
                    symbols_array = extract_symbols(content)
                    # Add unique symbols to the set
                    symbols_set.update(symbols_array)

    # Print the unique stock symbols to the terminal
    print("Unique Stock Symbols:")
    print("'" + "','".join(sorted(symbols_set)) + "'")

def extract_symbols(text):
    pattern = r"'\b([A-Z]{2,5})\b'"
    matches = re.findall(pattern, text)
    return list(set(matches))

# Provide the path to your project directory
project_directory = "E:/Quantconnect/Yellow Cat On Fire/Strategies"

# Run the script
extract_stock_symbols(project_directory)
#region imports
from AlgorithmImports import *
#endregion
import os
import re

def replace_pattern(project_dir):
    pattern = r"CumReturn\(self\.algo,\s*'([A-Z]+)',\s*(\d+)\)\s*([<>]=?)\s*([-+]?\d+(?:\.\d+)?)"
    
    for root, dirs, files in os.walk(project_dir):
        for file in files:
            if file.endswith(".py"):
                file_path = os.path.join(root, file)
                with open(file_path, "r") as f:
                    content = f.read()
                
                matches = list(re.finditer(pattern, content))
                modified_content = content
                
                for match in reversed(matches):
                    found = match.group()
                    number = float(match.group(4))
                    
                    if abs(number) >= 1:
                        fixed = replace_match(match)
                        modified_content = modified_content[:match.start()] + fixed + modified_content[match.end():]
                        print(f"File: {file_path}")
                        print(f"Found: {found}")
                        print(f"Fixed: {fixed}")
                        print("---")
                
                if modified_content != content:
                    with open(file_path, "w") as f:
                        f.write(modified_content)

def replace_match(match):
    ticker = match.group(1)
    period = match.group(2)
    operator = match.group(3)
    number = float(match.group(4))
    
    if abs(number) >= 1:
        number /= 100
    
    return f"CumReturn(self.algo, '{ticker}', {period}) {operator} {number}"

# Provide the path to your project directory
project_directory = "E:/Quantconnect/Yellow Cat On Fire/Strategies"

# Run the script
replace_pattern(project_directory)
#region imports
from AlgorithmImports import *
#endregion
import os
import re

def replace_pattern(project_dir):
    patterns = [
        r"CumReturn\(self\.algo,\s*'([A-Z]+)',\s*(\d+)\)\s*([<>]=?)\s*([-+]?\d+(?:\.\d+)?)",
        r"MaxDD\(self\.algo,\s*'([A-Z]+)',\s*(\d+)\)\s*([<>]=?)\s*([-+]?\d+(?:\.\d+)?)"
    ]
    
    for root, dirs, files in os.walk(project_dir):
        for file in files:
            if file.endswith(".py"):
                file_path = os.path.join(root, file)
                with open(file_path, "r") as f:
                    content = f.read()
                
                modified_content = content
                
                for pattern in patterns:
                    matches = list(re.finditer(pattern, modified_content))
                    for match in reversed(matches):
                        found = match.group()
                        fixed = replace_match(match, pattern)
                        modified_content = modified_content[:match.start()] + fixed + modified_content[match.end():]
                        print(f"File: {file_path}")
                        print(f"Found: {found}")
                        print(f"Fixed: {fixed}")
                        print("---")
                
                if modified_content != content:
                    with open(file_path, "w") as f:
                        f.write(modified_content)

def replace_match(match, pattern):
    function = match.group(0).split('(')[0]
    ticker = match.group(1)
    period = match.group(2)
    operator = match.group(3)
    number = float(match.group(4))
    
    if "MaxDD" in pattern:
        if number > 1:
            number /= 100
        elif -1 <= number < 0:
            number = abs(number)
        elif number < -1:
            number = abs(number) / 100
    else:  # CumReturn
        if number > 1:
            number /= 100
        elif number < -1:
            number = abs(number) / 100
    
    return f"{function}(self.algo, '{ticker}', {period}) {operator} {number}"

# Provide the path to your project directory
project_directory = "E:/Quantconnect/Yellow Cat On Fire/Strategies"

# Run the script
replace_pattern(project_directory)
#region imports
from AlgorithmImports import *
#endregion
import os
import re

def find_nested_groupsort(project_dir):
    # Regular expression pattern to match nested GroupSort
    pattern = r"def\s+(\w+)\(self\):\s*\n\s+GroupSort\(.*?\(self\.(\w+)\(.*?\)"

    # Traverse through all subdirectories in the project directory
    for root, dirs, files in os.walk(project_dir):
        for file in files:
            if file.endswith(".py"):
                file_path = os.path.join(root, file)
                with open(file_path, "r") as f:
                    content = f.read()
                    class_match = re.search(r"class\s+(\w+)\(", content)
                    if class_match:
                        class_name = class_match.group(1)
                        matches = re.findall(pattern, content, re.DOTALL)
                        for match in matches:
                            def_name = match[0]
                            nested_def_name = match[1]
                            print(f"Nested GroupSort found in: {file_path} at def {def_name} (nested def: {nested_def_name}) in class {class_name}")
                            print("---")

def find_groupsort_with_1_def(project_dir):
    # Regular expression pattern to match GroupSort with 1 def
    pattern = r"def\s+(\w+)\(self\):\s*\n\s+GroupSort\(.*?,.*?,\((?:self\.(\w+)\(\)|'?\w+'?)\),.*?\)"

    # Traverse through all subdirectories in the project directory
    for root, dirs, files in os.walk(project_dir):
        for file in files:
            if file.endswith(".py"):
                file_path = os.path.join(root, file)
                with open(file_path, "r") as f:
                    content = f.read()
                    class_match = re.search(r"class\s+(\w+)\(", content)
                    if class_match:
                        class_name = class_match.group(1)
                        matches = re.findall(pattern, content, re.DOTALL)
                        for match in matches:
                            def_name = match[0]
                            nested_def_name = match[1]
                            if nested_def_name:
                                print(f"GroupSort with 1 def found in: {file_path} at def {def_name} (nested def: {nested_def_name}) in class {class_name}")
                            else:
                                print(f"GroupSort with 1 def found in: {file_path} at def {def_name} in class {class_name}")
                            print("---")

# Provide the path to your project directory
project_directory = "E:/Quantconnect/Yellow Cat On Fire/Strategies"

print("Searching for nested GroupSort...")
find_nested_groupsort(project_directory)

print("Searching for GroupSort with 1 def...")
find_groupsort_with_1_def(project_directory)
#region imports
from AlgorithmImports import *
#endregion


# Your New Python File
#CombinedStrategy1/version1.py
from AlgorithmImports import *
from indicators import *
from main import YellowCatStrat

class TQQQFTLTStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'SPY')>SMA(self.algo,'SPY',200):
            if RSI(self.algo,'TQQQ',10)>78:
                AH(self.algo,['BIL','UVXY','BIL'],1,0.33)
            else:
                if RSI(self.algo,'SPXL',10)>79:
                    AH(self.algo,['BIL','UVXY','BIL'],1,0.33)
                else:
                    if CumReturn(self.algo, 'TQQQ', 4) > 0.2:
                        if RSI(self.algo,'TQQQ',10)<31:
                            AH(self.algo,'TQQQ',1,1)
                        else:
                            if RSI(self.algo,'UVXY',10)>RSI(self.algo,'SQQQ',10):
                                AH(self.algo,['BIL','UVXY','BIL'],1,0.33)
                            else:
                                AH(self.algo,'SQQQ',1,1)
                    else:
                        AH(self.algo,'TQQQ',1,1)
        else:
            if RSI(self.algo,'TQQQ',10)<31:
                AH(self.algo,'TECL',1,1)
            else:
                if RSI(self.algo,'SMH',10)<30:
                    AH(self.algo,'SOXL',1,1)
                else:
                    if RSI(self.algo,'DIA',10)<27:
                        AH(self.algo,'UDOW',1,1)
                    else:
                        if RSI(self.algo,'SPY',14)<28:
                            AH(self.algo,'UPRO',1,1)
                        else:
                            self.Group1()
                            self.Group2()

    def Group1(self):
        if CumReturn(self.algo, 'QQQ', 200) < -0.2:
            if GetCurrentPrice(self.algo,'QQQ')<SMA(self.algo,'QQQ',20):
                if CumReturn(self.algo, 'QQQ', 60) < -0.12:
                    self.Group5()
                    self.Group6()
                else:
                    if RSI(self.algo,'TLT',10)>RSI(self.algo,'SQQQ',10):
                        AH(self.algo,'TQQQ',1,0.5)
                    else:
                        AH(self.algo,'SQQQ',1,0.5)
            else:
                if RSI(self.algo,'SQQQ',10)<31:
                    AH(self.algo,'PSQ',1,0.5)
                else:
                    if CumReturn(self.algo, 'QQQ', 9) > 0.055:
                        AH(self.algo,'PSQ',1,0.5)
                    else:
                        if RSI(self.algo,'TQQQ',10)>RSI(self.algo,'SOXL',10):
                            AH(self.algo,'TQQQ',1,0.5)
                        else:
                            AH(self.algo,'SOXL',1,0.5)

    def Group2(self):
        if GetCurrentPrice(self.algo,'QQQ')<SMA(self.algo,'QQQ',20):
            if CumReturn(self.algo, 'QQQ', 60) < -0.12:
                self.Group3()
                self.Group4()
            else:
                if RSI(self.algo,'TLT',10)>RSI(self.algo,'SQQQ',10):
                    AH(self.algo,'TQQQ',1,0.5)
                else:
                    AH(self.algo,'SQQQ',1,0.5)
        else:
            if RSI(self.algo,'TQQQ',10)>RSI(self.algo,'SOXL',10):
                AH(self.algo,'TQQQ',1,0.5)
            else:
                AH(self.algo,'SOXL',1,0.5)

    def Group3(self):
        if GetCurrentPrice(self.algo,'SPY')>SMA(self.algo,'SPY',20):
            AH(self.algo,'SPY',1,0.25)
        else:
            if RSI(self.algo,'TLT',10)>RSI(self.algo,'SQQQ',10):
                AH(self.algo,'QQQ',1,0.25)
            else:
                AH(self.algo,'PSQ',1,0.25)

    def Group4(self):
        if RSI(self.algo,'TLT',10)>RSI(self.algo,'SQQQ',10):
            AH(self.algo,'QQQ',1,0.25)
        else:
            AH(self.algo,'PSQ',1,0.25)

    def Group5(self):
        if GetCurrentPrice(self.algo,'SPY')>SMA(self.algo,'SPY',20):
            AH(self.algo,'SPY',1,0.25)
        else:
            if RSI(self.algo,'TLT',10)>RSI(self.algo,'SQQQ',10):
                AH(self.algo,'QQQ',1,0.25)
            else:
                AH(self.algo,'PSQ',1,0.25)
    def Group6(self):
        if RSI(self.algo,'TLT',10)>RSI(self.algo,'SQQQ',10):
            AH(self.algo,'QQQ',1,0.25)
        else:
            AH(self.algo,'PSQ',1,0.25)

class TQQQorNotStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'TQQQ',10)>78:
            AH(self.algo,['BIL','UVXY','BIL'],2,1/3)
        else:
            if CumReturn(self.algo, 'TQQQ', 6) < -0.12:
                if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                    AH(self.algo,['BIL','UVXY','BIL'],2,1/3)
                else:
                    if RSI(self.algo,'TQQQ',10)<32:
                        AH(self.algo,'TQQQ',2,1)
                    else:
                        if MaxDD(self.algo, 'TMF', 10) < 0.07:
                            AH(self.algo,'TQQQ',2,1)
                        else:
                            AH(self.algo,'BIL',2,1)
            else:
                if MaxDD(self.algo, 'QQQ', 10) > 0.06:
                    AH(self.algo,'BIL',2,1)
                else:
                    if MaxDD(self.algo, 'TMF', 10) > 0.07:
                        AH(self.algo,'BIL',2,1)
                    else:
                        if GetCurrentPrice(self.algo,'QQQ')>SMA(self.algo,'QQQ',25):
                            AH(self.algo,'TQQQ',2,1)
                        else:
                            if RSI(self.algo,'SPY',60)>50:
                                if RSI(self.algo,'BND',45)>RSI(self.algo,'SPY',45):
                                    AH(self.algo,'TQQQ',2,1)
                                else:
                                    AH(self.algo,'BIL',2,1)
                            else:
                                if RSI(self.algo,'IEF',200)<RSI(self.algo,'TLT',200):
                                    if RSI(self.algo,'BND',45)>RSI(self.algo,'SPY',45):
                                        AH(self.algo,'TQQQ',2,1)
                                    else:
                                        AH(self.algo,'BIL',2,1)
                                else:
                                    AH(self.algo,'BIL',2,1)



class DereckCustomBetaBallerStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.DereckCustomBetaBaller()

    def DereckCustomBetaBaller(self):
        if SMADayRet(self.algo,'TLT',350)<SMADayRet(self.algo,'TLT',550):
            if GetCurrentPrice(self.algo,'SPY')<SMA(self.algo,'SPY',200):
                self.V1()
            else:
                self.B2()
        else:
            self.N3()
    def V1(self):
        if RSI(self.algo,'BIL',8)<35:
            if RSI(self.algo,'TQQQ',10)>80:
                self.O6()
            else:
                AH(self.algo,'SOXL',3,1)
        else:
            if RSI(self.algo,'SPY',6)<27:
                self.E77()
            else:
                self.B5()
    def O6(self):
        Sort(self.algo,'RSI',['VIXM','VIXY'],13,False,1,3,1)

    def E77(self):
        if RSI(self.algo,'BSV',7)<RSI(self.algo,'SPHB',7):
            Sort(self.algo,'RSI',['SOXS','SOXS'],7,False,1,3,1)
        else:
           Sort(self.algo,'RSI',['SOXL','TECL'],7,False,1,3,1)
    def B5(self):
        if RSI(self.algo,'BSV',7)>RSI(self.algo,'SHY',7):
            self.B4()
        else:
            AH(self.algo,'SOXL',3,1)
    def B4(self):
        if RSI(self.algo,'QQQ',10)<30:
            Sort(self.algo,'SMADayRet',['TQQQ','SPXL','SOXL','UPRO'],5,True,1,3,1)
        else:
            if RSI(self.algo,'SPY',10)<30:
                AH(self.algo,'UPRO',3,1)
            else:
                if GetCurrentPrice(self.algo,'QLD')>SMA(self.algo,'QLD',20):
                    self.B14()
                else:
                    self.A42()
    def B14(self):
        if 50 >RSI(self.algo,'IEF',7):
            self.B15()
        else:
            if RSI(self.algo,'SPY',6)>75:
                AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
            else:
                AH(self.algo,'SOXL',3,1)
    def B15(self):
        if GetCurrentPrice(self.algo,'TLT')<SMA(self.algo,'TLT',21):
            self.B16()
        else:
            self.B17()
    def B16(self):
        if EMA(self.algo,'SPY',210)<=SMA(self.algo,'SPY',360):
            if RSI(self.algo,'TQQQ',10)<30:
                Sort(self.algo,'SMADayRet',['TQQQ','SOXL','UPRO'],5,True,1,3,1)
            else:
                if CumReturn(self.algo, 'SPY', 2) < -0.02:
                    Sort(self.algo,'CumReturn',['SPXS','TECS','SOXS','SQQQ','ERX'],5,False,1,3,1)
                else:
                    if CumReturn(self.algo,'SPXU',6)>CumReturn(self.algo,'UPRO',3):
                        Sort(self.algo,'CumReturn',['SOXS','SQQQ','EPI'],5,True,1,3,1)
                    else:
                        Sort(self.algo,'SMADayRet',['TECL','SOXL','TMV'],5,False,1,3,1)
        else:
            if SMADayRet(self.algo,'SPY',210)>SMADayRet(self.algo,'DBC',360):
                if RSI(self.algo,'TQQQ',11)>77:
                    AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                else:
                    if CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                        if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                            AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                        else:
                            Sort(self.algo,'SMADayRet',['SOXL','IYK','TMV'],5,False,1,3,1)
                    else:
                        if 50 <RSI(self.algo,'IEF',7):
                            Sort(self.algo,'SMADayRet',['TQQQ','IYK','SOXL','UPRO','TECL'],5,True,1,3,1)
                        else:
                            Sort(self.algo,'SMADayRet',['SOXL','IYK','UPRO'],22,False,1,3,1)
            else:
                self.Defence()
    def Defence(self):
        if STD(self.algo,'DBC',20)>STD(self.algo,'SPY',20):
            if STD(self.algo,'DBC',10)>0.03:
                if STD(self.algo,'TMV',5)<STD(self.algo,'DBC',5):
                    AH(self.algo,'TMV',3,1)
                else:
                    AH(self.algo,'DBC',3,1)
            else:
                if 50 <RSI(self.algo,'IEF',7):
                    Sort(self.algo,'SMADayRet',['TMV','SOXS','SPXU'],5,True,1,3,1)

                else:
                    Sort(self.algo,'CumReturn',['EFA','EEM','SPXS','SOXS','UCO','TMV'],5,False,1,3,1)
        else:
            if 50 <RSI(self.algo,'IEF',7):
                Sort(self.algo,'SMADayRet',['EPI','SOXL','UPRO','IYK'],5,False,1,3,1)

            else:
                Sort(self.algo,'CumReturn',['EWZ','TECS','SOXS','EUO','YCS','TMV'],5,False,1,3,1)
    def B17(self):
        if EMA(self.algo,'SPY',210)<=SMA(self.algo,'SPY',360):
            if CumReturn(self.algo, 'SPY', 2) < -0.02:
                Sort(self.algo,'SMADayRet',['SPXS','TECS','SOXS','SQQQ'],5,True,1,3,1)
            else:
                if CumReturn(self.algo,'SPXU',6)>CumReturn(self.algo,'UPRO',3):
                    Sort(self.algo,'CumReturn',['BIL','AGG','TMF'],5,False,1,3,1)
                else:
                    Sort(self.algo,'SMADayRet',['TECL','SOXL','TQQQ','EWZ','TMF'],5,False,1,3,1)
        else:
            if SMADayRet(self.algo,'SPY',210)>SMADayRet(self.algo,'DBC',360):
                if EMA(self.algo,'SPY',210)>EMA(self.algo,'SPY',360):
                    if RSI(self.algo,'TQQQ',11)>77:
                        AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                    else:
                        if CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                            if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                                AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                            else:
                                Sort(self.algo,'SMADayRet',['TECL','TQQQ','SPXL','EPI','SOXL','UPRO','QLD','EWZ','MVV','XLU','IYK','USD','TMF'],7,False,1,3,1)
                        if 50 <RSI(self.algo,'IEF',7):
                            Sort(self.algo,'SMADayRet',['TECL','SPXL','EPI','SOXL','UPRO','MVV'],7,False,1,3,1)
                        else:
                            Sort(self.algo,'CumReturn',['SOXS','TMF'],5,True,1,3,1)
                else:
                    Sort(self.algo,'RSI',['SPXS','SQQQ','TECS','SOXS'],5,False,1,3,1)
            else:
                self.Defence2()
    def Defence2(self):
        if STD(self.algo,'DBC',20)>STD(self.algo,'SPY',20):
            Sort(self.algo,'RSI',['SPXS','EPI','TECS','SOXS','SQQQ'],5,False,1,3,1)
        else:
            Sort(self.algo,'SMADayRet',['TECL','TQQQ','SOXL','TMF'],5,True,1,3,1)
    def A42(self):
        if RSI(self.algo,'TQQQ',9)<32:
            if CumReturn(self.algo,'TQQQ',2)>CumReturn(self.algo,'TQQQ',5):
                self.A41()
            else:
                Sort(self.algo,'RSI',['TMF','UCO','USD','SOXL','SQQQ'],5,False,1,3,1)
        else:
             self.A43()
    def A41(self):
        self.Substrategy1()
        self.Substrategy2()
    def Substrategy1(self):
        Sort(self.algo,'RSI',['TECL','SOXL','SHY'],10,False,1,3,0.5)
    def Substrategy2(self):
        Sort(self.algo,'RSI',['SHY','SOXL'],5,False,1,3,0.5)
    def A43(self):
        if GetCurrentPrice(self.algo,'TLT')>SMA(self.algo,'TLT',200):
            self.A19()
        else:
            self.B18()
    def A19(self):
        if SMADayRet(self.algo,'TLT',20)<0:
            self.A44()
        else:
            self.A55()
    def A44(self):
        if EMA(self.algo,'SPY',210)<=SMA(self.algo,'SPY',360):
            if RSI(self.algo,'TQQQ',10)<30:
                Sort(self.algo,'SMADayRet',['TECL','TQQQ','SOXL','UPRO'],5,False,1,3,1)
            else:
                if CumReturn(self.algo,'SPXU',6)>CumReturn(self.algo,'UPRO',3):
                    Sort(self.algo,'CumReturn',['SOXS','EUO','YCS'],5,True,1,3,1)
                else:
                    Sort(self.algo,'SMADayRet',['TECL','SOXL','TQQQ','CURE'],5,False,1,3,1)
        else:
            if RSI(self.algo,'TQQQ',11)>77:
                AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
            else:
                Sort(self.algo,'SMADayRet',['SOXL','TECL','TMV','TQQQ','UPRO'],5,False,1,3,1)
    def A55(self):
        if EMA(self.algo,'SPY',210)<=SMA(self.algo,'SPY',360):
            if RSI(self.algo,'TQQQ',10)<30:
                Sort(self.algo,'SMADayRet',['TECL','SOXL','TQQQ'],5,False,1,3,1)
            else:
                if CumReturn(self.algo, 'SPY', 2) < -0.02:
                    Sort(self.algo,'CumReturn',['TECS','SOXS','SQQQ'],5,True,1,3,1)
                else:
                    if CumReturn(self.algo,'SPXU',6)>CumReturn(self.algo,'UPRO',3):
                        Sort(self.algo,'CumReturn',['ERX','EUO','YCS'],5,True,1,3,1)
                    else:
                        Sort(self.algo,'SMADayRet',['EWZ','SOXL','MVV','USD'],5,False,1,3,1)
        else:
            if SMADayRet(self.algo,'SPY',210)>SMADayRet(self.algo,'DBC',360):
                if RSI(self.algo,'TQQQ',11)>77:
                    AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                else:
                    if CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                        if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                            AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                        else:
                            if 50 <RSI(self.algo,'IEF',7):
                                AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                            else:
                                Sort(self.algo,'CumReturn',['EWZ','UUP','TMF','UCO'],5,True,1,3,1)
                    else:
                        if 50 <RSI(self.algo,'IEF',7):
                            Sort(self.algo,'SMADayRet',['TQQQ','SPXL','QLD','USD','TECL'],5,False,1,3,1)
                        else:
                            Sort(self.algo,'CumReturn',['EWZ','EWZ','TMF'],5,True,1,3,1)
            else:
                self.Defence3()
    def Defence3(self):
        if STD(self.algo,'DBC',20)>STD(self.algo,'SPY',20):
            Sort(self.algo,'RSI',['SHY','EWZ','GLD','SPXS','TECS','SOXS','UCO','YCS'],5,False,1,3,1)
        else:
            if 50 <RSI(self.algo,'IEF',7):
                Sort(self.algo,'SMADayRet',['SOXL','USD','TMF'],5,False,1,3,1)
            else:
                Sort(self.algo,'CumReturn',['EWZ','SPXS','SOXS','UCO','YCS'],5,True,1,3,1)
    def B18(self):
        if SMADayRet(self.algo,'TLT',20)<0:
            self.A57()
        else:
            self.B17()
    def A57(self):
        if EMA(self.algo,'SPY',210)<=SMA(self.algo,'SPY',360):
            if RSI(self.algo,'TQQQ',10)<30:
                Sort(self.algo,'SMADayRet',['TQQQ','SOXL','UPRO'],5,True,1,3,1)
            else:
                if CumReturn(self.algo, 'SPY', 2) < -0.02:
                    Sort(self.algo,'CumReturn',['SPXS','TECS','SOXS','SQQQ','ERX'],5,False,1,3,1)
                else:
                    if CumReturn(self.algo,'SPXU',6)>CumReturn(self.algo,'UPRO',3):
                        Sort(self.algo,'CumReturn',['SOXS','SQQQ','EPI'],5,True,1,3,1)
                    else:
                        Sort(self.algo,'SMADayRet',['TECL','SOXL','TMV'],5,False,1,3,1)
        else:
            if SMADayRet(self.algo,'SPY',210)>SMADayRet(self.algo,'DBC',360):
                if RSI(self.algo,'TQQQ',11)>77:
                    AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                else:
                    if CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                        if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                            AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                        else:
                            Sort(self.algo,'SMADayRet',['SOXL','IYK','TMV'],5,False,1,3,1)
                    else:
                        if 50 <RSI(self.algo,'IEF',7):
                            Sort(self.algo,'SMADayRet',['TQQQ','SOXL','IYK','TMV','UPRO','TECL'],5,True,1,3,1)
                        else:
                            Sort(self.algo,'SMADayRet',['SOXL','IYK','UPRO'],22,False,1,3,1)
            else:
                self.Defence()
    def B2(self):
        if RSI(self.algo,'SPY',40)>75:
            if 50 <RSI(self.algo,'IEF',7):
                AH(self.algo,'QQQ',3,1)
            else:
                AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
        else:
            self.A54()
    def A54(self):
        if 50 >RSI(self.algo,'IEF',7):
            self.A53()
        else:
            if RSI(self.algo,'SPY',6)>75:
                AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
            else:
                AH(self.algo,'SOXL',3,1)
    def A53(self):
        if RSI(self.algo,'TQQQ',14)>75:
            AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
        else:
            if RSI(self.algo,'SPXL',10)>80:
                AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
            else:
                self.B23()
    def B23(self):
        if GetCurrentPrice(self.algo,'TLT')>SMA(self.algo,'TLT',200):
            self.A24()
        else:
            self.A52()
    def A24(self):
        if RSI(self.algo,'TLT',14)<50:
            self.A22()
        else:
            self.A26()
    def A22(self):
        if GetCurrentPrice(self.algo,'TLT')>SMA(self.algo,'TLT',5):
            self.A25()
        else:
            self.A51()
    def A25(self):
        if EMA(self.algo,'SPY',210)<=SMA(self.algo,'SPY',360):
            if RSI(self.algo,'TQQQ',10)<30:
                Sort(self.algo,'SMADayRet',['TQQQ','SOXL','UPRO','TECL','SPXL'],5,True,1,3,1)
            else:
                if CumReturn(self.algo,'SPXU',6)>CumReturn(self.algo,'UPRO',3):
                    Sort(self.algo,'CumReturn',['TECS','SOXS','SQQQ','TMF','SHY'],5,True,1,3,1)
                else:
                    Sort(self.algo,'SMADayRet',['TECL','SOXL','UPRO','EWZ','TMF','TQQQ'],5,False,1,3,1)
        else:
            if CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                Sort(self.algo,'SMADayRet',['TECL','TQQQ','TMF'],7,False,1,3,1)
            else:
                Sort(self.algo,'SMADayRet',['SOXL','TMF'],7,False,1,3,1)
    def A51(self):
        if RSI(self.algo,'TLT',14)<20:
            AH(self.algo,'SHY',3,1)
        else:
            if SMADayRet(self.algo,'TLT',20)<0:
                self.A21()
            else:
                self.A50()
    def A21(self):
        if EMA(self.algo,'SPY',210)<=SMA(self.algo,'SPY',360):
            if CumReturn(self.algo,'SPXU',6)>= CumReturn(self.algo,'UPRO',3):
                Sort(self.algo,'CumReturn',['SOXS','ERX','SHY'],5,True,1,3,1)
            else:
                Sort(self.algo,'SMADayRet',['TQQQ','SOXL','CURE','EWZ','SHY'],5,False,1,3,1)
        else:
            if SMA(self.algo,'SPY',210)>SMA(self.algo,'DBC',360):
                if RSI(self.algo,'TQQQ',11)>77:
                    AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                else:
                    if CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                        if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                            AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                        else:
                            Sort(self.algo,'SMADayRet',['TECL','TQQQ','SOXL','UPRO','TMV','SHY'],5,False,1,3,1)
                    else:
                        Sort(self.algo,'SMADayRet',['TECL','TQQQ','SOXL','UPRO','TMV','SHY'],5,True,1,3,1)
            else:
                self.A49()
    def A49(self):
        if STD(self.algo,'DBC',20)>STD(self.algo,'SPY',20):
            Sort(self.algo,'RSI',['EEM','TECS','SOXS','TMV'],5,False,1,3,1)
        else:
            Sort(self.algo,'RSI',['EEM','TECS','SOXS','TMV'],10,False,1,3,1)
    def A50(self):
        if EMA(self.algo,'SPY',210)<=SMA(self.algo,'SPY',360):
            if CumReturn(self.algo,'SPXU',6)>= CumReturn(self.algo,'UPRO',3):
                Sort(self.algo,'SMADayRet',['TQQQ','SOXL','UPRO','TECL','TMF'],5,True,1,3,1)
            else:
                Sort(self.algo,'SMADayRet',['TECL','TQQQ','SOXL','TMF'],5,False,1,3,1)
        elif SMADayRet(self.algo,'SPY',210)>SMADayRet(self.algo,'DBC',360):
            if RSI(self.algo,'TQQQ',11)>77:
                AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
            elif CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                    AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                else:
                    Sort(self.algo,'SMADayRet',['TECL','TQQQ','SPXL','EPI','SOXL','UPRO','QLD','EWZ','MVV','PUI','IYK','USD','TMF'],7,False,1,3,1)
            else:
                if 50 <RSI(self.algo,'IEF',7):
                    Sort(self.algo,'SMADayRet',['TECL','TQQQ','SOXL','PUI'],5,False,1,3,1)
                else:
                    Sort(self.algo,'CumReturn',['SOXS','SQQQ','UCO','DIG'],5,False,1,3,1)
        else:
            Sort(self.algo,'SMADayRet',['EPI','UPRO','SOXL','TQQQ'],5,True,1,3,1)
    def A26(self):
        if RSI(self.algo,'TLT',14)>80:
            self.A27()
        else:
            if GetCurrentPrice(self.algo,'TLT')<SMA(self.algo,'TLT',21):
                self.A44()
            else:
                self.A55()
    def A27(self):
        if SMADayRet(self.algo,'SPY',210)>SMADayRet(self.algo,'DBC',360):
            if CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                    AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                else:
                    Sort(self.algo,'SMADayRet',['TECL','TQQQ','SOXL','UPRO'],5,False,1,3,1)
            else:
                Sort(self.algo,'RSI',['SQQQ','TECS','SOXS','TMV'],5,True,1,3,1)
        else:
            Sort(self.algo,'SMADayRet',['EPI','UPRO','SOXL','TQQQ','TMV'],5,True,1,3,1)
    def A52(self):
        if GetCurrentPrice(self.algo,'TLT')<SMA(self.algo,'TLT',21):
            self.A57()
        else:
            self.A56()
    def A56(self):
        if EMA(self.algo,'SPY',210)<=SMA(self.algo,'SPY',360):
            if CumReturn(self.algo, 'SPY', 2) <= -0.02:
                Sort(self.algo,'CumReturn',['SPXS','TECS','SOXS','SQQQ'],5,True,1,3,1)
            elif CumReturn(self.algo,'SPXU',6)>= CumReturn(self.algo,'UPRO',3):
                Sort(self.algo,'CumReturn',['BIL','AGG','TMF'],5,False,1,3,1)
            else:
                Sort(self.algo,'SMADayRet',['TECL','TQQQ','SOXL','EWZ','TMF'],5,False,1,3,1)
        elif SMADayRet(self.algo,'SPY',210)>SMADayRet(self.algo,'DBC',360):
            if EMA(self.algo,'SPY',210)>EMA(self.algo,'SPY',360):
                if RSI(self.algo,'TQQQ',11)>77:
                    AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                elif CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                    if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                        AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                    else:
                        Sort(self.algo,'SMADayRet',['TECL','TQQQ','SPXL','EPI','SOXL','UPRO','QLD','EWZ','MVV','XLU','IYK','USD','TMF'],7,False,1,3,1)
                elif 50 <RSI(self.algo,'IEF',7):
                    Sort(self.algo,'SMADayRet',['TECL','SPXL','EPI','SOXL','UPRO','MVV','UGE'],7,False,1,3,1)
                else:
                    Sort(self.algo,'CumReturn',['SOXS','TMF'],5,True,1,3,1)
            else:
                Sort(self.algo,'RSI',['SPXS','SQQQ','TECS','SOXS'],5,False,1,3,1)
        else:
            self.Defence2()
    def N3(self):
        if GetCurrentPrice(self.algo,'SPY')>SMA(self.algo,'SPY',200):
            if RSI(self.algo,'QQQ',14)>80:
                AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
            else:
                if RSI(self.algo,'SPY',10)>80:
                    AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                else:
                    self.A31()
        else:
            if RSI(self.algo,'TQQQ',9)<32:
                if CumReturn(self.algo,'TQQQ',2)>= CumReturn(self.algo,'TQQQ',5):
                    self.A41()
                else:
                    if RSI(self.algo,'SPY',10)<30:
                        self.A40()
                    else:
                        if GetCurrentPrice(self.algo,'TQQQ')>SMA(self.algo,'TQQQ',20):
                            if RSI(self.algo,'SQQQ',10)<31:
                                AH(self.algo,'SQQQ',3,1)
                            else:
                                AH(self.algo,'TQQQ',3,1)
                        else:
                            Sort(self.algo,'RSI',['TMF','UCO','USD','SOXL','SQQQ'],5,False,1,3,1)
            else:
                self.A31()
    def A31(self):
        if GetCurrentPrice(self.algo,'TLT')>SMA(self.algo,'TLT',200):
            self.A30()
        else:
            self.A37()
    def A30(self):
        if RSI(self.algo,'TLT',14)<50:
            self.A29()
        else:
            self.A28()
    def A29(self):
        if GetCurrentPrice(self.algo,'TLT')>SMA(self.algo,'TLT',5):
            self.A32()
        else:
            self.A33()
    def A32(self):
        if EMA(self.algo,'SPY',210)<=SMA(self.algo,'SPY',360):
            if RSI(self.algo,'TQQQ',10)<30:
                Sort(self.algo,'SMADayRet',['TECL','TQQQ','SOXL','UPRO'],5,True,1,3,1)
            else:
                if CumReturn(self.algo,'SPXU',6)>= CumReturn(self.algo,'UPRO',3):
                    Sort(self.algo,'CumReturn',['TECS','SOXS','SQQQ','TMF','SHY'],5,True,1,3,1)
                else:
                    Sort(self.algo,'SMADayRet',['TECL','TQQQ','SOXL','UPRO','EWZ','TMF'],5,False,1,3,1)
        else:
            if CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                Sort(self.algo,'SMADayRet',['TECL','TQQQ','TMF'],7,False,1,3,1)
            else:
                Sort(self.algo,'SMADayRet',['SOXL','TMF'],7,False,1,3,1)
    def A33(self):
        if RSI(self.algo,'TLT',14)<20:
            AH(self.algo,'TMF',3,1)
        else:
            if SMADayRet(self.algo,'TLT',20)<0:
                self.A21()
            else:
                self.A34()
    def A34(self):
        if EMA(self.algo,'SPY',210)<=SMA(self.algo,'SPY',360):
            if CumReturn(self.algo,'SPXU',6)>= CumReturn(self.algo,'UPRO',3):
                Sort(self.algo,'SMADayRet',['TQQQ','SOXL','UPRO','TECL','TMF'],5,True,1,3,1)
            else:
                Sort(self.algo,'SMADayRet',['TECL','TQQQ','SOXL','TMF'],5,False,1,3,1)
        elif SMA(self.algo,'SPY',210)>SMA(self.algo,'DBC',360):
            if RSI(self.algo,'TQQQ',11)>77:
                AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
            elif CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                    AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                else:
                    Sort(self.algo,'SMADayRet',['TECL','TQQQ','EPI','SOXL','UPRO','QLD','EWZ','MVV','XLU','USD','TMF'],7,False,1,3,1)
            elif 50 <RSI(self.algo,'IEF',7):
                Sort(self.algo,'SMADayRet',['TECL','TQQQ','SOXL','XLU'],5,False,1,3,1)
            else:
                Sort(self.algo,'CumReturn',['SOXS','SQQQ','UCO','DIG'],5,False,1,3,1)
        else:
            Sort(self.algo,'SMADayRet',['EPI','UPRO','SOXL','TQQQ'],5,True,1,3,1)
    def A28(self):
        if RSI(self.algo,'TLT',14)>80:
            self.A27()
        else:
            self.A35()
    def A35(self):
        if SMADayRet(self.algo,'TLT',20)<0:
            self.A44()
        else:
            self.A36()
    def A36(self):
        if EMA(self.algo,'SPY',210)<=SMA(self.algo,'SPY',360):
            if RSI(self.algo,'TQQQ',10)<30:
                Sort(self.algo,'SMADayRet',['TECL','TQQQ','SOXL'],5,False,1,3,1)
            elif CumReturn(self.algo, 'SPY', 2) <= -0.02:
                Sort(self.algo,'CumReturn',['TECS','SOXS','SQQQ'],5,True,1,3,1)
            elif CumReturn(self.algo,'SPXU',6)>= CumReturn(self.algo,'UPRO',3):
                Sort(self.algo,'CumReturn',['ERX','EUO','YCS'],5,True,1,3,1)
            else:
                Sort(self.algo,'SMADayRet',['SOXL','EWZ','MVV','USD'],5,False,1,3,1)
        elif SMADayRet(self.algo,'SPY',210)>SMADayRet(self.algo,'DBC',360):
            if RSI(self.algo,'TQQQ',11)>77:
                AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
            elif CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                    AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                elif 50 <RSI(self.algo,'IEF',7):
                    AH(self.algo,'SOXL',3,1)
                else:
                    Sort(self.algo,'CumReturn',['EWZ','UUP','TMF','UCO'],5,True,1,3,1)
            elif 50 <RSI(self.algo,'IEF',7):
                Sort(self.algo,'SMADayRet',['TECL','TQQQ','UPRO','QLD','USD'],5,False,1,3,1)
            else:
                Sort(self.algo,'CumReturn',['EWZ','UUP','TMF'],5,True,1,3,1)
        else:
            self.A45()
    def A45(self):
        if STD(self.algo,'DBC',20)>STD(self.algo,'SPY',20):
            Sort(self.algo,'RSI',['SHY','EWZ','GLD','SPXU','TECS','SOXS','UCO','YCS'],5,False,1,3,1)
        elif 50 <RSI(self.algo,'IEF',7):
            Sort(self.algo,'SMADayRet',['SOXL','USD','TMF'],5,False,1,3,1)
        else:
            Sort(self.algo,'CumReturn',['EWZ','SPXU','SOXS','UCO','YCS'],5,True,1,3,1)
    def A37(self):
        if GetCurrentPrice(self.algo,'TLT')<SMA(self.algo,'TLT',21):
            self.A38()
        else:
            self.A39()
    def A38(self):
        if EMA(self.algo,'SPY',210)<=SMA(self.algo,'SPY',360):
            if RSI(self.algo,'TQQQ',10)<30:
                Sort(self.algo,'SMADayRet',['TQQQ','SOXL','UPRO'],5,True,1,3,1)
            else:
                if CumReturn(self.algo, 'SPY', 2) <= -0.02:
                    Sort(self.algo,'CumReturn',['SPXU','TECS','SOXS','SQQQ','ERX'],5,False,1,3,1)
                else:
                    if CumReturn(self.algo,'SPXU',6)>= CumReturn(self.algo,'UPRO',3):
                        Sort(self.algo,'CumReturn',['SOXS','SQQQ','EPI'],5,True,1,3,1)
                    else:
                        Sort(self.algo,'SMADayRet',['TECL','SOXL','TMV'],5,False,1,3,1)
        else:
            if SMA(self.algo,'SPY',210)>SMA(self.algo,'DBC',360):
                if RSI(self.algo,'TQQQ',11)>77:
                    AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                else:
                    if CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                        if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                            AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                        else:
                            Sort(self.algo,'SMADayRet',['SOXL','IYK','TMV'],5,False,1,3,1)
                    else:
                        if 50 <RSI(self.algo,'IEF',7):
                            Sort(self.algo,'SMADayRet',['TQQQ','SOXL','UPRO','TMV','TECL'],5,True,1,3,1)
                        else:
                            Sort(self.algo,'SMADayRet',['SOXL','UPRO','IYK'],22,False,1,3,1)
            else:
                self.A46()
    def A46(self):
        if STD(self.algo,'DBC',20)>STD(self.algo,'SPY',20):
            if STD(self.algo,'DBC',10)>= 0.03:
                if STD(self.algo,'TMV',5)<=STD(self.algo,'DBC',5):
                    AH(self.algo,'TMV',3,1)
                else:
                    AH(self.algo,'DBC',3,1)
            else:
                if 50 <RSI(self.algo,'IEF',7):
                    Sort(self.algo,'SMADayRet',['TMV','SOXS','SPXU'],5,True,1,3,1)
                else:
                    Sort(self.algo,'CumReturn',['EFA','EEM','SPXU','SOXS','UCO','TMV'],5,False,1,3,1)
        else:
            if 50 <RSI(self.algo,'IEF',7):
                Sort(self.algo,'SMADayRet',['EPI','SOXL','UPRO'],5,False,1,3,1)
            else:
                Sort(self.algo,'CumReturn',['EWZ','TECS','SOXS','EUO','YCS','TMV'],5,True,1,3,1)
    def A39(self):
        if EMA(self.algo,'SPY',210)<=SMA(self.algo,'SPY',360):
            if CumReturn(self.algo, 'SPY', 2) < -0.02:
                Sort(self.algo,'CumReturn',['SPXU','TECS','SOXS','SQQQ'],5,True,1,3,1)
            else:
                if CumReturn(self.algo,'SPXU',6)>= CumReturn(self.algo,'UPRO',3):
                    Sort(self.algo,'CumReturn',['BIL','AGG','TMF'],5,False,1,3,1)
                else:
                    Sort(self.algo,'CumReturn',['TECL','TQQQ','SOXL','EWZ','TMF'],5,False,1,3,1)
        else:
            if SMA(self.algo,'SPY',210)>SMA(self.algo,'DBC',360):
                if EMA(self.algo,'SPY',210)>EMA(self.algo,'SPY',360):
                    if RSI(self.algo,'TQQQ',11)>77:
                        AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                    else:
                        if CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                            if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                                AH(self.algo,['BIL','UVXY','SQQQ'],3,0.33)
                            else:
                                Sort(self.algo,'SMADayRet',['TECL','TQQQ','EPI','SOXL','UPRO','QLD','EWZ','MVV','XLU','USD','TMF'],7,True,1,3,1)
                        else:
                            if 50 <RSI(self.algo,'IEF',7):
                                Sort(self.algo,'SMADayRet',['TECL','EPI','SOXL','UPRO','MVV'],7,False,1,3,1)
                            else:
                                Sort(self.algo,'CumReturn',['SOXS','TMF'],5,True,1,3,1)
                else:
                    Sort(self.algo,'RSI',['SPXU','SQQQ','TECS','SOXS'],5,False,1,3,1)
            else:
                self.A47()
    def A47(self):
        if STD(self.algo,'DBC',20)>STD(self.algo,'SPY',20):
            Sort(self.algo,'RSI',['SPXU','EPI','TECS','SOXS','SQQQ'],5,False,1,3,1)
        else:
            Sort(self.algo,'SMADayRet',['TECL','TQQQ','SOXL','TMF'],5,True,1,3,1)
    def A40(self):
        Sort(self.algo,'SMADayRet',['TECL','TQQQ','SOXL','UPRO','QLD'],5,False,1,3,1)

#https://app.composer.trade/symphony/PUwnNnExWNsJsQvIexsm/details

class AAnimalCrackersProteusJpwnStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.animal_crackers_proteus_jpwn_()
    
    def animal_crackers_proteus_jpwn_(self):
        Sort(self.algo,'CumReturn',('CAT','PETS','TIGR','DOG','DOGZ','BIRD','SWAN','TAIL','OTTR','BUCK','DUK','COWS','COWZ','BEEZ','HON','HIVE','BUL','BULZ','FROG','HOG','MOO','HKND','OWL','GOOS','SNAL','PAWZ','BUG','ZBRA','WOOF','WOLF','BFLY','CALF'),5,True,1,4,0.33)
        Sort(self.algo,'STD',('CAT','PETS','TIGR','DOG','DOGZ','BIRD','SWAN','TAIL','OTTR','BUCK','DUK','COWS','COWZ','BEEZ','HON','HIVE','BUL','BULZ','FROG','HOG','MOO','HKND','OWL','GOOS','SNAL','PAWZ','BUG','ZBRA','WOOF','WOLF','BFLY','CALF'),63,False,4,4,0.33)    
        Sort(self.algo,'SMADayRet',('CAT','PETS','TIGR','DOG','DOGZ','BIRD','TAIL','OTTR','SWAN','BUCK','DUK','COWS','COWZ','HON','HIVE','BUL','BULZ','FROG','HOG','MOO','HKND','OWL','GOOS','SNAL','PAWZ','BUG','ZBRA','WOOF','WOLF','BFLY','CALF'),100,True,4,4,0.33)
#https://app.composer.trade/symphony/p29T4nppixfx8kkqLaSX/details

class AAnansiPortfolioV7UltraLBT20120802Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'SOXL',8)<53.83:
            AH(self.algo,'MSFU',5,1)
        else:
            if MaxDD(self.algo, 'QQQ', 6) < 0.035:
                AH(self.algo,'AAPU',5,1)
            else:
                AH(self.algo,'TECS',5,1)
    
#https://app.composer.trade/symphony/KYaGOhJXKW72bASOpnlI/details

class AAILongBetStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        Sort(self.algo,'SMADayRet',('AMZU','MSFU','NVDU','FBL','NVDL'),9,True,1,6,0.5)
        Sort(self.algo,'CumReturn',('AAPD','GGLS'),37,True,1,6,0.5)

#https://app.composer.trade/symphony/pD0yMALVhlVfRcIcMkkq/details

class AAIDigitalCurrencyRevolutionStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.growth()
        self.Ayield()
    def Ayield(self):
        AH(self.algo,'QQQY',7,0.12)
        AH(self.algo,'JEPI',7,0.12)
        AH(self.algo,'MSFO',7,0.12)
        AH(self.algo,'HTGC',7,0.12)
    def semis(self):
        AH(self.algo,'SOXL',7,0.25)
        AH(self.algo,'USD',7,0.25)
    def btc(self):
        self.semis()
    def growth(self):
        self.btc()

#https://app.composer.trade/symphony/ld2dd0ta3VDPjVn7LBzO/details

class A230326V301BeattheMarketSharedCopyStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v3_beat_the_market()
    def v3_beat_the_market(self):
        if RSI(self.algo,'QQQ',45)>50:
            Sort(self.algo,'RSI',('SOXX','QQQ','XLK','FNGS'),4,True,2,8,1.0)
        else:
            if RSI(self.algo,'QQQ',10)<30:
                Sort(self.algo,'RSI',('SOXL','HIBL','FNGU','TECL','TQQQ'),4,False,2,8,1.0)
            else:
                if RSI(self.algo,'QQQ',10)>45:
                    Sort(self.algo,'RSI',('SOXX','QQQ','IEF','TLT'),4,False,2,8,1.0)
                else:
                    Sort(self.algo,'RSI',('TBF','TBX','USDU'),4,False,2,8,1.0)

#https://app.composer.trade/symphony/nXk5JBw5lIKArezuBIL2/details

class A5050MinVolCBV3Anansi20180412Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo
    def Execute(self):
        self.v2a_bitcoin_strategy_dereckn()
    def v2a_bitcoin_strategy_dereckn(self):
        if GetCurrentPrice(self.algo,'SPY')>SMA(self.algo,'SPY',200):
            if GetCurrentPrice(self.algo,'BITO')>SMA(self.algo,'BITO',15):
                AH(self.algo,'BITO',9,1.0)
            else:
                AH(self.algo,'SHY',9,1.0)
        else:
            if GetCurrentPrice(self.algo,'BITO')>SMA(self.algo,'BITO',200):
                AH(self.algo,'BITO',9,1.0)
            else:
                if RSI(self.algo,'BITO',10)<30:
                    AH(self.algo,'BITO',9,1.0)
                else:
                    if GetCurrentPrice(self.algo,'BITO')<SMA(self.algo,'BITO',15):
                        Sort(self.algo,'RSI',('BITI','TMV'),10,True,1,9,1.0)
                    else:
                        if RSI(self.algo,'BITO',10)>59:
                            AH(self.algo,'SHY',9,1.0)
                        else:
                            AH(self.algo,'BITO',9,1.0)

#https://app.composer.trade/symphony/W4agjJM4tEYLefrDpHeR/details

class A40dRSISortTop2Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo
    def Execute(self):
        self.A40d_rsi_sort_top_2()
    def A40d_rsi_sort_top_2(self):
        if RSI(self.algo,'VIXM',40)>69:
            AH(self.algo,'SPXU',10,1.0)
        else:
            Sort(self.algo,'RSI',('AAPL','MSFT','NVDA','AMD','XOM','NFLX','META','TSLA','AMZN','GOOGL','COIN'),40,True,2,10,1.0)

#https://app.composer.trade/symphony/hqZ8RdtyjUL1DyYK1Iyg/details

class A20dBNDvs60dSHXLKXLPLSRotatorokhi2ueditionStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo
    def Execute(self):
        self.A20d_bnd_vs_60d_sh_xlkxlp()
    def longshort_rotator(self):
        Sort(self.algo,'STD',('TMV','TMF','BIL','KMLM'),5,False,3,11,1.0)
    def A20d_bnd_vs_60d_sh_xlkxlp(self):
        if RSI(self.algo,'BND',20)>RSI(self.algo,'SH',60):
            if GetCurrentPrice(self.algo,'SPY')>SMA(self.algo,'SPY',200):
                AH(self.algo,'QLD',11,1.0)
            else:
                if RSI(self.algo,'QQQ',10)<30:
                    AH(self.algo,'QLD',11,1.0)
                else:
                    AH(self.algo,'XLP',11,1.0)
        else:
            if RSI(self.algo,'QQQ',10)<30:
                AH(self.algo,'QLD',11,1.0)
            else:
                self.longshort_rotator()

#https://app.composer.trade/symphony/o2CEBZVH85jH58xOVwVS/details

class A3xMeltingPotStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo
    def Execute(self):
        Sort(self.algo,'SMA',('BRZU','CURE','DFEN','DPST','DRN','DRV','DUSL','EDC','EDZ','ERX','ERY','EURL','FAS','FAZ','GDXD','GDXU','INDL','KORU','LABD','LABU','MEXX','MIDU','NAIL','OILD','GUSH','PILL','RETL','SDOW','SMDD','SOXL','SOXS','SPXL','SPXS','SQQQ','SRTY','TMF','TMV','TNA','TQQQ','TYD','TYO','TZA','UBOT','UDOW','URTY','UTSL','WTID','ERX','YANG','YINN'),5,False,3,12,1)

#https://app.composer.trade/symphony/1q6jGMW8CjyuRR0R5IUp/details

class A230414V101BOTZbotQLDAIFTLTSharedCopyStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo
    def Execute(self):
        if GetCurrentPrice(self.algo,'SPY')>SMA(self.algo,'SPY',200):
            if RSI(self.algo,'QQQ',10)>81:
                AH(self.algo,'PSQ',13,0.5)
                AH(self.algo,'VIXM',13,0.5)
            else:
                Sort(self.algo,'CumReturn',('QQQ','BOTZ','SVXY'),5,True,1,13,1)
        else:
            if RSI(self.algo,'QQQ',10)<30:
                AH(self.algo,'QLD',13,1)
            else:
                if RSI(self.algo,'SPY',10)<30:
                    AH(self.algo,'SPY',13,1)
                else:
                    if GetCurrentPrice(self.algo,'QQQ')<SMA(self.algo,'QQQ',20):
                        Sort(self.algo,'RSI',('PSQ','SHY','VIXM'),10,True,1,13,0.25)
                        Sort(self.algo,'CumReturn',('SH','BOTZ','VIXM','BOTZ'),5,True,2,13,0.75)
                    else:
                        AH(self.algo,'QQQ',13,1)

#https://app.composer.trade/symphony/6E69uwV5LmGygr5nCz2l/details

class A230221V2RisingRateswithVolSwitchsharedCopyStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo
    def Execute(self):
        if MaxDD(self.algo, 'QQQ', 10) >= 0.06:
            self.risk_on_core_risk_parity()
        else:
            if MaxDD(self.algo, 'TMF', 10) <= 0.07:
                self.risk_off_()
            else:
                self.risk_on_core_risk_parity()
    def risk_on_core_risk_parity(self):
        AHIV(self.algo,('DBMF','UUP','GLD'),45,14,1.0)
    def risk_off_(self):
        AHIV(self.algo,('UPRO','TQQQ','TMF','FAS','FNGU','SOXL'),45,14,1.0)

#https://app.composer.trade/symphony/2SVN8PTIzCAIENePM1qR/details

class A2060FTLTv11nicomavisStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo
    def Execute(self):
        self.A2060_ftlt()
    def A2060_ftlt(self):
        if RSI(self.algo,'BND',20)>RSI(self.algo,'SH',60):
            if GetCurrentPrice(self.algo,'QQQ')>SMA(self.algo,'QQQ',200):
                AH(self.algo,'TQQQ',15,0.25)
                AH(self.algo,'UPRO',15,0.25)
                AH(self.algo,'DBMF',15,0.25)
                AH(self.algo,'EDV',15,0.25)
            else:
                AH(self.algo,'VT',15,1.0)
        else:
            if RSI(self.algo,'QQQ',14)<35:
                AH(self.algo,'QQQ',15,0.5)
                AH(self.algo,'VT',15,0.5)
            else:
                if RSI(self.algo,'IEF',7)>RSI(self.algo,'PSQ',20):
                    AH(self.algo,'VT',15,0.5)
                    AH(self.algo,'BND',15,0.5)
                else:
                    AH(self.algo,'BTAL',15,1.0)

#https://app.composer.trade/symphony/jKE01T3GqLpXduJ4ZKKN/details

#https://app.composer.trade/symphony/xGOMAc7Tow4jelDsnhKM/details
class A230610ACollectionofReallyWorseBadIdeassharedStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo
    def Execute(self):
        self.A230610_a_collection_of_really_worse_bad_ideas_shared()
    def a_really_worse_idea_using_svix_delete_for_longer_bt_ar_1593_dd_154_beta_012(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.11:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                AH(self.algo,'SPXS',17,0.33)
            else:
                AH(self.algo,'SVIX',17,0.33)
        else:
            AH(self.algo,'SPXS',17,0.16)
            AH(self.algo,'SVIX',17,0.16)
    def base_015_beta(self):
        AH(self.algo,'SMH',17,0.055)
        AH(self.algo,'VIXM',17,0.055)
        AH(self.algo,'SVXY',17,0.055)
        AH(self.algo,'XLK',17,0.055)
        AH(self.algo,'SPY',17,0.055)
        AH(self.algo,'QQQ',17,0.055)
    def long_high_beta_23(self):
        AH(self.algo,'SOXL',17,0.066)
        AH(self.algo,'UPRO',17,0.066)
        AH(self.algo,'TQQQ',17,0.066)
        AH(self.algo,'SVXY',17,0.066)
        AH(self.algo,'TECL',17,0.066)
    def short_negative_beta_1_to_3(self):
        AH(self.algo,'SOXS',17,0.066)
        AH(self.algo,'SPXS',17,0.066)
        AH(self.algo,'SQQQ',17,0.066)
        AH(self.algo,'TECS',17,0.066)
        AH(self.algo,'VIXY',17,0.066)
    def a_really_worse_idea_using_3x_ar_1160_dd_259_beta_110(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.11:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                self.short_negative_beta_1_to_3()
            else:
                self.long_high_beta_23()
        else:
            self.base_015_beta()
    def a_really_worse_idea_using_svxy_ar_587_dd_180_beta_011(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.11:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                AH(self.algo,'SPXS',17,0.33)
            else:
                AH(self.algo,'SVXY',17,0.33)
        else:
            AH(self.algo,'SVXY',17,0.11)
            AH(self.algo,'VIXM',17,0.11)
            AH(self.algo,'SPXS',17,0.11)
    def A230610_a_collection_of_really_worse_bad_ideas_shared(self):
        self.a_really_worse_idea_using_svxy_ar_587_dd_180_beta_011()
        self.a_really_worse_idea_using_3x_ar_1160_dd_259_beta_110()
        self.a_really_worse_idea_using_svix_delete_for_longer_bt_ar_1593_dd_154_beta_012()

#https://app.composer.trade/symphony/xJX0SWVIbDwVH13YxRNk/details

class ABTVersionv001ForgedSteelBT033019AR847MDD76Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.A230610_a_collection_of_really_worse_bad_ideas_shared()
    
    def a_really_worse_bad_idea_using_svix_delete_for_longer_bt_ar_1593_dd_154_beta_012(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.11:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                AH(self.algo,'SPXS',18,0.33)
            else:
                AH(self.algo,'SVIX',18,0.33)
        else:
            AH(self.algo,'SPXS',18,0.16)
            AH(self.algo,'SVIX',18,0.16)
    
    def base_015_beta(self):
        AH(self.algo,'SMH',18,0.055)
        AH(self.algo,'VIXM',18,0.055)
        AH(self.algo,'SVXY',18,0.055)
        AH(self.algo,'XLK',18,0.055)
        AH(self.algo,'SPY',18,0.055)
        AH(self.algo,'QQQ',18,0.055)

    def long_high_beta_23(self):
        AH(self.algo,'SOXL',18,0.066)
        AH(self.algo,'UPRO',18,0.066)
        AH(self.algo,'TQQQ',18,0.066)
        AH(self.algo,'SVXY',18,0.066)
        AH(self.algo,'TECL',18,0.066)
    
    def short_negative_beta_1_to_3(self):
        AH(self.algo,'SOXS',18,0.066)
        AH(self.algo,'SPXS',18,0.066)
        AH(self.algo,'SQQQ',18,0.066)
        AH(self.algo,'TECS',18,0.066)
        AH(self.algo,'VIXY',18,0.066)
    
    def a_really_worse_bad_idea_using_3x_ar_1160_dd_259_beta_110(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.11:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                self.short_negative_beta_1_to_3()
            else:
                self.long_high_beta_23()
        else:
            self.base_015_beta()
    
    def a_really_worse_bad_idea_using_svxy_ar_587_dd_180_beta_011(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.11:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                AH(self.algo,'SPXS',18,0.33)
            else:
                AH(self.algo,'SVXY',18,0.33)
        else:
            AH(self.algo,'SVXY',18,0.11)
            AH(self.algo,'VIXM',18,0.11)
            AH(self.algo,'SPXS',18,0.11)
    
    def A230610_a_collection_of_really_worse_bad_ideas_shared(self):
        self.a_really_worse_bad_idea_using_svxy_ar_587_dd_180_beta_011()
        self.a_really_worse_bad_idea_using_3x_ar_1160_dd_259_beta_110()
        self.a_really_worse_bad_idea_using_svix_delete_for_longer_bt_ar_1593_dd_154_beta_012()
    
#https://app.composer.trade/symphony/znwPl6sKTVZrGVABYE5x/details

class ABTCvsMinerRotationStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if MaxDD(self.algo, 'TMF', 9) >= 0.1:
            AH(self.algo,'WGMI',19,0.5)
            AH(self.algo,'BLOK',19,0.5)
        else:
            AH(self.algo,'IBIT',19,1)
    #https://app.composer.trade/symphony/kGaoD6SPkLS2qXMaouZf/details

class ABoringTQQQTrendzStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'SPY')>SMA(self.algo,'SPY',200):
            if RSI(self.algo,'TQQQ',10)>79:
                AH(self.algo,'UVXY',20,0.2)
            else:
                if RSI(self.algo,'SPXL',10)>80:
                    AH(self.algo,'UVXY',20,0.2)
                else:
                    AH(self.algo,'TQQQ',20,0.2)
        else:
            if RSI(self.algo,'TQQQ',10)<31:
                AH(self.algo,'TECL',20,0.2)
            else:
                if RSI(self.algo,'SPY',10)<30:
                    AH(self.algo,'SPXL',20,0.2)
                else:
                    if RSI(self.algo,'UVXY',10)>74:
                        if RSI(self.algo,'UVXY',10)>84:
                            if GetCurrentPrice(self.algo,'TQQQ')>SMA(self.algo,'TQQQ',20):
                                AH(self.algo,'TQQQ',20,0.2)
                            else:
                                Sort(self.algo,'RSI',('SQQQ','BSV'),10,True,1,20,0.2)
                        else:
                            AH(self.algo,'UVXY',20,0.2)
                    else:
                        if GetCurrentPrice(self.algo,'TQQQ')>SMA(self.algo,'TQQQ',20):
                            AH(self.algo,'TQQQ',20,0.2)
                        else:
                            Sort(self.algo,'RSI',('SQQQ','BSV'),10,True,1,20,0.1)
                            Sort(self.algo,'CumReturn',('SPY','TLT','GLD','UUP','DBC','SHV'),120,True,2,20,0.1)
        self.not_boring_dip_buyer()
    
    def risk_on_core_risk_parity(self):
        AHIV(self.algo,('TMF','TQQQ'),45,20,0.8)
    
    def risk_off_(self):
        AHIV(self.algo,('GLD','UUP','SPY','TLT'),45,20,0.8)
    
    def risk_off(self):
        if RSI(self.algo,'QQQ',10)<32:
            AH(self.algo,'TQQQ',20,0.8)
        else:
            AHIV(self.algo,('GLD','TLT','QQQ','UUP'),45,20,0.8)

    def not_boring_dip_buyer(self):
        if MaxDD(self.algo, 'QQQ', 10) > 0.06:
            self.risk_off()
        else:
            if MaxDD(self.algo, 'TLT', 10) > 0.04:
                self.risk_off_()
            else:
                self.risk_on_core_risk_parity()
    #https://app.composer.trade/symphony/akRPvZ8ry2MYqFocRTre/details

class ABitcoinStrategiesStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.bitcoin_strategies()
    
    def _bitcoin_signal_rsi_check(self):
        if CumReturn(self.algo, 'BITO', 5) > 0.0:
            if RSI(self.algo,'SPY',21)<RSI(self.algo,'SHY',21):
                AH(self.algo,'BIL',21,0.5)
            else:
                AH(self.algo,'SPXS',21,0.5)
        else:
            if CumReturn(self.algo, 'BITO', 21) > 0.0:
                AH(self.algo,'SPXL',21,0.5)
            else:
                AH(self.algo,'BIL',21,0.5)
    
    def gbtc_bito_correlation(self):
        if EMA(self.algo,'GBTC',100)>SMA(self.algo,'GBTC',300):
            if SMADayRet(self.algo,'GBTC',50)>0:
                if GetCurrentPrice(self.algo,'GBTC')>SMA(self.algo,'GBTC',20):
                    if EMA(self.algo,'GBTC',10)>SMA(self.algo,'GBTC',20):
                        if RSI(self.algo,'GBTC',10)<75:
                            AH(self.algo,'SPXL',21,0.25)
                        else:
                            AH(self.algo,'BIL',21,0.25)
                    else:
                        AH(self.algo,'BIL',21,0.25)
                else:
                    AH(self.algo,'BIL',21,0.25)
            else:
                AH(self.algo,'BIL',21,0.25)
        else:
            AH(self.algo,'BIL',21,0.25)
        if EMA(self.algo,'BITO',100)>SMA(self.algo,'BITO',300):
            if SMADayRet(self.algo,'BITO',50)>0:
                if GetCurrentPrice(self.algo,'BITO')>SMA(self.algo,'BITO',20):
                    if EMA(self.algo,'BITO',10)>SMA(self.algo,'BITO',20):
                        if RSI(self.algo,'BITO',10)<75:
                            AH(self.algo,'TQQQ',21,0.25)
                        else:
                            AH(self.algo,'BIL',21,0.25)
                    else:
                        AH(self.algo,'BIL',21,0.25)
                else:
                    AH(self.algo,'BIL',21,0.25)
            else:
                AH(self.algo,'BIL',21,0.25)
        else:
            AH(self.algo,'BIL',21,0.25)
    
    def bitcoin_strategies(self):
        self.gbtc_bito_correlation()
        self._bitcoin_signal_rsi_check()

    #https://app.composer.trade/symphony/NQL07teiuOvfMTQZzjsk/details

class ABitcoinsignalRSICheckStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if CumReturn(self.algo, 'BITO', 5) > 0.0:
            if RSI(self.algo,'SPY',21)<RSI(self.algo,'SHY',21):
                AH(self.algo,'BIL',22,1)
            else:
                AH(self.algo,'SPXU',22,1)
        else:
            if CumReturn(self.algo, 'BITO', 21) > 0.0:
                AH(self.algo,'UPRO',22,1)
            else:
                AH(self.algo,'BIL',22,1)
    #https://app.composer.trade/symphony/aq11pJKFhhjkOKgwYAJ6/details

class ABitcoin200dMovingAverageMonthlyStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'BITO')>SMA(self.algo,'BITO',200):
            AH(self.algo,'BITO',23,1)
        else:
            AH(self.algo,'SHV',23,1)
    
    #https://app.composer.trade/symphony/n1LIsQg0RgaSkXPD36cM/details

class ABigDumbSortV2Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.big_dumb_sort_v2()
    
    def big_dumb_sort_v2(self):
        if RSI(self.algo,'QQQ',10)>40:
            if RSI(self.algo,'QQQ',10)<75:
                Sort(self.algo,'SMADayRet',('ERX','RETL','DRN','FAZ','TMV','GUSH','TQQQ','UPRO','UDOW','NAIL','WANT','DPST','WEBL','TECL','TNA','FNGU','LLY','NVDA','UVXY'),10,True,4,24,0.33)
                Sort(self.algo,'STD',('ERX','RETL','DRN','FAZ','TMV','GUSH','TQQQ','UPRO','UDOW','NAIL','WANT','WEBL','DPST','TECL','TNA','FNGU','LLY','NVDA','UVXY'),10,False,4,24,0.33)
                Sort(self.algo,'MaxDD',('ERX','RETL','DRN','FAZ','TMV','GUSH','TQQQ','UPRO','UDOW','NAIL','WANT','WEBL','TECL','DPST','TNA','FNGU','LLY','NVDA','UVXY'),10,False,4,24,0.33)
            else:
                if RSI(self.algo,'QQQ',10)>80:
                    AH(self.algo,'VIXY',24,1.0)
                else:
                    AH(self.algo,'VIXM',24,1.0)
        else:
            if RSI(self.algo,'QQQ',10)<30:
                AH(self.algo,'TECL',24,1)
            else:
                AH(self.algo,'BTAL',24,1.0)
    #https://app.composer.trade/symphony/OdylXAplIVk3rbl4aMEV/details

class ABigDumbSortStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'QQQ',10)>40:
            if RSI(self.algo,'QQQ',10)<75:
                Sort(self.algo,'SMADayRet',('ERX','RETL','DRN','FAZ','TMV','GUSH','TQQQ','SPXL','UDOW','NAIL','WANT','DPST','WEBL','TECL','TNA','FNGU','LLY','NVDA'),10,True,4,25,0.333)
                Sort(self.algo,'STD',('ERX','RETL','DRN','FAZ','TMV','GUSH','TQQQ','SPXL','UDOW','NAIL','WANT','WEBL','DPST','TECL','TNA','FNGU','LLY','NVDA'),10,False,4,25,0.333)
                Sort(self.algo,'MaxDD',('ERX','RETL','DRN','FAZ','TMV','GUSH','TQQQ','SPXL','UDOW','NAIL','WANT','WEBL','TECL','DPST','TNA','FNGU','LLY','NVDA'),10,False,4,25,0.333)
            else:
                AH(self.algo,'BIL',25,1)
        else:
            AH(self.algo,'BIL',25,1)
    
#https://app.composer.trade/symphony/SVkgFvKDs8CQe69QXV0w/details

class ACopyofCurrentv2Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if EMA(self.algo,'TSLA',21)<GetCurrentPrice(self.algo,'TSLA'):
            AH(self.algo,'TSLL',26,0.5)
        else:
            AH(self.algo,'TSLQ',26,0.5)
        if EMA(self.algo,'NVDA',21)<GetCurrentPrice(self.algo,'NVDA'): 
            AH(self.algo,'NVDL',26,0.5)
        else:
            AH(self.algo,'NVDS',26,0.5)
#https://app.composer.trade/symphony/gaQiNRWi5Ruq4vDZ0Rxo/details
class RabbitVsTurtleStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo, 'QQQE', 10) > 79:
            self.uvxy_uvix()
        elif RSI(self.algo, 'VTV', 10) > 79:
            self.uvxy_uvix()
        elif RSI(self.algo, 'VOX', 10) > 79:
            self.uvxy_uvix()
        elif RSI(self.algo, 'TECL', 10) > 79:
            self.uvxy_uvix()
        elif RSI(self.algo, 'VOOG', 10) > 79:
            self.uvxy_uvix()
        elif RSI(self.algo, 'VOOV', 10) > 79:
            self.uvxy_uvix()
        elif RSI(self.algo, 'XLP', 10) > 75:
            self.uvxy_uvix()
        elif RSI(self.algo, 'TQQQ', 10) > 79:
            self.uvxy_uvix()
        elif RSI(self.algo, 'XLY', 10) > 80:
            self.uvxy_uvix()
        elif RSI(self.algo, 'FAS', 10) > 80:
            self.uvxy_uvix()
        elif RSI(self.algo, 'SPY', 10) > 80:
            self.uvxy_uvix()
        elif CumReturn(self.algo, 'MSFT', 1) < CumReturn(self.algo, 'QQQ', 1):
            AH(self.algo, 'MSFX', 16, 1)
        elif CumReturn(self.algo, 'AAPL', 1) < CumReturn(self.algo, 'QQQ', 1):
            AH(self.algo, 'AAPX', 16, 1)
        else:
            AH(self.algo, 'TQQQ', 16, 1)

    def uvxy_uvix(self):
        AH(self.algo, 'UVXY', 16, 0.5)
        AH(self.algo, 'UVXY', 16, 0.5)
from AlgorithmImports import *
import math
import pandas as pd
from cmath import sqrt
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Data.Custom import *
from QuantConnect.Python import PythonData

class IntelligentSkyRodent(QCAlgorithm):
    def Initialize(self):
        self.cash = 80000
        self.buffer_pct = 0.03
        self.SetStartDate(2023, 6, 1)
        self.SetEndDate(2024, 6, 5)
        self.SetCash(self.cash)
        self.equities = ['FNGS','SPLV','TMV', 'VCIT', 'XLY', 'HIBL', 'XLK', 'XLP', 'SVXY', 'QID', 'TBF', 'TSLA', 'LQD', 'VTIP', 'EDV', 'STIP', 'SPTL', 'IEI', 'USDU', 'SQQQ', 'VIXM', 'SPXU', 'QQQ', 'BSV', 'TQQQ', 'SPY', 'DBC', 'SHV', 'IAU', 'VEA', 'UTSL', 'UVXY', 'UPRO', 'EFA', 'EEM', 'TLT', 'SHY', 'GLD', 'SLV', 'USO', 'WEAT', 'CORN', 'SH', 'DRN', 'PDBC', 'COMT', 'KOLD', 'BOIL', 'ESPO', 'PEJ', 'UGL', 'URE', 'VXX', 'UUP', 'BND', 'DUST', 'JDST', 'JNUG', 'GUSH', 'DBA', 'DBB', 'COM', 'PALL', 'AGQ', 'BAL', 'WOOD', 'URA', 'SCO', 'UCO', 'DBO', 'TAGS', 'CANE', 'REMX', 'COPX', 'IEF', 'SPDN', 'CHAD', 'DRIP', 'SPUU', 'INDL', 'BRZU', 'ERX', 'ERY', 'CWEB', 'CHAU', 'KORU', 'MEXX', 'EDZ', 'EURL', 'YINN', 'YANG', 'TNA', 'TZA', 'SPXL', 'SPXS', 'MIDU', 'TYD', 'TYO', 'TMF', 'TECL', 'TECS', 'SOXL', 'SOXS', 'LABU', 'LABD', 'RETL', 'DPST', 'DRV', 'PILL', 'CURE', 'FAZ', 'FAS', 'EWA', 'EWGS', 'EWG', 'EWP', 'EWQ', 'EWU', 'EWJ', 'EWI', 'EWN', 'ECC', 'NURE', 'VNQI', 'VNQ', 'VDC', 'VIS', 'VGT', 'VAW', 'VPU', 'VOX', 'VFH', 'VHT', 'VDE', 'SMH', 'DIA', 'UDOW', 'PSQ', 'SOXX', 'VTI', 'COST', 'UNH', 'SPHB', 'BTAL', 'VIXY', 'WEBL', 'WEBS', 'UBT', 'PST', 'TLH', 'QLD', 'SQM', 'SSO', 'SD', 'DGRO', 'SCHD', 'SGOL', 'TIP', 'DUG', 'EWZ', 'TBX', 'VGI', 'XLU', 'XLV', 'EUO', 'YCS', 'MVV', 'USD', 'BIL', 'TMF', 'EPI', 'IYK', 'DIG', 'AGG', 'PUI', 'UDN', 'QQQE', 'VTV', 'VOOG', 'VOOV']

        self.MKT = self.AddEquity("SPY",Resolution.Daily).Symbol
        self.mkt = []
        for equity in self.equities:
            self.AddEquity(equity,Resolution.Minute)
            self.Securities[equity].SetDataNormalizationMode(DataNormalizationMode.Adjusted)
        self.AddEquity('BIL',Resolution.Minute)
        self.Securities['BIL'].SetDataNormalizationMode(DataNormalizationMode.TotalReturn)
       
        self.PT1 = 0.94

        self.HT1 = {str(i).zfill(2): 0 for i in range(1,10)}
        self.HTS1 = {str(i).zfill(2): [] for i in range(1,10)}
        self.HT2 = {str(i).zfill(2): 0 for i in range(1,10)}
        self.HTS2 = {str(i).zfill(2): [] for i in range(1,10)}
        self.HT3 = {str(i).zfill(2): 0 for i in range(1,10)}
        self.HTS3 = {str(i).zfill(2): [] for i in range(1,10)}

        self.Schedule.On(self.DateRules.EveryDay("SPY"),
                self.TimeRules.BeforeMarketClose("SPY", 2),
                self.FunctionBeforeMarketClose)
    def RSI(self,equity,period):
        extension = min(period*5,250)
        r_w = RollingWindow[float](extension)
        history = self.History(equity,extension - 1,Resolution.Daily)
        for historical_bar in history:
            r_w.Add(historical_bar.Close)
        while r_w.Count < extension:
            current_price = self.Securities[equity].Price
            r_w.Add(current_price)
        if r_w.IsReady:
            average_gain = 0
            average_loss = 0
            gain = 0
            loss = 0
            for i in range(extension - 1,extension - period -1,-1):
                gain += max(r_w[i-1] - r_w[i],0)
                loss += abs(min(r_w[i-1] - r_w[i],0))
            average_gain = gain/period
            average_loss = loss/period
            for i in range(extension - period - 1,0,-1):
                average_gain = (average_gain*(period-1) + max(r_w[i-1] - r_w[i],0))/period
                average_loss = (average_loss*(period-1) + abs(min(r_w[i-1] - r_w[i],0)))/period
            if average_loss == 0:
                return 100
            else:
                rsi = 100 - (100/(1 + average_gain / average_loss))
                return rsi
        else:
            return None

    def CumReturn(self,equity,period):

        history = self.History(equity, period, Resolution.Daily)
        closing_prices = pd.Series([bar.Close for bar in history])
        current_price = self.Securities[equity].Price
        # Convert current_price to a Series and use pd.concat to append it to closing_prices
        closing_prices = pd.concat([closing_prices, pd.Series([current_price])]).reset_index(drop=True)
        first_price = closing_prices.iloc[0]
        if first_price == 0:
            return None
        else:
            return_val = (current_price / first_price) - 1
            return return_val
    def STD(self,equity,period):
        r_w = RollingWindow[float](period + 1)
        r_w_return = RollingWindow[float](period)
        history = self.History(equity,period,Resolution.Daily)
        for historical_bar in history:
            r_w.Add(historical_bar.Close)
        while r_w.Count < period + 1:
            current_price = self.Securities[equity].Price
            r_w.Add(current_price)
        for i in range (period,0,-1):
            daily_return = (r_w[i-1]/r_w[i] - 1)
            r_w_return.Add(daily_return)
        dfstd = pd.DataFrame({'r_w_return':r_w_return})
        if r_w.IsReady:
            std = dfstd['r_w_return'].std()
            if std == 0:
                return 0
            else:
                return std
        else:
            return 0

    def MaxDD(self,equity,period):
        history = self.History(equity,period - 1,Resolution.Daily)
        closing_prices = pd.Series([bar.Close for bar in history])
        current_price = self.Securities[equity].Price
        closing_prices = closing_prices.append(pd.Series([current_price]))
        rolling_max = closing_prices.cummax()
        drawdowns = (rolling_max - closing_prices) / rolling_max
        max_dd = drawdowns.min()
        return max_dd

    def SMA(self,equity,period):
        r_w = RollingWindow[float](period)
        history = self.History(equity,period - 1,Resolution.Daily)
        for historical_bar in history:
            r_w.Add(historical_bar.Close)
        while r_w.Count < period:
            current_price = self.Securities[equity].Price
            r_w.Add(current_price)        
        if r_w.IsReady:
            sma = sum(r_w) / period
            return sma
        else:
            return 0

    def IV(self,equity,period):
        r_w = RollingWindow[float](period + 1)
        r_w_return = RollingWindow[float](period)
        history = self.History(equity,period,Resolution.Daily)
        for historical_bar in history:
            r_w.Add(historical_bar.Close)
        while r_w.Count < period + 1:
            current_price = self.Securities[equity].Price
            r_w.Add(current_price)
        for i in range (period,0,-1):
            if r_w[i] == 0:
                return 0
            else:
                daily_return = (r_w[i-1]/r_w[i] - 1)
                r_w_return.Add(daily_return)
        dfinverse = pd.DataFrame({'r_w_return':r_w_return})       
        if r_w.IsReady:
            std = dfinverse['r_w_return'].std()
            if std == 0:
                return 0
            else:
                inv_vol = 1 / std
                return inv_vol
        else:
            return 0

    def SMADayRet(self,equity,period):
        r_w = RollingWindow[float](period + 1)
        r_w_return = RollingWindow[float](period)
        history = self.History(equity,period,Resolution.Daily)
        for historical_bar in history:
            r_w.Add(historical_bar.Close)
        while r_w.Count < period + 1:
            current_price = self.Securities[equity].Price
            r_w.Add(current_price)
        for i in range (period,0,-1):
            if r_w[i] == 0:
                return None
            daily_return = (r_w[i-1]/r_w[i] - 1)
            r_w_return.Add(daily_return)
        if r_w.IsReady:
            smareturn = sum(r_w_return) / period
            return smareturn
        else:
            return 0
            
    def EMA(self,equity,period):
        extension = period + 50
        r_w = RollingWindow[float](extension)
        history = self.History(equity,extension - 1,Resolution.Daily)
        for historical_bar in history:
            r_w.Add(historical_bar.Close)
        while r_w.Count < extension:
            current_price = self.Securities[equity].Price
            r_w.Add(current_price)
        if r_w.IsReady:
            total_price = 0
            for i in range(extension - 1,extension - period - 2,-1):
                total_price += r_w[i]
            average_price = total_price/period
            for i in range(extension - period - 2,-1,-1):
                average_price = r_w[i]*2/(period+1) + average_price*(1-2/(period+1))
            return average_price
        else:
            return None
    def Sort(self,sort_type,equities,period,reverse,number,multiplier,holdings=1):
        self.PT = getattr(self,f"PT{number}") * multiplier /  holdings
        returns = {}
        for equity in equities:
            returns[equity] = getattr(self,sort_type)(equity,period)
        s_e = sorted([item for item in returns.items() if item[1] is not None],key = lambda x: x[1],reverse = reverse)
        t3e = s_e[:holdings]
        ht = getattr(self,f"HT{number}")
        hts = getattr(self,f"HTS{number}")
        for ticker in t3e:
            for i in ht.keys():
                if ht[i] == 0:
                    ht[i] = self.PT
                    hts[i].append(ticker[0])
                    break
        setattr(self,f"HT{number}",ht)
        setattr(self,f"HTS{number}",hts)

    def AH(self, equities, PTnumber, multiplier): #AppendHolding
        if not isinstance(equities, list):
            equities = [equities]
        
        HT = getattr(self, f"HT{PTnumber}")
        HTS = getattr(self, f"HTS{PTnumber}")
        PT = getattr(self, f"PT{PTnumber}") * multiplier
        
        for equity in equities:
            for i in HT.keys():
                if HT[i] == 0:
                    HT[i] = PT
                    HTS[i].append(equity)
                    break

    def OnData (self,data):
        pass

    def FunctionBeforeMarketClose(self):
        mkt_price = self.History(self.MKT,2,Resolution.Daily)['close'].unstack(level= 0).iloc[-1]
        self.mkt.append(mkt_price)
        mkt_perf = self.cash * self.mkt[-1] / self.mkt[0]
        self.Plot('Strategy Equity',self.MKT,mkt_perf)
        self.tqqq_ftlt()
        self.ExecuteTrade()

    
    def sideways_market_deleverage(self):
            if self.Securities['SPY'].Price > self.SMA('SPY', 20):
                self.AH('SPY', 1, 1.0)
            else:
                if self.RSI('TLT', 10) > self.RSI('SQQQ', 10):
                    self.AH('QQQ', 1, 1.0)
                else:
                    self.AH('PSQ', 1, 1.0)
            if self.RSI('TLT', 10) > self.RSI('SQQQ', 10):
                self.AH('QQQ', 1, 1.0)
            else:
                self.AH('PSQ', 1, 1.0)
    
    def nasdaq_in_crash_territory_time_to_deleverage(self):
        if self.Securities['QQQ'].Price < self.SMA('QQQ', 20):
            if self.CumReturn('QQQ', 60) <= -12:
                self.sideways_market_deleverage()
            else:
                if self.RSI('TLT', 10) > self.RSI('SQQQ', 10):
                    self.AH('TQQQ', 1, 1.0)
                else:
                    self.AH('SQQQ', 1, 1.0)
        else:
            if self.RSI('SQQQ', 10) < 31:
                self.AH('PSQ', 1, 1.0)
            else:
                if self.CumReturn('QQQ', 10) > 5.5:
                    self.AH('PSQ', 1, 1.0)
                else:
                    self.Sort('RSI',('QQQ','SMH'),10,True,1,1.0)
    
    def bear_market_sideways_protection(self):
        if self.CumReturn('QQQ', 252) < -20:
            self.nasdaq_in_crash_territory_time_to_deleverage()
        else:
            if self.Securities['QQQ'].Price < self.SMA('QQQ', 20):
                if self.RSI('TLT', 10) > self.RSI('SQQQ', 10):
                    self.AH('TQQQ', 1, 1.0)
                else:
                    self.AH('SQQQ', 1, 1.0)
            else:
                if self.RSI('SQQQ', 10) < 31:
                    self.AH('SQQQ', 1, 1.0)
                else:
                    if self.CumReturn('QQQ', 10) > 5.5:
                        self.AH('SQQQ', 1, 1.0)
                    else:
                        self.Sort('RSI',('TQQQ','SOXL'),10,True,1,1.0)
        if self.Securities['QQQ'].Price < self.SMA('QQQ', 20):
            if self.CumReturn('QQQ', 60) <= -12:
                self.sideways_market_deleverage()
            else:
                if self.RSI('TLT', 10) > self.RSI('SQQQ', 10):
                    self.AH('TQQQ', 1, 1.0)
                else:
                    self.AH('SQQQ', 1, 1.0)
        else:
            if self.RSI('SQQQ', 10) < 31:
                self.AH('SQQQ', 1, 1.0)
            else:
                if self.CumReturn('QQQ', 70) < -15:
                    self.Sort('RSI',('TQQQ','SOXL'),10,True,1,1.0)
                else:
                    self.Sort('CumReturn',('SPY','QQQ','DIA','XLP'),15,True,1,1.0)
    
    def dip_buy_strategy(self):
        if self.RSI('TQQQ', 10) < 31:
            self.AH('TECL', 1, 1.0)
        else:
            if self.RSI('SMH', 10) < 30:
                self.AH('SOXL', 1, 1.0)
            else:
                if self.RSI('SPY', 10) < 30:
                    self.AH('UPRO', 1, 1.0)
                else:
                    self.bear_market_sideways_protection()
    
    def svxy_ftlt(self):
        if self.RSI('QQQ', 10) > 80:
            self.AH('VIXY', 1, 0.33)
        else:
            if self.RSI('SPY', 10) > 80:
                self.AH('VIXY', 1, 0.33)
            else:
                if self.RSI('QQQ', 10) < 30:
                    self.AH('XLK', 1, 0.33)
                else:
                    if self.Securities['SVXY'].Price > self.SMA('SVXY', 24):
                        self.Sort('SMADayRet',('SVXY','SPY'),20,True,1,0.33)
                    else:
                        self.AH('BTAL', 1, 0.33)
    
    def spy_cooloff_period(self):
        self.AH('SHV', 1, 1.0)
    
    def bull_market(self):
            if self.RSI('QQQ', 10) > 80:
                self.AH('UVXY', 1, 1.0)
            else:
                if self.RSI('SPY', 10) > 80:
                    self.AH('UVXY', 1, 1.0)
                else:
                    if self.RSI('SPY', 60) > 60:
                        self.spy_cooloff_period()
                    else:
                        self.Sort('SMADayRet',('TQQQ','TECL','UDOW','UPRO'),21,True,1,0.67, 2)
                        self.svxy_ftlt()
    
    def tqqq_ftlt(self):
        if self.Securities['SPY'].Price > self.SMA('SPY', 200):
            self.bull_market()
        else:
            self.dip_buy_strategy()

    def ExecuteTrade(self):
        group1 = {
            'HTS': [self.HTS1[i][0] if len(self.HTS1[i]) == 1 else self.HTS1[i] for i in self.HTS1],
            'HT': [self.HT1[i] for i in self.HT1]
        }
        df1 = pd.DataFrame(group1)
        group2 = {
            'HTS': [self.HTS2[i][0] if len(self.HTS2[i]) == 1 else self.HTS2[i] for i in self.HTS2],
            'HT': [self.HT2[i] for i in self.HT2]
        }
        df2 = pd.DataFrame(group2)


        group3 = {
            'HTS': [self.HTS3[i][0] if len(self.HTS3[i]) == 1 else self.HTS3[i] for i in self.HTS3],
            'HT': [self.HT3[i] for i in self.HT3]
        }
        df3 = pd.DataFrame(group3)

        df = pd.concat([df1, df2, df3])
        df['HTS'] = df['HTS'].astype(str)
        result = df.groupby(['HTS']).sum().reset_index()
        for equity in self.equities:
            if all(not pd.isnull(result.iloc[i,0]) and not equity == result.iloc[i,0] for i in range(len(result))):
                if self.Portfolio[equity].HoldStock:
                    self.Liquidate(equity)
        output = "*****"
        for i in range(len(result)):
            if result.iloc[i,0]:
                percentage = round(result.iloc[i,1] * 100,2)
                output += "{}: {}% - ".format(result.iloc[i,0],percentage)
        output = output.rstrip(" - ")
        self.Log(output)
        for i in range(len(result)):
            if not result.iloc[i,1] == 0 and not result.iloc[i,0] == 'BIL':
                percentage_equity = self.Portfolio[result.iloc[i,0]].HoldingsValue / self.Portfolio.TotalPortfolioValue
                if result.iloc[i,1] < percentage_equity and abs(result.iloc[i,1] / percentage_equity - 1) > self.buffer_pct:
                    self.SetHoldings(result.iloc[i,0],result.iloc[i,1])
                else:
                    pass
        for i in range(len(result)):
            if not result.iloc[i,1] == 0 and not result.iloc[i,0] == 'BIL':
                percentage_equity = self.Portfolio[result.iloc[i,0]].HoldingsValue / self.Portfolio.TotalPortfolioValue
                if result.iloc[i,1] > percentage_equity and abs(percentage_equity / result.iloc[i,1] - 1) > self.buffer_pct:
                    self.SetHoldings(result.iloc[i,0],result.iloc[i,1])
                else:
                    pass

        self.HT1 = {str(i).zfill(2): 0 for i in range(1,10)}
        self.HTS1 = {str(i).zfill(2): [] for i in range(1,10)}
        self.HT2 = {str(i).zfill(2): 0 for i in range(1,10)}
        self.HTS2 = {str(i).zfill(2): [] for i in range(1,10)}
        self.HT3 = {str(i).zfill(2): 0 for i in range(1,10)}
        self.HTS3 = {str(i).zfill(2): [] for i in range(1,10)}
from AlgorithmImports import *
from indicators import *
from main import YellowCatStrat

#https://app.composer.trade/symphony/C5cBLyws1feYttagA8Pz/details

class LeveragedDeETFBalancedMixStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_leveraged_deetf_balanced_mix()

    def group_leveraged_deetf_balanced_mix(self):
        if RSI(self.algo, 'VTV', 10) > 79:
            AH(self.algo, 'UVXY', 274, 1)
        elif RSI(self.algo, 'VOX', 10) > 79:
            AH(self.algo, 'UVXY', 274, 1)
        elif RSI(self.algo, 'TECL', 10) > 79:
            AH(self.algo, 'UVXY', 274, 1)
        elif RSI(self.algo, 'TQQQ', 10) > 79:
            AH(self.algo, 'UVXY', 274, 1)
        elif RSI(self.algo, 'TQQQ', 10) < 30:
            AH(self.algo, 'TECL', 274, 1)
        else:
            self.group_leveraged_deetf_mix_no_frontrunners()

    def group_leveraged_deetf_mix_no_frontrunners(self):
        self.group_deetf_leveraged(0.4)
        self.group_200d_cross_volmageddon(0.3)
        self.group_bonds(0.3)

    def group_deetf_leveraged(self, weight):
        assets = ['MSFU', 'AAPU', 'NVDA', 'AMZU', 'META', 'GGLL', 'AVGO', 'AMD', 'TSLL', 'NFLX', 'ADBE']
        Sort(self.algo, 'RSI', assets, 45, True, 2, 274, weight)

    def group_200d_cross_volmageddon(self, weight):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            if SMA(self.algo, 'SPY', 3) < SMA(self.algo, 'SPY', 200):
                self.group_bull_cross_mod_tqqq(weight)
            else:
                self.group_volmageddon_2_no_fr(weight)
        else:
            if SMA(self.algo, 'SPY', 3) > SMA(self.algo, 'SPY', 200):
                self.group_bear_cross_mod_sqqq(weight)
            else:
                self.group_volmageddon_2_no_fr(weight)

    def group_bull_cross_mod_tqqq(self, weight):
        AH(self.algo, 'TQQQ', 274, weight * 0.5)
        self.group_rotator_tqqq_tecl_svxy(weight * 0.5)

    def group_rotator_tqqq_tecl_svxy(self, weight):
        assets = ['SVXY', 'TQQQ', 'TECL']
        Sort(self.algo, 'RSI', assets, 5, True, 1, 274, weight)

    def group_bear_cross_mod_sqqq(self, weight):
        AH(self.algo, 'SQQQ', 274, weight * 0.5)
        self.group_rotator_sqqq_tecs_vixy(weight * 0.5)

    def group_rotator_sqqq_tecs_vixy(self, weight):
        assets = ['VIXY', 'SQQQ', 'TECS']
        Sort(self.algo, 'RSI', assets, 5, True, 1, 274, weight)

    def group_volmageddon_2_no_fr(self, weight):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.12:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                AH(self.algo, 'UVXY', 274, weight)
            else:
                self.group_tecl_svxy(weight)
        else:
            self.group_volatility_time(weight)

    def group_tecl_svxy(self, weight):
        AH(self.algo, 'TECL', 274, weight * 0.5)
        AH(self.algo, 'SVXY', 274, weight * 0.5)

    def group_volatility_time(self, weight):
        if STD(self.algo, 'UVXY', 10) > 10:
            self.group_vixy_or_safety(weight)
        else:
            self.group_svxy_or_spxu(weight)

    def group_vixy_or_safety(self, weight):
        if RSI(self.algo, 'UVXY', 10) > 70:
            assets = ['UVXY', 'VIXY']
            Sort(self.algo, 'SMADayRet', assets, 5, True, 1, 274, weight)
        else:
            assets = ['VTI', 'BIL']
            Sort(self.algo, 'SMADayRet', assets, 14, True, 1, 274, weight)

    def group_svxy_or_spxu(self, weight):
        if RSI(self.algo, 'IEF', 10) > RSI(self.algo, 'PSQ', 20):
            self.group_70_svxy_30_spxu_or_svxy(weight)
        else:
            self.group_70_spxu_30_svxy_or_spxu(weight)

    def group_70_svxy_30_spxu_or_svxy(self, weight):
        assets = [('group_70_svxy_30_spxu', 0.5), ('SVXY', 0.5)]
        GroupSort(self.algo, 'RSI', assets, 5, False, 1, 274, weight)

    def group_70_svxy_30_spxu(self):
        AH(self.algo, 'SPXU', 274, 0.3)
        AH(self.algo, 'SVXY', 274, 0.7)

    def group_70_spxu_30_svxy_or_spxu(self, weight):
        assets = [('group_70_spxu_30_svxy', 0.5), ('SPXU', 0.5)]
        GroupSort(self.algo, 'RSI', assets, 5, False, 1, 274, weight)

    def group_70_spxu_30_svxy(self):
        AH(self.algo, 'SPXU', 274, 0.7)
        AH(self.algo, 'SVXY', 274, 0.3)

    def group_bonds(self, weight):
        if RSI(self.algo, 'TMF', 10) < 30:
            AH(self.algo, 'TMF', 274, weight)
        elif MaxDD(self.algo, 'TMV', 10) < 0.07:
            if MaxDD(self.algo, 'TQQQ', 10) < 0.07:
                AH(self.algo, 'TMF', 274, weight)
            else:
                self.group_bond_momentum_1(weight)
        else:
            self.group_bond_momentum_2(weight)

    def group_bond_momentum_1(self, weight):
        if EMA(self.algo, 'TMF', 5) > SMA(self.algo, 'TMF', 200):
            AH(self.algo, 'TMF', 274, weight)
        elif EMA(self.algo, 'TMV', 3) > SMA(self.algo, 'TMV', 20):
            AH(self.algo, 'TMV', 274, weight)
        else:
            self.group_bond_momentum_3(weight)

    def group_bond_momentum_2(self, weight):
        self.group_tmf_momentum(weight * 1/3)
        self.group_tmv_momentum(weight * 1/3)
        self.group_tlt_momentum(weight * 1/3)

    def group_bond_momentum_3(self, weight):
        self.group_tmf_momentum(weight * 1/3)
        self.group_tmv_momentum(weight * 1/3)
        self.group_tlt_momentum(weight * 1/3)

    def group_tmf_momentum(self, weight):
        if RSI(self.algo, 'TMF', 10) < 32:
            AH(self.algo, 'TMF', 274, weight)
        elif SMA(self.algo, 'TLT', 21) > SMA(self.algo, 'TLT', 110):
            AH(self.algo, 'TMF', 274, weight)
        elif EMA(self.algo, 'TLT', 8) < EMA(self.algo, 'TLT', 20):
            AH(self.algo, 'BIL', 274, weight)
        else:
            AH(self.algo, 'TMF', 274, weight)

    def group_tmv_momentum(self, weight):
        if RSI(self.algo, 'TMF', 10) < 32:
            AH(self.algo, 'TMF', 274, weight)
        elif SMA(self.algo, 'TMV', 15) > SMA(self.algo, 'TMV', 50):
            if GetCurrentPrice(self.algo, 'TMV') > SMA(self.algo, 'TMV', 135):
                if RSI(self.algo, 'TMV', 10) > 71:
                    AH(self.algo, 'BND', 274, weight)
                elif RSI(self.algo, 'TMV', 60) > 59:
                    AH(self.algo, 'TLT', 274, weight)
                else:
                    AH(self.algo, 'TMV', 274, weight)
            else:
                AH(self.algo, 'BND', 274, weight)
        else:
            AH(self.algo, 'BND', 274, weight)

    def group_tlt_momentum(self, weight):
        if SMA(self.algo, 'TLT', 350) > SMA(self.algo, 'TLT', 550):
            if RSI(self.algo, 'TLT', 60) > 62:
                AH(self.algo, 'BIL', 274, weight)
            else:
                AH(self.algo, 'TLT', 274, weight)
        elif RSI(self.algo, 'TLT', 60) > 53:
            AH(self.algo, 'TLT', 274, weight)
        else:
            AH(self.algo, 'BIL', 274, weight)

#https://app.composer.trade/symphony/c0YGbjDGGcHEYMziHgMz/details

class TheTreasuryEffectStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group1()
        self.group2()

    def group1(self):
        self.tmv_momentum()
        self.tmf_momentum()

    def group2(self):
        self.svxy_ftlt()
        self.tqqq_ftlt()

    def tmv_momentum(self):
        if RSI(self.algo, 'TMF', 10) < 32:
            AH(self.algo, 'TMF', 275, 0.25)
        else:
            if SMA(self.algo, 'TMV', 15) > SMA(self.algo, 'TMV', 50):
                if GetCurrentPrice(self.algo, 'TMV') > SMA(self.algo, 'TMV', 135):
                    if RSI(self.algo, 'TMV', 10) > 71:
                        AH(self.algo, 'SHV', 275, 0.25)
                    else:
                        if RSI(self.algo, 'TMV', 60) > 59:
                            AH(self.algo, 'TLT', 275, 0.25)
                        else:
                            AH(self.algo, 'TMV', 275, 0.25)
                else:
                    AH(self.algo, 'BND', 275, 0.25)
            else:
                AH(self.algo, 'BND', 275, 0.25)

    def tmf_momentum(self):
        if RSI(self.algo, 'TMF', 10) < 32:
            AH(self.algo, 'TMF', 275, 0.25)
        else:
            if RSI(self.algo, 'BIL', 30) < RSI(self.algo, 'TLT', 20):
                if EMA(self.algo, 'TMF', 8) < SMA(self.algo, 'TMF', 10):
                    if RSI(self.algo, 'TMF', 10) > 72:
                        AH(self.algo, 'SHV', 275, 0.25)
                    else:
                        AH(self.algo, 'TMF', 275, 0.25)
                else:
                    if RSI(self.algo, 'TQQQ', 10) < 31:
                        AH(self.algo, 'TECL', 275, 0.25)
                    else:
                        AH(self.algo, 'SHV', 275, 0.25)
            else:
                if RSI(self.algo, 'TQQQ', 10) < 31:
                    AH(self.algo, 'TECL', 275, 0.25)
                else:
                    AH(self.algo, 'SHV', 275, 0.25)

    def svxy_ftlt(self):
        if RSI(self.algo, 'QQQ', 10) > 80:
            AH(self.algo, 'VIXY', 275, 0.25)
        else:
            if RSI(self.algo, 'SPY', 10) > 80:
                AH(self.algo, 'VIXY', 275, 0.25)
            else:
                if RSI(self.algo, 'QQQ', 10) < 30:
                    AH(self.algo, 'XLK', 275, 0.25)
                else:
                    if GetCurrentPrice(self.algo, 'SVXY') > SMA(self.algo, 'SVXY', 24):
                        Sort(self.algo, 'SMADayRet', ('SVXY', 'SPY'), 20, True, 1, 275, 0.25)
                    else:
                        AH(self.algo, 'BTAL', 275, 0.25)

    def tqqq_ftlt(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            self.bull_market_strategy()
        else:
            self.bear_market_strategy()

    def bull_market_strategy(self):
        if RSI(self.algo, 'QQQ', 10) > 81:
            AH(self.algo, 'UVXY', 275, 0.25)
        elif RSI(self.algo, 'SPY', 10) > 80:
            AH(self.algo, 'UVXY', 275, 0.25)
        elif RSI(self.algo, 'SPY', 60) > 60:
            Sort(self.algo, 'SMADayRet', ('TMF', 'UUP', 'VIXY', 'XLP', 'VTI', 'IWM', 'SCO'), 15, True, 1, 275, 0.25)
        else:
            Sort(self.algo, 'SMADayRet', ('TQQQ', 'SOXL', 'TECL', 'UDOW', 'UPRO'), 21, True, 3, 275, 0.125)
            AH(self.algo, 'SVXY', 275, 0.125)

    def bear_market_strategy(self):
        if RSI(self.algo, 'TQQQ', 10) < 31:
            AH(self.algo, 'TECL', 275, 0.25)
        elif RSI(self.algo, 'SMH', 10) < 30:
            AH(self.algo, 'SOXL', 275, 0.25)
        elif RSI(self.algo, 'SPY', 10) < 30:
            AH(self.algo, 'UPRO', 275, 0.25)
        else:
            self.bear_market_sideways_protection()

    def bear_market_sideways_protection(self):
        if CumReturn(self.algo, 'QQQ', 252) < -0.2:
            self.nasdaq_crash_territory()
        else:
            self.nasdaq_not_crash_territory()

    def nasdaq_crash_territory(self):
        if GetCurrentPrice(self.algo, 'QQQ') < SMA(self.algo, 'QQQ', 20):
            if CumReturn(self.algo, 'QQQ', 60) <= -0.12:
                self.sideways_market_deleverage()
            else:
                if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'SQQQ', 10):
                    AH(self.algo, 'TQQQ', 275, 0.25)
                else:
                    AH(self.algo, 'SQQQ', 275, 0.25)
        else:
            if RSI(self.algo, 'SQQQ', 10) < 31:
                AH(self.algo, 'PSQ', 275, 0.25)
            elif CumReturn(self.algo, 'QQQ', 10) > 0.055:
                AH(self.algo, 'PSQ', 275, 0.25)
            else:
                Sort(self.algo, 'RSI', ('QQQ', 'SMH'), 10, True, 1, 275, 0.25)

    def nasdaq_not_crash_territory(self):
        if GetCurrentPrice(self.algo, 'QQQ') < SMA(self.algo, 'QQQ', 20):
            if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'SQQQ', 10):
                AH(self.algo, 'TQQQ', 275, 0.25)
            else:
                AH(self.algo, 'SQQQ', 275, 0.25)
        else:
            if RSI(self.algo, 'SQQQ', 10) < 31:
                AH(self.algo, 'SQQQ', 275, 0.25)
            elif CumReturn(self.algo, 'QQQ', 10) > 0.055:
                AH(self.algo, 'SQQQ', 275, 0.25)
            else:
                Sort(self.algo, 'RSI', ('TQQQ', 'SOXL'), 10, True, 1, 275, 0.25)

    def sideways_market_deleverage(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 20):
            AH(self.algo, 'SPY', 275, 0.125)
        else:
            if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'SQQQ', 10):
                AH(self.algo, 'QQQ', 275, 0.125)
            else:
                AH(self.algo, 'PSQ', 275, 0.125)
        
        if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'SQQQ', 10):
            AH(self.algo, 'QQQ', 275, 0.125)
        else:
            AH(self.algo, 'PSQ', 275, 0.125)

#https://app.composer.trade/symphony/ggaxKDFmLxU2oxNzbhG8/details

class SVXYFTLTv2Strategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_SVXY_FTLT_V2()

    def group_SVXY_FTLT_V2(self):
        if RSI(self.algo, 'QQQ', 10) > 80:
            AH(self.algo, 'UVXY', 276, 1)
        elif RSI(self.algo, 'SPY', 10) > 80:
            AH(self.algo, 'UVXY', 276, 1)
        elif RSI(self.algo, 'QQQ', 10) < 30:
            AH(self.algo, 'XLK', 276, 1)
        elif GetCurrentPrice(self.algo, 'SVXY') > SMA(self.algo, 'SVXY', 21):
            Sort(self.algo, 'SMADayRet', ('SVXY', 'VTI'), 20, True, 1, 276, 0.7)
            AH(self.algo, 'VIXM', 276, 0.3)
        else:
            Sort(self.algo, 'SMADayRet', ('BTAL', 'DBMF'), 20, True, 1, 276, 1)

#https://app.composer.trade/symphony/B1rcZOA1VJKFxmSNaBQ6/details

class QSPopBotLETFAWPStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_qqq_pop_bot()
        self.group_soxx_pop_bot()

    def group_qqq_pop_bot(self):
        if RSI(self.algo, 'TQQQ', 16) > 78:
            AH(self.algo, 'SQQQ', 114, 0.5)
        else:
            if RSI(self.algo, 'TQQQ', 15) < 25:
                AH(self.algo, 'TQQQ', 114, 0.5)
            else:
                self.group_letf_awp1()

    def group_soxx_pop_bot(self):
        if RSI(self.algo, 'SOXL', 15) > 80:
            AH(self.algo, 'SOXS', 114, 0.5)
        else:
            if RSI(self.algo, 'SOXL', 10) < 30:
                AH(self.algo, 'SOXL', 114, 0.5)
            else:
                self.group_letf_awp2()

    def group_letf_awp1(self):
        if RSI(self.algo, 'VIXM', 10) > 75:
            AH(self.algo, 'ICSH', 114, 0.5)
        else:
            if RSI(self.algo, 'IEF', 200) > RSI(self.algo, 'TLT', 200):
                self.group_tmf_bull1()
            else:
                if RSI(self.algo, 'SPY', 60) > 50:
                    self.group_tmv_bull1()
                else:
                    self.group_tmv_bear1()

    def group_letf_awp2(self):
        if RSI(self.algo, 'VIXM', 10) > 75:
            AH(self.algo, 'ICSH', 114, 0.5)
        else:
            if RSI(self.algo, 'IEF', 200) > RSI(self.algo, 'TLT', 200):
                self.group_tmf_bull2()
            else:
                if RSI(self.algo, 'SPY', 60) > 50:
                    self.group_tmv_bull2()
                else:
                    self.group_tmv_bear2()

    def group_tmf_bull1(self):
        AH(self.algo, 'TMF', 114, 0.056)
        AH(self.algo, 'TYD', 114, 0.056)
        AH(self.algo, 'UPRO', 114, 0.056)
        AH(self.algo, 'UDOW', 114, 0.056)
        AH(self.algo, 'TQQQ', 114, 0.056)
        AH(self.algo, 'URTY', 114, 0.056)
        AH(self.algo, 'UTSL', 114, 0.056)
        AH(self.algo, 'NUGT', 114, 0.056)
        AH(self.algo, 'UPRO', 114, 0.056)

    def group_tmf_bull2(self):
        AH(self.algo, 'TMF', 114, 0.056)
        AH(self.algo, 'TYD', 114, 0.056)
        AH(self.algo, 'UPRO', 114, 0.056)
        AH(self.algo, 'UDOW', 114, 0.056)
        AH(self.algo, 'TQQQ', 114, 0.056)
        AH(self.algo, 'URTY', 114, 0.056)
        AH(self.algo, 'UTSL', 114, 0.056)
        AH(self.algo, 'NUGT', 114, 0.056)
        AH(self.algo, 'UPRO', 114, 0.056)

    def group_tmv_bull1(self):
        AH(self.algo, 'TMV', 114, 0.2)
        AH(self.algo, 'USDU', 114, 0.05)
        AH(self.algo, 'UTSL', 114, 0.1)
        AH(self.algo, 'NUGT', 114, 0.05)
        AH(self.algo, 'TYO', 114, 0.1)

    def group_tmv_bull2(self):
        AH(self.algo, 'TMV', 114, 0.2)
        AH(self.algo, 'USDU', 114, 0.05)
        AH(self.algo, 'UTSL', 114, 0.1)
        AH(self.algo, 'NUGT', 114, 0.05)
        AH(self.algo, 'TYO', 114, 0.1)

    def group_tmv_bear1(self):
        AH(self.algo, 'TMV', 114, 0.25)
        AH(self.algo, 'USDU', 114, 0.25)

    def group_tmv_bear2(self):
        AH(self.algo, 'TMV', 114, 0.25)
        AH(self.algo, 'USDU', 114, 0.25)

#https://app.composer.trade/symphony/6A3cs4s9ZqtjLSpNmteK/details
class TSLAandBTCDeez11NOV2022Strategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo, 'BSV', 20) > RSI(self.algo, 'SQQQ', 20):
            AH(self.algo, 'BIL', 169, 0.1)
            AH(self.algo, 'JEPQ', 169, 0.1)
            AH(self.algo, 'TSLA', 169, 0.4)
            AH(self.algo, 'MSTR', 169, 0.4)
        else:
            AH(self.algo, 'BIL', 169, 0.4)
            AH(self.algo, 'JEPQ', 169, 0.4)
            AH(self.algo, 'TSLA', 169, 0.1)
            AH(self.algo, 'MSTR', 169, 0.1)


#https://app.composer.trade/symphony/fdLmBrvPaUv2pMAkkn1j/details
class MonthlyDividendsWithBlackSwanCatcherStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo, 'VIXM', 10) > 70:
            self.v210_pop_bots()
        else:
            self.popped_monthly_dividends()

    def v210_pop_bots(self):
        self.spy_pop_bot_v1()
        self.qqq_pop_bot_v1()
        self.smh_pop_bot_v1()

    def spy_pop_bot_v1(self):
        if RSI(self.algo, 'SPXL', 10) > 80:
            AH(self.algo, 'UVXY', 261, 0.33)
        elif RSI(self.algo, 'SPXL', 10) < 30:
            AH(self.algo, 'SPXL', 261, 0.33)
        else:
            AH(self.algo, 'BIL', 261, 0.33)

    def qqq_pop_bot_v1(self):
        if RSI(self.algo, 'TQQQ', 10) > 80:
            AH(self.algo, 'UVXY', 261, 0.33)
        elif RSI(self.algo, 'TQQQ', 10) < 30:
            AH(self.algo, 'TQQQ', 261, 0.33)
        else:
            AH(self.algo, 'BIL', 261, 0.33)

    def smh_pop_bot_v1(self):
        if RSI(self.algo, 'SOXL', 10) < 30:
            AH(self.algo, 'SOXL', 261, 0.33)
        else:
            AH(self.algo, 'BIL', 261, 0.33)

    def popped_monthly_dividends(self):
        self.spy_pop_bot_v2()
        self.qqq_pop_bot_v2()
        self.smh_pop_bot_v2()

    def spy_pop_bot_v2(self):
        if RSI(self.algo, 'SPXL', 10) > 80:
            AH(self.algo, 'UVXY', 261, 0.33)
        elif RSI(self.algo, 'SPXL', 10) < 30:
            AH(self.algo, 'SPXL', 261, 0.33)
        else:
            self.monthly_dividend_group()

    def qqq_pop_bot_v2(self):
        if RSI(self.algo, 'TQQQ', 10) > 80:
            AH(self.algo, 'UVXY', 261, 0.33)
        elif RSI(self.algo, 'TQQQ', 10) < 30:
            AH(self.algo, 'TQQQ', 261, 0.33)
        else:
            self.monthly_dividend_group()

    def smh_pop_bot_v2(self):
        if RSI(self.algo, 'SOXL', 10) < 30:
            AH(self.algo, 'SOXL', 261, 0.33)
        else:
            self.monthly_dividend_group()

    def monthly_dividend_group(self):
        AH(self.algo, 'CII', 261, 0.165)
        AH(self.algo, 'AMZA', 261, 0.165)
#https://app.composer.trade/symphony/YW7cvPP2J1h0VGyhUo59/details
#https://app.composer.trade/symphony/ReK7huWMgkQqGVfG1WBV/details
class V1TMVTMFSelectorMichaelBStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_v1_tmv_tmf_selector()

    def group_v1_tmv_tmf_selector(self):
        if MaxDD(self.algo, 'TMV', 5) < 0.1:
            if MaxDD(self.algo, 'TMF', 5) < 0.1:
                AH(self.algo, 'SPY', 282, 1)
            else:
                Sort(self.algo, 'MaxDD', ('TMF', 'TMV'), 5, True, 1, 282, 1)
        else:
            Sort(self.algo, 'MaxDD', ('TMF', 'TMV'), 5, True, 1, 282, 1)
#https://app.composer.trade/symphony/uWiUrImsqQRsD8s5upvC/details

#https://app.composer.trade/symphony/q1iJqyUqHDdGFl6H7ZtT/details
class QLDForTheLongTermStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_qld_ftlt()

    def group_qld_ftlt(self):
        if RSI(self.algo, 'QQQ', 10) < 30:
            AH(self.algo, 'ROM', 284, 1)
        else:
            if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
                if RSI(self.algo, 'QQQ', 10) > 80:
                    AH(self.algo, 'TLT', 284, 1)
                else:
                    if RSI(self.algo, 'SPY', 10) > 80:
                        AH(self.algo, 'TLT', 284, 1)
                    else:
                        if RSI(self.algo, 'SPY', 60) > 60:
                            AH(self.algo, 'TLT', 284, 1)
                        else:
                            AH(self.algo, 'QLD', 284, 1)
            else:
                self.bear_market_protection()

    def bear_market_protection(self):
        if CumReturn(self.algo, 'QQQ', 252) < 0.2:
            self.nasdaq_crash_territory()
        else:
            self.non_crash_territory()

    def nasdaq_crash_territory(self):
        if GetCurrentPrice(self.algo, 'QQQ') < SMA(self.algo, 'QQQ', 20):
            if CumReturn(self.algo, 'QQQ', 60) <= 0.12:
                self.sideways_market_deleverage()
            else:
                if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'PSQ', 10):
                    AH(self.algo, 'QLD', 284, 1)
                else:
                    AH(self.algo, 'QID', 284, 1)
        else:
            if RSI(self.algo, 'PSQ', 10) < 31:
                AH(self.algo, 'PSQ', 284, 1)
            else:
                if CumReturn(self.algo, 'QQQ', 10) > 0.055:
                    AH(self.algo, 'PSQ', 284, 1)
                else:
                    Sort(self.algo, 'RSI', ('QQQ','SMH'), 10, True, 1, 284, 1)

    def non_crash_territory(self):
        if GetCurrentPrice(self.algo, 'QQQ') < SMA(self.algo, 'QQQ', 20):
            if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'PSQ', 10):
                AH(self.algo, 'QLD', 284, 1)
            else:
                AH(self.algo, 'QID', 284, 1)
        else:
            if RSI(self.algo, 'PSQ', 10) < 31:
                AH(self.algo, 'QID', 284, 1)
            else:
                if CumReturn(self.algo, 'QQQ', 10) > 0.055:
                    AH(self.algo, 'QID', 284, 1)
                else:
                    Sort(self.algo, 'RSI', ('QLD','USD'), 10, True, 1, 284, 1)

    def sideways_market_deleverage(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 20):
            AH(self.algo, 'SPY', 284, 0.5)
        else:
            if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'PSQ', 10):
                AH(self.algo, 'QQQ', 284, 0.5)
            else:
                AH(self.algo, 'PSQ', 284, 0.5)
        
        if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'PSQ', 10):
            AH(self.algo, 'QQQ', 284, 0.5)
        else:
            AH(self.algo, 'PSQ', 284, 0.5)
#https://app.composer.trade/symphony/imWPtKnMK9FbSPXh08Hu/details
class v211DoublePopBotsOct28th2011Strategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_v211_double_pop_bots()

    def group_v211_double_pop_bots(self):
        self.group_spy_double_pop_bot()
        self.group_qqq_double_pop_bot()
        self.group_smh_double_pop_bot()

    def group_spy_double_pop_bot(self):
        if RSI(self.algo, 'SPXL', 10) > 80:
            AH(self.algo, 'UVXY', 285, 0.33)
        else:
            if RSI(self.algo, 'SPXL', 10) < 30:
                AH(self.algo, 'SPXL', 285, 0.33)
            else:
                if RSI(self.algo, 'SPY', 60) > 50:
                    self.group_double_pop_bot_spy()
                else:
                    self.group_bond_market_check_spy()

    def group_double_pop_bot_spy(self):
        if RSI(self.algo, 'BND', 20) > RSI(self.algo, 'SPY', 20):
            if RSI(self.algo, 'SPY', 60) > 60:
                AH(self.algo, 'TMF', 285, 0.33)
            else:
                AH(self.algo, 'SPXL', 285, 0.33)
        else:
            AH(self.algo, 'BIL', 285, 0.33)

    def group_bond_market_check_spy(self):
        if RSI(self.algo, 'IEF', 200) < RSI(self.algo, 'TLT', 200):
            if RSI(self.algo, 'BND', 20) > RSI(self.algo, 'SPY', 20):
                if RSI(self.algo, 'SPY', 60) > 60:
                    AH(self.algo, 'TMF', 285, 0.33)
                else:
                    AH(self.algo, 'SPXL', 285, 0.33)
            else:
                AH(self.algo, 'BIL', 285, 0.33)
        else:
            AH(self.algo, 'BIL', 285, 0.33)

    def group_qqq_double_pop_bot(self):
        if RSI(self.algo, 'TQQQ', 10) > 80:
            AH(self.algo, 'UVXY', 285, 0.33)
        else:
            if RSI(self.algo, 'TQQQ', 10) < 31:
                AH(self.algo, 'TQQQ', 285, 0.33)
            else:
                if RSI(self.algo, 'SPY', 60) > 50:
                    self.group_double_pop_bot_qqq()
                else:
                    self.group_bond_market_check_qqq()

    def group_double_pop_bot_qqq(self):
        if RSI(self.algo, 'BND', 20) > RSI(self.algo, 'SPY', 20):
            if RSI(self.algo, 'SPY', 60) > 60:
                AH(self.algo, 'TMF', 285, 0.33)
            else:
                AH(self.algo, 'TQQQ', 285, 0.33)
        else:
            AH(self.algo, 'BIL', 285, 0.33)

    def group_bond_market_check_qqq(self):
        if RSI(self.algo, 'IEF', 200) < RSI(self.algo, 'TLT', 200):
            if RSI(self.algo, 'BND', 20) > RSI(self.algo, 'SPY', 20):
                if RSI(self.algo, 'SPY', 60) > 60:
                    AH(self.algo, 'TMF', 285, 0.33)
                else:
                    AH(self.algo, 'TQQQ', 285, 0.33)
            else:
                AH(self.algo, 'BIL', 285, 0.33)
        else:
            AH(self.algo, 'BIL', 285, 0.33)

    def group_smh_double_pop_bot(self):
        if RSI(self.algo, 'SOXL', 10) < 30:
            AH(self.algo, 'SOXL', 285, 0.33)
        else:
            if RSI(self.algo, 'SPY', 60) > 50:
                self.group_double_pop_bot_smh()
            else:
                self.group_bond_market_check_smh()

    def group_double_pop_bot_smh(self):
        if RSI(self.algo, 'BND', 20) > RSI(self.algo, 'SPY', 20):
            if RSI(self.algo, 'QQQ', 60) > 60:
                AH(self.algo, 'TMF', 285, 0.33)
            else:
                AH(self.algo, 'SOXL', 285, 0.33)
        else:
            AH(self.algo, 'BIL', 285, 0.33)

    def group_bond_market_check_smh(self):
        if RSI(self.algo, 'IEF', 200) < RSI(self.algo, 'TLT', 200):
            if RSI(self.algo, 'BND', 20) > RSI(self.algo, 'SPY', 20):
                if RSI(self.algo, 'QQQ', 60) > 60:
                    AH(self.algo, 'TMF', 285, 0.33)
                else:
                    AH(self.algo, 'SOXL', 285, 0.33)
            else:
                AH(self.algo, 'BIL', 285, 0.33)
        else:
            AH(self.algo, 'BIL', 285, 0.33)
#https://app.composer.trade/symphony/BNHl9Wkj9VS1OVX9JPID/details
class V11DerecksSecularMarketFrameworkSTDDevModGarenStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if SMA(self.algo, 'SPY', 200) > SMA(self.algo, 'SPY', 1000):
            self.secular_bull_market()
        else:
            self.secular_bear_market()
            
    def secular_bull_market(self):
        if SMA(self.algo, 'SPY', 50) > SMA(self.algo, 'SPY', 200):
            self.golden_cross_continuation()
        else:
            self.death_cross_bear_market()
            
    def golden_cross_continuation(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            if RSI(self.algo, 'SPY', 60) > 60:
                self.spy_becoming_overbought()
            else:
                self.stddev_mod_garen()
        else:
            if RSI(self.algo, 'QQQ', 10) < 30:
                Sort(self.algo, 'RSI', ('XLK','SOXX'), 10, False, 1, 287, 1)
            else:
                AH(self.algo, 'SHY', 287, 1)
                
    def spy_becoming_overbought(self):
        AH(self.algo, 'SPY', 287, 0.55)
        AH(self.algo, 'TLT', 287, 0.45)
        
    def stddev_mod_garen(self):
        if STD(self.algo, 'SPY', 10) < 2.5:
            AH(self.algo, 'QLD', 287, 1)
        else:
            AH(self.algo, 'SPY', 287, 1)
            
    def death_cross_bear_market(self):
        if RSI(self.algo, 'QQQ', 10) < 30:
            AH(self.algo, 'XLK', 287, 1)
        else:
            if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
                AH(self.algo, 'SPY', 287, 0.6)
                AH(self.algo, 'IEI', 287, 0.4)
            else:
                AH(self.algo, 'IEI', 287, 1)
                
    def secular_bear_market(self):
        if RSI(self.algo, 'QQQ', 10) < 30:
            Sort(self.algo, 'RSI', ('XLK','SOXX'), 10, False, 1, 287, 1)
        else:
            if SMA(self.algo, 'SPY', 50) > SMA(self.algo, 'SPY', 200):
                self.golden_cross_continuation_bear()
            else:
                self.death_cross_bear_market_begin_short()
                
    def golden_cross_continuation_bear(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            AH(self.algo, 'SPY', 287, 1)
        else:
            AH(self.algo, 'IEF', 287, 1)
            
    def death_cross_bear_market_begin_short(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            AH(self.algo, 'SPY', 287, 0.4)
            AH(self.algo, 'IEF', 287, 0.6)
        else:
            if GetCurrentPrice(self.algo, 'QQQ') < SMA(self.algo, 'QQQ', 20):
                Sort(self.algo, 'RSI', ('TLT','PSQ'), 10, True, 1, 287, 1)
            else:
                AH(self.algo, 'XLP', 287, 0.4)
                AH(self.algo, 'IEF', 287, 0.6)

#https://app.composer.trade/symphony/0xfD9vpl6QdaoJKylVOO/details
class Club100Deez27JUN2023Strategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group1()
        self.group2()
        self.group3()
        self.group4()

    def group1(self):
        if RSI(self.algo, 'SOXX', 14) < 35:
            AH(self.algo, 'SOXL', 288, 0.25)
        else:
            if RSI(self.algo, 'SPY', 14) > 62:
                AH(self.algo, 'DRV', 288, 0.25)
            else:
                Sort(self.algo, 'CumReturn', ('DE','ES','NU','TS'), 60, True, 1, 288, 0.25)

    def group2(self):
        if RSI(self.algo, 'SOXX', 10) > 63:
            AH(self.algo, 'SOXS', 288, 0.25)
        else:
            if RSI(self.algo, 'SOXX', 2) < 41:
                if RSI(self.algo, 'SOXL', 10) < 57:
                    AH(self.algo, 'SOXL', 288, 0.25)
                else:
                    AH(self.algo, 'SOXS', 288, 0.25)
            else:
                self.group2a()

    def group2a(self):
        if EMA(self.algo, 'UUP', 42) > EMA(self.algo, 'UUP', 100):
            Sort(self.algo, 'RSI', ('UUP','USDU'), 14, False, 1, 288, 0.25*0.45)
        else:
            Sort(self.algo, 'STD', ('BIL','SOXL','DBC'), 14, True, 2, 288, 0.25*0.45)

        if RSI(self.algo, 'BIL', 10) < RSI(self.algo, 'IEF', 10):
            if RSI(self.algo, 'SPY', 7) > 76:
                AH(self.algo, 'UGL', 288, 0.25*0.45)
            else:
                Sort(self.algo, 'MaxDD', ('SOXL','SMH'), 6, True, 1, 288, 0.25*0.45)
        else:
            if RSI(self.algo, 'SPY', 7) < 27:
                if RSI(self.algo, 'SHY', 10) < RSI(self.algo, 'VTI', 10):
                    AH(self.algo, 'SOXS', 288, 0.25*0.45)
                else:
                    AH(self.algo, 'SOXL', 288, 0.25*0.45)
            else:
                AH(self.algo, 'UGL', 288, 0.25*0.45/3)
                AH(self.algo, 'SH', 288, 0.25*0.45/3)
                AH(self.algo, 'PSQ', 288, 0.25*0.45/3)

        self.group2b()

    def group2b(self):
        if RSI(self.algo, 'COST', 14) < 69:
            if MaxDD(self.algo, 'SPY', 5) > 0.12:
                AH(self.algo, 'BIL', 288, 0.25*0.1*0.2)
            else:
                AH(self.algo, 'COST', 288, 0.25*0.1*0.2)
        else:
            AH(self.algo, 'BIL', 288, 0.25*0.1*0.2)

        if RSI(self.algo, 'UNH', 14) < 79:
            if MaxDD(self.algo, 'SPY', 5) > 0.12:
                AH(self.algo, 'BIL', 288, 0.25*0.1*0.8)
            else:
                AH(self.algo, 'UNH', 288, 0.25*0.1*0.8)
        else:
            AH(self.algo, 'BIL', 288, 0.25*0.1*0.8)

    def group3(self):
        if RSI(self.algo, 'BIL', 10) < RSI(self.algo, 'SOXX', 10):
            if RSI(self.algo, 'SPY', 6) > 75:
                Sort(self.algo, 'RSI', ('UVXY','VIXY'), 13, False, 1, 288, 0.25)
            else:
                AH(self.algo, 'SOXL', 288, 0.25)
        else:
            if RSI(self.algo, 'SOXX', 10) > 76:
                AH(self.algo, 'SOXS', 288, 0.25)
            else:
                if RSI(self.algo, 'SOXX', 2) < 42:
                    if RSI(self.algo, 'SOXL', 10) < 57:
                        AH(self.algo, 'SOXL', 288, 0.25)
                    else:
                        AH(self.algo, 'SOXS', 288, 0.25)
                else:
                    if GetCurrentPrice(self.algo, 'SPY') >= SMA(self.algo, 'SPY', 2):
                        if SMA(self.algo, 'SPY', 5) < SMA(self.algo, 'SPY', 10):
                            AH(self.algo, 'SPXU', 288, 0.25)
                        else:
                            AH(self.algo, 'UPRO', 288, 0.25)
                    else:
                        if RSI(self.algo, 'SPY', 3) >= RSI(self.algo, 'SPY', 21):
                            AH(self.algo, 'SQQQ', 288, 0.25)
                        else:
                            AH(self.algo, 'TQQQ', 288, 0.25)

    def group4(self):
        if RSI(self.algo, 'BSV', 20) > RSI(self.algo, 'SQQQ', 20):
            AH(self.algo, 'BIL', 288, 0.25*0.1)
            AH(self.algo, 'JEPQ', 288, 0.25*0.1)
            AH(self.algo, 'TSLA', 288, 0.25*0.4)
            AH(self.algo, 'MSTR', 288, 0.25*0.4)
        else:
            AH(self.algo, 'BIL', 288, 0.25*0.4)
            AH(self.algo, 'JEPQ', 288, 0.25*0.4)
            AH(self.algo, 'TSLA', 288, 0.25*0.1)
            AH(self.algo, 'MSTR', 288, 0.25*0.1)
#https://app.composer.trade/symphony/Erqhn1qppgjzh60Tfje6/details
class PopBotW1x6040PrivateCopyStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_SPXL_pop_bot()
        self.group_TQQQ_pop_bot()
        self.group_SOXL_pop_bot()

    def group_SPXL_pop_bot(self):
        if RSI(self.algo, 'SPXL', 10) > 80:
            AH(self.algo, 'UVXY', 289, 0.333)
        else:
            if RSI(self.algo, 'SPXL', 10) < 30:
                AH(self.algo, 'SPXL', 289, 0.333)
            else:
                if SMADayRet(self.algo, 'SPY', 10) > 0:
                    AH(self.algo, 'SPY', 289, 0.2)
                    AH(self.algo, 'SHY', 289, 0.133)
                else:
                    AH(self.algo, 'BIL', 289, 0.333)

    def group_TQQQ_pop_bot(self):
        if RSI(self.algo, 'TQQQ', 10) > 80:
            AH(self.algo, 'UVXY', 289, 0.333)
        else:
            if RSI(self.algo, 'TQQQ', 10) < 30:
                AH(self.algo, 'TQQQ', 289, 0.333)
            else:
                if SMADayRet(self.algo, 'QQQ', 10) > 0:
                    AH(self.algo, 'QQQ', 289, 0.2)
                    AH(self.algo, 'SHY', 289, 0.133)
                else:
                    AH(self.algo, 'BIL', 289, 0.333)

    def group_SOXL_pop_bot(self):
        if RSI(self.algo, 'SOXL', 10) > 80:
            AH(self.algo, 'UVXY', 289, 0.333)
        else:
            if RSI(self.algo, 'SOXL', 10) < 30:
                AH(self.algo, 'SOXL', 289, 0.333)
            else:
                if SMADayRet(self.algo, 'SMH', 10) > 0:
                    AH(self.algo, 'SMH', 289, 0.2)
                    AH(self.algo, 'SHY', 289, 0.133)
                else:
                    AH(self.algo, 'BIL', 289, 0.333)
#https://app.composer.trade/symphony/0sRUoMwYmwuKWhZrO3Qq/details
#https://app.composer.trade/symphony/os3RnD25lMXOlHQFy69p/details
class PopBotW1x6040INVESTTLTvsSHYEDITIONStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_SPXL_pop_bot()
        self.group_TQQQ_pop_bot()
        self.group_SOXL_pop_bot()

    def group_SPXL_pop_bot(self):
        if RSI(self.algo, 'SPXL', 10) > 80:
            AH(self.algo, 'UVXY', 290, 0.33)
        else:
            if RSI(self.algo, 'SPXL', 10) < 30:
                AH(self.algo, 'SPXL', 290, 0.33)
            else:
                if CumReturn(self.algo, 'SPY', 10) > 0.0:
                    AH(self.algo, 'SPY', 290, 0.198)
                    if CumReturn(self.algo, 'BND', 40) >= CumReturn(self.algo, 'BIL', 40):
                        AH(self.algo, 'TLT', 290, 0.132)
                    else:
                        AH(self.algo, 'SHY', 290, 0.132)
                else:
                    AH(self.algo, 'BIL', 290, 0.33)

    def group_TQQQ_pop_bot(self):
        if RSI(self.algo, 'TQQQ', 10) > 80:
            AH(self.algo, 'UVXY', 290, 0.33)
        else:
            if RSI(self.algo, 'TQQQ', 10) < 30:
                AH(self.algo, 'TQQQ', 290, 0.33)
            else:
                if CumReturn(self.algo, 'QQQ', 10) > 0.0:
                    AH(self.algo, 'QQQ', 290, 0.198)
                    if CumReturn(self.algo, 'BND', 40) >= CumReturn(self.algo, 'BIL', 40):
                        AH(self.algo, 'TLT', 290, 0.132)
                    else:
                        AH(self.algo, 'SHY', 290, 0.132)
                else:
                    AH(self.algo, 'BIL', 290, 0.33)

    def group_SOXL_pop_bot(self):
        if RSI(self.algo, 'SOXL', 10) > 80:
            AH(self.algo, 'UVXY', 290, 0.33)
        else:
            if RSI(self.algo, 'SOXL', 10) < 30:
                AH(self.algo, 'SOXL', 290, 0.33)
            else:
                if CumReturn(self.algo, 'SMH', 10) > 0.0:
                    AH(self.algo, 'SMH', 290, 0.198)
                    if CumReturn(self.algo, 'BND', 40) >= CumReturn(self.algo, 'BIL', 40):
                        AH(self.algo, 'TLT', 290, 0.132)
                    else:
                        AH(self.algo, 'SHY', 290, 0.132)
                else:
                    AH(self.algo, 'BIL', 290, 0.33)
#https://app.composer.trade/symphony/WJTrsOhXD1So3t1D8hVw/details
#https://app.composer.trade/symphony/ex1oPM8lUsbCE4suA5ve/details
class LongTerm510YearStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo, 'VIXY', 10) < 73:
            AH(self.algo, 'VTI', 291, 0.45)
            AH(self.algo, 'SPUU', 291, 0.45)
        else:
            AH(self.algo, 'BIL', 291, 0.9)

        if RSI(self.algo, 'BITO', 10) > 27:
            AH(self.algo, 'BRK/B', 291, 0.05)
        else:
            AH(self.algo, 'BITX', 291, 0.05)

        AH(self.algo, 'VUG', 291, 0.05)
#https://app.composer.trade/symphony/yMwr30LNrwARptSRGO2g/details
class AAntiChopQLDForTheLongTermStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            if RSI(self.algo, 'QQQ', 10) > 81:
                AH(self.algo, 'PSQ', 292, 1)
            else:
                AH(self.algo, 'QLD', 292, 1)
        else:
            if RSI(self.algo, 'QQQ', 10) < 30:
                AH(self.algo, 'QLD', 292, 1)
            else:
                if RSI(self.algo, 'SPY', 10) < 30:
                    AH(self.algo, 'SPY', 292, 1)
                else:
                    if GetCurrentPrice(self.algo, 'QQQ') < SMA(self.algo, 'QQQ', 20):
                        if SMA(self.algo, 'QQQ', 4) < SMA(self.algo, 'QQQ', 20):
                            if SMA(self.algo, 'QQQ', 6) < SMA(self.algo, 'QQQ', 20):
                                Sort(self.algo, 'RSI', ('PSQ','SHY'), 10, True, 1, 292, 1)
                            else:
                                AH(self.algo, 'QQQ', 292, 0.33)
                                Sort(self.algo, 'RSI', ('PSQ','SHY'), 10, True, 1, 292, 0.67)
                        else:
                            AH(self.algo, 'QQQ', 292, 0.67)
                            Sort(self.algo, 'RSI', ('PSQ','SHY'), 10, True, 1, 292, 0.33)
                    else:
                        if SMA(self.algo, 'QQQ', 4) > SMA(self.algo, 'QQQ', 20):
                            if SMA(self.algo, 'QQQ', 6) > SMA(self.algo, 'QQQ', 20):
                                AH(self.algo, 'QQQ', 292, 1)
                            else:
                                AH(self.algo, 'QQQ', 292, 0.66)
                                Sort(self.algo, 'RSI', ('PSQ','SHY'), 10, True, 1, 292, 0.34)
                        else:
                            AH(self.algo, 'QQQ', 292, 0.33)
                            Sort(self.algo, 'RSI', ('PSQ','SHY'), 10, True, 1, 292, 0.67)
#https://app.composer.trade/symphony/sPmonUWG0WYWNUoJB7lk/details
#286 283
#region imports
from AlgorithmImports import *
#endregion


# Your New Python File
#CombinedStrategy2 version1.py
from AlgorithmImports import *
#endregion
from AlgorithmImports import *
from indicators import *
from main import YellowCatStrat

#https://app.composer.trade/symphony/ltty8FHaiUsCZEh2ei8z/details

class ACopyofINVMegafolioStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.just_run_this_ftlt_dia()
    
    def just_run_this_ftlt_dia(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if RSI(self.algo,'SPY',10) > 80:
                AH(self.algo,'VIXY',30,1.0)
            else:
                if RSI(self.algo,'QQQ',10) > 79:
                    AH(self.algo,'VIXY',30,1.0)
                else:
                    if RSI(self.algo,'XLK',10) > 79:
                        AH(self.algo,'VIXY',30,1.0)
                    else:
                        if RSI(self.algo,'IYY',10) > 79:
                            AH(self.algo,'VIXY',30,1.0)
                        else:
                            if RSI(self.algo,'VTV',10) > 79:
                                AH(self.algo,'VIXY',30,1.0)
                            else:
                                if RSI(self.algo,'XLP',10) > 75:
                                    AH(self.algo,'VIXY',30,1.0)
                                else:
                                    if RSI(self.algo,'XLF',10) > 80:
                                        AH(self.algo,'VIXY',30,1.0)
                                    else:
                                        if RSI(self.algo,'VOX',10) > 79:
                                            AH(self.algo,'VIXY',30,1.0)
                                        else:
                                            AH(self.algo,'DIA',30,1.0)
        else:
            if RSI(self.algo,'TQQQ',10) < 30:
                AH(self.algo,'TECL',30,1.0)
            else:
                if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',30):
                    AH(self.algo,'DIA',30,1) 
                else:
                    AH(self.algo,'BTAL',30,1.0)
#https://app.composer.trade/symphony/ulRwr7fceLqeSQaoRccj/details

class ACopyofNVDAorSS40dRSIleveragedStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.nvda_or_ss_40d_rsi()
    
    def ss_40d_rsi(self):
        if RSI(self.algo,'VIXM',40) > 69:
            AH(self.algo,'SPXU',31,1.0)
        else:
            Sort(self.algo,'RSI',('MSFU','NVDL','XOM'),40,True,1,31,1.0)

    def huge_volatility(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.13:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.06:
                AH(self.algo,'SOXS',31,1.0)
            else:
                AH(self.algo,'NVDL',31,1.0)
        else:
            self.ss_40d_rsi()
    
    def nvda_or_ss_40d_rsi(self):
        if RSI(self.algo,'TQQQ',10) > 79:
            AH(self.algo,'SOXS',31,1.0)
        else:
            self.huge_volatility()
    
#https://app.composer.trade/symphony/hzJbZvvI8UlgpYjp8xKY/details

class ACopyofV1dMelkorsFollyStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.a20d_bnd_vs_60d_sh_xlkxlp()
    
    def longshort_rotator(self):
        Sort(self.algo,'STD',('TMV','TMF','BIL','KMLM'),5,False,3,32,1.0)
    
    def a20d_bnd_vs_60d_sh_xlkxlp(self):
        if RSI(self.algo,'BND',20) > RSI(self.algo,'SH',60):
            if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
                AH(self.algo,'QLD',32,1.0)
            else:
                if RSI(self.algo,'QQQ',10) < 30:
                    AH(self.algo,'QLD',32,1.0)
                else:
                    AH(self.algo,'XLP',32,1.0)
        else:
            if RSI(self.algo,'QQQ',10) < 30:
                AH(self.algo,'QLD',32,1.0)
            else:
                self.longshort_rotator()

#https://app.composer.trade/symphony/QDk0o0jhWHmWwrQ1lXFl/details

class ACopyofV2noleverage698w220ddsince102811Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if RSI(self.algo,'QQQ',10) > 79:
                AH(self.algo,'VIXY',33,1)
            else:
                if RSI(self.algo,'SPY',10) > 80:
                    AH(self.algo,'VIXY',33,1)
                else:
                    AH(self.algo,'QQQ',33,1)
        else:
            if RSI(self.algo,'QQQ',10) < 31:
                AH(self.algo,'QQQ',33,1)
            else:
                if RSI(self.algo,'SPY',10) < 30:
                    AH(self.algo,'SPY',33,1)
                else:
                    if RSI(self.algo,'VIXY',10) > 74:
                        if RSI(self.algo,'VIXY',10) > 84:
                            if GetCurrentPrice(self.algo,'QQQ') > SMA(self.algo,'QQQ',20):
                                if RSI(self.algo,'SH',10) < 31:
                                    AH(self.algo,'TLT',33,1)
                                else:
                                    AH(self.algo,'QQQ',33,1)
                            else:
                                Sort(self.algo,'RSI',('SH','BSV'),10,True,1,33,1)
                        else:
                            AH(self.algo,'VIXY',33,1)
                    else:
                        if GetCurrentPrice(self.algo,'QQQ') > SMA(self.algo,'QQQ',20):
                            if RSI(self.algo,'SH',10) < 31:
                                AH(self.algo,'SH',33,1)
                            else:
                                AH(self.algo,'QQQ',33,1)
                        else:
                            Sort(self.algo,'RSI',('SH','TLT'),10,True,1,33,1)

#https://app.composer.trade/symphony/ObXR8dVzzO92UGmNmO4F/details

class ADeETFFTLT570109Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.deetf_ftlt_570109()
    
    def dip_buy_highlow_beta(self):
        if RSI(self.algo,'SOXX',10) < 30:
            AH(self.algo,'SOXL',35,1.0)
        else:
            if RSI(self.algo,'QQQ',10) < 30:
                AH(self.algo,'TECL',35,1.0)
            else:
                if GetCurrentPrice(self.algo,'QQQ') > SMA(self.algo,'QQQ',30):
                    if RSI(self.algo,'PSQ',10) < 35:
                        AH(self.algo,'BTAL',35,1.0)
                    else:
                        AH(self.algo,'SPHB',35,1.0)
                else:
                    if RSI(self.algo,'PSQ',10) > 65:
                        AH(self.algo,'SPHB',35,1.0)
                    else:
                        AH(self.algo,'BTAL',35,1.0)
    
    def deetf_20d_cr_t3(self):
        Sort(self.algo,'CumReturn',('MSFT','AAPL','NVDA','AMZN','GOOGL','META','BRK/B','LLY','NVO','TSLA','PG','COST','MRK','ABBV','AMD','ADBE','GE'),20,True,3,35,1.0)
    
    def frontrunner_deetf(self):
        if RSI(self.algo,'SPY',10) > 80:
            AH(self.algo,'VIXY',35,1.0)
        else:
            if RSI(self.algo,'QQQ',10) > 79:
                AH(self.algo,'VIXY',35,1.0)
            else:
                if RSI(self.algo,'XLK',10) > 79:
                    AH(self.algo,'VIXY',35,1.0)
                else:
                    if RSI(self.algo,'IYY',10) > 79:
                        AH(self.algo,'VIXY',35,1.0)
                    else:
                        if RSI(self.algo,'VTV',10) > 79:
                            AH(self.algo,'VIXY',35,1.0)
                        else:
                            if RSI(self.algo,'XLP',10) > 75:
                                AH(self.algo,'VIXY',35,1.0)
                            else:
                                if RSI(self.algo,'XLF',10) > 80:
                                    AH(self.algo,'VIXY',35,1.0)
                                else:
                                    if RSI(self.algo,'VOX',10) > 79:
                                        AH(self.algo,'VIXY',35,1.0)
                                    else:
                                        self.deetf_20d_cr_t3()
    
    def deetf_ftlt_570109(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            self.frontrunner_deetf()
        else:
            self.dip_buy_highlow_beta()

#https://app.composer.trade/symphony/gjOnZgSmGTWSwS75uFE1/details

class ADerecksPortfolioLowBetaInvestCopyStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.svxy_ftlt_v2()
    
    def svxy_ftlt_v2(self):
        if RSI(self.algo,'QQQ',10) > 80:
            AH(self.algo,'UVXY',36,1.0)
        else:
            if RSI(self.algo,'SPY',10) > 80:
                AH(self.algo,'UVXY',36,1.0)
            else:
                if RSI(self.algo,'QQQ',10) < 30:
                    AH(self.algo,'XLK',36,1.0)
                else:
                    if GetCurrentPrice(self.algo,'SVXY') > SMA(self.algo,'SVXY',21):
                        Sort(self.algo,'SMADayRet',('SVXY','VTI'),20,True,1,36,0.7)
                        AH(self.algo,'VIXM',36,0.3)
                    else:
                        Sort(self.algo,'SMADayRet',('BTAL','DBMF'),20,True,1,36,1.0)
    
#https://app.composer.trade/symphony/vGPBvNyZlBLF7CcTNFHN/details

class ADerecksPortfolioPublicCopyStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1_botz_bot_botz_bot_qld_ai_ftlt_()
        self.pure_bs_catcher()
    
    def pure_bs_catcher(self):
        if SMA(self.algo,'SPY',200) < GetCurrentPrice(self.algo,'SPY'):
            if RSI(self.algo,'TQQQ',14) > 75:
                AH(self.algo,'UVXY',37,0.5)
            else:
                if RSI(self.algo,'SPXL',10) > 80:
                    AH(self.algo,'UVXY',37,0.5)
                else:
                    AH(self.algo,'BSV',37,0.5)
        else:
            if RSI(self.algo,'SPY',10) < 30:
                AH(self.algo,'BSV',37,0.5)
            else:
                if RSI(self.algo,'UVXY',10) > 74:
                    if RSI(self.algo,'UVXY',10) < 84:
                        AH(self.algo,'UVXY',37,0.5)
                    else:
                        AH(self.algo,'BSV',37,0.5) 
                else:
                     AH(self.algo,'BSV',37,0.5)
    
    def v1_botz_bot_botz_bot_qld_ai_ftlt_(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if RSI(self.algo,'QQQ',10) > 81:
                AH(self.algo,'PSQ',37,0.5)
            else:
                Sort(self.algo,'CumReturn',('QQQ','BOTZ'),5,True,1,37,0.5)
        else:
            if RSI(self.algo,'QQQ',10) < 30:
                AH(self.algo,'QLD',37,0.5)
            else:
                if RSI(self.algo,'SPY',10) < 30:
                    AH(self.algo,'SPY',37,0.5)
                else:
                    if GetCurrentPrice(self.algo,'QQQ') < SMA(self.algo,'QQQ',20):
                        Sort(self.algo,'RSI',('PSQ','SHY'),10,True,1,37,0.25)
                        Sort(self.algo,'CumReturn',('SH','BOTZ'),5,True,1,37,0.25)
                    else:
                        AH(self.algo,'QQQ',37,0.5)

#https://app.composer.trade/symphony/wSmWZsOG4ZE51An2G4wX/details

class ADirexionSS40dRSIStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.direxion_ss_40d_rsi()
    
    def direxion_ss_40d_rsi(self):
        if RSI(self.algo,'VIXM',40) > 69:
            AH(self.algo,'SPXU',38,1.0)
        else:
            Sort(self.algo,'RSI',('MSFU','NVDA','XOM'),40,True,1,38,1.0)
    
#https://app.composer.trade/symphony/Oa04VbiHNI4CFepyD21w/details

class ADividends3070wBlackSwanStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.a3070_dividends_w_black_swan_catcher()
    
    def smh_pop_bot(self):
        if RSI(self.algo,'SOXL',10) < 30:
            AH(self.algo,'SOXL',39,0.05)
        else:
            AH(self.algo,'CII',39,0.05)
    
    def qqq_pop_bot(self):
        if RSI(self.algo,'TQQQ',10) > 80:
            AH(self.algo,'UVXY',39,0.05)
        else:
            if RSI(self.algo,'TQQQ',10) < 30:
                AH(self.algo,'TQQQ',39,0.05)
            else:
                AH(self.algo,'CII',39,0.05)
    
    def spy_pop_bot(self):
        if RSI(self.algo,'SPXL',10) > 80:
            AH(self.algo,'UVXY',39,0.05)
        else:
            if RSI(self.algo,'SPXL',10) < 30:
                AH(self.algo,'SPXL',39,0.05)
            else:
                AH(self.algo,'CII',39,0.05)
    
    def popped_monthly_divs_to_try_to_inject_capital(self):
        self.spy_pop_bot()
        self.qqq_pop_bot()
        self.smh_pop_bot()
    
    def quarterly_dividends(self):
        AH(self.algo,'SCHD',39,0.16) 
        AH(self.algo,'DGRO',39,0.16) 
        AH(self.algo,'DBMF',39,0.16)
    
    def dividends_more_in_the_monthly_payment_to_maximize_the_(self):
        self.quarterly_dividends()
        self.popped_monthly_divs_to_try_to_inject_capital()
    
    def v20_pop_bots_l_briane_l_with_bil(self):
        self.spy_pop_bot()
        self.qqq_pop_bot()
        self.smh_pop_bot()
    
    def a3070_dividends_w_black_swan_catcher(self):
        if RSI(self.algo,'VIXM',10) > 70:
            self.v20_pop_bots_l_briane_l_with_bil()
        else:
            self.dividends_more_in_the_monthly_payment_to_maximize_the_()

#https://app.composer.trade/symphony/SyHbd8fg1hTona86RW5f/details

class Adraftv001V212TheManhattanProjectslimedStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.four_corners()
    
    def ief_vs_psq_ltpz_or_psq(self):
        if RSI(self.algo,'IEF',7) > RSI(self.algo,'PSQ',20):
            AH(self.algo,'LTPZ',40,0.5)
        else:
            AH(self.algo,'PSQ',40,0.5)
    
    def bear_market(self):
        AH(self.algo,'BTAL',40,0.5)
        self.ief_vs_psq_ltpz_or_psq()
    
    def hedge(self):
        AH(self.algo,'VT',40,0.33)
        AH(self.algo,'VWO',40,0.33)
        AH(self.algo,'VCLT',40,0.33)
    
    def ief_vs_psq_qqq_or_psq(self):
        if RSI(self.algo,'IEF',7) > RSI(self.algo,'PSQ',20):
            AH(self.algo,'TQQQ',40,0.5) 
            AH(self.algo,'BIL',40,0.5)
        else:
            AH(self.algo,'PSQ',40,1)
    
    def bull_market(self):
        AH(self.algo,'TQQQ',40,0.25)
        AH(self.algo,'UPRO',40,0.25)
        AH(self.algo,'VWO',40,0.25)
        AH(self.algo,'CORP',40,0.25)
    
    def core_logic_2x2(self):
        if RSI(self.algo,'QQQ',100) > RSI(self.algo,'VPU',100):
            if CumReturn(self.algo,'CORP',60) > CumReturn(self.algo,'BIL',60):
                self.bull_market()
            else:
                self.hedge()
        else:
            if CumReturn(self.algo,'CORP',60) > CumReturn(self.algo,'BIL',60):
                self.hedge()
            else:
                self.bear_market()
    
    def quick_overbought_pop(self):
        AH(self.algo,'TMF',40,0.33) 
        AH(self.algo,'BTAL',40,0.33) 
        AH(self.algo,'VIXY',40,0.33)

    def quick_oversold_bounce(self):
        AH(self.algo,'TECL',40,0.33) 
        AH(self.algo,'SOXL',40,0.33) 
        AH(self.algo,'TLT',40,0.33)
    
    def quick_high_volatility_safety(self):
        if RSI(self.algo,'IEF',7) > RSI(self.algo,'PSQ',20):
            AH(self.algo,'VT',40,0.5) 
            AH(self.algo,'CORP',40,0.5)
        else:
            AH(self.algo,'SH',40,0.33) 
            AH(self.algo,'UUP',40,0.33) 
            AH(self.algo,'TLT',40,0.33)
    
    def four_corners(self):
        if STD(self.algo,'QQQ',10) > 3:
            self.quick_high_volatility_safety()
        else:
            if RSI(self.algo,'QQQ',10) < 31:
                self.quick_oversold_bounce()
            else:
                if RSI(self.algo,'QQQ',10) > 78:
                    self.quick_overbought_pop()
                else:
                    self.core_logic_2x2()
    
#https://app.composer.trade/symphony/T4OjBUxqrLB35cJQiHYO/details

class ADumpsterFireSmoothCriminal420Deez14JUN2023Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.yieldmax_ss_sdmacrrsi()
    
    def rsi(self):
        Sort(self.algo,'RSI',('APLY','FBY','MSFO','NFLY','CONY'),10,True,1,41,0.25)
    
    def cr(self):
        Sort(self.algo,'CumReturn',('APLY','FBY','MSFO','NFLY','CONY'),10,True,1,41,0.25)
    
    def ma(self):
        Sort(self.algo,'SMADayRet',('APLY','FBY','MSFO','NFLY','CONY'),10,True,1,41,0.25)
    
    def sd(self):
        Sort(self.algo,'STD',('APLY','FBY','MSFO','NFLY','CONY'),10,True,1,41,0.25)
    
    def yieldmax_ss_sdmacrrsi(self):
        GroupSort(self.algo,'MaxDD',(self.sd(),self.ma(),self.cr(),self.rsi()),10,False,3,41,1.0)

#https://app.composer.trade/symphony/z1XRvNEku4S0L8u7t1rp/details

class AEarlyWorksTotalMarketPopped2xStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.early_works_pop_bots_()
    
    def bull_market_stock_selector(self):
        Sort(self.algo,'RSI',('BSV','QLD','SSO'),20,False,1,42,0.33)
    
    def bear_market_stock_selector(self):
        Sort(self.algo,'RSI',('QID','SDS','BSV'),10,False,1,42,0.33)
    
    def market_strategy(self):
        if MaxDD(self.algo, 'SPY', 10) > 0.06:
            self.bear_market_stock_selector()
        else:
            self.bull_market_stock_selector()
    
    def smh_pop_bot(self):
        if RSI(self.algo,'SOXL',10) < 30:
            AH(self.algo,'USD',42,0.33)
        else:
            self.market_strategy()
    
    def qqq_pop_bot(self):
        if RSI(self.algo,'TQQQ',10) > 80:
            AH(self.algo,'UVXY',42,0.33)
        else:
            if RSI(self.algo,'TQQQ',10) < 30:
                AH(self.algo,'QLD',42,0.33)
            else:
                self.market_strategy()
    
    def spy_pop_bot(self):
        if RSI(self.algo,'SPXL',10) > 80:
            AH(self.algo,'UVXY',42,0.33)
        else:
            if RSI(self.algo,'SPXL',10) < 30:
                AH(self.algo,'SSO',42,0.33)
            else:
                self.market_strategy()
    
    def early_works_pop_bots_(self):
        self.spy_pop_bot()
        self.qqq_pop_bot()
        self.smh_pop_bot()
    
#https://app.composer.trade/symphony/KIzxfWQ1vH06KVUeEOfa/details

class AEqualWeightNVDALLYNoSPXUSQQQStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.equal_weight_nvda_lly_no_spxu_sqqq()
    
    def equal_weight_nvda_lly_no_spxu_sqqq(self):
        if RSI(self.algo,'VIXM',40) > 69:
            AH(self.algo,'SH',43,1.0)
        else:
            if RSI(self.algo,'TQQQ',10) > 79:
                AH(self.algo,'BTAL',43,1.0)
            else:
                AH(self.algo,'NVDA',43,0.5) 
                AH(self.algo,'LLY',43,0.5)

#https://app.composer.trade/symphony/iiu1SqkRcSLjK3h6Hhf1/details

class AFEPIwYieldMaxStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        AH(self.algo,'FEPI',44,0.2)
        Sort(self.algo,'CumReturn',('TSLY','CONY','NVDY','AMDY','APLY','AMZY','OARK','DISO','GOOY','PYPY','MSFO','JPMO','XOMO','NFLY','FBY','SQY','MRNY'),4,True,2,44,0.8)
    
#https://app.composer.trade/symphony/NK9h8z5y14T32d7cDVuc/details

class AFourCornersv12nicomavisStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.four_corners()
    
    def ief_vs_psq_vpugdx_or_psq(self):
        if RSI(self.algo,'IEF',7) > RSI(self.algo,'PSQ',20):
            AH(self.algo,'VT',45,0.25) 
            AH(self.algo,'GDX',45,0.25)
        else:
            AH(self.algo,'PSQ',45,0.25)
            AH(self.algo,'FMF',45,0.25)
    
    def bear_market(self):
        AH(self.algo,'BTAL',45,0.5)
        self.ief_vs_psq_vpugdx_or_psq()
    
    def materials_mining(self):
        AH(self.algo,'VAW',45,0.08)
        AH(self.algo,'PICK',45,0.08)
        AH(self.algo,'GDX',45,0.08)
    
    def hedge(self):
        AH(self.algo,'VT',45,0.25)
        AH(self.algo,'VWO',45,0.25)
        AH(self.algo,'BLV',45,0.25)
        self.materials_mining()
    
    def ief_vs_psq_tqqqpick_or_btal(self):
        if RSI(self.algo,'IEF',7) > RSI(self.algo,'PSQ',20):
            AH(self.algo,'TQQQ',45,0.5) 
            AH(self.algo,'PICK',45,0.5)
        else:
            AH(self.algo,'BTAL',45,1)
    
    def bull_market(self):
        AH(self.algo,'TQQQ',45,0.25)
        AH(self.algo,'UPRO',45,0.25)
        AH(self.algo,'EEMS',45,0.25)
        AH(self.algo,'BLV',45,0.25)
    
    def core_logic_2x2(self):
        if RSI(self.algo,'QQQ',100) > RSI(self.algo,'VPU',100):
            if CumReturn(self.algo,'CORP',60) > CumReturn(self.algo,'BIL',60):
                self.bull_market()
            else:
                self.hedge()
        else:
            if CumReturn(self.algo,'CORP',60) > CumReturn(self.algo,'BIL',60):
                self.hedge()
            else:
                self.bear_market()
    
    def quick_overbought_pop(self):
        AH(self.algo,'TMF',45,0.33) 
        AH(self.algo,'BTAL',45,0.33) 
        AH(self.algo,'VIXY',45,0.33)
    
    def quick_oversold_bounce(self):
        AH(self.algo,'TECL',45,0.25)
        AH(self.algo,'TQQQ',45,0.25)
        AH(self.algo,'IEF',45,0.25)
        AH(self.algo,'UUP',45,0.25)
    
    def four_corners(self):
        if RSI(self.algo,'QQQ',10) < 30:
            self.quick_oversold_bounce()
        else:
            if RSI(self.algo,'QQQ',10) > 79:
                self.quick_overbought_pop()
            else:
                if RSI(self.algo,'VTV',10) > 79:
                    self.quick_overbought_pop()
                else:
                    self.core_logic_2x2()

#https://app.composer.trade/symphony/NMxsNt4RnIbgNSZfQ7RN/details

class AFrontrunnerEquitiesUnifiedEquityBlock20120627Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.four_corners()
    
    def ief_vs_psq_vpugdx_or_psq(self):
        if RSI(self.algo,'IEF',7) > RSI(self.algo,'PSQ',20):
            AH(self.algo,'VT',46,0.25) 
            AH(self.algo,'GDX',46,0.25)
        else:
            AH(self.algo,'PSQ',46,0.25)
            AH(self.algo,'FMF',46,0.25)
    
    def bear_market(self):
        AH(self.algo,'BTAL',46,0.5)
        self.ief_vs_psq_vpugdx_or_psq()
    
    def materials_mining(self):
        AH(self.algo,'VAW',46,0.08)
        AH(self.algo,'PICK',46,0.08)
        AH(self.algo,'GDX',46,0.08)
    
    def hedge(self):
        AH(self.algo,'VT',46,0.25)
        AH(self.algo,'VWO',46,0.25)
        AH(self.algo,'BLV',46,0.25)
        self.materials_mining()
    
    def ief_vs_psq_tqqqpick_or_btal(self):
        if RSI(self.algo,'IEF',7) > RSI(self.algo,'PSQ',20):
            AH(self.algo,'TQQQ',46,0.5) 
            AH(self.algo,'PICK',46,0.5)
        else:
            AH(self.algo,'BTAL',46,1)
    
    def bull_market(self):
        AH(self.algo,'TQQQ',46,0.25)
        AH(self.algo,'UPRO',46,0.25)
        AH(self.algo,'EEMS',46,0.25)
        AH(self.algo,'BLV',46,0.25)
    
    def core_logic_2x2(self):
        if RSI(self.algo,'QQQ',100) > RSI(self.algo,'VPU',100):
            if CumReturn(self.algo,'CORP',60) > CumReturn(self.algo,'BIL',60):
                self.bull_market()
            else:
                self.hedge()
        else:
            if CumReturn(self.algo,'CORP',60) > CumReturn(self.algo,'BIL',60):
                self.hedge()
            else:
                self.bear_market()
    
    def quick_overbought_pop(self):
        AH(self.algo,'TMF',46,0.33) 
        AH(self.algo,'BTAL',46,0.33) 
        AH(self.algo,'VIXY',46,0.33)
    
    def quick_oversold_bounce(self):
        AH(self.algo,'TECL',46,0.25)
        AH(self.algo,'TQQQ',46,0.25)
        AH(self.algo,'IEF',46,0.25)
        AH(self.algo,'UUP',46,0.25)

    def four_corners(self):
        if RSI(self.algo,'QQQ',10) < 30:
            self.quick_oversold_bounce()
        else:
            if RSI(self.algo,'QQQ',10) > 79:
                self.quick_overbought_pop()
            else:
                if RSI(self.algo,'VTV',10) > 79:
                    self.quick_overbought_pop()
                else:
                    self.core_logic_2x2()
    
#https://app.composer.trade/symphony/xFvLzc9pvGReRQzQWDTi/details

class ABEsPoppedMonthlyDividendsStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.bes_tqqq_ftlts_dividends()
    
    def smh_pop_bot(self):
        if RSI(self.algo, 'SOXL', 10) < 30:
            AH(self.algo, 'SOXL', 47, 0.33*0.5)
        else:
            AH(self.algo, 'DHS', 47, 0.33*0.5)
    
    def qqq_pop_bot(self):
        if RSI(self.algo, 'TQQQ', 10) > 80:
            AH(self.algo, 'UVXY', 47, 0.33*0.5)
        else:
            if RSI(self.algo, 'TQQQ', 10) < 30:
                AH(self.algo, 'TQQQ', 47, 0.33*0.5)
            else:
                AH(self.algo, 'PEY', 47, 0.33*0.5)
    
    def spy_pop_bot(self):
        if RSI(self.algo, 'SPXL', 10) > 80:
            AH(self.algo, 'UVXY', 47, 0.33*0.5)
        else:
            if RSI(self.algo, 'SPXL', 10) < 30:
                AH(self.algo, 'SPXL', 47, 0.33*0.5)
            else:
                AH(self.algo, 'SPHD', 47, 0.33*0.5)
    
    def dividend_pop_l_briane_l_19_dd(self):
        self.spy_pop_bot()
        self.qqq_pop_bot()
        self.smh_pop_bot()
    
    def v210_pop_bots_l_dont_replace_the_bil_here(self):
        self.spy_pop_bot()
        self.qqq_pop_bot()
        self.smh_pop_bot()
    
    def monthly_dividend_group(self):
        if RSI(self.algo, 'VIXM', 10) > 70:
            self.v210_pop_bots_l_dont_replace_the_bil_here()
        else:
            self.dividend_pop_l_briane_l_19_dd()

    def bear_search(self):
        Sort(self.algo,'RSI',('SQQQ','BSV'),10,True,1,47,0.5*0.5)
    
    def bull_search(self):
        Sort(self.algo,'RSI',('TQQQ','BSV'),10,False,1,47,0.5*0.5)
    
    def vixn_ftlt(self):
        if CumReturn(self.algo, 'SVXY', 5) > 0.0:
            self.bull_search()
        else:
            if RSI(self.algo, 'TQQQ', 60) > 50:
                self.bull_search()
            else:
                self.bear_search()
    
    def bull_market_stock_selector(self):
        Sort(self.algo,'RSI',('BSV','TQQQ','SPXL'),20,False,1,47,0.5*0.5)
    
    def bear_market_stock_selector(self):
        Sort(self.algo,'RSI',('SQQQ','SPXU','BSV'),10,False,1,47,0.5*0.5)
    
    def max_dd_total_market_popped_3x_29_dd(self):
        if MaxDD(self.algo, 'SPY', 10) > 0.06:
            self.bear_market_stock_selector()
        else:
            self.bull_market_stock_selector()
    
    def tqqq_ftlt(self):
        self.max_dd_total_market_popped_3x_29_dd()
        self.vixn_ftlt()
    
    def bes_tqqq_ftlts(self):
        if RSI(self.algo, 'VIXM', 10) > 70:
            self.v210_pop_bots_l_dont_replace_the_bil_here()
        else:
            self.tqqq_ftlt()
    
    def bes_tqqq_ftlts_dividends(self):
        self.bes_tqqq_ftlts()
        self.monthly_dividend_group()
    

#https://app.composer.trade/symphony/wPXL0F2O6UKWTbfAjdGZ/details

class AHEDGEDLEVERAGEDBONDSSTOCKSV411ReplaceUPROwithTECLTQQQandSOXLStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'TLT') > SMA(self.algo,'TLT',150):
            if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
                AH(self.algo,'TECL',48,0.2)
                AH(self.algo,'TQQQ',48,0.2)
                AH(self.algo,'SOXL',48,0.2)
                AH(self.algo,'TMF',48,0.2)
                AH(self.algo,'PHDG',48,0.2)
            else:
                AH(self.algo,'TLT',48,1)
        else:
            if GetCurrentPrice(self.algo,'TLT') < SMA(self.algo,'TLT',23):
                AH(self.algo,'TMV',48,0.5) 
                AH(self.algo,'UDOW',48,0.5)
            else:
                Sort(self.algo,'CumReturn',('TMF','UPRO','TMV','MOAT','BRK/B','USMV'),30,True,1,48,1)
    
#https://app.composer.trade/symphony/aTBB1RLG6t5nz2vmHV1J/details

class AHedgedRegimeSwitching22Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.hedged_regime_switching_22()
    
    def fund_surf_bottom_1_20d_rsi(self):
        Sort(self.algo,'RSI',('SHY','QLD','SSO','SPY','QQQ'),20,False,1,49,1.0)
    
    def simple_regime_switching_v22(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            self.fund_surf_bottom_1_20d_rsi()
        else:
            if SMA(self.algo,'SPY',200) > SMA(self.algo,'SPY',50):
                if SMA(self.algo,'TLT',200) > SMA(self.algo,'TLT',50):
                    AH(self.algo,'UUP',49,1.0)
                else:
                    AH(self.algo,'TLT',49,1.0)
            else:
                if RSI(self.algo,'SPY',10) < 30:
                    AH(self.algo,'QLD',49,1.0)
                else:
                    AH(self.algo,'QID',49,0.5)
                    AH(self.algo,'XLP',49,0.5)
    
    def total_market_strategy(self):
        self.simple_regime_switching_v22()
    
    def short_fund_surf_hedged_an_attempt_to_profit_from_short_term_bear_market_sentiment(self):
        Sort(self.algo,'RSI',('BSV','PSQ'),10,False,1,49,1.0)
    
    def _this_is_an_attempt_to_create_an_indicator_that_scans_for_black_swan_events(self):
        self.short_fund_surf_hedged_an_attempt_to_profit_from_short_term_bear_market_sentiment()
    
    def _this_is_an_attempt_to_hedge_against_extreme_market_volatility_(self):
        AH(self.algo,'UVXY',49,1.0)
    
    def layer_1_broad_market_hedges(self):
        if RSI(self.algo,'SPY',10) >= 80:
            self._this_is_an_attempt_to_hedge_against_extreme_market_volatility_()
        else:
            if RSI(self.algo,'QQQ',10) >= 80:
                self._this_is_an_attempt_to_hedge_against_extreme_market_volatility_()
            else:
                if RSI(self.algo,'UVXY',10) > 70:
                    self._this_is_an_attempt_to_create_an_indicator_that_scans_for_black_swan_events()
                else:
                    self.total_market_strategy()
    
    def hedged_regime_switching_22(self):
        self.layer_1_broad_market_hedges()
    
#https://app.composer.trade/symphony/Zt96r6DsP7cRnSZ0uLpK/details

class AHFEADiverseDeez12JUN2023Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        AHIV(self.algo,('IEF','IEI','UTWO','TLT'),42,50,0.4)
        AHIV(self.algo,('TQQQ','SOXL','SPXL'),69,50,0.6)
    
#https://app.composer.trade/symphony/cSpuUW4m1cnqRLB6o9NT/details

class AIAintScaredofYINNakaYINNBABAxBWCMinVolStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1b_magic_internet_money_golden_baller()
    
    def golden_bear(self):
        AH(self.algo,'UGL',51,0.33)
        AH(self.algo,'PSQ',51,0.33)
        AH(self.algo,'SH',51,0.33)
    
    def extremely_oversold_sp_low_rsi_double_check_with_bond_mkt_before_going_long(self):
        if RSI(self.algo,'SHY',10) < RSI(self.algo,'VTI',10):
            AH(self.algo,'SOXS',51,1.0)
        else:
            AH(self.algo,'SOXL',51,1.0)
    
    def semis(self):
        Sort(self.algo,'MaxDD',('SOXL','SMH'),6,True,1,51,1.0)
    
    def golden_baller(self):
        if RSI(self.algo,'BIL',10) < RSI(self.algo,'IEF',10):
            if RSI(self.algo,'SPY',7) > 76:
                AH(self.algo,'UGL',51,1.0)
            else:
                self.semis()
        else:
            if RSI(self.algo,'SPY',7) < 27:
                self.extremely_oversold_sp_low_rsi_double_check_with_bond_mkt_before_going_long()
            else:
                self.golden_bear()
    
    def biti_bot(self):
        if RSI(self.algo,'BITO',14) > 60:
            AH(self.algo,'BITI',51,1.0)
        else:
            if CumReturn(self.algo, 'BITI', 1) <= -0.01:
                AH(self.algo,'MSTR',51,1.0)
            else:
                if CumReturn(self.algo,'BITO',5) >= STD(self.algo,'BITO',10):
                    AH(self.algo,'BITI',51,1.0)
                else:
                    if CumReturn(self.algo,'BITO',2) >= STD(self.algo,'BITO',5):
                        if CumReturn(self.algo,'BITO',1) > CumReturn(self.algo,'BITI',3):
                            AH(self.algo,'MSTR',51,1.0)
                        else:
                            self.golden_baller()
                    else:
                        self.golden_baller()
    
    def v1b_magic_internet_money_golden_baller(self):
        if GetCurrentPrice(self.algo,'BITO') <= SMA(self.algo,'BITO',62):
            self.biti_bot()
        else:
            self.golden_baller()

#https://app.composer.trade/symphony/eAoYMVUOg2eZNa8kOgAd/details

class AIFFFundDeviationfromtheStandardv4Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.sloth_tortoise()
    
    def sloth(self):
        AH(self.algo,'MNST',52,0.02)
        AH(self.algo,'COST',52,0.02)
        AH(self.algo,'ULTA',52,0.02) 
        AH(self.algo,'DBMF',52,0.02) 
        AH(self.algo,'BRK/B',52,0.02)
    
    def sloth_tortoise(self):
        AH(self.algo,'KLAC',52,0.11)
        AH(self.algo,'NVDA',52,0.11)
        AH(self.algo,'ASML',52,0.11)
        AH(self.algo,'LLY',52,0.11)
        AH(self.algo,'KNSL',52,0.11)
        AH(self.algo,'SGML',52,0.11)
        AH(self.algo,'FLNG',52,0.11)
        AH(self.algo,'ENPH',52,0.11)
        self.sloth()
    
#https://app.composer.trade/symphony/cVPiYbHH4RtFx5NZzZDW/details

class AInternationalPortfolioBT11232022Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'CEW',27) > RSI(self.algo,'UUP',63):
            self.international_value_and_momentum_factors()
        else:
            if RSI(self.algo,'VOO',5) > RSI(self.algo,'VEU',14):
                Sort(self.algo,'SMADayRet',('BRK/B','QQQ','VOO','VOOG','VOOV','DIA'),5,True,1,53,1)
            else:
                if RSI(self.algo,'GLD',15) > 63:
                    AH(self.algo,'IAUM',53,1)
                else:
                    Sort(self.algo,'SMADayRet',('BIL','SHY','TLT','BNDW'),14,True,1,53,1)
        
    def international_sectors_nations(self):
        Sort(self.algo,'EMA',('INTF','IGRO','EWJV','LDEM','ESGD','ACWV','LCTD','EFAV','ESGE','EEMV','IQLT','IVLU','IMTM','ERET','EFV','EFG','PICK','RING','SLVP','FILL','VEGI','ICLN','IXN','IOO','IGF','MXI','KXI','RXI','IXJ','IXG','EXI','IXP','WOOD','JXI','IXC','XT','IVEG','EPP','ILF','JPXN','DVYE','SDG','DVYA','EWJ','EWC','EWU','EWG','AIA','EWL','EWA','EWH','EWW','EWQ','EWI','EWS','EWN','EWM','ENZL','EWO','EIRL','EWK','EZU','IDV','EUFN','EDEN','ENOR','EWD','EFNL','THD','EWT','EWY','EWZ','ECH','EIDO','EZA','EPOL','TUR','EIS','EPHE','EWUS','EPU','EWZS','QAT','ECNS','UAE','TCHI','EMIF','INDA','IEV','HEEM','FXI','KSA','KWT','FM','SMIN','INDY','EEM','EEMA','EEMS','FRDM','CQQQ'),5,True,3,53,0.33)
    
    def leverage(self):
        Sort(self.algo,'EMA',('EURL','EDC','MEXX','KORU','YINN'),4,True,1,53,0.33)
    
    def developed_and_emerging_markets(self):
        if RSI(self.algo,'VEU',7) > RSI(self.algo,'VOO',7):
            if MaxDD(self.algo,'VEU',5) < MaxDD(self.algo,'VOO',5):
                self.leverage()
            else:
                self.international_sectors_nations()
        else:
            Sort(self.algo,'RSI',('BWX','HYEM','ICSH'),5,True,1,53,0.33)
    
    def international_value_and_momentum_factors(self):
        AHIV(self.algo,('IVAL','IAUM'),7,53,0.33)
        if RSI(self.algo,'IMOM',3) > RSI(self.algo,'VEU',3):
            AH(self.algo,'IMOM',53,0.33)
        else:
            if RSI(self.algo,'GLD',21) > RSI(self.algo,'ICSH',21):
                AH(self.algo,'IAUM',53,0.33)
            else:
                Sort(self.algo,'RSI',('BWX','HYEM','ICSH'),5,True,1,53,0.33)
        self.developed_and_emerging_markets()

#https://app.composer.trade/symphony/gBP1xC5FtU8n7U4cTt5j/details

class AJJsCanaryLeveragev22Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if CumReturn(self.algo,'BND',60) > CumReturn(self.algo,'BIL',60):
            self.main_canary_off()
        else:
            self.main_canary_on_rsi_catcher_7530()
    
    def safe_haven_momentum(self):
        Sort(self.algo,'CumReturn',('UUP','TMF','DBC','UGL','IEO','XLU','VIXM'),30,True,4,54,1.0)
    
    def main_canary_on_rsi_catcher_7530(self):
        if RSI(self.algo,'SPY',10) > 75:
            AH(self.algo,'UVXY',54,1.0)
        else:
            if RSI(self.algo,'SPY',10) < 30:
                AH(self.algo,'UPRO',54,1.0)
            else:
                self.safe_haven_momentum()
    
    def risk_off(self):
        AH(self.algo,'TMF',54,0.5)
        if RSI(self.algo,'SPY',10) > 80:
            AH(self.algo,'UVXY',54,0.5)
        else:
            AH(self.algo,'UPRO',54,0.5)

    def risk_off_cautious(self):
        AHIV(self.algo,('UPRO','TMF','VIXM'),45,54,1.0)
    
    def risk_on(self):
        if RSI(self.algo,'QQQ',10) > 80:
            AH(self.algo,'UVXY',54,1.0)
        else:
            AH(self.algo,'TQQQ',54,1.0)
    
    def main_canary_off(self):
        if EMA(self.algo,'VWO',365) > SMA(self.algo,'VWO',365):
            if CumReturn(self.algo,'WOOD',45) > CumReturn(self.algo,'GLD',45):
                self.risk_on()
            else:
                if RSI(self.algo,'VIXY',14) > 70:
                    self.risk_off_cautious()
                else:
                    self.risk_off()
        else:
            if RSI(self.algo,'VIXY',14) > 70:
                self.risk_off_cautious()
            else:
                self.risk_off()
#https://app.composer.trade/symphony/cX9rAj8S4ngyDALZxaIP/details

class AJJsCanaryLeveragev22bReplaceUPROwithTQQQStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if CumReturn(self.algo,'BND',60) > CumReturn(self.algo,'BIL',60):
            self.main_canary_off()
        else:
            self.main_canary_on_rsi_catcher_7530()
    
    def safe_haven_momentum(self):
        Sort(self.algo,'CumReturn',('UUP','TMF','DBC','UGL','IEO','XLU','VIXM'),30,True,4,55,1.0)
    
    def main_canary_on_rsi_catcher_7530(self):
        if RSI(self.algo,'SPY',10) > 75:
            AH(self.algo,'UVXY',55,1.0)
        else:
            if RSI(self.algo,'SPY',10) < 30:
                AH(self.algo,'TQQQ',55,1.0)
            else:
                self.safe_haven_momentum()

    def risk_off(self):
        AH(self.algo,'TMF',55,0.5)
        if RSI(self.algo,'SPY',10) > 80:
            AH(self.algo,'UVXY',55,0.5)
        else:
            AH(self.algo,'TQQQ',55,0.5)
    
    def risk_off_cautious(self):
        AHIV(self.algo,('TQQQ','TMF','VIXM'),45,55,1.0)
    
    def risk_on(self):
        if RSI(self.algo,'QQQ',10) > 80:
            AH(self.algo,'UVXY',55,1.0)
        else:
            AH(self.algo,'TQQQ',55,1.0)
    
    def main_canary_off(self):
        if EMA(self.algo,'VWO',365) > SMA(self.algo,'VWO',365):
            if CumReturn(self.algo,'WOOD',45) > CumReturn(self.algo,'GLD',45):
                self.risk_on()
            else:
                if RSI(self.algo,'VIXY',14) > 70:
                    self.risk_off_cautious()
                else:
                    self.risk_off()
        else:
            if RSI(self.algo,'VIXY',14) > 70:
                self.risk_off_cautious()
            else:
                self.risk_off()
    
#https://app.composer.trade/symphony/KErzsOKhplZ7TORsyqxD/details

class AJustRunThisFTLT560913Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.just_run_this_ftlt_560913()
    
    def dip_buy_highlow_beta(self):
        if RSI(self.algo,'SOXX',10) < 30:
            AH(self.algo,'SOXL',56,1.0)
        else:
            if RSI(self.algo,'QQQ',10) < 30:
                AH(self.algo,'TECL',56,1.0)
            else:
                if GetCurrentPrice(self.algo,'QQQ') > SMA(self.algo,'QQQ',30):
                    if RSI(self.algo,'PSQ',10) < 35:
                        AH(self.algo,'BTAL',56,1.0)
                    else:
                        AH(self.algo,'SPHB',56,1.0)
                else:
                    if RSI(self.algo,'PSQ',10) > 65:
                        AH(self.algo,'SPHB',56,1.0)
                    else:
                        AH(self.algo,'BTAL',56,1.0)
    
    def frontrunner_inverse_vol_blend(self):
        if RSI(self.algo,'SPY',10) > 80:
            AH(self.algo,'VIXY',56,1.0)
        else:
            if RSI(self.algo,'QQQ',10) > 79:
                AH(self.algo,'VIXY',56,1.0)
            else:
                if RSI(self.algo,'XLK',10) > 79:
                    AH(self.algo,'VIXY',56,1.0)
                else:
                    if RSI(self.algo,'IYY',10) > 79:
                        AH(self.algo,'VIXY',56,1.0)
                    else:
                        if RSI(self.algo,'VTV',10) > 79:
                            AH(self.algo,'VIXY',56,1.0)
                        else:
                            if RSI(self.algo,'XLP',10) > 75:
                                AH(self.algo,'VIXY',56,1.0)
                            else:
                                if RSI(self.algo,'XLF',10) > 80:
                                    AH(self.algo,'VIXY',56,1.0)
                                else:
                                    if RSI(self.algo,'VOX',10) > 79:
                                        AH(self.algo,'VIXY',56,1.0)
                                    else:
                                        AHIV(self.algo,('LLY','NVO','COST','GE'),20,56,1.0)
    
    def just_run_this_ftlt_560913(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            self.frontrunner_inverse_vol_blend()
        else:
            self.dip_buy_highlow_beta()
    
#https://app.composer.trade/symphony/W50OKxJaEcQqYN7d0UWe/details

class AKearsarge13ThresholdReplaceBOXXwUSDUv4Popsv121USDUCommoditiesStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.A40d_rsi_sort_top_2()
    
    def A40d_rsi_sort_top_2(self):
        if RSI(self.algo,'VIXM',40) > 69:
            AH(self.algo,'SPXU',57,1.0)
        else:
            Sort(self.algo,'RSI',('AAPL','MSFT','NVDA','AMD','XOM','NFLX','META','TSLA','AMZN','GOOGL','COIN'),40,True,2,57,1.0)
    
#https://app.composer.trade/symphony/KT0wwAfN7bfMwzxQTb4x/details

class ALCCLowCorrelationCollectionBT31114211321194InvestCopyStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.equal_weight_nvda_lly_no_spxu_sqqq()
    
    def equal_weight_nvda_lly_no_spxu_sqqq(self):
        if RSI(self.algo,'VIXM',40) > 69:
            AH(self.algo,'SH',58,1.0)
        else:
            if RSI(self.algo,'TQQQ',10) > 79:
                AH(self.algo,'BTAL',58,1.0)
            else:
                AH(self.algo,'NVDA',58,0.5) 
                AH(self.algo,'LLY',58,0.5)
    
#https://app.composer.trade/symphony/VRdZBN0WijDYlPP2Uqjq/details

class ALevSPYBRKBBSBondMeanRevLevSPYv102Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if SMA(self.algo,'SPY',5) > GetCurrentPrice(self.algo,'SPY'):
            Sort(self.algo,'SMADayRet',('SPXL','SPLG','SPXL','QQQ','TQQQ','SPYU'),25,True,2,59,0.33)
            AH(self.algo,'QQQ',59,0.33)
            AH(self.algo,'SPY',59,0.33)
        else:
            if RSI(self.algo,'BRK/B',15) < 50:
                AH(self.algo,'USO',59,1)
            else:
                self.huge_volatility()
    
    def bond_midterm_longterm(self):
        if RSI(self.algo,'IEF',200) < RSI(self.algo,'TLT',200):
            if RSI(self.algo,'BND',45) > RSI(self.algo,'SPY',45):
                AH(self.algo,'OEF',59,1.0)
            else:
                AH(self.algo,'BIL',59,0.5)
                AH(self.algo,'USO',59,0.5)
        else:
            AH(self.algo,'BIL',59,0.5)
            AH(self.algo,'USO',59,0.5)
    
    def bond_stock(self):
        if RSI(self.algo,'BND',45) > RSI(self.algo,'SPY',45):
            AH(self.algo,'OEF',59,1.0)
        else:
            AH(self.algo,'BIL',59,0.5)
            AH(self.algo,'USO',59,0.5)
    
    def normal_market(self):
        if MaxDD(self.algo, 'QQQ', 10) > 0.06:
            AH(self.algo,'BRK/B',59,1.0)
        else:
            if MaxDD(self.algo, 'TMF', 10) > 0.07:
                AH(self.algo,'USO',59,0.5) 
                AH(self.algo,'BIL',59,0.5)
            else:
                if GetCurrentPrice(self.algo,'QQQ') > SMA(self.algo,'QQQ',25):
                    AH(self.algo,'OEF',59,1.0)
                else:
                    if RSI(self.algo,'SPY',60) > 50:
                        self.bond_stock()
                    else:
                        self.bond_midterm_longterm()
    
    def mean_rev(self):
        if RSI(self.algo,'QQQ',10) < 32:
            AH(self.algo,'OEF',59,1.0)
        else:
            if MaxDD(self.algo, 'TMF', 10) < 0.07:
                AH(self.algo,'BRK/B',59,1.0)
            else:
                AH(self.algo,'OILK',59,0.33)
                AH(self.algo,'BIL',59,0.33)
                AH(self.algo,'USO',59,0.33)
    
    def huge_volatility(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.12:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                AH(self.algo,'VIXY',59,0.5) 
                AH(self.algo,'VIXM',59,0.5)
            else:
                self.mean_rev()
        else:
            self.normal_market()
    
#https://app.composer.trade/symphony/dicy705jFMcHWSdXI09k/details

class ABWCStockStrategiaCompetitionEntryStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.A9_ifs_max_191_dd_4_year_bt_feb_42020_to_feb_4_2024_2672_ar()
    
    def rotator_qqqbtal(self):
        AH(self.algo, 'QQQ', 60, 0.25)
        AH(self.algo, 'BTAL', 60, 0.25)
    
    def rotator(self):
        Sort(self.algo,'STD',('TMV','TMF','SVXY','VIXM'),5,False,1,60,0.25)
        AH(self.algo, 'TQQQ', 60, 0.25)
    
    def long_grouprotator(self):
        self.rotator()
        self.rotator_qqqbtal()
    
    def antibetashort(self):
        if GetCurrentPrice(self.algo, 'SPY') < SMA(self.algo, 'SPY', 200):
            Sort(self.algo,'CumReturn',('BTAL','BTAL','SDS','SH','BIL'),10,True,2,60,0.5)
            Sort(self.algo,'RSI',('BTAL','BTAL','SDS','SH','BIL'),10,False,2,60,0.5)
        else:
            AH(self.algo, 'BTAL', 60, 1.0)
    
    def long_group_tqqq(self):
        self.rotator()
    
    def wam_1_if(self):
        if RSI(self.algo, 'BND', 15) > RSI(self.algo, 'QQQ', 15):
            self.long_group_tqqq()
        else:
            self.antibetashort()
    
    def bwc_group(self):
        Sort(self.algo,'CumReturn',('DBC','UPRO','UPRO','TQQQ','TQQQ','SVXY','SVXY','BTAL','SH'),20,True,4,60,1)
    
    def bull_trend(self):
        self.long_group_tqqq()
    
    def normal_market_strategy_5_sub_ifs(self):
        if RSI(self.algo, 'SPY', 10) > 80:
            AH(self.algo, 'UVXY', 60, 1.0)
        else:
            if RSI(self.algo, 'QQQ', 10) > 80:
                AH(self.algo, 'UVXY', 60, 1.0)
            else:
                if RSI(self.algo, 'SPY', 35) > RSI(self.algo, 'SPY', 45):
                    self.bull_trend()
                else:
                    if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'SPY', 10):
                        self.wam_1_if()
                    else:
                        self.long_grouprotator()
    
    def antibetashort_1_if(self):
        if GetCurrentPrice(self.algo, 'SPY') < SMA(self.algo, 'SPY', 200):
            Sort(self.algo,'CumReturn',('BTAL','BTAL','SDS','SH','BIL'),10,True,2,60,0.5)
            Sort(self.algo,'RSI',('BTAL','BTAL','SDS','SH','BIL'),10,False,2,60,0.5)
        else:
            AH(self.algo, 'BTAL', 60, 1.0)
    
    def long_high_beta(self):
        Sort(self.algo,'STD',('TECL','TQQQ','FNGU','SOXL','SVXY'),10,False,1,60,0.5)
        Sort(self.algo,'RSI',('TECL','TQQQ','FNGU','SOXL','SVXY'),14,False,1,60,0.5)
    
    def weak_market_strategy_3_sub_ifs(self):
        if RSI(self.algo, 'SPY', 10) < 30:
            self.long_high_beta()
        else:
            if RSI(self.algo, 'TQQQ', 10) < 31:
                self.long_high_beta()
            else:
                self.antibetashort_1_if()
    
    def A9_ifs_max_191_dd_4_year_bt_feb_42020_to_feb_4_2024_2672_ar(self):
        if CumReturn(self.algo, 'SPY', 10) < 0.0:
            self.weak_market_strategy_3_sub_ifs()
        else:
            self.normal_market_strategy_5_sub_ifs()

#https://app.composer.trade/symphony/nmGGd7doJYJfZ6N5LHwn/details

class AMagicInternetMoneyTQQQFTLTStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.magic_internet_money_tqqq_ftlt()
    
    def bull_market_stock_selector(self):
        Sort(self.algo,'RSI',('BSV','TQQQ','UPRO'),20,False,1,61,1.0)
    
    def bear_market_stock_selector(self):
        Sort(self.algo,'RSI',('SQQQ','SPXU','BSV'),10,False,1,61,1.0)
    
    def market_strategy(self):
        if MaxDD(self.algo, 'SPY', 10) > 0.06:
            self.bear_market_stock_selector()
        else:
            self.bull_market_stock_selector()

    def tqqq_ftlt(self):
        if RSI(self.algo,'TQQQ',10) > 80:
            AH(self.algo,'UVXY',61,1.0)
        else:
            if RSI(self.algo,'TQQQ',10) < 30:
                AH(self.algo,'TQQQ',61,1.0)
            else:
                self.market_strategy()
    
    def biti_bot(self):
        if RSI(self.algo,'BITO',14) > 60:
            AH(self.algo,'BITI',61,1.0)
        else:
            if CumReturn(self.algo, 'BITI', 1) <= -0.01:
                AH(self.algo,'MSTR',61,1.0)
            else:
                if CumReturn(self.algo,'BITO',5) >= STD(self.algo,'BITO',10):
                    AH(self.algo,'BITI',61,1.0)
                else:
                    if CumReturn(self.algo,'BITO',2) >= STD(self.algo,'BITO',5):
                        if CumReturn(self.algo,'BITO',1) > CumReturn(self.algo,'BITI',3):
                            AH(self.algo,'MSTR',61,1.0)
                        else:
                            self.tqqq_ftlt()
                    else:
                        self.tqqq_ftlt()
    
    def magic_internet_money_tqqq_ftlt(self):
        if GetCurrentPrice(self.algo,'BITO') <= SMA(self.algo,'BITO',62):
            self.biti_bot()
        else:
            self.tqqq_ftlt()

#https://app.composer.trade/symphony/SXXPAli4XeQoFetK4pdt/details

class AMECHACHEETAHCONSR3mutationStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if EMA(self.algo,'TSLA',21) < GetCurrentPrice(self.algo,'TSLA'):
            AH(self.algo,'TSLL',62,0.5)
        else:
            AH(self.algo,'TSLQ',62,0.5)
        if EMA(self.algo,'NVDA',21) < GetCurrentPrice(self.algo,'NVDA'): 
            AH(self.algo,'NVDL',62,0.5) 
        else:
            AH(self.algo,'NVDS',62,0.5)
    
#https://app.composer.trade/symphony/by88GyS7bvSK5xHGviqX/details

class AMicrosectorsBT15Feb2023Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.energy()
        self.big_oil()
        self.oil_gas_exploration()
        self.big_banks()
        self.travel()
    
    def travel(self):
        if RSI(self.algo,'BND',5) > 55:
            AH(self.algo,'FLYU',64,0.2)
        else:
            if CumReturn(self.algo, 'XLY', 10) < 0.0:
                AH(self.algo,'FLYD',64,0.2) 
            else:
                AH(self.algo,'BIL',64,0.2)
    
    def big_banks(self):
        if RSI(self.algo,'XLF',5) > 55:
            AH(self.algo,'FAS',64,0.2)
        else:
            if STD(self.algo,'XLF',10) > 2:
                AH(self.algo,'BNKD',64,0.2)
            else:
                AH(self.algo,'BIL',64,0.2)

    def oil_gas_exploration(self):
        if RSI(self.algo,'IEO',5) > 55:
            AH(self.algo,'GUSH',64,0.2)
        else:
            if STD(self.algo,'IEO',10) > 1:
                AH(self.algo,'OILD',64,0.2)
            else:
                AH(self.algo,'BIL',64,0.2)
    
    def big_oil(self):
        if RSI(self.algo,'XLE',5) > 55:
            AH(self.algo,'GUSH',64,0.2)
        else:
            if STD(self.algo,'VT',10) > 1:
                AH(self.algo,'NRGD',64,0.2)
            else:
                AH(self.algo,'BIL',64,0.2)
    
    def energy(self):
        if RSI(self.algo,'XLE',5) > 55:
            AH(self.algo,'ERX',64,0.2)
        else:
            if STD(self.algo,'XLE',10) > 1:
                AH(self.algo,'WTID',64,0.2)
            else:
                AH(self.algo,'BIL',64,0.2)
    
#https://app.composer.trade/symphony/fWPMrKgL68frCOXwQOpF/details

class ModifiedGainTrainStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group1()
        self.group2()

    def group1(self):
        if EMA(self.algo,'UUP',42) > EMA(self.algo,'UUP',100):
            AH(self.algo,'UUP',65,0.5)
        else:
            Sort(self.algo,'STD',('BIL','SOXL','DBC'),14,True,2,65,0.25)

    def group2(self):
        if RSI(self.algo,'BIL',10) < RSI(self.algo,'IEF',10):
            if RSI(self.algo,'SPY',7) > 80:
                self.group_overbought_sp_sell_the_rip_buy_volatility()
            else:
                Sort(self.algo,'MaxDD',('SOXL','SMH'),6,True,1,65,0.5)
        else:
            if RSI(self.algo,'SPY',10) < 30:
                self.group_extremely_oversold_sp_low_rsi_double_check_with_bond_mkt_before_going_long()
            else:
                AH(self.algo,'UGL',65,0.166)
                AH(self.algo,'SH',65,0.166)
                AH(self.algo,'PSQ',65,0.166)

    def group_overbought_sp_sell_the_rip_buy_volatility(self):
        AH(self.algo,'UGL',65,0.5)

    def group_extremely_oversold_sp_low_rsi_double_check_with_bond_mkt_before_going_long(self):
        if RSI(self.algo,'SHY',10) < RSI(self.algo,'VTI',10):
            AH(self.algo,'SOXS',65,0.5)
        else:
            AH(self.algo,'SOXL',65,0.5)
        
#https://app.composer.trade/symphony/iODQgNTdbvrA0SgBzXfg/details

class AMonthlyVolTradeinvvol200dinsteadofequal5dmatop1Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.volatility()
    
    def vol_trend_detection(self):
        Sort(self.algo,'SMADayRet',('SVIX','VIXY','VIXM','BTAL'),5,True,1,66,0.5)
    
    def uhhhhhh_idk_monthly_vol_i_guess(self):
        AHIV(self.algo,('WEIX','SVOL'),200,66,0.5)
    
    def volatility(self):
        self.uhhhhhh_idk_monthly_vol_i_guess()
        self.vol_trend_detection()
#region imports
from AlgorithmImports import *
#endregion


# Your New Python File
from AlgorithmImports import *
from indicators import *
from main import YellowCatStrat
    
#https://app.composer.trade/symphony/nMpcL9e6j8HmZNFe6b56/details

class ACOMBINEDK1FreeStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'SPY')>SMA(self.algo,'SPY',200):
            if RSI(self.algo,'QQQ',10)>79:
                AH(self.algo,'SOXS',27,0.2)
            else:
                if RSI(self.algo,'SPY',10)>80:
                    AH(self.algo,'SOXS',27,0.2)
                else:
                    AH(self.algo,'TQQQ',27,0.2)
        else:
            if RSI(self.algo,'QQQ',10)<31:
                AH(self.algo,'TECL',27,0.2)
            else:
                if RSI(self.algo,'SPY',10)<30:
                    AH(self.algo,'UPRO',27,0.2)
                else:
                    if GetCurrentPrice(self.algo,'QQQ')<SMA(self.algo,'QQQ',20):
                        Sort(self.algo,'RSI',('SQQQ','TLT'),10,True,1,27,0.2)
                    else:
                        if RSI(self.algo,'PSQ',10)<31:
                            AH(self.algo,'SQQQ',27,0.2)
                        else:
                            AH(self.algo,'TQQQ',27,0.2)
        if RSI(self.algo,'QQQ',10)>79:
            AH(self.algo,'SOXS',27,0.8)
        else:
            if RSI(self.algo,'SPY',10)>80:
                AH(self.algo,'SOXS',27,0.8)
            else:
                if RSI(self.algo,'QQQ',10)<31:
                    AH(self.algo,'TQQQ',27,0.8)
                else:
                    if RSI(self.algo,'IEF',10)>RSI(self.algo,'PSQ',20):
                        Sort(self.algo,'SMADayRet',('TQQQ','XYLD','XLY','FAZ','FBND','SVOL','TFLO'),14,True,3,27,0.8)
                    else:
                        AH(self.algo,'PSQ',27,0.8)

#https://app.composer.trade/symphony/o60ycDw5Ac7EmSxG5KUr/details

class ACollection10Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        Sort(self.algo,'SMA',('BRZU','CURE','DFEN','DPST','DRN','DRV','DUSL','EDC','EDZ','ERX','ERY','EURL','FAS','FAZ','GDXD','GDXU','INDL','KORU','LABD','LABU','MEXX','MIDU','NAIL','OILD','GUSH','PILL','RETL','SDOW','SMDD','SOXL','SOXS','SPXL','SPXS','SQQQ','SRTY','TMF','TMV','TNA','TQQQ','TYD','TYO','TZA','UBOT','UDOW','URTY','UTSL','WTID','ERX','YANG','YINN'),5,False,3,28,1)
#https://app.composer.trade/symphony/wGairbxWAWSgR1UzKUZA/details

class ACNDefianceFundPRD10Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        Sort(self.algo,'STD',('RTX','PLTR','AMZN','MSFT','IBM','GOOGL','CRWD','ZS','CHKP','FTNT','PANW','LMT','VSAT','AVAV','NOC','BA','GD','INTC','AMD','CYBR','QLYS','S','AKAM','OKTA','BRK/B','CNI','WM','CAT','DE','ECL','ASML','INTC','TSM','AMAT','ARM','NVDA'),12,True,4,67,0.8)
        self.group()
    
    def natural_gas(self):
        if SMA(self.algo,'FCG',100) > SMA(self.algo,'FCG',500):
            AH(self.algo,'FCG',67,0.9*0.2)
            if GetCurrentPrice(self.algo,'UNG') > SMA(self.algo,'UNG',50):
                AH(self.algo,'BOIL',67,0.1*0.2)
            else:
                AH(self.algo,'KOLD',67,0.1*0.2)
        else:
            if SMA(self.algo,'UNG',50) < SMA(self.algo,'UNG',400):
                if GetCurrentPrice(self.algo,'UNG') < SMA(self.algo,'UNG',10):
                    AH(self.algo,'KOLD',67,0.5*0.2) 
                    AH(self.algo,'BIL',67,0.5*0.2)
                else:
                    AH(self.algo,'BIL',67,1.0*0.2)
            else:
                AH(self.algo,'UNG',67,0.25*0.2)
                AH(self.algo,'WOOD',67,0.25*0.2) 
                AH(self.algo,'AA',67,0.25*0.2) 
                AH(self.algo,'PANW',67,0.25*0.2)
    
    def group(self):
           self.natural_gas()

#https://app.composer.trade/symphony/eQLH8exlZQZZdznxzHM1/details

class ACHIPStoaTrillyStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.chip_engr()
    
    def rotator(self):
        Sort(self.algo,'STD',('SOXX','NVDA','AMD','XLE','AMAT','ASML','INTC','TSM','MU','SH','ARM','KLAC','SOF'),5,True,2,68,0.5)
        Sort(self.algo,'CumReturn',('MU','AMAT','ASML','TSM','AMD','XLE','NVDA','SOXX','INTC','KLAC'),300,True,2,68,0.5)
    
    def chip_engr(self):
        if RSI(self.algo,'SOXX',31) > 68:
            AH(self.algo,'SOXS',68,1.0)
        else:
            self.rotator()

#https://app.composer.trade/symphony/0QfVvcQsIc2rOZKfB0Ls/details

class AnansiPortfolioV15UltraLBT20111122Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'TQQQ') > SMA(self.algo,'TQQQ',200):
            if RSI(self.algo,'QQQ',10) > 80:
                AH(self.algo,'UVXY',69,1)
            else:
                AH(self.algo,'TQQQ',69,1)
        else:
            if RSI(self.algo,'TQQQ',10) < 31:
                AH(self.algo,'TECL',69,1)
            else:
                if RSI(self.algo,'UPRO',10) < 31:
                    AH(self.algo,'SPYU',69,1)
                else:
                    if GetCurrentPrice(self.algo,'TQQQ') > SMA(self.algo,'TQQQ',20):
                        AH(self.algo,'TQQQ',69,1)
                    else:
                        Sort(self.algo,'RSI',('TLT','SQQQ'),10,True,1,69,1)


#https://app.composer.trade/symphony/hSADI32liniTnjRcY0qQ/details

class ANuclearEnergyTrendMARStrategy(YellowCatStrat):

    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if MaxDD(self.algo, 'SPY', 10) < 0.05:
            self.risk_on()
        else:
            self.risk_off()
    
    def risk_off(self):
        AH(self.algo,'IEI',70,0.25)
        AH(self.algo,'GLD',70,0.25) 
        AH(self.algo,'TIP',70,0.25) 
        AH(self.algo,'BSV',70,0.25)
    
    def risk_on(self):
        Sort(self.algo,'SMADayRet',('CCJ','DNN','NLR','SMR','URA','URNM','NLR','UEC','URNJ','UROY','UUUU','LEU'),10,True,2,70,0.2)
        Sort(self.algo,'SMADayRet',('CCJ','DNN','NLR','SMR','URA','URNM','NLR','UEC','URNJ','UROY','UUUU','LEU'),20,True,2,70,0.2)
        Sort(self.algo,'SMADayRet',('CCJ','DNN','NLR','SMR','URA','URNM','NLR','UEC','URNJ','UROY','UUUU','LEU'),50,True,2,70,0.2)
        Sort(self.algo,'SMADayRet',('CCJ','DNN','NLR','SMR','URA','URNM','NLR','UEC','URNJ','UROY','UUUU','LEU'),100,True,2,70,0.2)
        Sort(self.algo,'SMADayRet',('CCJ','DNN','NLR','URA','URNM','NLR','UEC','UROY','UUUU','LEU','SMR'),200,True,2,70,0.2)

#https://app.composer.trade/symphony/Lq31hW0fOU8WuHq5NW9K/details

class ANVDYorYieldmax40dRSISortTop2Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.nvdy_or_yieldmax_40d_rsi_sort_top_2()
    
    def yieldmax_40d_rsi_sort_top_2(self):
        if RSI(self.algo,'VIXM',40) > 69:
            AH(self.algo,'SPXU',71,1.0)
        else:
            Sort(self.algo,'RSI',('APLY','MSFO','NVDY','AMDY','XOMO','NFLY','FBY','TSLY','AMZY','GOOY','CONY'),40,True,2,71,1.0)
    
    def huge_volatility(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.13:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.06:
                AH(self.algo,'SOXS',71,1.0)
            else:
                AH(self.algo,'NVDY',71,1.0)
        else:
            self.yieldmax_40d_rsi_sort_top_2()
    
    def nvdy_or_yieldmax_40d_rsi_sort_top_2(self):
        if RSI(self.algo,'TQQQ',10) > 79:
            AH(self.algo,'SOXS',71,1.0)
        else:
            self.huge_volatility()
#https://app.composer.trade/symphony/30MWKj1fMIAU3HV7tzAb/details

class HWRT24Strategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.isolated_volatility_bomb_block()

    def isolated_volatility_bomb_block(self):
        if RSI(self.algo, 'UVXY', 21) > 65:
            if RSI(self.algo, 'UVXY', 10) > 74:
                if RSI(self.algo, 'UVXY', 10) < 84:
                    AH(self.algo, 'UVXY', 72, 1)
                else:
                    AH(self.algo, 'BIL', 72, 1)
            else:
                AH(self.algo, 'BIL', 72, 1)
        else:
            self.high_win_rates_anansi_scale_in()

    def high_win_rates_anansi_scale_in(self):
        if RSI(self.algo, 'IOO', 10) > 80:
            self.scale_in_vix_plus_to_vix_plus_plus()
        else:
            self.tqqq_condition()

    def scale_in_vix_plus_to_vix_plus_plus(self):
        if RSI(self.algo, 'IOO', 10) > 82.5:
            self.vix_blend_plus_plus()
        else:
            self.vix_blend_plus()

    def vix_blend_plus_plus(self):
        AH(self.algo, 'UVXY', 72, 1/3)
        AH(self.algo, 'UVXY', 72, 1/3)
        AH(self.algo, 'UVXY', 72, 1/3)

    def vix_blend_plus(self):
        AH(self.algo, 'UVXY', 72, 1/3)
        AH(self.algo, 'UVXY', 72, 1/3)
        AH(self.algo, 'UVXY', 72, 1/3)

    def tqqq_condition(self):
        if RSI(self.algo, 'TQQQ', 10) > 81:
            if RSI(self.algo, 'UVXY', 60) > 40:
                AH(self.algo, 'UVXY', 72, 1)
            else:
                self.retl_condition()
        else:
            self.spy_condition()

    def retl_condition(self):
        if RSI(self.algo, 'RETL', 10) > 82:
            self.scale_in_btal_to_vix()
        else:
            self.xlf_condition()

    def scale_in_btal_to_vix(self):
        if RSI(self.algo, 'RETL', 10) > 85:
            self.vix_blend()
        else:
            self.btal_bil()

    def vix_blend(self):
        AH(self.algo, 'UVXY', 72, 1/3)
        AH(self.algo, 'UVXY', 72, 1/3)
        AH(self.algo, 'UVXY', 72, 1/3)

    def btal_bil(self):
        AH(self.algo, 'BTAL', 72, 0.5)
        AH(self.algo, 'SHV', 72, 0.5)

    def xlf_condition(self):
        if RSI(self.algo, 'XLF', 10) > 81:
            self.scale_in_vix_to_vix_plus()
        else:
            AH(self.algo, 'SHV', 72, 1)

    def scale_in_vix_to_vix_plus(self):
        if RSI(self.algo, 'XLF', 10) > 85:
            self.vix_blend_plus()
        else:
            self.vix_blend()

    def spy_condition(self):
        if RSI(self.algo, 'SPY', 10) > 80:
            if RSI(self.algo, 'UVXY', 60) > 40:
                AH(self.algo, 'UVXY', 72, 1)
            else:
                self.retl_condition()
        else:
            self.soxl_condition()

    def soxl_condition(self):
        if RSI(self.algo, 'SOXL', 14) < 30:
            AH(self.algo, 'SOXL', 72, 1)
        else:
            self.tecl_condition()

    def tecl_condition(self):
        if RSI(self.algo, 'TECL', 14) < 30:
            AH(self.algo, 'TECL', 72, 1)
        else:
            self.labu_condition()

    def labu_condition(self):
        if RSI(self.algo, 'LABU', 10) < 22:
            Sort(self.algo, 'CumReturn', ('LABU', 'SOXL'), 1, False, 1, 72, 1)
        else:
            self.qqq_condition()

    def qqq_condition(self):
        if RSI(self.algo, 'QQQ', 14) < 30:
            AH(self.algo, 'TECL', 72, 1)
        else:
            self.smh_condition()

    def smh_condition(self):
        if RSI(self.algo, 'SMH', 10) < 25:
            AH(self.algo, 'SOXL', 72, 1)
        else:
            self.tqqq_inverse_condition()

    def tqqq_inverse_condition(self):
        if RSI(self.algo, 'TQQQ', 14) > 80:
            AH(self.algo, 'TECS', 72, 1)
        else:
            self.soxl_inverse_condition()

    def soxl_inverse_condition(self):
        if RSI(self.algo, 'SOXL', 14) > 80:
            AH(self.algo, 'SOXS', 72, 1)
        else:
            self.tmv_condition()

    def tmv_condition(self):
        if RSI(self.algo, 'TMV', 14) > 80:
            AH(self.algo, 'TMF', 72, 1)
        else:
            self.smh_inverse_condition()

    def smh_inverse_condition(self):
        if RSI(self.algo, 'SMH', 10) > 80:
            AH(self.algo, 'SOXS', 72, 1)
        else:
            self.retl_scale_in_condition()

    def retl_scale_in_condition(self):
        if RSI(self.algo, 'RETL', 10) > 82:
            self.scale_in_btal_to_vix()
        else:
            self.xlf_scale_in_condition()

    def xlf_scale_in_condition(self):
        if RSI(self.algo, 'XLF', 10) > 81:
            self.scale_in_vix_to_vix_plus()
        else:
            self.spy_scale_in_condition()

    def spy_scale_in_condition(self):
        if RSI(self.algo, 'SPY', 10) > 80:
            self.vix_blend_plus_plus()
        else:
            self.ioo_scale_in_condition()

    def ioo_scale_in_condition(self):
        if RSI(self.algo, 'IOO', 10) > 80:
            self.scale_in_vix_plus_to_vix_plus_plus()
        else:
            self.qqq_scale_in_condition()

    def qqq_scale_in_condition(self):
        if RSI(self.algo, 'QQQ', 10) > 79:
            self.scale_in_vix_plus_to_vix_plus_plus()
        else:
            self.vtv_condition()

    def vtv_condition(self):
        if RSI(self.algo, 'VTV', 10) > 79:
            self.vix_blend()
        else:
            self.xlp_condition()

    def xlp_condition(self):
        if RSI(self.algo, 'XLP', 10) > 77:
            self.vix_blend()
        else:
            self.xlf_final_condition()

    def xlf_final_condition(self):
        if RSI(self.algo, 'XLF', 10) > 81:
            self.vix_blend()
        else:
            self.spy_final_condition()

    def spy_final_condition(self):
        if RSI(self.algo, 'SPY', 70) > 62:
            self.overbought_condition()
        else:
            self.high_vix_condition()

    def overbought_condition(self):
        if RSI(self.algo, 'AGG', 15) > RSI(self.algo, 'QQQ', 15):
            self.ticker_mixer()
        else:
            self.gld_slv_dbc()

    def ticker_mixer(self):
        assets = ['SPXL', 'TQQQ', 'TECL', 'SOXL', 'FNGU']
        Sort(self.algo, 'SMADayRet', assets, 15, True, 3, 72, 0.5)
        AH(self.algo, 'TQQQ', 72, 0.5)

    def gld_slv_dbc(self):
        AH(self.algo, 'GLD', 72, 0.5)
        AH(self.algo, 'SLV', 72, 0.25)
        AH(self.algo, 'DBC', 72, 0.25)

    def high_vix_condition(self):
        if CumReturn(self.algo, 'VIXY', 9) > 0.2:
            self.high_vix_spy_condition()
        else:
            AH(self.algo, 'BIL', 72, 1)

    def high_vix_spy_condition(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            self.high_vix_uvxy_condition()
        else:
            self.volmageddon_protection()

    def high_vix_uvxy_condition(self):
        if RSI(self.algo, 'UVXY', 21) > 65:
            self.bsc_31_rsi()
        else:
            self.high_vix_svxy_condition()

    def bsc_31_rsi(self):
        if RSI(self.algo, 'SPY', 10) > 31:
            if MaxDD(self.algo, 'SVXY', 5) > 0.15:
                self.uvix_volatility()
            else:
                self.uvxy_volatility()
        else:
            self.svxy_condition()

    def uvix_volatility(self):
        AH(self.algo, 'UVXY', 72, 0.1)
        AH(self.algo, 'BTAL', 72, 0.9)

    def uvxy_volatility(self):
        AH(self.algo, 'UVXY', 72, 0.1)
        self.vix_mix(0.3)
        AH(self.algo, 'BTAL', 72, 0.6)

    def vix_mix(self, weight):
        assets = ['SOXS', 'TECS', 'SQQQ', 'OILD', 'TMV', 'FAZ', 'DRV', 'EDZ', 'DXD', 'SPXS', 'SDOW', 'FNGD']
        Sort(self.algo, 'SMADayRet', assets, 10, False, 2, 72, weight)

    def svxy_condition(self):
        if MaxDD(self.algo, 'SVXY', 3) > 0.2:
            self.volmageddon_protection()
        else:
            self.svxy_vixy_condition()

    def volmageddon_protection(self):
        AH(self.algo, 'BTAL', 72, 1/3)
        AH(self.algo, 'USMV', 72, 1/3)
        self.svix_svxy_condition(1/3)

    def svix_svxy_condition(self, weight):
        if CumReturn(self.algo, 'SVXY', 1) > 0.05:
            AH(self.algo, 'SVIX', 72, weight)
        else:
            AH(self.algo, 'SVXY', 72, weight)

    def svxy_vixy_condition(self):
        if CumReturn(self.algo, 'VIXY', 5) > 0.45:
            AH(self.algo, 'SVIX', 72, 0.5)
        else:
            AH(self.algo, 'SVXY', 72, 0.5)
            self.inverse_vix_mix(0.5)

    def inverse_vix_mix(self, weight):
        assets = ['QLD', 'UYG', 'SAA', 'EFO', 'SSO', 'UDOW', 'UWM', 'ROM', 'ERX']
        Sort(self.algo, 'SMADayRet', assets, 10, False, 2, 72, weight)

    def high_vix_svxy_condition(self):
        if MaxDD(self.algo, 'SVXY', 3) > 0.2:
            self.volmageddon_protection()
        else:
            self.svxy_vixy_condition()

    def pick_bottom_3_1_5x(self):
        assets_3x = ['SPXL', 'TQQQ', 'TECL', 'SOXL']
        assets_1x = ['SPY', 'QQQ', 'XLK', 'SOXX']
        Sort(self.algo, 'SMADayRet', assets_3x, 10, False, 3, 72, 0.5)
        Sort(self.algo, 'SMADayRet', assets_1x, 10, False, 3, 72, 0.5)
 #https://app.composer.trade/symphony/rheIMQZxPaB9k82wTRcL/details

class AOGv11BuyTheDips150dMABasketwithbondselectorlessk1editionStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'TQQQ',10) > 79:
            AH(self.algo,'UVXY',73,0.25)
            AH(self.algo,'XLP',73,0.75)
        else:
            if RSI(self.algo,'TQQQ',10) < 31:
                AH(self.algo,'TECL',73,0.5)
                AH(self.algo,'XLP',73,0.5)
            else:
                if RSI(self.algo,'SPY',10) < 30:
                    AH(self.algo,'UPRO',73,0.5)
                    AH(self.algo,'XLP',73,0.5)
                else:
                    self.group_150_ma_selector()
                    self.group_tlt_selector()

    def group_150_ma_selector(self):
        Sort(self.algo,'SMADayRet',('TQQQ','SPY','TLT','BSV','XLP','SOXL','XLE','PDBC','XLV','USDU','UDOW','UPRO','GLD','DUG','EWZ'),150,True,4,73,0.7)

    def group_tlt_selector(self):
        if GetCurrentPrice(self.algo,'TLT') > SMA(self.algo,'TLT',150):
            AH(self.algo,'TMF',73,0.3)
        else:
            if GetCurrentPrice(self.algo,'TLT') < SMA(self.algo,'TLT',23):
                AH(self.algo,'TMV',73,0.3)
            else:
                AH(self.algo,'TMF',73,0.3)

#https://app.composer.trade/symphony/z3EF1nItjcVAy2mOkRkE/details

class APheonixandJrmungandrwoCounterbalancerDDCorrelationCRinStdevBT12042019AR260MDD139Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.early_works_pop_bots_()
    
    def bull_market_stock_selector(self):
        Sort(self.algo,'RSI',('BSV','QLD','SSO'),20,False,1,74,0.33)
    
    def bear_market_stock_selector(self):
        Sort(self.algo,'RSI',('QID','SDS','BSV'),10,False,1,74,0.33)
    
    def market_strategy(self):
        if MaxDD(self.algo, 'SPY', 10) > 0.06:
            self.bear_market_stock_selector()
        else:
            self.bull_market_stock_selector()

    def smh_pop_bot(self):
        if RSI(self.algo,'SOXL',10) < 30:
            AH(self.algo,'USD',74,0.33)
        else:
            self.market_strategy()
    
    def qqq_pop_bot(self):
        if RSI(self.algo,'TQQQ',10) > 80:
            AH(self.algo,'UVXY',74,0.33)
        else:
            if RSI(self.algo,'TQQQ',10) < 30:
                AH(self.algo,'QLD',74,0.33)
            else:
                self.market_strategy()
    
    def spy_pop_bot(self):
        if RSI(self.algo,'SPXL',10) > 80:
            AH(self.algo,'UVXY',74,0.33)
        else:
            if RSI(self.algo,'SPXL',10) < 30:
                AH(self.algo,'SSO',74,0.33)
            else:
                self.market_strategy()

    def early_works_pop_bots_(self):
        self.spy_pop_bot()
        self.qqq_pop_bot()
        self.smh_pop_bot()

#https://app.composer.trade/symphony/Z8yB2V4UI8g60rSKXagt/details

class APizzaTQQQForTheLongTermRedditPostLinkreplaceTQQQUPROwSPYUStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if RSI(self.algo,'TQQQ',10) > 79:
                AH(self.algo,'UVXY',75,1)
            else:
                if RSI(self.algo,'SPXL',10) > 80:
                    AH(self.algo,'UVXY',75,1)
                else:
                    AH(self.algo,'SPYU',75,1)
        else:
            if RSI(self.algo,'TQQQ',10) < 31:
                AH(self.algo,'TECL',75,1)
            else:
                if RSI(self.algo,'SPY',10) < 30:
                    AH(self.algo,'SPYU',75,1)
                else:
                    if GetCurrentPrice(self.algo,'TQQQ') < SMA(self.algo,'TQQQ',20):
                        Sort(self.algo,'RSI',('SQQQ','TLT'),10,True,1,75,1)
                    else:
                        if RSI(self.algo,'SQQQ',10) < 31:
                            AH(self.algo,'SQQQ',75,1)
                        else:
                            AH(self.algo,'SPYU',75,1)
    
#https://app.composer.trade/symphony/dxKPxALaiKnMqzTA5HHh/details

class APoppedStockBondStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.popped_stockbond_l_oct_28th_2011()
    
    def tmv_bear(self):
        AH(self.algo,'TMV',76,0.08)
        AH(self.algo,'UUP',76,0.08)
        AH(self.algo,'CURE',76,0.08)
        AH(self.algo,'SPXU',76,0.08)

    def tmv_bull(self):
        AH(self.algo,'TMV',76,0.08)
        AH(self.algo,'UUP',76,0.08)
        AH(self.algo,'MIDU',76,0.08)
        AH(self.algo,'CURE',76,0.08)
    
    def tmf_bull(self):
        AH(self.algo,'TMF',76,0.08)
        AH(self.algo,'TYD',76,0.08)
        AH(self.algo,'MIDU',76,0.08)
        AH(self.algo,'CURE',76,0.08)
    
    def simple_base(self):
        if RSI(self.algo,'IEF',200) > RSI(self.algo,'TLT',200):
            self.tmf_bull()
        else:
            if RSI(self.algo,'SPY',60) > 50:
                self.tmv_bull()
            else:
                self.tmv_bear()
    
    def smh_pop_bot(self):
        if RSI(self.algo,'SOXL',10) < 30:
            AH(self.algo,'SOXL',76,0.33)
        else:
            self.simple_base()

    def qqq_pop_bot(self):
        if RSI(self.algo,'TQQQ',10) > 80:
            AH(self.algo,'UVXY',76,0.33)
        else:
            if RSI(self.algo,'TQQQ',10) < 30:
                AH(self.algo,'TQQQ',76,0.33)
            else:
                self.simple_base()
    
    def spy_pop_bot(self):
        if RSI(self.algo,'SPXL',10) > 80:
            AH(self.algo,'UVXY',76,0.33)
        else:
            if RSI(self.algo,'SPXL',10) < 30:
                AH(self.algo,'SPXL',76,0.33)
            else:
                self.simple_base()

    def pop_bots_stocks_and_bonds(self):
        self.spy_pop_bot()
        self.qqq_pop_bot()
        self.smh_pop_bot()
    
    def v210_pop_bots_l_oct_28th_2011(self):
        self.spy_pop_bot()
        self.qqq_pop_bot()
        self.smh_pop_bot()

    def popped_stockbond_l_oct_28th_2011(self):
        if RSI(self.algo,'VIXM',10) > 70:
            self.v210_pop_bots_l_oct_28th_2011()
        else:
            self.pop_bots_stocks_and_bonds()
#https://app.composer.trade/symphony/yUG4CgzXokqgROc1SxwM/details

class AQQQForTheLongTermV2WITHUVXY1045RR221MaxDDStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if RSI(self.algo,'QQQ',10) > 80:
                AH(self.algo,'UVXY',77,1)
            else:
                if RSI(self.algo,'SPY',10) > 80:
                    AH(self.algo,'UVXY',77,1)
                else:
                    AH(self.algo,'QQQ',77,1)
        else:
            if RSI(self.algo,'QQQ',10) < 30:
                AH(self.algo,'QQQ',77,1)
            else:
                if RSI(self.algo,'SPY',10) < 30:
                    AH(self.algo,'SPY',77,1)
                else:
                    if RSI(self.algo,'UVXY',10) > 74:
                        if RSI(self.algo,'UVXY',10) > 84:
                            if GetCurrentPrice(self.algo,'QQQ') > SMA(self.algo,'QQQ',20):
                                AH(self.algo,'QQQ',77,1)
                            else:
                                Sort(self.algo,'RSI',('BSV','TLT'),10,True,1,77,1)
                        else:
                            AH(self.algo,'UVXY',77,1)
                    else:
                        if GetCurrentPrice(self.algo,'QQQ') > SMA(self.algo,'QQQ',20):
                            if RSI(self.algo,'PSQ',10) < 35:
                                AH(self.algo,'PSQ',77,1)
                            else:
                                AH(self.algo,'QQQ',77,1)
                        else:
                            if RSI(self.algo,'PSQ',10) > 65:
                                Sort(self.algo,'RSI',('XLP','TLT'),10,True,1,77,1)
                            else:
                                Sort(self.algo,'RSI',('PSQ','BSV'),10,True,1,77,1)
    

#https://app.composer.trade/symphony/lSeRcENgfDaexjIq77rZ/details

class ASelfReplicatingBootstrapsStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'TQQQ',10) > 79:
            AH(self.algo,'UVXY',78,1)
        else:
            if RSI(self.algo,'UPRO',10) > 80:
                AH(self.algo,'UVXY',78,1)
            else:
                if RSI(self.algo,'QQQ',7) <= 18:
                    AH(self.algo,'TECL',78,1)
                else:
                    if RSI(self.algo,'SPY',10) < 69:
                        if RSI(self.algo,'SPY',10) > 51:
                            AHIV(self.algo,('VOO','TQQQ','TSLA','UPRO','TNA','IWB','QQQ'),10,78,1)
                        else:
                            AH(self.algo,'UUP',78,1)
                    else:
                        AH(self.algo,'UUP',78,1)
    
#https://app.composer.trade/symphony/bmKKnEFG4s7oczb8bMEW/details

class ASeriousBusinessStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v11_what_more_do_you_need_even_longer_backtest()
    
    def v11_what_more_do_you_need_even_longer_backtest(self):
        if RSI(self.algo,'QQQ',10) > 80:
            AH(self.algo,'TLT',79,1.0)
        else:
            if RSI(self.algo,'SPY',10) > 80:
                AH(self.algo,'TLT',79,1.0)
            else:
                if RSI(self.algo,'QQQ',10) < 30:
                    Sort(self.algo,'RSI',('QLD','ROM','SHY'),10,False,1,79,1.0)
                else:
                    if RSI(self.algo,'IEF',10) > RSI(self.algo,'PSQ',20):
                        Sort(self.algo,'RSI',('QLD','ROM'),20,False,1,79,0.5)
                        Sort(self.algo,'SMADayRet',('QLD','ROM','QQQ','SHV'),20,True,1,79,0.5)
                    else:
                        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
                            AH(self.algo,'XLP',79,0.5)
                            Sort(self.algo,'RSI',('DBO','UUP','SPY'),20,True,1,79,0.5)
                        else:
                            if GetCurrentPrice(self.algo,'QLD') < SMA(self.algo,'QLD',20):
                                Sort(self.algo,'SMADayRet',('QID','SH','BIL'),20,True,1,79,0.5)
                                Sort(self.algo,'RSI',('QID','UUP'),11,False,1,79,0.5)
                            else:
                                AH(self.algo,'IEF',79,1.0)
#https://app.composer.trade/symphony/LKu57ILs6rj3nNqz5CHh/details

class ATESTPORT021V2BWCMinVolatilityFund6Dalio2024EditionStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'SPY',10) > 80:
            AH(self.algo,'UVXY',80,1)
        else:
            if RSI(self.algo,'QQQ',10) > 81:
                AH(self.algo,'UVXY',80,1)
            else:
                self.rest_rsi()
    
    def rest_rsi(self):
        if RSI(self.algo,'VOO',14) > 70:
            AH(self.algo,'CURE',80,1.0)
        else:
            if RSI(self.algo,'TQQQ',14) < 30:
                AH(self.algo,'TQQQ',80,1.0)
            else:
                if RSI(self.algo,'VOO',14) > 40:
                    if RSI(self.algo,'VOO',14) < 60:
                        AH(self.algo,'QYLD',80,1.0)
                    else:
                        if RSI(self.algo,'VOO',14) > 60:
                            if RSI(self.algo,'VOO',14) < 70:
                                AH(self.algo,'SPUU',80,1.0)
                            else:
                                AH(self.algo,'VOO',80,1.0)
                        else:
                            AH(self.algo,'VOO',80,1.0)
                else:
                    AH(self.algo,'VOO',80,1.0)
#https://app.composer.trade/symphony/ZCHboIFjGmVG5LmpzC4D/details

class ATESTPORT022V1BWCMinVolatilityFundxantibeta2024EditionNOPXDStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if RSI(self.algo,'TQQQ',10) > 79:
                AH(self.algo,'UVXY',81,1)
            else:
                if RSI(self.algo,'SPXL',10) > 80:
                    AH(self.algo,'UVXY',81,1)
                else:
                    AH(self.algo,'SPYU',81,1)
        else:
            if RSI(self.algo,'TQQQ',10) < 31:
                AH(self.algo,'TECL',81,1)
            else:
                if RSI(self.algo,'SPY',10) < 30:
                    AH(self.algo,'SPYU',81,1)
                else:
                    if GetCurrentPrice(self.algo,'TQQQ') < SMA(self.algo,'TQQQ',20):
                        Sort(self.algo,'RSI',('SQQQ','TLT'),10,True,1,81,1)
                    else:
                        if RSI(self.algo,'SQQQ',10) < 31:
                            AH(self.algo,'SQQQ',81,1)
                        else:
                            AH(self.algo,'SPYU',81,1)
    
#https://app.composer.trade/symphony/NSUAX6dxiQz2D1GO3xBM/details

class ATESTPORT045StuffVoxUnderstands2Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if CumReturn(self.algo, 'BITO', 5) > 0.0:
            if RSI(self.algo,'SPY',21) < RSI(self.algo,'SHY',21):
                AH(self.algo,'BIL',82,1)
            else:
                AH(self.algo,'SPXU',82,1)
        else:
            if CumReturn(self.algo, 'BITO', 21) > 0.0:
                AH(self.algo,'UPRO',82,1) 
            else:
                AH(self.algo,'BIL',82,1)
    
#https://app.composer.trade/symphony/bNMKwwuh90GZlPfiQaBB/details

class ATESTPORT089EastboundDownStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.eastbound_down()
    
    def eastbound_down(self):
        if RSI(self.algo,'TECB',12) > 100:
            AH(self.algo,'SHV',83,1.0)
        else:
            if RSI(self.algo,'VIXM',14) > 70:
                AH(self.algo,'SHV',83,1.0)
            else:
                if RSI(self.algo,'BND',15) > RSI(self.algo,'QQQ',15):
                    if RSI(self.algo,'SMH',10) < 65:
                        if GetCurrentPrice(self.algo,'RINF') > SMA(self.algo,'RINF',100):
                            AH(self.algo,'SOXL',83,0.5) 
                            AH(self.algo,'XLK',83,0.5)
                        else:
                            AH(self.algo,'TECL',83,0.5) 
                            AH(self.algo,'TMV',83,0.5)
                    else:
                        if RSI(self.algo,'SMH',10) > 75:
                            AH(self.algo,'SOXS',83,1.0)
                        else:
                            AH(self.algo,'SHV',83,1.0)
                else:
                    if RSI(self.algo,'SMH',10) > 80:
                        AH(self.algo,'SOXS',83,1.0)
                    else:
                        if RSI(self.algo,'SMH',10) < 25:
                            AH(self.algo,'SOXL',83,1.0)
                        else:
                            AH(self.algo,'PSQ',83,0.33)
                            AH(self.algo,'TLT',83,0.33)
                            AH(self.algo,'SHV',83,0.33)

#https://app.composer.trade/symphony/LnWvq7ezc8lmqsxYXQIg/details

class ATimCooksExcellentAdventureStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.tim_cooks_excellent_adventure()
    
    def tim_cooks_excellent_adventure(self):
        if RSI(self.algo,'QQQ',10) > 80:
            AH(self.algo,'UVXY',84,1.0)
        else:
            if RSI(self.algo,'SPY',10) > 80:
                AH(self.algo,'UVXY',84,1.0)
            else:
                if RSI(self.algo,'TQQQ',10) < 31:
                    AH(self.algo,'TECL',84,1.0)
                else:
                    if RSI(self.algo,'IEF',20) > RSI(self.algo,'PSQ',20):
                        if EMA(self.algo,'AAPL',8) > SMA(self.algo,'AAPL',20):
                            AH(self.algo,'AAPB',84,1.0)
                        else:
                            if RSI(self.algo,'AAPL',10) < 24:
                                AH(self.algo,'TECL',84,1.0)
                            else:
                                AH(self.algo,'SHV',84,1.0)
                    else:
                        if RSI(self.algo,'AAPL',10) < 24:
                            AH(self.algo,'AAPB',84,1.0)
                        else:
                            AH(self.algo,'SHV',84,1.0)


#https://app.composer.trade/symphony/lRTiChQ27FIDxdOPuExA/details

class ATMBPEspicyeditionStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'TQQQ',10) > 79:
            AH(self.algo,'UVXY',85,1)
        else:
            if RSI(self.algo,'UPRO',10) > 80:
                AH(self.algo,'UVXY',85,1)
            else:
                if RSI(self.algo,'QQQ',7) <= 18:
                    AH(self.algo,'TECL',85,1)
                else:
                    if RSI(self.algo,'SPY',10) < 69:
                        if RSI(self.algo,'SPY',10) > 51:
                            AHIV(self.algo,('VOO','TQQQ','TSLA','UPRO','TNA','IWB','QQQ'),10,85,1)
                        else:
                            AHIV(self.algo,('UUP'),60,85,1)
                    else:
                        AH(self.algo,'UUP',85,1)
        
#https://app.composer.trade/symphony/WKTJk4T7hdsgCzbtEVCK/details

class ATMHewStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.tmhew()
    
    def rotator(self):
        Sort(self.algo,'STD',('TMV','TMF','SVXY','VIXM'),5,False,1,86,0.25)
        AH(self.algo,'DIVO',86,0.25)
    
    def long_high_beta(self):
        Sort(self.algo,'STD',('TECL','TQQQ','FNGU','SOXL','SVXY'),10,False,1,86,0.5)
    
    def long_group_svxy(self):
        self.long_high_beta()
        self.rotator()
    
    def short_negative_beta_1_to_3(self):
        Sort(self.algo,'STD',('TECS','SQQQ','SOXS','UVXY'),10,True,1,86,0.5)
    
    def short_group_divo(self):
        self.short_negative_beta_1_to_3()
        self.rotator()

    def tmhew(self):
        if RSI(self.algo,'SPY',10) > 79:
            self.short_group_divo()
        else:
            if RSI(self.algo,'QQQ',10) > 79:
                self.short_group_divo()
            else:
                if RSI(self.algo,'QQQ',10) < 31:
                    self.long_group_svxy()
                else:
                    if RSI(self.algo,'SPY',10) < 31:
                        self.long_group_svxy()
                    else:
                        if MaxDD(self.algo, 'SPY', 10) > 0.06:
                            self.short_group_divo()
                        else:
                            self.long_group_svxy()
#https://app.composer.trade/symphony/sfMBos3VNEbmoAFHDLH2/details

class ATotalBitcoinStrategyIRAStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.total_bitcoin_strategy_ira()
    
    def _bitcoin_signal_rsi_check_ira(self):
        if CumReturn(self.algo, 'GBTC', 5) > 0.0:
            if RSI(self.algo,'SPY',21) < RSI(self.algo,'SHY',21):
                AH(self.algo,'USFR',87,0.125)
            else:
                AH(self.algo,'SPXU',87,0.125)
        else:
            if CumReturn(self.algo, 'GBTC', 21) > 0.0:
                AH(self.algo,'UPRO',87,0.125)
            else:
                AH(self.algo,'USFR',87,0.125)
    
    def bitcoin_signal(self):
        self._bitcoin_signal_rsi_check_ira()
        self._bitcoin_signal_rsi_check_ira()
    
    def gbtc_bito_correlation(self):
        if EMA(self.algo,'GBTC',100) > SMA(self.algo,'GBTC',300):
            if SMADayRet(self.algo,'GBTC',50) > 0:
                if GetCurrentPrice(self.algo,'GBTC') > SMA(self.algo,'GBTC',20):
                    if EMA(self.algo,'GBTC',10) > SMA(self.algo,'GBTC',20):
                        if RSI(self.algo,'GBTC',10) < 75:
                            AH(self.algo,'UPRO',87,0.25)
                        else:
                            AH(self.algo,'USFR',87,0.25)
                    else:
                        AH(self.algo,'USFR',87,0.25)
                else:
                    AH(self.algo,'USFR',87,0.25)
            else:
                AH(self.algo,'USFR',87,0.25)
        else:
            AH(self.algo,'USFR',87,0.25)
        if EMA(self.algo,'BITO',100) > SMA(self.algo,'BITO',300):
            if SMADayRet(self.algo,'BITO',50) > 0:
                if GetCurrentPrice(self.algo,'BITO') > SMA(self.algo,'BITO',20):
                    if EMA(self.algo,'BITO',10) > SMA(self.algo,'BITO',20):
                        if RSI(self.algo,'BITO',10) < 75:
                            AH(self.algo,'TQQQ',87,0.25)
                        else:
                            AH(self.algo,'USFR',87,0.25)
                    else:
                        AH(self.algo,'USFR',87,0.25)
                else:
                    AH(self.algo,'USFR',87,0.25)
            else:
                AH(self.algo,'USFR',87,0.25)
        else:
            AH(self.algo,'USFR',87,0.25)
    
    def bitcoin_strategies_ira(self):
           self.gbtc_bito_correlation()
           self.bitcoin_signal()
    
    def total_bitcoin_strategy_ira(self):
           AHIV(self.algo,('GBTC','BITX'),21,87,0.25)
           self.bitcoin_strategies_ira()
#https://app.composer.trade/symphony/QQLtb2t9XmjCt3gLQ0vj/details

class ATRACKv11TQQQorSafetyTownAllSharedVersionsBlackSwanMeanRevBondSignalStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        Sort(self.algo,'CumReturn',('TSLY','CONY','NVDY','AMDY','APLY','AMZY','OARK','DISO','GOOY','PYPY','MSFO','JPMO','XOMO','NFLY','FBY','SQY','MRNY','FEPI'),25,True,2,88,1)
    
#https://app.composer.trade/symphony/uUlerOq4FEtjgAne97Sx/details

class AUSECopyofTQQQFTLTOVERFITschd1116RR254MaxDDsince111311Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if RSI(self.algo,'TQQQ',10) > 79:
                AH(self.algo,'UVXY',89,1)
            else:
                if RSI(self.algo,'SPY',10) > 80:
                    AH(self.algo,'UVXY',89,1)
                else:
                    AH(self.algo,'TQQQ',89,0.9)
                    AH(self.algo,'SOXL',89,0.1)
        else:
            if RSI(self.algo,'TQQQ',10) < 31:
                AH(self.algo,'TECL',89,1)
            else:
                if RSI(self.algo,'SPY',10) < 30:
                    AH(self.algo,'UPRO',89,1)
                else:
                    if RSI(self.algo,'UVXY',10) > 74:
                        if RSI(self.algo,'UVXY',10) > 84:
                            if GetCurrentPrice(self.algo,'TQQQ') > SMA(self.algo,'TQQQ',20):
                                AH(self.algo,'BSV',89,1)
                            else:
                                Sort(self.algo,'RSI',('TMF','SCHD'),10,True,1,89,1)
                        else:
                            AH(self.algo,'UVXY',89,1)
                    else:
                        if GetCurrentPrice(self.algo,'TQQQ') > SMA(self.algo,'TQQQ',20):
                            if RSI(self.algo,'SQQQ',10) < 32:
                                AH(self.algo,'SQQQ',89,1)
                            else:
                                AH(self.algo,'TQQQ',89,1)
                        else:
                            if RSI(self.algo,'SQQQ',10) > 65:
                                Sort(self.algo,'RSI',('TQQQ','TMF'),10,True,1,89,1)
                            else:
                                Sort(self.algo,'RSI',('SQQQ','BSV'),10,True,1,89,0.33)
                                AH(self.algo,'SCHD',89,0.33) 
                                AH(self.algo,'XLP',89,0.33)

#https://app.composer.trade/symphony/Pdf60LIRrhNo80XXspT4/details


#https://app.composer.trade/symphony/dV6yz7i5iqb2O5yka1Pi/details

class ATinFoilSlippers17CMPK1FreeStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo
    def Execute(self):
        if CumReturn(self.algo,'AGG',60) > CumReturn(self.algo,'BIL',60):
            self.group_interest_rates_down()
        else:
            self.group_tmf_tmv_usdu_selector_cmp()
            self.group_i_dont_even_know_man_4_cmp()

    def group_interest_rates_down(self):
        if MaxDD(self.algo, 'SPY', 10) > 0.04:
            self.group_spy_down()
        else:
            self.group_risk_on_core_risk_parity()

    def group_spy_down(self):
        if RSI(self.algo,'VIXM',10) > RSI(self.algo,'VIXM',14):
            self.group_vol_up()
        else:
            self.group_vol_down()

    def group_vol_up(self):
        AH(self.algo,'BIL',91,1)

    def group_vol_down(self):
        self.group_risk_on_core_risk_parity()

    def group_risk_on_core_risk_parity(self):
        AHIV(self.algo,('TMF','FAS','TQQQ','UPRO'),45,91,1)

    def group_tmf_tmv_usdu_selector_cmp(self):
        if CumReturn(self.algo,'VGLT',21) < CumReturn(self.algo,'BIL',21):
            self.group_rising_rates_usd_tmv_surf()
        else:
            self.group_falling_rates_usd_tmf_surf()

    def group_rising_rates_usd_tmv_surf(self):
        Sort(self.algo,'RSI',('TMV','USDU'),20,False,1,91,0.25)
        Sort(self.algo,'MaxDD',('USDU','GLD','BTAL'),20,False,1,91,0.25)

    def group_falling_rates_usd_tmf_surf(self):
        Sort(self.algo,'RSI',('TMF','USDU'),20,False,1,91,0.25)
        Sort(self.algo,'MaxDD',('USDU','GLD','BTAL'),20,False,1,91,0.25)

    def group_i_dont_even_know_man_4_cmp(self):
        if RSI(self.algo,'TMV',12) > RSI(self.algo,'TQQQ',12):
            self.group_tmv_to_the_btal_cmp()
        else:
            Sort(self.algo,'SMADayRet',('TQQQ','TMV'),10,True,1,91,0.125)
            Sort(self.algo,'RSI',('TQQQ','BTAL'),14,False,1,91,0.125)
            Sort(self.algo,'MaxDD',('TQQQ','TMV'),14,False,1,91,0.125) 
            Sort(self.algo,'RSI',('SQQQ','BIL'),14,True,1,91,0.125)

    def group_tmv_to_the_btal_cmp(self):
        self.group_cum_return()
        self.group_max_dd()  
        self.group_rsi()
        AH(self.algo,'TMV',91,0.125)

    def group_cum_return(self):
        Sort(self.algo,'CumRet',('BTAL','TMV'),30,True,1,91,0.125)

    def group_max_dd(self):  
        Sort(self.algo,'MaxDD',('BTAL','TMV'),90,False,1,91,0.125)

    def group_rsi(self):
        Sort(self.algo,'RSI',('BTAL','TMV'),90,False,1,91,0.125)

    
#https://app.composer.trade/symphony/jNgZOo7FbniGn5ZOOnfT/details

class AV001ManagedMadnessStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v2b_bitcoin_strategy_dereckn()
    
    def v2b_bitcoin_strategy_dereckn(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if GetCurrentPrice(self.algo,'BITO') > SMA(self.algo,'BITO',15):
                AH(self.algo,'BITO',92,1.0)
            else:
                AH(self.algo,'SHY',92,1.0)
        else:
            if GetCurrentPrice(self.algo,'BITO') > SMA(self.algo,'BITO',200):
                AH(self.algo,'BITO',92,1.0)
            else:
                if RSI(self.algo,'BITO',10) < 30:
                    AH(self.algo,'BITO',92,1.0)
                else:
                    if GetCurrentPrice(self.algo,'BITO') < SMA(self.algo,'BITO',15):
                        Sort(self.algo,'RSI',('BITI','TMV'),10,True,1,92,1.0)
                    else:
                        if RSI(self.algo,'BITO',10) > 59:
                            AH(self.algo,'BITI',92,1.0)
                        else:
                            AH(self.algo,'BITO',92,1.0)
#https://app.composer.trade/symphony/OshbKgPjjRAcyVJKHDO1/details

class AV1aAmoebalDNsCOWCOiNSStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.simplified_base_2_msfu()
    
    def simplified_base_2_msfu(self):
        if RSI(self.algo,'QQQE',10) > 79:
            AH(self.algo,'BIL',93,1.0)
        else:
            if RSI(self.algo,'VTV',10) > 79:
                AH(self.algo,'BTAL',93,1.0)
            else:
                if RSI(self.algo,'VOX',10) > 79:
                    AH(self.algo,'BTAL',93,1.0)
                else:
                    if RSI(self.algo,'TECL',10) > 79:
                        AH(self.algo,'BTAL',93,1.0)
                    else:
                        if RSI(self.algo,'VOOG',10) > 79:
                            AH(self.algo,'BIL',93,1.0)
                        else:
                            if RSI(self.algo,'VOOV',10) > 79:
                                AH(self.algo,'BIL',93,1.0)
                            else:
                                if RSI(self.algo,'XLP',10) > 75:
                                    AH(self.algo,'BTAL',93,1.0)
                                else:
                                    if RSI(self.algo,'TQQQ',10) > 79:
                                        AH(self.algo,'BTAL',93,1.0)
                                    else:
                                        if RSI(self.algo,'XLY',10) > 80:
                                            AH(self.algo,'BTAL',93,1.0)
                                        else:
                                            if RSI(self.algo,'FAS',10) > 80:
                                                AH(self.algo,'BTAL',93,1.0)
                                            else:
                                                if RSI(self.algo,'SPY',10) > 80:
                                                    AH(self.algo,'BTAL',93,1.0)
                                                else:
                                                    if CumReturn(self.algo, 'TQQQ', 6) < -0.12:
                                                        if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                                                            AH(self.algo,'BTAL',93,1.0)
                                                        else:
                                                            AH(self.algo,'MSFU',93,1.0)
                                                    else:
                                                        AH(self.algo,'MSFU',93,1.0)
#https://app.composer.trade/symphony/QGJXyGajnNFr2nUzBtFx/details

class AV1aBentoManhattanBBHGTQStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if RSI(self.algo,'QQQ',10) > 79:
                AH(self.algo,'VIXY',94,1)
            else:
                if RSI(self.algo,'SPY',10) > 80:
                    AH(self.algo,'VIXY',94,1)
                else:
                    AH(self.algo,'QQQ',94,1)
        else:
            if RSI(self.algo,'QQQ',10) < 31:
                AH(self.algo,'QQQ',94,1)
            else:
                if RSI(self.algo,'SPY',10) < 30:
                    AH(self.algo,'SPY',94,1)
                else:
                    if RSI(self.algo,'VIXY',10) > 74:
                        if RSI(self.algo,'VIXY',10) > 84:
                            if GetCurrentPrice(self.algo,'QQQ') > SMA(self.algo,'QQQ',20):
                                if RSI(self.algo,'SH',10) < 31:
                                    AH(self.algo,'TLT',94,1)
                                else:
                                    AH(self.algo,'QQQ',94,1)
                            else:
                                Sort(self.algo,'RSI',('SH','BSV'),10,True,1,94,1)
                        else:
                            AH(self.algo,'VIXY',94,1)
                    else:
                        if GetCurrentPrice(self.algo,'QQQ') > SMA(self.algo,'QQQ',20):
                            if RSI(self.algo,'SH',10) < 31:
                                AH(self.algo,'SH',94,1)
                            else:
                                AH(self.algo,'QQQ',94,1)
                        else:
                            Sort(self.algo,'RSI',('SH','TLT'),10,True,1,94,1)
    
#https://app.composer.trade/symphony/prpB0SEY7pLh0jTYG3FA/details

class AV1aSimpleSortwLeverageStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1a_simple_sort_w_leverage()
    
    def simple_sort_w_leverage(self):
        Sort(self.algo,'RSI',('AAPU','MSFU','NFLX','NVDA','XOM'),14,True,2,95,1.0)
    
    def v1a_simple_sort_w_leverage(self):
        if RSI(self.algo,'VIXM',40) > 69:
            AH(self.algo,'SPXU',95,1.0)
        else:
            self.simple_sort_w_leverage()
#https://app.composer.trade/symphony/aF0ak6oEhY51tu5cM8FZ/details

class AV1aZeroBetaSackofYOLOStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v3_beat_the_market()
    
    def v3_beat_the_market(self):
        if SMA(self.algo,'SPY',21) > SMA(self.algo,'SPY',210):
            Sort(self.algo,'SMADayRet',('SOXX','QQQ','XLK','FNGS'),4,False,1,96,1.0)
        else:
            if RSI(self.algo,'QQQ',10) < 30:
                Sort(self.algo,'SMADayRet',('SOXL','HIBL','FNGU','TARK','GUSH','DRN'),4,False,1,96,1.0)
            else:
                if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',31):
                    Sort(self.algo,'SMADayRet',('SOXX','QQQ','IEF'),4,False,1,96,1.0)
                else:
                    Sort(self.algo,'SMADayRet',('TBF','TBX','USDU'),4,False,1,96,1.0)
#https://app.composer.trade/symphony/hKarRS5XXSPTS0oj97Pu/details

class AV1bABetterBuytheDipsNasdaqbyGarenPhillipswDividendsStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1b_a_better_()
    
    def v1b_a_better_(self):
        if CumReturn(self.algo, 'QQQ', 5) < -0.06:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.05:
                AH(self.algo,'SQQQ',97,1.0)
            else:
                if RSI(self.algo,'TQQQ',10) > 31:
                    AH(self.algo,'SQQQ',97,1.0)
                else:
                    AH(self.algo,'TQQQ',97,1.0)
        else:
            if RSI(self.algo,'QQQ',10) > 80:
                AH(self.algo,'SQQQ',97,1.0)
            else:
                if RSI(self.algo,'QQQ',10) < 31:
                    AH(self.algo,'TQQQ',97,1.0)
                else:
                    if RSI(self.algo,'VIXM',40) > 69:
                        AH(self.algo,'SPXU',97,1.0)
                    else:
                        Sort(self.algo,'RSI',('APLY','MSFO','NVDY','TSLY','XOMO'),40,True,1,97,1.0)

#https://app.composer.trade/symphony/Q7hAQDhQVOicfnjHYvrj/details

  
#https://app.composer.trade/symphony/cOt90IJOan2jhkBOBCYI/details

class AV1bMagicInternetMoneyGoldenBallerStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1b_magic_internet_money_golden_baller()
    
    def golden_bear(self):
        AH(self.algo,'UGL',98,0.33)
        AH(self.algo,'PSQ',98,0.33)
        AH(self.algo,'SH',98,0.33)
    
    def extremely_oversold_sp_low_rsi_double_check_with_bond_mkt_before_going_long(self):
        if RSI(self.algo,'SHY',10) < RSI(self.algo,'VTI',10):
            AH(self.algo,'SOXS',98,1.0)
        else:
            AH(self.algo,'SOXL',98,1.0)
    
    def semis(self):
        Sort(self.algo,'MaxDD',('SOXL','SMH'),6,True,1,98,1.0)
    
    def golden_baller(self):
        if RSI(self.algo,'BIL',10) < RSI(self.algo,'IEF',10):
            if RSI(self.algo,'SPY',7) > 76:
                AH(self.algo,'UGL',98,1.0)
            else:
                self.semis()
        else:
            if RSI(self.algo,'SPY',7) < 27:
                self.extremely_oversold_sp_low_rsi_double_check_with_bond_mkt_before_going_long()
            else:
                self.golden_bear()
    
    def biti_bot(self):
        if RSI(self.algo,'BITO',14) > 60:
            AH(self.algo,'BITI',98,1.0)
        else:
            if CumReturn(self.algo, 'BITI', 1) <= -0.01:
                AH(self.algo,'MSTR',98,1.0)
            else:
                if CumReturn(self.algo,'BITO',5) >= STD(self.algo,'BITO',10):
                    AH(self.algo,'BITI',98,1.0)
                else:
                    if CumReturn(self.algo,'BITO',2) >= STD(self.algo,'BITO',5):
                        if CumReturn(self.algo,'BITO',1) > CumReturn(self.algo,'BITI',3):
                            AH(self.algo,'MSTR',98,1.0)
                        else:
                            self.golden_baller()
                    else:
                        self.golden_baller()
    
    def v1b_magic_internet_money_golden_baller(self):
        if GetCurrentPrice(self.algo,'BITO') <= SMA(self.algo,'BITO',62):
            self.biti_bot()
        else:
            self.golden_baller()
 
#region imports
from AlgorithmImports import *
#endregion


# Your New Python File
from AlgorithmImports import *
from indicators import *
from main import YellowCatStrat

#https://app.composer.trade/symphony/sABrZAnOdWij5JbmlRAy/details

class AV1bMECHACHEETAHCONSR3RRStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1c_weekly_simplified_holiday_competition()
    
    def v1c_weekly_simplified_holiday_competition(self):
        if SMADayRet(self.algo,'QQQ',20) > SMADayRet(self.algo,'QQQE',20):
            Sort(self.algo,'RSI',('AAPL','NVDA','NFLX'),40,True,1,99,1.0)
        else:
            Sort(self.algo,'STD',('LLY','MRNA'),10,False,1,99,1.0)

#https://app.composer.trade/symphony/QAnDnJEORlTbwVgXFcNq/details

    
#https://app.composer.trade/symphony/hfdlHwJQe63LhAP1aRI3/details

class AV1BWCSplitPersonalityStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if MaxDD(self.algo, 'SPY', 10) < 0.05:
            self.risk_on()
        else:
            self.risk_off()
    
    def risk_off(self):
        AH(self.algo,'IEI',100,0.25)
        AH(self.algo,'GLD',100,0.25) 
        AH(self.algo,'TIP',100,0.25) 
        AH(self.algo,'BSV',100,0.25)
    
    def risk_on(self):
        Sort(self.algo,'SMADayRet',('CCJ','DNN','NLR','SMR','URA','URNM','NLR','UEC','URNJ','UROY','UUUU','LEU'),10,True,2,100,0.2)
        Sort(self.algo,'SMADayRet',('CCJ','DNN','NLR','SMR','URA','URNM','NLR','UEC','URNJ','UROY','UUUU','LEU'),20,True,2,100,0.2)
        Sort(self.algo,'SMADayRet',('CCJ','DNN','NLR','SMR','URA','URNM','NLR','UEC','URNJ','UROY','UUUU','LEU'),50,True,2,100,0.2)
        Sort(self.algo,'SMADayRet',('CCJ','DNN','NLR','SMR','URA','URNM','NLR','UEC','URNJ','UROY','UUUU','LEU'),100,True,2,100,0.2)
        Sort(self.algo,'SMADayRet',('CCJ','DNN','NLR','URA','URNM','NLR','UEC','UROY','UUUU','LEU','SMR'),200,True,2,100,0.2)
    
 #https://app.composer.trade/symphony/vDMviB9fXFH8tb1mCfAU/details

class AV1BOTZbotQLDAIFTLTPureBSCatcherGarenPhillipsStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1_botz_bot_botz_bot_qld_ai_ftlt_()
        self.pure_bs_catcher()
    
    def pure_bs_catcher(self):
        if SMA(self.algo,'SPY',200) < GetCurrentPrice(self.algo,'SPY'):
            if RSI(self.algo,'TQQQ',14) > 75:
                AH(self.algo,'UVXY',101,0.5)
            else:
                if RSI(self.algo,'SPXL',10) > 80:
                    AH(self.algo,'UVXY',101,0.5)
                else:
                    AH(self.algo,'BSV',101,0.5)
        else:
            if RSI(self.algo,'SPY',10) < 30:
                AH(self.algo,'BSV',101,0.5)
            else:
                if RSI(self.algo,'UVXY',10) > 74:
                    if RSI(self.algo,'UVXY',10) < 84:
                        AH(self.algo,'UVXY',101,0.5)
                    else:
                        AH(self.algo,'BSV',101,0.5) 
                else:
                    AH(self.algo,'BSV',101,0.5)
    
    def v1_botz_bot_botz_bot_qld_ai_ftlt_(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if RSI(self.algo,'QQQ',10) > 81:
                AH(self.algo,'PSQ',101,0.5)
            else:
                Sort(self.algo,'CumReturn',('QQQ','BOTZ'),5,True,1,101,0.5)
        else:
            if RSI(self.algo,'QQQ',10) < 30:
                AH(self.algo,'QLD',101,0.5)
            else:
                if RSI(self.algo,'SPY',10) < 30:
                    AH(self.algo,'SPY',101,0.5)
                else:
                    if GetCurrentPrice(self.algo,'QQQ') < SMA(self.algo,'QQQ',20):
                        Sort(self.algo,'RSI',('PSQ','SHY'),10,True,1,101,0.25)
                        Sort(self.algo,'CumReturn',('SH','BOTZ'),5,True,1,101,0.25)
                    else:
                        AH(self.algo,'QQQ',101,0.5)
        
 #https://app.composer.trade/symphony/yJw5iixqyLyzQ4LOkFkW/details


#https://app.composer.trade/symphony/nX9tHUhASw5dJqRw1yDU/details

class AV2aBitcoinStrategyDereckNStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v2a_bitcoin_strategy_dereckn()
    
    def v2a_bitcoin_strategy_dereckn(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if GetCurrentPrice(self.algo,'BITO') > SMA(self.algo,'BITO',15):
                AH(self.algo,'BITO',102,1.0)
            else:
                AH(self.algo,'SHY',102,1.0)
        else:
            if GetCurrentPrice(self.algo,'BITO') > SMA(self.algo,'BITO',200):
                AH(self.algo,'BITO',102,1.0)
            else:
                if RSI(self.algo,'BITO',10) < 30:
                    AH(self.algo,'BITO',102,1.0)
                else:
                    if GetCurrentPrice(self.algo,'BITO') < SMA(self.algo,'BITO',15):
                        Sort(self.algo,'RSI',('BITI','TMV'),10,True,1,102,1.0)
                    else:
                        if RSI(self.algo,'BITO',10) > 59:
                            AH(self.algo,'SHY',102,1.0)
                        else:
                            AH(self.algo,'BITO',102,1.0)
#https://app.composer.trade/symphony/SB7HXakSSJ2MHHJr4NC4/details

class AV2BWCMinVolatilityFund1MedTermSwitching2024EditionStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.yieldmax_monthly_mar_ss()
    
    def yieldmax_monthly_mar_ss(self):
        Sort(self.algo,'SMADayRet',('APLY','MSFO','NVDY','TSLY'),10,True,1,103,1.0)

#https://app.composer.trade/symphony/Peae9H3Vh436Nr8lAsFA/details

#https://app.composer.trade/symphony/W57VLRspcOKYbSpz671H/details

class AV2GainTrainDGAFDeezA030B001R20R002BT1JAN2015Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_v2_gain_train_dgaf_deez_a030_b001_r20_r002_bt_1jan2015()

    def group_v2_gain_train_dgaf_deez_a030_b001_r20_r002_bt_1jan2015(self):
        if EMA(self.algo,'UUP',42) > EMA(self.algo,'UUP',100):
            Sort(self.algo,'RSI',('UUP','USDU'),14,False,1,104,0.45)
        else:
            Sort(self.algo,'STD',('BIL','SOXL','DBC'),14,True,2,104,0.45)
        
        if RSI(self.algo,'BIL',10) < RSI(self.algo,'IEF',10):
            if RSI(self.algo,'SPY',7) > 76:
                self.group_overbought_sp_sell_the_rip_buy_volatility()
            else:
                Sort(self.algo,'MaxDD',('SOXL','SMH'),6,True,1,104,0.45)
        else:
            if RSI(self.algo,'SPY',7) < 27:
                self.group_extremely_oversold_sp_low_rsi_double_check_with_bond_mkt_before_going_long()
            else:
                AH(self.algo,'UGL',104,0.15)
                AH(self.algo,'SH',104,0.15) 
                AH(self.algo,'PSQ',104,0.15)
        
        self.group_hotdogs_n_healthcare_low_touch_4_logic_gates_3y_bt_ar_309_dd_217()

    def group_overbought_sp_sell_the_rip_buy_volatility(self):
        AH(self.algo,'UGL',104,0.45)

    def group_extremely_oversold_sp_low_rsi_double_check_with_bond_mkt_before_going_long(self):
        if RSI(self.algo,'SHY',10) < RSI(self.algo,'VTI',10):
            AH(self.algo,'SOXS',104,0.45)
        else:
            AH(self.algo,'SOXL',104,0.45)

    def group_hotdogs_n_healthcare_low_touch_4_logic_gates_3y_bt_ar_309_dd_217(self):
        if RSI(self.algo,'COST',14) < 69:
            if MaxDD(self.algo, 'SPY', 5) > 0.12:
                AH(self.algo,'BIL',104,0.05)
            else:
                AH(self.algo,'COST',104,0.05)
        else:
            AH(self.algo,'BIL',104,0.05)

        if RSI(self.algo,'UNH',14) < 79:
            if MaxDD(self.algo, 'SPY', 5) > 0.12:
                AH(self.algo,'BIL',104,0.05)
            else:
                AH(self.algo,'UNH',104,0.05)
        else:
            AH(self.algo,'BIL',104,0.05)

 #https://app.composer.trade/symphony/aBtx3hFpxZT14bBKk50F/details

class AV3BeattheMarketStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v3_beat_the_market()
    
    def v3_beat_the_market(self):
        if SMA(self.algo,'SPY',21) > SMA(self.algo,'SPY',210):
            Sort(self.algo,'SMADayRet',('SOXX','QQQ','XLK','FNGS'),4,False,1,105,1.0)
        else:
            if RSI(self.algo,'QQQ',10) < 30:
                Sort(self.algo,'SMADayRet',('SOXL','HIBL','FNGU','TARK','GUSH','DRN'),4,False,1,105,1.0)
            else:
                if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',31):
                    Sort(self.algo,'SMADayRet',('SOXX','QQQ','IEF'),4,False,1,105,1.0)
                else:
                    Sort(self.algo,'SMADayRet',('TBF','TBX','USDU'),4,False,1,105,1.0)
 #https://app.composer.trade/symphony/cVVJ5JKWGGtbzH54522L/details

class AV3BWCMcBallsyBBYOLOModStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'CEW',27) > RSI(self.algo,'UUP',63):
            self.international_value_and_momentum_factors()
        else:
            if RSI(self.algo,'VOO',5) > RSI(self.algo,'VEU',14):
                Sort(self.algo,'SMADayRet',('BRK/B','QQQ','VOO','VOOG','VOOV','DIA'),5,True,1,106,1)
            else:
                if RSI(self.algo,'GLD',15) > 63:
                    AH(self.algo,'IAUM',106,1)
                else:
                    Sort(self.algo,'SMADayRet',('BIL','SHY','TLT','BNDW'),14,True,1,106,1)
    
    def international_sectors_nations(self):
        Sort(self.algo,'EMA',('INTF','IGRO','EWJV','LDEM','ESGD','ACWV','LCTD','EFAV','ESGE','EEMV','IQLT','IVLU','IMTM','ERET','EFV','EFG','PICK','RING','SLVP','FILL','VEGI','ICLN','IXN','IOO','IGF','MXI','KXI','RXI','IXJ','IXG','EXI','IXP','WOOD','JXI','IXC','XT','IVEG','EPP','ILF','JPXN','DVYE','SDG','DVYA','EWJ','EWC','EWU','EWG','AIA','EWL','EWA','EWH','EWW','EWQ','EWI','EWS','EWN','EWM','ENZL','EWO','EIRL','EWK','EZU','IDV','EUFN','EDEN','ENOR','EWD','EFNL','THD','EWT','EWY','EWZ','ECH','EIDO','EZA','EPOL','TUR','EIS','EPHE','EWUS','EPU','EWZS','QAT','ECNS','UAE','TCHI','EMIF','INDA','IEV','HEEM','FXI','KSA','KWT','FM','SMIN','INDY','EEM','EEMA','EEMS','FRDM','CQQQ'),5,True,3,106,0.33)
    
    def leverage(self):
        Sort(self.algo,'EMA',('EURL','EDC','MEXX','KORU','YINN'),4,True,1,106,0.33)
    
    def developed_and_emerging_markets(self):
        if RSI(self.algo,'VEU',7) > RSI(self.algo,'VOO',7):
            if MaxDD(self.algo,'VEU',5) < MaxDD(self.algo,'VOO',5):
                self.leverage()
            else:
                self.international_sectors_nations()
        else:
            Sort(self.algo,'RSI',('BWX','HYEM','ICSH'),5,True,1,106,0.33)
    def international_value_and_momentum_factors(self):
        AHIV(self.algo,('IVAL','IAUM'),7,106,0.33)
        if RSI(self.algo,'IMOM',3) > RSI(self.algo,'VEU',3):
            AH(self.algo,'IMOM',106,0.33)
        else:
            if RSI(self.algo,'GLD',21) > RSI(self.algo,'ICSH',21):
                AH(self.algo,'IAUM',106,0.33)
            else:
                Sort(self.algo,'RSI',('BWX','HYEM','ICSH'),5,True,1,106,0.33)
        self.developed_and_emerging_markets()

#https://app.composer.trade/symphony/cZ3yeg2l4AopolFtVYU6/details

class AWAMmerTimeStrychnineStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.wammer_time_strychnine()
    
    def wam_ftlt_short_backtest(self):
        if RSI(self.algo,'IEF',11) > RSI(self.algo,'IWM',16):
            Sort(self.algo,'SMADayRet',('TECL','TQQQ','DRN','HIBL','TARK','URTY','TMF','SPXL'),4,False,2,107,0.5)
        else:
            Sort(self.algo,'SMADayRet',('PSQ','TYO','HIBS','DRV','TMV','SH','SPXS'),4,False,2,107,0.5)
    
    def wam_ftlt_long_backtest(self):
        if RSI(self.algo,'IEF',11) > RSI(self.algo,'IWM',16):
            Sort(self.algo,'SMADayRet',('TECL','TQQQ','DRN','URTY','TMF','SPXL'),4,False,2,107,0.5)
        else:
            Sort(self.algo,'SMADayRet',('PSQ','TYO','DRV','TMV','SH','SPXS'),4,False,2,107,0.5)
    
    def wam_ftlt_no_tmf_check(self):
        self.wam_ftlt_long_backtest()
        self.wam_ftlt_short_backtest()
    
    def wam_ftlt_tmf_check(self):
        self.wam_ftlt_long_backtest()
        self.wam_ftlt_short_backtest()
    
    def wammer_time_strychnine(self):
        if RSI(self.algo,'SPY',10) > 71:
            self.wam_ftlt_tmf_check()
        else:
            self.wam_ftlt_no_tmf_check()
#https://app.composer.trade/symphony/gDn7W1u6a9eJcSZTy5Om/details

class AV6BWCWMDYNForTheLongTermAR6895SR591StdDev364MaxDD109BTJan102023OOSDec22023Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if CumReturn(self.algo,'BND',60) > CumReturn(self.algo,'BIL',60):
            self.main_canary_off()
        else:
            self.main_canary_on_rsi_catcher_7530()
    
    def safe_haven_momentum(self):
        Sort(self.algo,'CumReturn',('UUP','TMF','DBC','UGL','IEO','XLU','VIXM'),30,True,4,108,1.0)
    
    def main_canary_on_rsi_catcher_7530(self):
        if RSI(self.algo,'SPY',10) > 75:
            AH(self.algo,'UVXY',108,1.0)
        else:
            if RSI(self.algo,'SPY',10) < 30:
                AH(self.algo,'UPRO',108,1.0)
            else:
                self.safe_haven_momentum()
    
    def risk_off(self):
        AH(self.algo,'TMF',108,0.5)
        if RSI(self.algo,'SPY',10) > 80:
            AH(self.algo,'UVXY',108,0.5)
        else:
            AH(self.algo,'UPRO',108,0.5)
    
    def risk_off_cautious(self):
        AHIV(self.algo,('UPRO','TMF','VIXM'),45,108,1.0)
    
    def risk_on(self):
        if RSI(self.algo,'QQQ',10) > 80:
            AH(self.algo,'UVXY',108,1.0)
        else:
            AH(self.algo,'TQQQ',108,1.0)
    
    def main_canary_off(self):
        if EMA(self.algo,'VWO',365) > SMA(self.algo,'VWO',365):
            if CumReturn(self.algo,'WOOD',45) > CumReturn(self.algo,'GLD',45):
                self.risk_on()
            else:
                if RSI(self.algo,'VIXY',14) > 70:
                    self.risk_off_cautious()
                else:
                    self.risk_off()
        else:
            if RSI(self.algo,'VIXY',14) > 70:
                self.risk_off_cautious()
            else:
                self.risk_off()
#https://app.composer.trade/symphony/Xtrq4m2S2qy0UVtquF5a/details

class AV11aZeroBetaSackofYOLOStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        Sort(self.algo,'STD',('NVDY','CONY','TSLY','AMDY','MSTY','MSFO','YMAX','AIYY','ULTY','FBY','OARK','NFLY','MRNY','YMAG','AMZY','APLY','GOOY','SQY','DISO','PYPY','QDTE','XDTE','BOXX','QQQY','XOMO','JPMO'),2,False,1,109,1)
#https://app.composer.trade/symphony/KFRWdTEvVxM34UmMVCj6/details

class AV11ChadfolioV42082055DeezNarwallStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.just_run_this_ftlt_20110913()
    
    def dip_buy_highlow_beta(self):
        if RSI(self.algo,'SOXX',10) < 30:
            AH(self.algo,'SOXL',110,1.0)
        else:
            if RSI(self.algo,'QQQ',10) < 30:
                AH(self.algo,'TECL',110,1.0)
            else:
                if GetCurrentPrice(self.algo,'QQQ') > SMA(self.algo,'QQQ',30):
                    if RSI(self.algo,'PSQ',10) < 35:
                        AH(self.algo,'BTAL',110,1.0)
                    else:
                        AH(self.algo,'SPHB',110,1.0)
                else:
                    if RSI(self.algo,'PSQ',10) > 65:
                        AH(self.algo,'SPHB',110,1.0)
                    else:
                        AH(self.algo,'BTAL',110,1.0)
    
    def frontrunner_inverse_vol_blend(self):
        if RSI(self.algo,'SPY',10) > 80:
            AH(self.algo,'VIXY',110,1.0)
        else:
            if RSI(self.algo,'QQQ',10) > 79:
                AH(self.algo,'VIXY',110,1.0)
            else:
                if RSI(self.algo,'XLK',10) > 79:
                    AH(self.algo,'VIXY',110,1.0)
                else:
                    if RSI(self.algo,'IYY',10) > 79:
                        AH(self.algo,'VIXY',110,1.0)
                    else:
                        if RSI(self.algo,'VTV',10) > 79:
                            AH(self.algo,'VIXY',110,1.0)
                        else:
                            if RSI(self.algo,'XLP',10) > 75:
                                AH(self.algo,'VIXY',110,1.0)
                            else:
                                if RSI(self.algo,'XLF',10) > 80:
                                    AH(self.algo,'VIXY',110,1.0)
                                else:
                                    if RSI(self.algo,'VOX',10) > 79:
                                        AH(self.algo,'VIXY',110,1.0)
                                    else:
                                        AHIV(self.algo,('LLY','NVO','COST','GE'),20,110,1.0)
    
    def just_run_this_ftlt_20110913(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            self.frontrunner_inverse_vol_blend()
        else:
            self.dip_buy_highlow_beta()
#https://app.composer.trade/symphony/y49zofXGxDuWkDQXKDE0/details

class AV11MagicInternetMoneyV21BitcoinStrategyStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v11_magic_internet_money_v21_bitcoin_strategy()
    
    def v21_bitcoin_strategy_dereckn(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if GetCurrentPrice(self.algo,'BITO') > SMA(self.algo,'BITO',15):
                Sort(self.algo,'RSI',('BITO','TYD','TMF','BULZ','FNGU'),10,False,1,111,1.0)
            else:
                AH(self.algo,'USDU',111,1.0)
        else:
            if GetCurrentPrice(self.algo,'BITO') > SMA(self.algo,'BITO',200):
                AH(self.algo,'BULZ',111,1.0)
            else:
                if RSI(self.algo,'BITO',10) < 30:
                    AH(self.algo,'BITO',111,1.0)
                else:
                    if GetCurrentPrice(self.algo,'BITO') < SMA(self.algo,'BITO',15):
                        Sort(self.algo,'RSI',('BITI','TYO','TMV'),10,True,1,111,1.0)
                    else:
                        if RSI(self.algo,'BITO',10) > 59:
                            AH(self.algo,'BITI',111,1.0)
                        else:
                            AH(self.algo,'FNGU',111,1.0)
    
    def v11_magic_internet_money_v21_bitcoin_strategy(self):
        if GetCurrentPrice(self.algo,'BITO') <= SMA(self.algo,'BITO',62):
            if RSI(self.algo,'BITO',14) > 60:
                AH(self.algo,'BITI',111,1.0)
            else:
                if CumReturn(self.algo, 'BITI', 1) <= -0.01:
                    if CumReturn(self.algo, 'BITO', 1) <= -0.02:
                        AH(self.algo,'BTAL',111,1.0)
                    else:
                        AH(self.algo,'MSTR',111,1.0)
                else:
                    if CumReturn(self.algo,'BITO',5) >= STD(self.algo,'BITO',10):
                        AH(self.algo,'BITI',111,1.0)
                    else:
                        if CumReturn(self.algo,'BITO',2) >= STD(self.algo,'BITO',5):
                            if CumReturn(self.algo,'BITO',1) > CumReturn(self.algo,'BITI',3):
                                Sort(self.algo,'RSI',('COIN','MSTR'),10,True,1,111,1.0)
                            else:
                                self.v21_bitcoin_strategy_dereckn()
                        else:
                            self.v21_bitcoin_strategy_dereckn()
        else:
            self.v21_bitcoin_strategy_dereckn()
#https://app.composer.trade/symphony/XqrH28pIqSYWMDOkyPUg/details

class AWagsOptionsSDReturnoftheOptionsDogswBOXXfloorv230403Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        Sort(self.algo,'STD',('NVDY','CONY','TSLY','AMDY','MSTY','MSFO','YMAX','AIYY','ULTY','FBY','OARK','NFLY','MRNY','YMAG','AMZY','APLY','GOOY','SQY','DISO','PYPY','QDTE','XDTE','BOXX','QQQY','XOMO','JPMO'),2,False,1,112,1)
    
#https://app.composer.trade/symphony/cYfOT0QRiDcseduq8kP2/details

#https://app.composer.trade/symphony/nkcmS1MPaZK6XXS5S4Tf/details

#https://app.composer.trade/symphony/ef6fNMJPErO0AJCJo6b4/details 

#https://app.composer.trade/symphony/n7TjESzWLfuwa5i5BrQV/details

class ASPYULStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.SPYUl()
    
    def bond_midterm_longterm(self):
        if RSI(self.algo,'IEF',200) < RSI(self.algo,'TLT',200):
            if RSI(self.algo,'BND',45) > RSI(self.algo,'SPY',45):
                AH(self.algo,'SPYU',115,1.0)
            else:
                AH(self.algo,'BIL',115,1.0)
        else:
            AH(self.algo,'BIL',115,1.0)
    
    def bond_stock(self):
        if RSI(self.algo,'BND',45) > RSI(self.algo,'SPY',45):
            AH(self.algo,'SPYU',115,1.0)
        else:
            AH(self.algo,'BIL',115,1.0)
    
    def normal_market(self):
        if MaxDD(self.algo, 'QQQ', 10) > 0.06:
            AH(self.algo,'BIL',115,1.0)
        else:
            if MaxDD(self.algo, 'TMF', 10) > 0.07:
                AH(self.algo,'BIL',115,1.0)
            else:
                if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',25):
                    AH(self.algo,'SPYU',115,1.0)
                else:
                    if RSI(self.algo,'SPY',60) > 50:
                        self.bond_stock()
                    else:
                        self.bond_midterm_longterm()
    
    def mean_rev(self):
        if RSI(self.algo,'SPY',10) < 30:
            AH(self.algo,'SPYU',115,1.0)
        else:
            if MaxDD(self.algo, 'TMF', 10) < 0.07:
                AH(self.algo,'SPYU',115,1.0)
            else:
                AH(self.algo,'BIL',115,1.0)
    
    def huge_volatility(self):
        if CumReturn(self.algo, 'SPYU', 6) < -0.13:
            if CumReturn(self.algo, 'SPYU', 1) > 0.06:
                AH(self.algo,'UVXY',115,1.0)
            else:
                self.mean_rev()
        else:
            self.normal_market()
    
    def SPYUl(self):
        if RSI(self.algo,'SPY',10) > 80:
            AH(self.algo,'UVXY',115,1.0)
        else:
            self.huge_volatility()
#https://app.composer.trade/symphony/QMk6DqM7klooDv4mqksW/details

class AYieldMax25dCRTop2wFEPIPWNStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
      Sort(self.algo,'CumReturn',('TSLY','CONY','NVDY','AMDY','APLY','AMZY','OARK','DISO','GOOY','PYPY','MSFO','JPMO','XOMO','NFLY','FBY','SQY','MRNY','FEPI'),25,True,2,116,1)
    


#https://app.composer.trade/symphony/S7sHo0RRUGToFio0MCqI/details

class AYieldmaxMonthlyMARSSStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.yieldmax_monthly_mar_ss()
    
    def yieldmax_monthly_mar_ss(self):
        Sort(self.algo,'SMADayRet',('APLY','MSFO','NVDY','TSLY'),10,True,1,118,1.0)
    
#https://app.composer.trade/symphony/id1SgOVUtgJPkP3lw1tQ/details

class AYieldMaxSS40dRSIStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.yieldmax_ss_40d_rsi()
    
    def yieldmax_ss_40d_rsi(self):
        if RSI(self.algo,'VIXM',40) > 69:
            AH(self.algo,'SPXU',119,1.0)
        else:
            Sort(self.algo,'RSI',('MSFO','NVDY','XOMO'),40,True,1,119,1.0)
    
#https://app.composer.trade/symphony/Szxg7zTuUsdde221TVHU/details

class AYieldmaxSSSDMACRRSIStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.yieldmax_ss_sdmacrrsi()
    
    def rsi(self):
        Sort(self.algo,'RSI',('APLY','FBY','MSFO','NFLY','CONY'),10,True,1,120,0.25)
    
    def cr(self):
        Sort(self.algo,'CumReturn',('APLY','FBY','MSFO','NFLY','CONY'),10,True,1,120,0.25)
    
    def ma(self):
        Sort(self.algo,'SMADayRet',('APLY','FBY','MSFO','NFLY','CONY'),10,True,1,120,0.25)
    
    def sd(self):
        Sort(self.algo,'STD',('APLY','FBY','MSFO','NFLY','CONY'),10,True,1,120,0.25)
    
    def yieldmax_ss_sdmacrrsi(self):
        GroupSort(self.algo,'MaxDD',(self.sd(),self.ma(),self.cr(),self.rsi()),10,False,3,120,0.25)

#https://app.composer.trade/symphony/IGit8jxO2D1V8oyNT3XQ/details

class BDirexionSSSDStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.direxion_ss_sd()
    
    def direxion_ss_sd(self):
        if RSI(self.algo,'VIXM',40) > 69:
            AH(self.algo,'SPXU',121,1.0)
        else:
            Sort(self.algo,'STD',('AAPU','MSFU','NVDA','AMD'),10,False,2,121,1.0)
    
#https://app.composer.trade/symphony/1yw8pT5c7IccxdQ25tCj/details

class BeefyTQQQFTLTV425aSidewaysMarketDeleverageNoK1editcopyStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.stock_surfing_w_leverage()
    
    def stock_surfing_w_leverage(self):
        if STD(self.algo,'SPY',21) < 1:
            Sort(self.algo,'RSI',('MSFU','AAPU'),21,False,1,122,0.5)
        else:
            AH(self.algo,'SHY',122,0.5)
        if STD(self.algo,'SPY',21) < 2:
            Sort(self.algo,'RSI',('MSFU','SHY'),21,False,1,122,0.5)
        else:
            AH(self.algo,'SHY',122,0.5)
    
#https://app.composer.trade/symphony/3hS6igrUOtdUwbg8fgpJ/details

class BigDumbSortV2Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.big_dumb_sort_v2()
    
    def big_dumb_sort_v2(self):
        if RSI(self.algo,'QQQ',10) > 40:
            if RSI(self.algo,'QQQ',10) < 77:
                Sort(self.algo,'SMADayRet',('ERX','RETL','DRN','FAZ','TMV','GUSH','TQQQ','SPXL','UDOW','NAIL','WANT','DPST','WEBL','TECL','TNA','FNGU','LLY','NVDA'),10,True,4,123,0.33)
                Sort(self.algo,'STD',('ERX','RETL','DRN','FAZ','TMV','GUSH','TQQQ','SPXL','UDOW','NAIL','WANT','WEBL','DPST','TECL','TNA','FNGU','LLY','NVDA'),10,False,4,123,0.33)
                Sort(self.algo,'MaxDD',('ERX','RETL','DRN','FAZ','TMV','GUSH','TQQQ','SPXL','UDOW','NAIL','WANT','WEBL','TECL','DPST','TNA','FNGU','LLY','NVDA'),10,False,4,123,0.33)
            else:
                AH(self.algo,'VIXY',123,1) 
        else:
            AH(self.algo,'BTAL',123,1.0)
    
#https://app.composer.trade/symphony/1xth4jAbQCKTgZh05qY4/details

class BitcoinArbitrageStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_bitcoin_arbitrage()

    def group_bitcoin_arbitrage(self):
        if GetCurrentPrice(self.algo,'BITO') > SMA(self.algo,'BITO',5):
            Sort(self.algo,'RSI',('BITO','BITB','IBIT','BITX'),2,False,1,124,1)
        else:
            AH(self.algo,'BIL',124,0.5)
            AH(self.algo,'BITI',124,0.5)
    
#https://app.composer.trade/symphony/HvI87SvjxFRFEzk4D8UF/details

class GV101aParetosPortfolioWeeklyEditionK1FreeStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.risk_off_volatility_spike()
    
    def bonds(self):
        Sort(self.algo,'SMADayRet',('AGG','IEF','EMB','BWX','TYD','TMF','TBT','TMV','UBT','USDU'),20,True,3,125,0.5)
    
    def commodities(self):
        Sort(self.algo,'SMADayRet',('FAAR','FTGC','PDBC','XME','USDU'),20,True,2,125,0.5)
    
    def risk_off_fed_is_cutting_rates(self):
        self.commodities()
        self.bonds()

    def dia(self):
        Sort(self.algo,'SMADayRet',('UNH','MSFT','GS','HD','MCD','JNJ','TRV','AXP','AAPL','HON','CRM','BA','AMGN','V','CAT'),20,True,3,125,0.33)
    
    def qqq(self):
        Sort(self.algo,'SMADayRet',('AMD','NFLX','CSCO','ADBE','COST','PEP','AVGO','GOOG','GOOGL','META','TSLA','AMZN','NVDA','AAPL','MSFT'),20,True,3,125,0.33)
    
    def spy(self):
        Sort(self.algo,'SMADayRet',('AAPL','MSFT','AMZN','NVDA','TSLA','GOOG','GOOGL','META','BRK/B','UNH','JNJ','JPM','XOM','V','LLY'),20,True,3,125,0.33)
    
    def riskon_stablenormal_rates(self):
        self.spy()
        self.qqq()
        self.dia()
    
    def risk_off_volatility_spike(self):
        if RSI(self.algo,'VIXY',10) > 75:
            AH(self.algo,'USDU',125,1.0)
        else:
            if CumReturn(self.algo, 'TIP', 60) > 0.0:
                self.riskon_stablenormal_rates()
            else:
                self.risk_off_fed_is_cutting_rates()
    
#https://app.composer.trade/symphony/FjhDCshn5CTReo0Y7Pdi/details

class HCopyofIFFFundCalmtheChaosBT122019AR369MDD19Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1_bwc_yieldmax_maxdd_btm_12()
    
    def rsi(self):
        Sort(self.algo,'RSI',('TSLY','CONY','NVDY','AMDY','APLY','AMZY','OARK','DISO','GOOY','PYPY','MSFO','JPMO','XOMO','NFLY','FBY','SQY','MRNY'),3,False,2,126,0.25)
    
    def ma(self):
        Sort(self.algo,'SMADayRet',('TSLY','CONY','NVDY','AMDY','APLY','AMZY','OARK','DISO','GOOY','PYPY','MSFO','JPMO','XOMO','NFLY','FBY','SQY','MRNY'),3,True,2,126,0.25)
    
    def cr(self):
        Sort(self.algo,'CumReturn',('TSLY','CONY','NVDY','AMDY','APLY','AMZY','OARK','DISO','GOOY','PYPY','MSFO','JPMO','XOMO','NFLY','FBY','SQY','MRNY'),3,True,2,126,0.25)
    
    def sd(self):
        Sort(self.algo,'STD',('TSLY','CONY','NVDY','AMDY','APLY','AMZY','OARK','DISO','GOOY','PYPY','MSFO','JPMO','XOMO','NFLY','FBY','SQY','MRNY'),3,True,2,126,0.25)
    
    def v1_bwc_yieldmax_maxdd_btm_12(self):
        GroupSort(self.algo,'MaxDD',(self.sd(),self.cr(),self.ma(),self.rsi()),3,False,2,126,0.5)
        GroupSort(self.algo,'MaxDD',(self.sd(),self.cr(),self.ma(),self.rsi()),3,False,1,126,0.5)

#https://app.composer.trade/symphony/0MEtMOUZJHlt2wk9qTQ0/details

class HolyGrailsimplifiedwithXStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'TQQQ') > SMA(self.algo,'TQQQ',200):
            if RSI(self.algo,'QQQ',10) > 80:
                AH(self.algo,'UVXY',127,1)
            else:
                AH(self.algo,'TQQQ',127,1)
        else:
            if RSI(self.algo,'TQQQ',10) < 31:
                AH(self.algo,'TECL',127,1)
            else:
                if RSI(self.algo,'UPRO',10) < 31:
                    AH(self.algo,'SPYU',127,1)
                else:
                    if GetCurrentPrice(self.algo,'TQQQ') > SMA(self.algo,'TQQQ',20):
                        AH(self.algo,'TQQQ',127,1)
                    else:
                        Sort(self.algo,'RSI',('TLT','SQQQ'),10,True,1,127,1)
    
#https://app.composer.trade/symphony/6bvg90QTOSvKxf8n4xVN/details

class IFFFundBlainesBoxofTricks3124SortingforthebestTradingStrategyStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.nvda_or_40d_rsi_sort_top_2()
    
    def A40d_rsi_sort_top_2(self):
        if RSI(self.algo,'VIXM',40) > 69:
            AH(self.algo,'SPXU',128,1.0)
        else:
            Sort(self.algo,'RSI',('AAPL','MSFT','NVDA','AMD','XOM','NFLX','META','TSLA','AMZN','GOOGL','COIN'),40,True,2,128,1.0)
    
    def huge_volatility(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.13:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.06:
                AH(self.algo,'SOXS',128,1.0)
            else:
                AH(self.algo,'NVDA',128,1.0)
        else:
            self.A40d_rsi_sort_top_2()
    
    def nvda_or_40d_rsi_sort_top_2(self):
        if RSI(self.algo,'TQQQ',10) > 79:
            AH(self.algo,'SOXS',128,1.0)
        else:
            self.huge_volatility()

    
#https://app.composer.trade/symphony/6Gnr8nnjDUlwb8ml7r58/details

class InterstellarCryptoETHStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if MaxDD(self.algo, 'QQQ', 10) >= 0.06:
            self.risk_on_core_risk_parity()
        else:
            if MaxDD(self.algo, 'TMF', 10) <= 0.07:
                self.risk_off_()
            else:
                self.risk_on_core_risk_parity()
    
    def risk_on_core_risk_parity(self):
        AHIV(self.algo,('DBMF','UUP','GLD'),45,129,1.0)
    
    def risk_off_(self):
        AHIV(self.algo,('UPRO','TQQQ','TMF','FAS','FNGU','SOXL'),45,129,1.0)
    
#https://app.composer.trade/symphony/HSAWtuy6iP14MLpJbtyO/details

class kMECHACHEETAH10Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.four_corners_nicomavis_20111004()
    
    def gold_mining(self):
        AH(self.algo,'GLD',130,0.08)
        AH(self.algo,'GDX',130,0.08)
    
    def utilities_vs_gold(self):
        AH(self.algo,'VPU',130,0.16)
        self.gold_mining()
    
    def tlt_or_psq(self):
        if RSI(self.algo,'IEF',7) > RSI(self.algo,'PSQ',20):
            AH(self.algo,'TLT',130,0.16)
        else:
            AH(self.algo,'PSQ',130,0.16)
    
    def tqqq_or_psq(self):
        if RSI(self.algo,'IEF',7) > RSI(self.algo,'PSQ',20):
            AH(self.algo,'TQQQ',130,0.33)
        else:
            AH(self.algo,'PSQ',130,0.33)
    
    def A3x_long(self):
        AH(self.algo,'TQQQ',130,0.33*0.5) 
        AH(self.algo,'UPRO',130,0.33*0.5)
        AH(self.algo,'TIP',130,0.33*0.5)
    
    def ballast(self):
        AH(self.algo,'TLT',130,0.5*0.5) 
        AH(self.algo,'GLD',130,0.5*0.5)
    
    def qqq_or_psq(self):
        if RSI(self.algo,'IEF',7) > RSI(self.algo,'PSQ',20):
            AH(self.algo,'QQQ',130,0.5*0.5)
        else:
            AH(self.algo,'PSQ',130,0.5*0.5)
    
    def four_corners_nicomavis_20111004(self):
        if STD(self.algo,'QQQ',10) > 3:
            self.qqq_or_psq()
            self.ballast()
        else:
            if RSI(self.algo,'QQQ',10) < 31:
                self.A3x_long()
                self.ballast()
            else:
                if RSI(self.algo,'QQQ',10) > 79:
                    AH(self.algo,'UVXY',130,0.5) 
                    AH(self.algo,'XLP',130,0.5)
                else:
                    if RSI(self.algo,'VTV',10) > 79:
                        AH(self.algo,'UVXY',130,0.5) 
                        AH(self.algo,'XLP',130,0.5)
                    else:
                        if RSI(self.algo,'QQQ',100) > RSI(self.algo,'VPU',100):
                            if CumReturn(self.algo,'CORP',60) > CumReturn(self.algo,'BIL',60):
                                self.A3x_long()
                            else:
                                AH(self.algo,'BTAL',130,0.33)
                                self.tqqq_or_psq()
                                self.utilities_vs_gold()
                        else:
                            if CumReturn(self.algo,'CORP',60) > CumReturn(self.algo,'BIL',60):
                                AH(self.algo,'QQQ',130,0.5) 
                                AH(self.algo,'TLT',130,0.5)
                            else:
                                AH(self.algo,'BTAL',130,0.33)
                                self.tlt_or_psq()
                                self.utilities_vs_gold()
    
#https://app.composer.trade/symphony/3dbI71EClAB0OnL97kFD/details

class KMLMvVTIMAStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.add_your_favorite_bsc_()
    
    def kmlm_v_vti(self):
        if SMADayRet(self.algo,'VTI',20) > SMADayRet(self.algo,'KMLM',20):
            Sort(self.algo,'STD',('SVIX','TECL'),20,False,1,131,1.0)
        else:
            Sort(self.algo,'STD',('VIXM','BTAL'),20,False,1,131,1.0)
    
    def add_your_favorite_bsc_(self):
           self.kmlm_v_vti()
    
#https://app.composer.trade/symphony/IYmUJPat3QjvnZH7nCoZ/details

class KSimplifiedBase2MSFOStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.simplified_base_2_msfo()
    
    def simplified_base_2_msfo(self):
        if RSI(self.algo,'QQQE',10) > 79:
            AH(self.algo,'BIL',132,1.0)
        else:
            if RSI(self.algo,'VTV',10) > 79:
                AH(self.algo,'BTAL',132,1.0)
            else:
                if RSI(self.algo,'VOX',10) > 79:
                    AH(self.algo,'BTAL',132,1.0)
                else:
                    if RSI(self.algo,'TECL',10) > 79:
                        AH(self.algo,'BTAL',132,1.0)
                    else:
                        if RSI(self.algo,'VOOG',10) > 79:
                            AH(self.algo,'BIL',132,1.0)
                        else:
                            if RSI(self.algo,'VOOV',10) > 79:
                                AH(self.algo,'BIL',132,1.0)
                            else:
                                if RSI(self.algo,'XLP',10) > 75:
                                    AH(self.algo,'BTAL',132,1.0)
                                else:
                                    if RSI(self.algo,'TQQQ',10) > 79:
                                        AH(self.algo,'BTAL',132,1.0)
                                    else:
                                        if RSI(self.algo,'XLY',10) > 80:
                                            AH(self.algo,'BTAL',132,1.0)
                                        else:
                                            if RSI(self.algo,'FAS',10) > 80:
                                                AH(self.algo,'BTAL',132,1.0)
                                            else:
                                                if RSI(self.algo,'SPY',10) > 80:
                                                    AH(self.algo,'BTAL',132,1.0)
                                                else:
                                                    if CumReturn(self.algo, 'TQQQ', 6) < -0.12:
                                                        if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                                                            AH(self.algo,'BTAL',132,1.0)
                                                        else:
                                                            AH(self.algo,'MSFO',132,1.0)
                                                    else:
                                                        AH(self.algo,'MSFO',132,1.0)
    
#https://app.composer.trade/symphony/FbZBHn83SJZFYb3pigM7/details


#https://app.composer.trade/symphony/DNBGWqI1IYBkqtiO3Fu7/details

class LCopyofV4BWCBUYWRITEIncomewBlackSwanCatcherDereckNModStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
       self.v4_bwc_buywrite_income_w_blackswancatcher_()
    
    def bond_midterm_longterm(self):
        if RSI(self.algo,'IEF',200) < RSI(self.algo,'TLT',200):
            if RSI(self.algo,'BND',45) > RSI(self.algo,'SPY',45):
                AH(self.algo,'SSO',134,1.0)
            else:
                AHIV(self.algo,('DIVO','XYLD','NUSI','SPYI','LQDW','TLTW','RYLD','ACIO','FTQI','PUTW'),10,134,1.0)
        else:
            AHIV(self.algo,('DIVO','XYLD','NUSI','SPYI','LQDW','TLTW','RYLD','ACIO','FTQI','PUTW'),10,134,1.0)
    
    def bond_stock(self):
        if RSI(self.algo,'BND',45) > RSI(self.algo,'SPY',45):
            AH(self.algo,'SSO',134,1.0)
        else:
            AHIV(self.algo,('DIVO','XYLD','NUSI','SPYI','LQDW','TLTW','RYLD','ACIO','FTQI','PUTW'),10,134,1.0)

    def normal_market(self):
        if MaxDD(self.algo, 'SPY', 10) > 0.06:
            AHIV(self.algo,('DIVO','XYLD','NUSI','SPYI','LQDW','TLTW','RYLD','ACIO','FTQI','PUTW'),10,134,1.0)
        else:
            if MaxDD(self.algo, 'TMF', 10) > 0.07:
                AHIV(self.algo,('DIVO','XYLD','NUSI','SPYI','LQDW','TLTW','RYLD','ACIO','FTQI','PUTW'),10,134,1.0)
            else:
                if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',25):
                    AH(self.algo,'SSO',134,1.0)
                else:
                    if RSI(self.algo,'SPY',60) > 40:
                        self.bond_stock()
                    else:
                        self.bond_midterm_longterm()
    
    def mean_rev(self):
        if RSI(self.algo,'SPY',5) < 30:
            AH(self.algo,'SSO',134,1.0)
        else:
            if MaxDD(self.algo, 'TMF', 10) < 0.07:
                AH(self.algo,'SSO',134,1.0)
            else:
                AHIV(self.algo,('DIVO','XYLD','NUSI','SPYI','LQDW','TLTW','RYLD','ACIO','FTQI','PUTW'),10,134,1.0)
    
    def huge_volatility(self):
        if CumReturn(self.algo, 'UPRO', 6) < -0.08:
            if CumReturn(self.algo, 'UPRO', 1) > 0.04:
                AH(self.algo,'SDS',134,1.0)
            else:
                self.mean_rev()
        else:
            self.normal_market()
    
    def v4_bwc_buywrite_income_w_blackswancatcher_(self):
        if RSI(self.algo,'SPY',10) > 84:
            AH(self.algo,'SPXS',134,1.0)
        else:
            self.huge_volatility()
    
#https://app.composer.trade/symphony/QTrk3L4gi0tPVxUZLiGH/details

class FullFrontrunnerAnansiStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_full_frontrunner_anansi()

    def group_full_frontrunner_anansi(self):
        if RSI(self.algo, 'SPY', 10) > 80:
            AH(self.algo, 'VIXY', 90, 1)
        elif RSI(self.algo, 'QQQ', 10) > 79:
            self.group_vix_blend()
        elif RSI(self.algo, 'VTV', 10) > 80:
            self.group_vix_blend()
        elif RSI(self.algo, 'VOX', 10) > 79:
            self.group_vix_blend()
        elif RSI(self.algo, 'XLP', 10) > 78:
            self.group_vix_blend()
        elif RSI(self.algo, 'XLF', 10) > 81:
            self.group_vix_blend()
        elif RSI(self.algo, 'SPY', 65) > 63:
            self.group_overbought_blend()
        elif CumReturn(self.algo, 'QQQ', 6) < -0.04:
            if CumReturn(self.algo, 'QQQ', 1) > 0.0175:
                self.group_vix_blend_plus()
            else:
                self.group_mr()
        else:
            self.group_200_day_cross()

    def group_vix_blend(self):
        AH(self.algo, 'VIXY', 90, 0.6)
        AH(self.algo, 'VIXM', 90, 0.2)
        AH(self.algo, 'BTAL', 90, 0.2)

    def group_overbought_blend(self):
        self.group_anti_beta()
        self.group_bond_signals()

    def group_anti_beta(self):
        AHIV(self.algo, ('VIXY', 'GLD'), 5, 90, 0.5)

    def group_bond_signals(self):
        self.group_15d_agg_vs_15d_qqq()
        self.group_20d_agg_vs_60d_sh()
        self.group_10d_ief_vs_20d_psq()

    def group_15d_agg_vs_15d_qqq(self):
        if RSI(self.algo, 'AGG', 15) > RSI(self.algo, 'QQQ', 15):
            AH(self.algo, 'SVXY', 90, 0.1667)
        else:
            AH(self.algo, 'SQQQ', 90, 0.1667)

    def group_20d_agg_vs_60d_sh(self):
        if RSI(self.algo, 'AGG', 20) > RSI(self.algo, 'SH', 60):
            AH(self.algo, 'SVXY', 90, 0.1667)
        else:
            AH(self.algo, 'SQQQ', 90, 0.1667)

    def group_10d_ief_vs_20d_psq(self):
        if RSI(self.algo, 'IEF', 10) > RSI(self.algo, 'PSQ', 20):
            AH(self.algo, 'SVXY', 90, 0.1667)
        else:
            AH(self.algo, 'SQQQ', 90, 0.1667)

    def group_vix_blend_plus(self):
        AH(self.algo, 'UVXY', 90, 0.55)
        AH(self.algo, 'EDV', 90, 0.25)
        AH(self.algo, 'BTAL', 90, 0.2)

    def group_mr(self):
        if RSI(self.algo, 'SOXX', 10) < 30:
            AH(self.algo, 'SOXL', 90, 1)
        elif RSI(self.algo, 'QQQ', 10) < 28:
            AH(self.algo, 'TQQQ', 90, 1)
        else:
            self.group_svxy()

    def group_svxy(self):
        if MaxDD(self.algo, 'SVXY', 3) > 0.2:
            AH(self.algo, 'BIL', 90, 1)
        else:
            AH(self.algo, 'SVXY', 90, 1)

    def group_200_day_cross(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            if SMA(self.algo, 'SPY', 3) < SMA(self.algo, 'SPY', 200):
                self.group_200d_bull_cross()
            else:
                AH(self.algo, 'BIL', 90, 1)
        else:
            if SMA(self.algo, 'SPY', 3) > SMA(self.algo, 'SPY', 200):
                self.group_200d_bear_cross()
            else:
                AH(self.algo, 'BIL', 90, 1)

    def group_200d_bull_cross(self):
        Sort(self.algo, 'RSI', ('TQQQ', 'TMF'), 10, True, 1, 90, 1)

    def group_200d_bear_cross(self):
        Sort(self.algo, 'RSI', ('SPXU', 'TMF'), 10, True, 1, 90, 1)

#https://app.composer.trade/symphony/uxCcDqCdSOLtbnlckDIJ/details

class RisingRatesWithVolSwitchStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_rising_rates_with_vol_switch()

    def group_rising_rates_with_vol_switch(self):
        if RSI(self.algo, 'VTV', 10) > 79:
            AH(self.algo, 'UVXY', 117, 1)
        else:
            self.check_vox()

    def check_vox(self):
        if RSI(self.algo, 'VOX', 10) > 79:
            AH(self.algo, 'UVXY', 117, 1)
        else:
            self.check_xlk()

    def check_xlk(self):
        if RSI(self.algo, 'XLK', 10) > 79:
            AH(self.algo, 'UVXY', 117, 1)
        else:
            self.check_qqq()

    def check_qqq(self):
        if RSI(self.algo, 'QQQ', 10) > 79:
            AH(self.algo, 'UVXY', 117, 1)
        elif RSI(self.algo, 'QQQ', 10) < 31:
            AH(self.algo, 'TQQQ', 117, 1)
        else:
            self.check_qqq_drawdown()

    def check_qqq_drawdown(self):
        if MaxDD(self.algo, 'QQQ', 12) > 0.06:
            Sort(self.algo, 'CumReturn', ('SQQQ', 'BSV'), 10, False, 1, 117, 1)
        else:
            self.check_tmf_drawdown()

    def check_tmf_drawdown(self):
        if MaxDD(self.algo, 'TMF', 10) > 0.07:
            Sort(self.algo, 'CumReturn', ('TMV', 'BSV'), 10, False, 1, 117, 1)
        else:
            self.group_kmlm_switcher()

    def group_kmlm_switcher(self):
        if RSI(self.algo, 'QQQE', 10) > 79:
            AH(self.algo, 'UVXY', 117, 1)
        else:
            self.check_vtv()

    def check_vtv(self):
        if RSI(self.algo, 'VTV', 10) > 79:
            AH(self.algo, 'UVXY', 117, 1)
        else:
            self.check_vox_again()

    def check_vox_again(self):
        if RSI(self.algo, 'VOX', 10) > 79:
            AH(self.algo, 'UVXY', 117, 1)
        else:
            self.check_tecl()

    def check_tecl(self):
        if RSI(self.algo, 'TECL', 10) > 79:
            AH(self.algo, 'UVXY', 117, 1)
        else:
            self.check_voog()

    def check_voog(self):
        if RSI(self.algo, 'VOOG', 10) > 79:
            AH(self.algo, 'UVXY', 117, 1)
        else:
            self.check_voov()

    def check_voov(self):
        if RSI(self.algo, 'VOOV', 10) > 79:
            AH(self.algo, 'UVXY', 117, 1)
        else:
            self.check_xlp()

    def check_xlp(self):
        if RSI(self.algo, 'XLP', 10) > 75:
            AH(self.algo, 'UVXY', 117, 1)
        else:
            self.check_tqqq()

    def check_tqqq(self):
        if RSI(self.algo, 'TQQQ', 10) > 79:
            AH(self.algo, 'UVXY', 117, 1)
        else:
            self.check_xly()

    def check_xly(self):
        if RSI(self.algo, 'XLY', 10) > 80:
            AH(self.algo, 'UVXY', 117, 1)
        else:
            self.check_fas()

    def check_fas(self):
        if RSI(self.algo, 'FAS', 10) > 80:
            AH(self.algo, 'UVXY', 117, 1)
        else:
            self.check_spy()

    def check_spy(self):
        if RSI(self.algo, 'SPY', 10) > 80:
            AH(self.algo, 'UVXY', 117, 1)
        else:
            self.group_single_popped_kmlm()

    def group_single_popped_kmlm(self):
        if RSI(self.algo, 'UVXY', 21) > 65:
            self.group_bsc()
        else:
            self.group_combined_pop_bot()

    def group_bsc(self):
        if RSI(self.algo, 'SPY', 21) > 30:
            AH(self.algo, 'VIXM', 117, 1)
        else:
            AH(self.algo, 'SPXL', 117, 1)

    def group_combined_pop_bot(self):
        if RSI(self.algo, 'TQQQ', 10) < 30:
            AH(self.algo, 'TECL', 117, 1)
        elif RSI(self.algo, 'SOXL', 10) < 30:
            AH(self.algo, 'SOXL', 117, 1)
        elif RSI(self.algo, 'SPXL', 10) < 30:
            AH(self.algo, 'SPXL', 117, 1)
        else:
            self.group_copypasta_yolo_gainzs()

    def group_copypasta_yolo_gainzs(self):
        self.group_kmlm_switcher_tecl_svix_ls_rotator()

    def group_kmlm_switcher_tecl_svix_ls_rotator(self):
        if RSI(self.algo, 'XLK', 10) > RSI(self.algo, 'KMLM', 10):
            Sort(self.algo, 'RSI', ('TECL', 'SVIX'), 10, False, 1, 117, 1)
        else:
            self.group_long_short_rotator()

    def group_long_short_rotator(self):
        Sort(self.algo, 'STD', ('TMV', 'TMF', 'SVXY', 'VIXM', 'FTLS', 'KMLM', 'UUP'), 6, False, 3, 117, 1)
#https://app.composer.trade/symphony/BofzuOqlEHaGnydtUVhc/details

class QuadFTLTAnansiStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_quad_ftlt()

    def group_quad_ftlt(self):
        if RSI(self.algo, 'SPY', 10) > 80:
            AH(self.algo, 'VIXY', 113, 1)
        else:
            self.check_qqq_rsi()

    def check_qqq_rsi(self):
        if RSI(self.algo, 'QQQ', 10) > 79:
            self.group_vix_blend(0.55, 0.25, 0.2)
        else:
            self.check_vtv_rsi()

    def check_vtv_rsi(self):
        if RSI(self.algo, 'VTV', 10) > 79:
            self.group_vix_blend(0.55, 0.25, 0.2)
        else:
            self.check_vox_rsi()

    def check_vox_rsi(self):
        if RSI(self.algo, 'VOX', 10) > 79:
            self.group_vix_blend(0.55, 0.25, 0.2)
        else:
            self.check_xlp_rsi()

    def check_xlp_rsi(self):
        if RSI(self.algo, 'XLP', 10) > 78:
            self.group_vix_blend(0.55, 0.25, 0.2)
        else:
            self.check_xlf_rsi()

    def check_xlf_rsi(self):
        if RSI(self.algo, 'XLF', 10) > 81:
            self.group_vix_blend(0.55, 0.25, 0.2)
        else:
            self.check_tqqq_cumulative_return()

    def check_tqqq_cumulative_return(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.12:
            self.check_tqqq_daily_return()
        else:
            self.group_200_day_cross()

    def check_tqqq_daily_return(self):
        if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
            self.group_vix_blend_plus()
        else:
            self.group_mr_minus()

    def group_vix_blend(self, vixy_weight, edv_weight, btal_weight):
        AH(self.algo, 'VIXY', 113, vixy_weight)
        AH(self.algo, 'EDV', 113, edv_weight)
        AH(self.algo, 'BTAL', 113, btal_weight)

    def group_vix_blend_plus(self):
        AH(self.algo, 'UVXY', 113, 0.55)
        AH(self.algo, 'EDV', 113, 0.25)
        AH(self.algo, 'BTAL', 113, 0.2)

    def group_mr_minus(self):
        if RSI(self.algo, 'SOXX', 10) < 30:
            AH(self.algo, 'SOXL', 113, 1)
        else:
            self.group_svxy()

    def group_svxy(self):
        if MaxDD(self.algo, 'SVXY', 3) > 0.2:
            self.group_volmageddon_protection()
        else:
            AH(self.algo, 'SVXY', 113, 1)

    def group_volmageddon_protection(self):
        AH(self.algo, 'BIL', 113, 1)

    def group_200_day_cross(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            self.check_spy_3d_200d_sma()
        else:
            self.check_spy_3d_200d_sma_bear()

    def check_spy_3d_200d_sma(self):
        if SMA(self.algo, 'SPY', 3) < SMA(self.algo, 'SPY', 200):
            self.group_200d_bull_cross()
        else:
            self.group_quad_ftlt_nested()

    def group_200d_bull_cross(self):
        Sort(self.algo, 'RSI', ('TQQQ', 'TMF'), 10, True, 1, 113, 1)

    def group_quad_ftlt_nested(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            self.check_spy_65d_rsi()
        else:
            self.check_qqq_10d_rsi()

    def check_spy_65d_rsi(self):
        if RSI(self.algo, 'SPY', 65) > 63:
            self.group_overbought_blend()
        else:
            self.group_quad()

    def group_overbought_blend(self):
        self.group_anti_beta()
        self.group_bond_signals()

    def group_anti_beta(self):
        AHIV(self.algo, ('VIXY', 'GLD'), 5, 113, 0.5)

    def group_bond_signals(self):
        self.group_10d_ief_vs_15d_psq()
        self.group_15d_agg_vs_15d_qqq()
        self.group_20d_agg_vs_60d_sh()

    def group_10d_ief_vs_15d_psq(self):
        if RSI(self.algo, 'IEF', 10) > RSI(self.algo, 'PSQ', 20):
            AH(self.algo, 'SVXY', 113, 1/6)
        else:
            AH(self.algo, 'SQQQ', 113, 1/6)

    def group_15d_agg_vs_15d_qqq(self):
        if RSI(self.algo, 'AGG', 15) > RSI(self.algo, 'QQQ', 15):
            AH(self.algo, 'SVXY', 113, 1/6)
        else:
            AH(self.algo, 'SQQQ', 113, 1/6)

    def group_20d_agg_vs_60d_sh(self):
        if RSI(self.algo, 'AGG', 20) > RSI(self.algo, 'SH', 60):
            AH(self.algo, 'SVXY', 113, 1/6)
        else:
            AH(self.algo, 'SQQQ', 113, 1/6)

    def group_quad(self):
        AHIV(self.algo, ('NVO', 'LLY', 'COST', 'GE'), 10, 113, 1)

    def check_qqq_10d_rsi(self):
        if RSI(self.algo, 'QQQ', 10) < 31:
            AH(self.algo, 'TECL', 113, 1)
        else:
            self.check_spy_10d_rsi()

    def check_spy_10d_rsi(self):
        if RSI(self.algo, 'SPY', 10) < 30:
            AH(self.algo, 'UPRO', 113, 1)
        else:
            self.check_qqq_60d_cumulative_return()

    def check_qqq_60d_cumulative_return(self):
        if CumReturn(self.algo, 'QQQ', 60) < -0.12:
            AH(self.algo, 'BIL', 113, 1)
        else:
            self.check_tqqq_20d_sma()

    def check_tqqq_20d_sma(self):
        if GetCurrentPrice(self.algo, 'TQQQ') > SMA(self.algo, 'TQQQ', 20):
            self.check_psq_10d_rsi()
        else:
            self.check_ief_10d_vs_psq_20d_rsi()

    def check_psq_10d_rsi(self):
        if RSI(self.algo, 'PSQ', 10) < 32.5:
            AH(self.algo, 'PSQ', 113, 1)
        else:
            self.group_quad()

    def check_ief_10d_vs_psq_20d_rsi(self):
        if RSI(self.algo, 'IEF', 10) > RSI(self.algo, 'PSQ', 20):
            AH(self.algo, 'PSQ', 113, 1)
        else:
            AH(self.algo, 'QID', 113, 1)

    def check_spy_3d_200d_sma_bear(self):
        if SMA(self.algo, 'SPY', 3) > SMA(self.algo, 'SPY', 200):
            self.group_200d_bear_cross()
        else:
            self.group_quad_ftlt_nested()

    def group_200d_bear_cross(self):
        Sort(self.algo, 'RSI', ('SPXU', 'TMF'), 10, True, 1, 113, 1)
#region imports
from AlgorithmImports import *
#endregion


# Your New Python File
from AlgorithmImports import *
from indicators import *
from main import YellowCatStrat

#https://app.composer.trade/symphony/7yTptWH5LX4dUtgVJzuE/details

class MagicInternetMoneyGoldenBallerStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.magic_internet_money_golden_baller()
    
    def golden_bear(self):
        AH(self.algo,'UGL',137,0.33)
        AH(self.algo,'PSQ',137,0.33)
        AH(self.algo,'SH',137,0.33)
    
    def extremely_oversold_sp_low_rsi_double_check_with_bond_mkt_before_going_long(self):
        if RSI(self.algo,'SHY',10) < RSI(self.algo,'VTI',10):
            AH(self.algo,'SOXS',137,1.0)
        else:
            AH(self.algo,'SOXL',137,1.0)
    
    def semis(self):
        Sort(self.algo,'MaxDD',('SOXL','SMH'),6,True,1,137,1.0)
    
    def golden_baller(self):
        if RSI(self.algo,'BIL',10) < RSI(self.algo,'IEF',10):
            if RSI(self.algo,'SPY',7) > 76:
                AH(self.algo,'UGL',137,1.0)
            else:
                self.semis()
        else:
            if RSI(self.algo,'SPY',7) < 27:
                self.extremely_oversold_sp_low_rsi_double_check_with_bond_mkt_before_going_long()
            else:
                self.golden_bear()
    
    def curet_search(self):
        Sort(self.algo,'CumReturn',('BITO','MSTR','COIN'),21,True,1,137,1.0)
    
    def biti_bot(self):
        if RSI(self.algo,'BITO',14) > 60:
            AH(self.algo,'BITI',137,1.0)
        else:
            if CumReturn(self.algo, 'BITI', 1) <= -0.01:
                AH(self.algo,'MSTR',137,1.0)
            else:
                if CumReturn(self.algo,'BITO',5) >= STD(self.algo,'BITO',10):
                    AH(self.algo,'BITI',137,1.0)
                else:
                    if CumReturn(self.algo,'BITO',2) >= STD(self.algo,'BITO',5):
                        if CumReturn(self.algo,'BITO',1) > CumReturn(self.algo,'BITI',3):
                            self.curet_search()
                        else:
                            self.golden_baller()
                    else:
                        self.golden_baller()
    
    def magic_internet_money_golden_baller(self):
        if GetCurrentPrice(self.algo,'BITO') <= SMA(self.algo,'BITO',62):
            self.biti_bot()
        else:
            self.golden_baller()
    
#https://app.composer.trade/symphony/2m59BThVxcTY0t2DkSKz/details

class OGv12BuyTheDips150dMABasketwithbondselectornok1editionSHAREDStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'TQQQ',10) > 79:
            AH(self.algo,'VXX',138,0.25)
            AH(self.algo,'BIL',138,0.75)
        else:
            if RSI(self.algo,'TQQQ',10) < 31:
                AH(self.algo,'TECL',138,0.5)
                AH(self.algo,'XLP',138,0.5)
            else:
                if RSI(self.algo,'SPY',10) < 30:
                    AH(self.algo,'UPRO',138,0.5)
                    AH(self.algo,'XLP',138,0.5)
                else:
                    self.group_150_ma_selector()
                    if GetCurrentPrice(self.algo,'TLT') > SMA(self.algo,'TLT',150):
                        AH(self.algo,'TMF',138,0.3)
                    else:
                        if GetCurrentPrice(self.algo,'TLT') < SMA(self.algo,'TLT',23):
                            AH(self.algo,'TMV',138,0.3)
                        else:
                            AH(self.algo,'TMF',138,0.3)

    def group_150_ma_selector(self):
        Sort(self.algo,'SMADayRet',('TQQQ','SPY','TLT','BSV','XLP','SOXL','XLE','PDBC','XLV','USDU','UDOW','UPRO','EWZ'),150,True,4,138,0.7)

#https://app.composer.trade/symphony/77ucD99tOJMTunCymyQB/details

class PizzaV1aTQQQornotReplaceUVXYwSOXSReplaceTQQQwSPYUStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1a_tqqq_or_not_replace_uvxy_w_soxs()
    
    def bond_midterm_longterm(self):
        if RSI(self.algo,'IEF',200) < RSI(self.algo,'TLT',200):
            if RSI(self.algo,'BND',45) > RSI(self.algo,'SPY',45):
                AH(self.algo,'SPYU',139,1.0)
            else:
                AH(self.algo,'BIL',139,1.0)
        else:
            AH(self.algo,'BIL',139,1.0)
    
    def bond_stock(self):
        if RSI(self.algo,'BND',45) > RSI(self.algo,'SPY',45):
            AH(self.algo,'SPYU',139,1.0)
        else:
            AH(self.algo,'BIL',139,1.0)
    
    def normal_market(self):
        if MaxDD(self.algo, 'QQQ', 10) > 0.06:
            AH(self.algo,'BIL',139,1.0)
        else:
            if MaxDD(self.algo, 'TMF', 10) > 0.07:
                AH(self.algo,'BIL',139,1.0)
            else:
                if GetCurrentPrice(self.algo,'QQQ') > SMA(self.algo,'QQQ',25):
                    AH(self.algo,'SPYU',139,1.0)
                else:
                    if RSI(self.algo,'SPY',60) > 50:
                        self.bond_stock()
                    else:
                        self.bond_midterm_longterm()
    
    def mean_rev(self):
        if RSI(self.algo,'TQQQ',10) < 32:
            AH(self.algo,'SOXL',139,1.0)
        else:
            if MaxDD(self.algo, 'TMF', 10) < 0.07:
                AH(self.algo,'SOXL',139,1.0)
            else:
                AH(self.algo,'BIL',139,1.0)
    
    def huge_volatility(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.12:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                AH(self.algo,'UVXY',139,1.0)
            else:
                self.mean_rev()
        else:
            self.normal_market()

    def bsmr230105_tqqq_or_not_blackswan_meanrev_bondsignal(self):
        if RSI(self.algo,'TQQQ',10) > 79:
            AH(self.algo,'SOXS',139,1.0)
        else:
            self.huge_volatility()
    
    def v1a_tqqq_or_not_replace_uvxy_w_soxs(self):
        self.bsmr230105_tqqq_or_not_blackswan_meanrev_bondsignal()

#https://app.composer.trade/symphony/JNJ1yam5fortZdZCqteM/details

class pV1BWCTheMarketAssassinfindsReligionStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        AHIV(self.algo,('TMV','SVIX'),3,140,1)
    
#https://app.composer.trade/symphony/BpL79MyTrKafLZuoLoAe/details

class ChampagneAndCocaineStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_champagne_and_cocaine()

    def group_champagne_and_cocaine(self):
        if CumReturn(self.algo, 'VIXY', 10) > 0.2:
            AH(self.algo, 'BIL', 141, 1)
        else:
            self.check_rsi_ioo()

    def check_rsi_ioo(self):
        if RSI(self.algo, 'IOO', 10) > 80:
            self.group_quick_overbought_pop()
        else:
            self.check_rsi_spy()

    def check_rsi_spy(self):
        if RSI(self.algo, 'SPY', 10) > 80:
            self.group_quick_overbought_pop()
        else:
            self.check_rsi_qqq()

    def check_rsi_qqq(self):
        if RSI(self.algo, 'QQQ', 10) > 80:
            self.group_quick_overbought_pop()
        elif RSI(self.algo, 'QQQ', 10) < 30:
            AH(self.algo, 'TQQQ', 141, 0.5)
            AH(self.algo, 'VWO', 141, 0.5)
        elif RSI(self.algo, 'SPY', 10) < 30:
            AH(self.algo, 'SPXL', 141, 0.5)
            AH(self.algo, 'VWO', 141, 0.5)
        else:
            self.group_strategies()

    def group_quick_overbought_pop(self):
        AH(self.algo, 'EDV', 141, 0.33)
        AH(self.algo, 'VIXY', 141, 0.33)
        AH(self.algo, 'BTAL', 141, 0.34)

    def group_strategies(self):
        self.group_nicomavis()
        self.group_kmlm_technology()
        self.group_em()
        self.group_jrt()

    def group_nicomavis(self):
        self.group_2060_ftlt()

    def group_2060_ftlt(self):
        if RSI(self.algo, 'BND', 20) > RSI(self.algo, 'SH', 60):
            self.check_qqq_ma()
        else:
            self.check_qqq_rsi()

    def check_qqq_ma(self):
        if GetCurrentPrice(self.algo, 'QQQ') > SMA(self.algo, 'QQQ', 200):
            AH(self.algo, 'TQQQ', 141, 0.25*0.25)
            AH(self.algo, 'UPRO', 141, 0.25*0.25)
            AH(self.algo, 'DBMF', 141, 0.25*0.25)
            AH(self.algo, 'EDV', 141, 0.25*0.25)
        else:
            AH(self.algo, 'VT', 141, 1*0.25)

    def check_qqq_rsi(self):
        if RSI(self.algo, 'QQQ', 14) < 35:
            AH(self.algo, 'QQQ', 141, 0.5*0.25)
            AH(self.algo, 'VT', 141, 0.5*0.25)
        else:
            self.check_ief_psq_rsi()

    def check_ief_psq_rsi(self):
        if RSI(self.algo, 'IEF', 7) > RSI(self.algo, 'PSQ', 20):
            AH(self.algo, 'VT', 141, 0.5*0.25)
            AH(self.algo, 'BND', 141, 0.5*0.25)
        else:
            AH(self.algo, 'BTAL', 141, 1*0.25)

    def group_kmlm_technology(self):
        if RSI(self.algo, 'XLK', 10) > RSI(self.algo, 'KMLM', 10):
            AH(self.algo, 'TECL', 141, 1*0.25)
        else:
            AH(self.algo, 'TECS', 141, 1*0.25)

    def group_em(self):
        if GetCurrentPrice(self.algo, 'RINF') > SMA(self.algo, 'RINF', 50):
            if GetCurrentPrice(self.algo, 'EEM') > SMA(self.algo, 'EEM', 200):
                self.group_iei_iwm()
            else:
                self.group_corp_eem()
                self.group_ief_spy()
                self.group_corp_spy()
        else:
            self.group_corp_spy()
            self.group_ief_spy()

    def group_iei_iwm(self):
        if RSI(self.algo, 'IEI', 10) > RSI(self.algo, 'IWM', 15):
            AH(self.algo, 'EDC', 141, 1*0.25)
        else:
            AH(self.algo, 'EDZ', 141, 1*0.25)

    def group_corp_eem(self):
        if RSI(self.algo, 'CORP', 15) > RSI(self.algo, 'EEM', 15):
            AH(self.algo, 'EDC', 141, 1*0.25/3)
        else:
            AH(self.algo, 'EDZ', 141, 1*0.25/3)

    def group_ief_spy(self):
        if RSI(self.algo, 'IEF', 7) > RSI(self.algo, 'SPY', 20):
            AH(self.algo, 'EDC', 141, 1*0.25/3)
        else:
            AH(self.algo, 'EDZ', 141, 1*0.25/3)

    def group_corp_spy(self):
        if RSI(self.algo, 'CORP', 10) > RSI(self.algo, 'SPY', 10):
            AH(self.algo, 'EDC', 141, 1*0.25/3)
        else:
            AH(self.algo, 'EDZ', 141, 1*0.25/3)

    def group_jrt(self):
        AHIV(self.algo, ('LLY', 'NVO', 'COST', 'PGR', 'GE'), 10, 141, 0.25)
    
#https://app.composer.trade/symphony/BpbX70xgVWA5up2CD6Fa/details

#https://app.composer.trade/symphony/2cJScc9MVKLi7oQ6aTyM/details

class IFFFundStrategySorterStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.A2060_ftlt()

    def A2060_ftlt(self):
        if RSI(self.algo,'BND',20) > RSI(self.algo,'SH',60):
            if GetCurrentPrice(self.algo,'QQQ') > SMA(self.algo,'QQQ',200):
                AH(self.algo,'TQQQ',142,0.25)
                AH(self.algo,'UPRO',142,0.25)
                AH(self.algo,'DBMF',142,0.25)
                AH(self.algo,'EDV',142,0.25)
            else:
                AH(self.algo,'VT',142,1.0)
        else:
            if RSI(self.algo,'QQQ',14) < 35:
                AH(self.algo,'QQQ',142,0.5) 
                AH(self.algo,'VT',142,0.5)
            else:
                if RSI(self.algo,'IEF',7) > RSI(self.algo,'PSQ',20):
                    AH(self.algo,'VT',142,0.5) 
                    AH(self.algo,'BND',142,0.5)
                else:
                    AH(self.algo,'BTAL',142,1.0)

#https://app.composer.trade/symphony/gE7JeAh3gkF1MxuPAWhN/details

class EV175dBetaBallerTCCCDeezBrianEHinnomTXDereckNGarenDJKeyholecomradeAR11845DD195BTdate1DEC19InvestCopyStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_v175b_beta_baller_tccc_deez_briane_hinnomtx_dereckn_garen_djkeyhole_comrade_ar_97176_dd_195_bt_date_1dec19()

    def group_v175b_beta_baller_tccc_deez_briane_hinnomtx_dereckn_garen_djkeyhole_comrade_ar_97176_dd_195_bt_date_1dec19(self):
        if RSI(self.algo,'BIL',10) < RSI(self.algo,'IEF',10):
            if RSI(self.algo,'SPY',6) > 75:
                self.group_overbought_sp_sell_the_rip_buy_volatility()
            else:
                AH(self.algo,'SOXL',143,1)
        else:
            if RSI(self.algo,'SPY',6) < 27:
                self.group_extremely_oversold_sp_low_rsi_double_check_with_bond_mkt_before_going_long()
            else:
                self.group_v021_tccc_stop_the_bleed_djkeyhole_12_of_momentum_mean_reversion()
                    
    def group_overbought_sp_sell_the_rip_buy_volatility(self):
        Sort(self.algo,'RSI',('UVXY','VIXY'),13,False,1,143,1)

    def group_extremely_oversold_sp_low_rsi_double_check_with_bond_mkt_before_going_long(self):
        if RSI(self.algo,'SHY',10) < RSI(self.algo,'HIBL',10):
            Sort(self.algo,'RSI',('SOXS','SQQQ'),7,False,1,143,1)
        else:
            Sort(self.algo,'RSI',('SOXL','TECL'),7,False,1,143,1)
            
    def group_v021_tccc_stop_the_bleed_djkeyhole_12_of_momentum_mean_reversion(self):
        if RSI(self.algo,'SPY',10) < 30:
            self.group_v12_five_and_below_djkeyhole_no_low_volume_letfs()
        else:
            if RSI(self.algo,'UVXY',10) > 74:
                if RSI(self.algo,'UVXY',10) > 84:
                    self.group_bear_stock_market_high_inflation_stripped_v202b_a_better_letf_basket_djkeyhole_bil_and_tmv()
                else:
                    AH(self.algo,'UVXY',143,1)
            else:
                self.group_bear_stock_market_high_inflation_stripped_v202b_a_better_letf_basket_djkeyhole_bil_and_tmv()
                
    def group_v12_five_and_below_djkeyhole_no_low_volume_letfs(self):
        Sort(self.algo,'SMADayRet',('TECL','TQQQ','SPXL','SOXL','UPRO','QLD'),5,False,1,143,1)
        
    def group_bear_stock_market_high_inflation_stripped_v202b_a_better_letf_basket_djkeyhole_bil_and_tmv(self):
        if GetCurrentPrice(self.algo,'TLT') > SMA(self.algo,'TLT',200):
            self.group_ab_medium_term_tlt_may_be_overbought()
        else:
            self.group_b_if_long_term_tlt_is_trending_down_safety_long_term_2_least_volatile()
            
    def group_ab_medium_term_tlt_may_be_overbought(self):
        if SMADayRet(self.algo,'TLT',20) < 0:
            self.group_abba_risk_off_rising_rates_tmv()
        else:
            self.group_abbb_risk_off_falling_rates_tmf()
            
    def group_abba_risk_off_rising_rates_tmv(self):
        if EMA(self.algo,'SPY',210) <= SMA(self.algo,'SPY',360):
            if RSI(self.algo,'TQQQ',10) < 30:
                Sort(self.algo,'SMADayRet',('TECL','TQQQ','SOXL','UPRO'),5,False,1,143,1)
            else:
                if CumReturn(self.algo,'SPXU',6) >= CumReturn(self.algo,'UPRO',3):
                    Sort(self.algo,'CumReturn',('SQQQ','EUO','YCS'),5,True,1,143,1)
                else:
                    Sort(self.algo,'SMADayRet',('TECL','TQQQ','SOXL','CURE'),5,False,1,143,1)
        else:
            if RSI(self.algo,'TQQQ',11) > 77:
                AH(self.algo,'UVXY',143,0.25)
            else:
                Sort(self.algo,'SMADayRet',('TECL','TQQQ','SOXL','UPRO','TMV'),5,False,1,143,1)
                
    def group_abbb_risk_off_falling_rates_tmf(self):
        if EMA(self.algo,'SPY',210) <= SMA(self.algo,'SPY',360):
            if RSI(self.algo,'TQQQ',10) < 30:
                Sort(self.algo,'SMADayRet',('TECL','TQQQ','SOXL'),5,False,1,143,1)
            else:
                if CumReturn(self.algo, 'SPY', 2) <= -0.02:
                    Sort(self.algo,'CumReturn',('TECS','SOXS','SQQQ'),5,True,1,143,1)
                else:
                    if CumReturn(self.algo,'SPXU',6) >= CumReturn(self.algo,'UPRO',3):
                        Sort(self.algo,'CumReturn',('ERX','EUO','YCS'),5,True,1,143,1)
                    else:
                        Sort(self.algo,'SMADayRet',('SOXL','EWZ','MVV','USD'),5,False,1,143,1)
        else:
            if SMADayRet(self.algo,'SPY',210) > SMADayRet(self.algo,'DBC',360):
                if RSI(self.algo,'TQQQ',11) > 77:
                    AH(self.algo,'UVXY',143,0.25)
                else:
                    if CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                        if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                            AH(self.algo,'UVXY',143,0.25)
                        else:
                            if RSI(self.algo,'BIL',7) < RSI(self.algo,'IEF',7):
                                Sort(self.algo,'SMADayRet',('SOXL'),5,False,1,143,1)
                            else:
                                Sort(self.algo,'CumReturn',('EWZ','UUP','TMF','UCO'),5,True,1,143,1)
                    else:
                        if RSI(self.algo,'BIL',7) < RSI(self.algo,'IEF',7):
                            Sort(self.algo,'SMADayRet',('TECL','TQQQ','SPXL','QLD','USD'),5,False,1,143,1)
                        else:
                            Sort(self.algo,'CumReturn',('EWZ','UUP','TMF'),5,True,1,143,1)
            else:
                self.group_defense_modified()
                
    def group_defense_modified(self):
        if STD(self.algo,'DBC',20) > STD(self.algo,'SPY',20):
            Sort(self.algo,'RSI',('SHY','EWZ','GLD','SPXS','TECS','SOXS','UCO','YCS'),5,False,1,143,1)
        else:
            if RSI(self.algo,'BIL',7) < RSI(self.algo,'IEF',7):
                Sort(self.algo,'SMADayRet',('SOXL','USD','TMF'),5,False,1,143,1)
            else:
                Sort(self.algo,'CumReturn',('EWZ','SPXS','SOXS','UCO','YCS'),5,True,1,143,1)
                
    def group_b_if_long_term_tlt_is_trending_down_safety_long_term_2_least_volatile(self):
        if SMADayRet(self.algo,'TLT',20) < 0:
            self.group_baa_risk_off_rising_rates_tmv_letf_basket()
        else:
            self.group_bab_risk_off_falling_rates_tmf_letf_basket()
            
    def group_baa_risk_off_rising_rates_tmv_letf_basket(self):
        if EMA(self.algo,'SPY',210) <= SMA(self.algo,'SPY',360):
            if RSI(self.algo,'TQQQ',10) < 30:
                Sort(self.algo,'SMADayRet',('TQQQ','SOXL','UPRO'),5,True,1,143,1)
            else:
                if CumReturn(self.algo, 'SPY', 2) <= -0.02:
                    Sort(self.algo,'CumReturn',('SPXS','TECS','SOXS','SQQQ','ERX'),5,False,1,143,1)
                else:
                    if CumReturn(self.algo,'SPXU',5) >= CumReturn(self.algo,'UPRO',4):
                        Sort(self.algo,'CumReturn',('SOXS','SQQQ','EPI'),5,True,1,143,1)
                    else:
                        if CumReturn(self.algo,'BIL',3) >= CumReturn(self.algo,'TMV',3):
                            Sort(self.algo,'SMADayRet',('TECL','SOXL','TNA','UPRO'),5,False,1,143,1)
                        else:
                            Sort(self.algo,'SMADayRet',('TECL','SOXL','TMV'),5,False,1,143,1)
        else:
            if SMADayRet(self.algo,'SPY',210) > SMADayRet(self.algo,'DBC',360):
                if RSI(self.algo,'TQQQ',11) > 77:
                    AH(self.algo,'UVXY',143,0.25)
                else:
                    if CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                        if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                            AH(self.algo,'UVXY',143,0.25)
                        else:
                            Sort(self.algo,'SMADayRet',('SOXL','TMV'),5,False,1,143,1)
                    else:
                        if RSI(self.algo,'BIL',7) < RSI(self.algo,'IEF',7):
                            Sort(self.algo,'SMADayRet',('TQQQ','SOXL','UPRO','TMV','TECL'),5,True,1,143,1)
                        else:
                            Sort(self.algo,'SMADayRet',('SOXL','UPRO'),22,False,1,143,1)
            else:
                self.group_defense_modified()
                
    def group_defense_modified(self):
        if STD(self.algo,'DBC',20) > STD(self.algo,'SPY',20):
            if STD(self.algo,'DBC',10) >= 3:
                if STD(self.algo,'TMV',5) <= STD(self.algo,'DBC',5):
                    AH(self.algo,'TMV',143,1)
                else:
                    AH(self.algo,'DBC',143,1)
            else:
                if RSI(self.algo,'BIL',7) < RSI(self.algo,'IEF',7):
                    Sort(self.algo,'SMADayRet',('TMV','SOXS','SPXU'),5,True,1,143,1)
                else:
                    Sort(self.algo,'CumReturn',('EFA','EEM','SPXS','SOXS','UCO','TMV'),5,False,1,143,1)
        else:
            if RSI(self.algo,'BIL',7) < RSI(self.algo,'IEF',7):
                Sort(self.algo,'SMADayRet',('EPI','SOXL','UPRO'),5,False,1,143,1)
            else:
                Sort(self.algo,'CumReturn',('EWZ','TECS','SOXS','EUO','YCS','TMV'),5,True,1,143,1)
                
    def group_bab_risk_off_falling_rates_tmf_letf_basket(self):
        if EMA(self.algo,'SPY',210) <= SMA(self.algo,'SPY',360):
            if CumReturn(self.algo, 'SPY', 2) <= -0.02:
                Sort(self.algo,'CumReturn',('SPXS','TECS','SOXS','SQQQ'),5,True,1,143,1)
            else:
                if CumReturn(self.algo,'SPXU',6) >= CumReturn(self.algo,'UPRO',3):
                    Sort(self.algo,'CumReturn',('BIL','AGG','TMF'),5,False,1,143,1)
                else:
                    Sort(self.algo,'SMADayRet',('TECL','TQQQ','SOXL','EWZ','TMF'),5,False,1,143,1)
        else:
            if SMADayRet(self.algo,'SPY',210) > SMADayRet(self.algo,'DBC',360):
                if EMA(self.algo,'SPY',210) > EMA(self.algo,'SPY',360):
                    if RSI(self.algo,'TQQQ',11) > 77:
                        AH(self.algo,'UVXY',143,1)
                    else:
                        if CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                            if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                                AH(self.algo,'UVXY',143,1)
                            else:
                                Sort(self.algo,'SMADayRet',('TECL','TQQQ','SPXL','EPI','SOXL','UPRO','QLD','EWZ','MVV','PUI','USD','TMF'),7,False,1,143,1)
                        else:
                            if RSI(self.algo,'BIL',7) < RSI(self.algo,'IEF',7):
                                Sort(self.algo,'SMADayRet',('TECL','SPXL','EPI','SOXL','UPRO','MVV'),7,False,1,143,1)
                            else:
                                Sort(self.algo,'CumReturn',('SOXS','TMF'),5,True,1,143,1)
                else:
                    Sort(self.algo,'RSI',('SPXS','SQQQ','TECS','SOXS'),5,False,1,143,1)
            else:
                self.group_defense_modified()

    def group_defense_modified(self):
        if STD(self.algo,'DBC',20) > STD(self.algo,'SPY',20):
            Sort(self.algo,'RSI',('SPXS','EPI','TECS','SOXS','SQQQ'),5,False,1,143,1)
        else:
            Sort(self.algo,'SMADayRet',('TECL','TQQQ','SOXL','TMF'),5,True,1,143,1)

#https://app.composer.trade/symphony/GSg2Fqr17Aw5V0Ba6efa/details

class ETFOnly6040V2CautiousFundSurfing3xwithV11BearBUYDIPSBullHFEARTQQQv04InvestCopyStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'TTT',30) > RSI(self.algo,'SHYG',30):
            self.bond_yield_risk_off()
        else:
            if STD(self.algo,'SPY',30) > STD(self.algo,'SPY',252):
                self.vol_risk_off()
            else:
                if CumReturn(self.algo, 'BND', 60) < -0.01:
                    AH(self.algo,'SHY',144,1) 
                else:
                    AH(self.algo,'SPY',144,1.0)
    
    def black_swan_catcher(self):
        Sort(self.algo,'STD',('SQQQ','TTT','SDS','BTAL','TMV','XLU'),5,False,3,144,1.0)
    
    def vol_risk_off(self):
        if RSI(self.algo,'VIXM',40) > 69:
            self.black_swan_catcher()
        else:
            AH(self.algo,'SHY',144,1.0)
    
    def bond_yield_risk_off(self):
        Sort(self.algo,'EMA',('USDU','BTAL','HDGE','SJB','URTY','TZA','ERX'),10,False,3,144,0.33)
        Sort(self.algo,'RSI',('SQQQ','TBF','TBT','SDY'),20,False,2,144,0.33)
        Sort(self.algo,'RSI',('SHV','SPLV','FAS','PDBC','XLY'),30,True,2,144,0.33)

#https://app.composer.trade/symphony/wsCOGKXEckd1OO8utNs6/details

class TMFMomentumStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_tmf_momentum()

    def group_tmf_momentum(self):
        if RSI(self.algo, 'QQQ', 10) > 80:
            AH(self.algo, 'VIXY', 145, 1)
        elif RSI(self.algo, 'SPY', 10) > 80:
            AH(self.algo, 'VIXY', 145, 1)
        elif RSI(self.algo, 'TMF', 10) < 32:
            AH(self.algo, 'TMF', 145, 1)
        elif RSI(self.algo, 'BIL', 30) < RSI(self.algo, 'TLT', 20):
            if EMA(self.algo, 'TMF', 8) < SMA(self.algo, 'TMF', 10):
                if RSI(self.algo, 'TMF', 10) > 72:
                    AH(self.algo, 'SHV', 145, 1)
                else:
                    AH(self.algo, 'TMF', 145, 1)
            else:
                if RSI(self.algo, 'TQQQ', 10) < 31:
                    AH(self.algo, 'TECL', 145, 1)
                else:
                    AH(self.algo, 'SHV', 145, 1)
        else:
            if RSI(self.algo, 'TQQQ', 10) < 31:
                AH(self.algo, 'TECL', 145, 1)
            else:
                AH(self.algo, 'SHV', 145, 1)
        
#https://app.composer.trade/symphony/i6xMQAqmefelIhXgtwcM/details

class INVMegafolioStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if SMA(self.algo,'QQQ',21) > SMA(self.algo,'QQQ',210):
            AH(self.algo,'QQQ',146,1)
        else:
            if RSI(self.algo,'TLT',60) < 50:
                AH(self.algo,'SHY',146,1) 
            else:
                AH(self.algo,'TLT',146,1)

#https://app.composer.trade/symphony/65YumFOfM8yaD1kFxiqm/details

class ISHPICKSSPXLSSTQQQvsBILSHYwsidewaysrecession2monthBULLlagtime34AR27SD30DD15threshholdStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        AHIV(self.algo,('AVGO','JNJ','PG','BIL','VV','BIL'),7,147,0.2)
        if GetCurrentPrice(self.algo,'BND') < SMA(self.algo,'BND',21):
            AH(self.algo,'BIL',147,0.2)
        else:
            AH(self.algo,'SPXL',147,0.2)
        if MaxDD(self.algo, 'VTI', 5) > 0.1:
            AH(self.algo,'BIL',147,0.2)
        else:
            AH(self.algo,'SPXL',147,0.2)
        if GetCurrentPrice(self.algo,'VOO') < SMA(self.algo,'VOO',46):
            AH(self.algo,'SPXS',147,0.2)
        else:
            AH(self.algo,'SPXL',147,0.2)
        if GetCurrentPrice(self.algo,'VOO') < SMA(self.algo,'VOO',77):
            AH(self.algo,'BIL',147,0.2)
        else:
            Sort(self.algo,'RSI',('TQQQ','SPXL'),14,False,1,147,0.2)

#https://app.composer.trade/symphony/p6f11dKfmpgPGg6EtGJJ/details

class HAACANARYDUALMOMENTUMBLACKSWANCATCHERStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.monthly_income_dividends_managed_futures()
    
    def monthly_income_dividends_managed_futures(self):
        AH(self.algo,'JEPI',148,0.5) 
        AH(self.algo,'DBMF',148,0.5)

#https://app.composer.trade/symphony/WAXmbfle6qDbFDMA3I51/details

class HAACANARYDUALMOMENTUMBLACKSWANCATCHERNowwithleverageStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if SMA(self.algo,'SPY',200) < GetCurrentPrice(self.algo,'SPY'):
            if RSI(self.algo,'TQQQ',14) > 75:
                AH(self.algo,'UVXY',149,1)
            else:
                if RSI(self.algo,'SPXL',10) > 80:
                    AH(self.algo,'UVXY',149,1)
                else:
                    if SMADayRet(self.algo,'TIP',365) >= 0:
                        self.offensive()
                    else:
                        self.defense()
        else:
            if RSI(self.algo,'SPY',10) < 30:
                AH(self.algo,'BIL',149,1)
            else:
                if RSI(self.algo,'UVXY',10) > 74:
                    if RSI(self.algo,'UVXY',10) < 84:
                        AH(self.algo,'UVXY',149,1)
                    else:
                        AH(self.algo,'BIL',149,1)
                else:
                    if SMADayRet(self.algo,'TIP',365) >= 0:
                        self.offensive()
                    else:
                        self.defense()
        
    def defense(self):
        AH(self.algo,'BIL',149,1.0)
    
    def offensive(self):
        Sort(self.algo,'SMADayRet',('BIL','UPRO','TMF','TYD','DBC','DRN','EDC','EFO','TNA'),365,True,4,149,0.25)
        Sort(self.algo,'SMADayRet',('BIL','UPRO','TMF','TYD','DBC','DRN','EDC','EFO','TNA'),182,True,4,149,0.25)
        Sort(self.algo,'SMADayRet',('BIL','UPRO','TMF','TYD','DBC','DRN','EDC','EFO','TNA'),91,True,4,149,0.25)
        Sort(self.algo,'SMADayRet',('BIL','UPRO','TMF','TYD','DBC','DRN','EDC','EFO','TNA'),30,True,4,149,0.25)

#https://app.composer.trade/symphony/9YybDib7qOKhoWC9EKiE/details

class HEDGEDLEVERAGEDBONDSSTOCKSV4bReplaceUPROwithTQQQStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'TLT') > SMA(self.algo,'TLT',150):
            AH(self.algo,'TQQQ',150,0.33) 
            AH(self.algo,'TMF',150,0.33) 
            AH(self.algo,'PHDG',150,0.33)
        else:
            if GetCurrentPrice(self.algo,'TLT') < SMA(self.algo,'TLT',23):
                AH(self.algo,'TMV',150,0.5) 
                AH(self.algo,'UDOW',150,0.5)
            else:
                Sort(self.algo,'CumReturn',('TMF','UPRO','TMV','MOAT','BRK/B','USMV'),30,True,1,150,1)
        
#https://app.composer.trade/symphony/NToA1tPovi18QUdxXfYP/details

class HEDGEDLEVERAGEDBONDSSTOCKSV21aReplaceUPROwithSOXLStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'TLT') > SMA(self.algo,'TLT',150):
            if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
                AH(self.algo,'SOXL',151,0.33) 
                AH(self.algo,'TMF',151,0.33) 
                AH(self.algo,'PHDG',151,0.33)
            else:
                AH(self.algo,'TLT',151,1)
        else:
            if GetCurrentPrice(self.algo,'TLT') < SMA(self.algo,'TLT',23):
                Sort(self.algo,'CumReturn',('TMV','UDOW','BIL'),5,True,2,151,1)
            else:
                Sort(self.algo,'CumReturn',('TMF','UPRO','TMV','MOAT','BRK/B','USMV'),30,True,1,151,1)
        
#https://app.composer.trade/symphony/OgGpXD0FQzbCxz24khvP/details

class HEDGEDLEVERAGEDBONDSSTOCKSV21BT1262012Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.exhibit_4_adaptive_asset_allocation_3_choose_2()
    
    def exhibit_4_adaptive_asset_allocation_3_choose_2(self):
        if CumReturn(self.algo,'SPY',126) > CumReturn(self.algo,'UUP',126):
            if CumReturn(self.algo,'UUP',126) > CumReturn(self.algo,'TLT',126):
                AHIV(self.algo,('SOXL','UUP'),21,152,1.0)
            else:
                AHIV(self.algo,('SOXL','TMF'),21,152,1.0)
        else:
            if CumReturn(self.algo,'SPY',126) > CumReturn(self.algo,'TLT',126):
                AHIV(self.algo,('UUP','SOXL'),21,152,1.0)
            else:
                AHIV(self.algo,('UUP','TMF'),21,152,1.0)
    
#https://app.composer.trade/symphony/dV4o25VsKVCfj8pDZcI9/details

class HEDGEDLEVERAGEDBONDSSTOCKSV42ReplaceUPROwithTECLTQQQandSOXLStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'TLT') > SMA(self.algo,'TLT',150):
            AH(self.algo,'TECL',153,0.2)
            AH(self.algo,'TQQQ',153,0.2)
            AH(self.algo,'SOXL',153,0.2)
            AH(self.algo,'TMF',153,0.2)
            AH(self.algo,'PHDG',153,0.2)
        else:
            if GetCurrentPrice(self.algo,'TLT') < SMA(self.algo,'TLT',23):
                AH(self.algo,'TMV',153,0.5) 
                AH(self.algo,'UDOW',153,0.5)
            else:
                Sort(self.algo,'CumReturn',('TMF','UPRO','TMV','MOAT','BRK/B','USMV'),30,True,1,153,1)
        
#https://app.composer.trade/symphony/bfm3RL7iIZy0GRqXsWzy/details

class HEDGEDLEVERAGEDBONDSSTOCKSV211BT1262012ReplaceUPROwithTECLTQQQandSOXLStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'TLT') > SMA(self.algo,'TLT',150):
            if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
                AH(self.algo,'TECL',154,0.2)
                AH(self.algo,'TQQQ',154,0.2)
                AH(self.algo,'SOXL',154,0.2)
                AH(self.algo,'TMF',154,0.2)
                AH(self.algo,'PHDG',154,0.2)
            else:
                AH(self.algo,'TLT',154,1)
        else:
            if GetCurrentPrice(self.algo,'TLT') < SMA(self.algo,'TLT',23):
                Sort(self.algo,'CumReturn',('TMV','UDOW','BIL'),5,True,2,154,1)
            else:
                Sort(self.algo,'CumReturn',('TMF','UPRO','TMV','MOAT','BRK/B','USMV'),30,True,1,154,1)
        
#https://app.composer.trade/symphony/0ECQqFHg7qnZ9q7LIvv0/details

class HODLStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        AH(self.algo,'META',155,0.125)
        AH(self.algo,'MSFT',155,0.125)
        AH(self.algo,'NVDA',155,0.125)
        AH(self.algo,'GOOG',155,0.125)
        AH(self.algo,'AMD',155,0.125) 
        AH(self.algo,'AMZN',155,0.125)
        self.group_small()
        self.group_crypto()
        self.group_pharma()

    def group_small(self):
        AH(self.algo,'SMCI',155,0.0625)  
        AH(self.algo,'LRCX',155,0.0625)

    def group_crypto(self):  
        AH(self.algo,'MARA',155,0.01845)
        AH(self.algo,'BITO',155,0.01845)
        AH(self.algo,'MSTR',155,0.01845)
        AH(self.algo,'EETH',155,0.01845)
        
    def group_pharma(self):
        AH(self.algo,'LLY',155,0.0625)
        AH(self.algo,'NVO',155,0.0625)

               
#https://app.composer.trade/symphony/EBwIN9y2OQmHI7ciJp2p/details

class HODLFundiesCryptostratDeez17JUL2023Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_daddy()
        self.group_dry_powder() 
        self.group_bangarang()
        
    def group_daddy(self):
        AH(self.algo,'UPRO',156,0.275)
        AH(self.algo,'TMF',156,0.225)
        
    def group_dry_powder(self):
        AH(self.algo,'BIL',156,0.25)
        
    def group_bangarang(self):  
        AHIV(self.algo,('TQQQ','SOXL'),90,156,0.25)

#https://app.composer.trade/symphony/1okaKQHMq2hTTAIlFapp/details

class LeveragedAppleLongTermInvestingeditedtouseAAPLinsteadofAAPUtobackto2010182Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if SMA(self.algo,'SPY',21) > SMA(self.algo,'SPY',210):
            AH(self.algo,'AAPL',157,1)
        else:
            if RSI(self.algo,'QQQ',10) < 30:
                AH(self.algo,'TQQQ',157,1)
            else:
                if GetCurrentPrice(self.algo,'QQQ') < SMA(self.algo,'QQQ',20):
                    Sort(self.algo,'RSI',('SQQQ','BSV'),10,True,1,157,1)
                else:
                    AH(self.algo,'AAPL',157,1)
    
#https://app.composer.trade/symphony/FonVuwvvWwR350m7Mc2Z/details

class LeveragedAdaptiveAssetAllocationGiantStepsRepaceUPROwithSOXLStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.exhibit_4_adaptive_asset_allocation_3_choose_2()
    
    def exhibit_4_adaptive_asset_allocation_3_choose_2(self):
        if CumReturn(self.algo,'SPY',126) > CumReturn(self.algo,'UUP',126):
            if CumReturn(self.algo,'UUP',126) > CumReturn(self.algo,'TLT',126):
                AHIV(self.algo,('SOXL','UUP'),21,158,1.0)
            else:
                AHIV(self.algo,('SOXL','TMF'),21,158,1.0)
        else:
            if CumReturn(self.algo,'SPY',126) > CumReturn(self.algo,'TLT',126):
                AHIV(self.algo,('UUP','SOXL'),21,158,1.0)
            else:
                AHIV(self.algo,('UUP','TMF'),21,158,1.0)

#https://app.composer.trade/symphony/P3CTBKLfWjpJiRXViuxI/details

class LeveragedAdaptiveAssetAllocationGiantStepsStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.exhibit_4_adaptive_asset_allocation_3_choose_2()
    
    def exhibit_4_adaptive_asset_allocation_3_choose_2(self):
        if CumReturn(self.algo,'SPY',126) > CumReturn(self.algo,'UUP',126):
            if CumReturn(self.algo,'UUP',126) > CumReturn(self.algo,'TLT',126):
                AHIV(self.algo,('UPRO','UUP'),21,159,1.0)
            else:
                AHIV(self.algo,('UPRO','TMF'),21,159,1.0)
        else:
            if CumReturn(self.algo,'SPY',126) > CumReturn(self.algo,'TLT',126):
                AHIV(self.algo,('UUP','UPRO'),21,159,1.0)
            else:
                AHIV(self.algo,('UUP','TMF'),21,159,1.0)
    
#https://app.composer.trade/symphony/AyfnADxTOP9JKb9Ddyyz/details

class Layer2HedgedBearMarketv11Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.layer_2_hedged_bear_market_v_11()
    
    def short_fund_surf_hedged(self):
        Sort(self.algo,'RSI',('SQQQ','SPXS','BSV'),10,True,1,160,1.0)
    
    def this_block_can_be_refined_it_is_the_current_bear_market_if_it_is_(self):
        Sort(self.algo,'RSI',('SHY','QQQ','SPY'),20,False,1,160,1.0)
    
    def short_fund_surf_directional(self):
        Sort(self.algo,'RSI',('SQQQ','SPXS'),10,True,1,160,1.0)
    
    def layer_3_bear_market_v11(self):
        if GetCurrentPrice(self.algo,'QQQ') > SMA(self.algo,'QQQ',20):
            if RSI(self.algo,'PSQ',10) < 30:
                self.short_fund_surf_directional()
            else:
                self.this_block_can_be_refined_it_is_the_current_bear_market_if_it_is_()
        else:
            self.short_fund_surf_hedged()

    def layer_4_standard_volatility_hedge_uupgld(self):
        AHIV(self.algo,('UUP','GLD'),30,160,1.0)
    
    def layer_2_hedged_bear_market_v_11(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            self.layer_4_standard_volatility_hedge_uupgld()
        else:
            if RSI(self.algo,'QQQ',10) < 30:
                self.layer_4_standard_volatility_hedge_uupgld()
            else:
                if RSI(self.algo,'SPY',10) < 30:
                    self.layer_4_standard_volatility_hedge_uupgld()
                else:
                    self.layer_3_bear_market_v11()

#https://app.composer.trade/symphony/Ad9gmLGgUCkx5oQCCZmk/details

class Layer1BlackSwanRSIStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.layer_1_black_swan_rsi()
    
    def layer_4_standard_volatility_hedge_uupgld(self):
        AHIV(self.algo,('UUP','GLD'),30,161,1.0)
    
    def layer_1_black_swan_rsi(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if RSI(self.algo,'TQQQ',10) > 79:
                AH(self.algo,'UVXY',161,1.0)
            else:
                if RSI(self.algo,'SPXL',10) > 79:
                    AH(self.algo,'UVXY',161,1.0)
                else:
                    self.layer_4_standard_volatility_hedge_uupgld()
        else:
            self.layer_4_standard_volatility_hedge_uupgld()

#https://app.composer.trade/symphony/cn4KvMbiPja54EHrWBao/details

class LABUDividendPaymentsRemovedBondsandAddedmoreDividendsPietrosManeosStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
       self.labu_insanity()
       self.group()
    
    def group(self):
        AH(self.algo,'SCHD',162,0.1)
        AH(self.algo,'VYM',162,0.1) 
        AH(self.algo,'NOBL',162,0.1) 
        AH(self.algo,'VIG',162,0.1) 
        AH(self.algo,'DGRW',162,0.1)
    
    def labu_insanity(self):
        if RSI(self.algo,'QQQ',10) > 80:
            AH(self.algo,'UVXY',162,0.5)
        else:
            if RSI(self.algo,'SPY',10) > 80:
                AH(self.algo,'UVXY',162,0.5)
            else:
                if RSI(self.algo,'TQQQ',10) < 31:
                    AH(self.algo,'TECL',162,0.5)
                else:
                    if RSI(self.algo,'TLT',10) > RSI(self.algo,'SPHB',20):
                        AH(self.algo,'LABU',162,0.5)
                    else:
                        AH(self.algo,'LABD',162,0.5)
    
#https://app.composer.trade/symphony/dSVpb6208YOvJtavFmVY/details

class LABUDividendPaymentsStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self._sedated_lab_rats_()
    
    def tribromoethanol_intraperitoneal_injection_(self):
        AH(self.algo,'KLAC',163,0.06)
        AH(self.algo,'LLY',163,0.06)
        AH(self.algo,'NVDA',163,0.06)
        AH(self.algo,'SMCI',163,0.06)
        Sort(self.algo,'SMADayRet',('KLAC','SMCI','NVDA','LLY','NVO','AMD'),10,True,1,163,0.12)
        Sort(self.algo,'SMADayRet',('KLAC','SMCI','NVDA','LLY','NVO','AMD'),21,True,1,163,0.12)

    def lab_rats_(self):
        if RSI(self.algo,'QQQ',10) > 80:
            AH(self.algo,'UVXY',163,0.5)
        else:
            if RSI(self.algo,'SPY',10) > 80:
                AH(self.algo,'UVXY',163,0.5)
            else:
                if RSI(self.algo,'TQQQ',10) < 31:
                    AH(self.algo,'TECL',163,0.5)
                else:
                    if RSI(self.algo,'TLT',10) > RSI(self.algo,'SPHB',20):
                        AH(self.algo,'LABU',163,0.25)
                    else:
                        AH(self.algo,'LABD',163,0.25)
                    if RSI(self.algo,'IEF',10) > RSI(self.algo,'IWM',16):
                        AH(self.algo,'LABU',163,0.25)
                    else:
                        AH(self.algo,'LABD',163,0.25)
    
    def _sedated_lab_rats_(self):
        self.lab_rats_()
        self.tribromoethanol_intraperitoneal_injection_()



#https://app.composer.trade/symphony/mewqlS4DHT2BPAv71PI1/details

class JEPQQQQYComboK1FreeStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if SMA(self.algo,'BITO',3) > SMA(self.algo,'BITO',7):
            Sort(self.algo,'CumReturn',('COIN','CONL','RIOT','MARA','MSTR'),12,True,3,164,1) 
        else:
            AH(self.algo,'BITI',164,1)
#https://app.composer.trade/symphony/LOoYRVtTyqZKEX9LXJCu/details

class JEPIDBMFTQQQSimpleMonthlyJefeStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
       self.jepidbmftqqq_simple_monthly_jefe()
    
    def jepidbmftqqq_simple_monthly_jefe(self):
        AH(self.algo,'JEPI',165,0.33)
        AH(self.algo,'DBMF',165,0.33)
        if SMA(self.algo,'QQQ',20) > SMA(self.algo,'QQQ',150):
            AH(self.algo,'TQQQ',165,0.33)
        else:
            AH(self.algo,'JEPI',165,0.16) 
            AH(self.algo,'DBMF',165,0.16)
    
#https://app.composer.trade/symphony/CzSYjmPntVomRwg3R9DN/details

class JamesDeepTestingofV01DEVBetaBallerDeezAR36596DD3781yrStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'BIL',7) < RSI(self.algo,'IEF',7):
            if RSI(self.algo,'SPY',7) > 72:
                AH(self.algo,'AA',166,1)
            else:
                AH(self.algo,'KO',166,1)
        else:
            if RSI(self.algo,'SPY',7) < 29:
                AH(self.algo,'XLK',166,1) 
            else:
                AH(self.algo,'SOXS',166,1)
#https://app.composer.trade/symphony/zHQdFCh7huREX9O0SaBk/details

class JJsCanaryLeverageLitev21Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if CumReturn(self.algo,'BND',60) > CumReturn(self.algo,'BIL',60):
            self.group_main_canary_off()
        else:
            self.group_main_canary_on_rsi_catcher_75_30()

    def group_main_canary_off(self):
        if EMA(self.algo,'VWO',365) > SMA(self.algo,'VWO',365):
            self.group_risk_on()
        else:
            self.group_risk_off()

    def group_risk_on(self):
        AH(self.algo,'TQQQ',167,1)

    def group_risk_off(self):
        AH(self.algo,'UPRO',167,0.5)
        AH(self.algo,'TMF',167,0.5)

    def group_main_canary_on_rsi_catcher_75_30(self):
        if RSI(self.algo,'SPY',10) > 75:
            AH(self.algo,'UVXY',167,1)
        else:
            if RSI(self.algo,'SPY',10) < 30:
                AH(self.algo,'UPRO',167,1)
            else:
                self.group_safe_haven_momentum()

    def group_safe_haven_momentum(self):
        Sort(self.algo,'CumReturn',('UUP','TMF','DBC','UGL','IEO','XLU'),30,True,3,167,1)

#https://app.composer.trade/symphony/tEq3s5F3AzjqcxwwvVVJ/details

class JosephStoryFundStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        AH(self.algo,'AMZN',168,0.33)
        AH(self.algo,'NFLX',168,0.21)
        AH(self.algo,'MSFT',168,0.13)
        AH(self.algo,'GOOG',168,0.12)
        AH(self.algo,'ADBE',168,0.06)
        AH(self.algo,'CRM',168,0.05)
        AH(self.algo,'AAPL',168,0.05)
        AH(self.algo,'BRK/B',168,0.03)
        AH(self.algo,'CROX',168,0.02)

#https://app.composer.trade/symphony/u5alZ35RwCHTcWOY238C/details

#https://app.composer.trade/symphony/u2LH9K4giH56C3D0hTAO/details

class LIQV1BBSignalCallforfireWalkontoTargetStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.bb_signal_call_for_fire_walk_onto_target()
    
    def soxl_if_10_day_rsi_bnd_bil_just_weiners(self):
        if RSI(self.algo,'BIL',6) < RSI(self.algo,'IEF',6):
            AH(self.algo,'TECL',170,1.0)
        else:
            AH(self.algo,'SOXS',170,1.0)
    
    def soxl_if_10_day_rsi_shy_sphb_else_weiners(self):
        if RSI(self.algo,'SHY',10) > RSI(self.algo,'SPHB',10):
            AH(self.algo,'SOXL',170,1.0)
        else:
            self.soxl_if_10_day_rsi_bnd_bil_just_weiners()
    
    def soxl_if_14_day_rsi_iei_sphb_else_weiners(self):
        if RSI(self.algo,'IEI',14) > RSI(self.algo,'SPHB',14):
            AH(self.algo,'SOXL',170,1.0)
        else:
            self.soxl_if_10_day_rsi_shy_sphb_else_weiners()
    
    def soxs_if_soxl_14_day_rsi_62(self):
        self.soxl_if_14_day_rsi_iei_sphb_else_weiners()
    
    def bb_signal_call_for_fire_walk_onto_target(self):
        self.soxs_if_soxl_14_day_rsi_62()

#https://app.composer.trade/symphony/lSQBZZQz4JSa3FtmR1G2/details

class LeWeinerDeez9JUN2023Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        Sort(self.algo,'MaxDD',('CLF','X','STLD','VALE','NUE','MT','SLX'),5,True,3,171,0.25)
        Sort(self.algo,'SMADayRet',('CLF','X','STLD','VALE','NUE','MT'),33,False,3,171,0.25)
        Sort(self.algo,'RSI',('CLF','X','STLD','VALE','NUE','MT','XME'),33,False,4,171,0.25)
        Sort(self.algo,'RSI',('BTAL','DBC','UVXY'),21,True,2,171,0.25)
    
#https://app.composer.trade/symphony/0MjEzggNFwCWBOYOKRYE/details

class LeveragedSPYMATrendScalingStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.spy_ma_trend_scaling()
    
    def risk_off(self):
        Sort(self.algo,'CumReturn',('TMF','TMV','BTAL','BIL','USDU','PDBC','IEO','UGL','XLU'),10,True,3,172,0.33)
    
    def leveraged_risk_on_basket(self):
        Sort(self.algo,'CumReturn',('SPXL','UDOW','TQQQ','SPXS'),10,True,2,172,0.33)
    
    def c20(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',20):
            self.leveraged_risk_on_basket()
        else:
            self.risk_off()

    def A50200(self):
        if SMA(self.algo,'SPY',50) > SMA(self.algo,'SPY',200):
            self.leveraged_risk_on_basket()
        else:
            self.risk_off()
    
    def A2050(self):
        if SMA(self.algo,'SPY',20) > SMA(self.algo,'SPY',50):
            self.leveraged_risk_on_basket()
        else:
            self.risk_off()
    
    def spy_ma_trend_scaling(self):
        self.A2050()
        self.A50200()
        self.c20()


#https://app.composer.trade/symphony/NJBy15U3zIlBmxyH8qFF/details

class LeveragedAppleLongTermInvestingStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if SMA(self.algo,'SPY',21) > SMA(self.algo,'SPY',210):
            AH(self.algo,'AAPU',173,1)
        else:
            if RSI(self.algo,'QQQ',10) < 30:
                AH(self.algo,'TQQQ',173,1)
            else:
                if GetCurrentPrice(self.algo,'QQQ') < SMA(self.algo,'QQQ',20):
                    Sort(self.algo,'RSI',('SQQQ','BSV'),10,True,1,173,1)
                else:
                    AH(self.algo,'AAPU',173,1)

#https://app.composer.trade/symphony/ArMJczSeFb5scRMhVa93/details

class LABRatFTLTStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.lab_rat_ftlt()
    
    def lab_rat_ftlt_no_tmf_check(self):
        if RSI(self.algo,'IEF',11) > RSI(self.algo,'IWM',16):
            AH(self.algo,'LABU',174,1.0)
        else:
            AH(self.algo,'LABD',174,1.0)
    
    def lab_rat_ftlt_tmf_check(self):
        if RSI(self.algo,'TMF',14) > 60:
            if RSI(self.algo,'IEF',11) < RSI(self.algo,'IWM',16):
                AH(self.algo,'LABU',174,1.0)
            else:
                AH(self.algo,'LABD',174,1.0)
        else:
            if RSI(self.algo,'IEF',11) > RSI(self.algo,'IWM',16):
                AH(self.algo,'LABU',174,1.0)
            else:
                AH(self.algo,'LABD',174,1.0)
    
    def lab_rat_ftlt(self):
        if RSI(self.algo,'SPY',10) > 71:
            self.lab_rat_ftlt_tmf_check()
        else:
            self.lab_rat_ftlt_no_tmf_check()

#https://app.composer.trade/symphony/IkxJFt3uB1G7Sp7UGXAm/details

class MonthlyIncomeDividendsManagedFuturesStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.monthly_income_dividends_managed_futures()
    
    def monthly_income_dividends_managed_futures(self):
        AH(self.algo,'JEPI',175,0.5) 
        AH(self.algo,'DBMF',175,0.5)
    
#https://app.composer.trade/symphony/3HvKhMMNxkFXUlkdPTGb/details

class MonthlyIncomeDividendsManagedFuturesTopDrawdownStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        
        AH(self.algo,'JEPI',176,0.5)
        AH(self.algo,'DBMF',176,0.5)
    
#https://app.composer.trade/symphony/FPWcQQFIs22zsnYxvgSQ/details

class MonthlyJNKcanaryStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1_safety_mix_michael_b()
        if RSI(self.algo,'SPY',14) >= 75:
            AH(self.algo,'UVXY',177,0.7)
        else:
            if CumReturn(self.algo,'JNK',30) > CumReturn(self.algo,'BIL',30):
                AH(self.algo,'SSO',177,0.7)
            else:
                if CumReturn(self.algo, 'TLT', 90) > 0.01:
                    AH(self.algo,'TMF',177,0.7)
                else:
                    if RSI(self.algo,'SPY',14) < 27:
                        AH(self.algo,'SSO',177,0.7)
                    else:
                        self.v1_safety_mix_michael_b()
    
    def v1_safety_mix_michael_b(self):
        AH(self.algo,'UUP',177,0.1)
        AH(self.algo,'GLD',177,0.1)
        AH(self.algo,'SHY',177,0.1)

#https://app.composer.trade/symphony/bfDWmOdCVXh1xHw92AdJ/details

class EaseUpOnTheGasV2aStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo, 'QQQ', 10) > 81:
            AH(self.algo, 'UVXY', 178, 1)
        elif RSI(self.algo, 'XLK', 10) > 80:
            AH(self.algo, 'UVXY', 178, 1)
        elif RSI(self.algo, 'VOOG', 10) > 79:
            AH(self.algo, 'UVXY', 178, 1)
        elif RSI(self.algo, 'SPY', 10) > 79:
            AH(self.algo, 'UVXY', 178, 1)
        else:
            self.dip_buy_strategy()

    def dip_buy_strategy(self):
        if RSI(self.algo, 'QQQ', 10) < 31:
            self.group_TECL()
        elif RSI(self.algo, 'XLK', 10) < 30:
            self.group_TECL()
        elif RSI(self.algo, 'SPY', 10) < 30:
            self.group_UPRO()
        else:
            self.group_BSC()

    def group_TECL(self):
        Sort(self.algo, 'RSI', ('TECL', 'TQQQ', 'BSV'), 10, False, 1, 178, 1)

    def group_UPRO(self):
        Sort(self.algo, 'RSI', ('UPRO', 'BSV'), 10, False, 1, 178, 1)

    def group_BSC(self):
        if RSI(self.algo, 'UVXY', 21) > 65:
            if RSI(self.algo, 'UVXY', 10) > 74:
                if RSI(self.algo, 'UVXY', 10) < 84:
                    AH(self.algo, 'UVXY', 178, 1)
                else:
                    AH(self.algo, 'TMF', 178, 1)
            else:
                AH(self.algo, 'TMF', 178, 1)
        else:
            self.pre_BSC()

    def pre_BSC(self):
        if RSI(self.algo, 'VIXY', 10) > 99:
            AH(self.algo, 'VIXM', 178, 0.5)
            AH(self.algo, 'VIXY', 178, 0.5)
        else:
            self.group_Algos()

    def group_Algos(self):
        rsi_qq = RSI(self.algo, 'QQQ', 14)
        
        if rsi_qq > 75:
            AH(self.algo, 'UVXY', 178, 0.1)
        else:
            AH(self.algo, 'QQQ', 178, 0.1)

        if rsi_qq > 70:
            AH(self.algo, 'VIXY', 178, 0.1)
        else:
            AH(self.algo, 'QQQ', 178, 0.1)

        if rsi_qq > 85:
            AH(self.algo, 'UVXY', 178, 0.1)
        else:
            AH(self.algo, 'QQQ', 178, 0.1)

        if rsi_qq > 80:
            AH(self.algo, 'UVXY', 178, 0.1)
        else:
            AH(self.algo, 'QQQ', 178, 0.1)

        if rsi_qq > 65:
            AH(self.algo, 'VIXY', 178, 0.1)
        else:
            AH(self.algo, 'QQQ', 178, 0.1)

        if rsi_qq > 35:
            AH(self.algo, 'QQQ', 178, 0.1)
        else:
            AH(self.algo, 'QLD', 178, 0.1)

        if rsi_qq > 30:
            AH(self.algo, 'QQQ', 178, 0.1)
        else:
            AH(self.algo, 'QLD', 178, 0.1)

        if rsi_qq > 25:
            AH(self.algo, 'QQQ', 178, 0.1)
        else:
            AH(self.algo, 'TQQQ', 178, 0.1)

        if rsi_qq > 20:
            AH(self.algo, 'QQQ', 178, 0.1)
        else:
            AH(self.algo, 'TQQQ', 178, 0.1)

        if rsi_qq > 15:
            AH(self.algo, 'QQQ', 178, 0.1)
        else:
            AH(self.algo, 'TQQQ', 178, 0.1)

#https://app.composer.trade/symphony/IqJTE7YuvhB2icgCVpIR/details

class MuricaStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        AH(self.algo,'DIS',179,0.1)
        AH(self.algo,'AAPL',179,0.1)
        AH(self.algo,'GOOGL',179,0.1)
        AH(self.algo,'AMZN',179,0.1)
        AH(self.algo,'PG',179,0.1)
        AH(self.algo,'KO',179,0.1)
        AH(self.algo,'JNJ',179,0.1) 
        AH(self.algo,'UNH',179,0.1) 
        AH(self.algo,'HD',179,0.1) 
        AH(self.algo,'XOM',179,0.1)

#https://app.composer.trade/symphony/lujjuK02wSBHmN5RpSUy/details

class MagicInternetMoneyCONSwithCONSv100RRV1a1515BBMIMCONSStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if CumReturn(self.algo, 'SPY', 20) > -0.01:
            AH(self.algo,'SSO',180,0.7)
            self.v11_low_beta_one_liner_no_k1_edition1()
        else:
            self.v11_low_beta_one_liner_no_k1_edition2()
        
    def v11_low_beta_one_liner_no_k1_edition1(self):
        Sort(self.algo,'CumReturn',('PDBC','GLD','TLT','SHY','XLE','IEF','XLV','TBF','XLP','EXG'),150,True,4,180,0.1)
        Sort(self.algo,'CumReturn',('PDBC','GLD','TLT','SHY','XLE','IEF','XLV','TBF','XLP','EXG'),100,True,4,180,0.1)
        Sort(self.algo,'CumReturn',('PDBC','GLD','TLT','SHY','XLE','IEF','XLV','TBF','XLP','EXG'),50,True,4,180,0.1)
    
    def v11_low_beta_one_liner_no_k1_edition2(self):
        Sort(self.algo,'CumReturn',('PDBC','GLD','TLT','SHY','XLE','IEF','XLV','TBF','XLP','EXG'),150,True,4,180,0.1)
        Sort(self.algo,'CumReturn',('PDBC','GLD','TLT','SHY','XLE','IEF','XLV','TBF','XLP','EXG'),100,True,4,180,0.1)
        Sort(self.algo,'CumReturn',('PDBC','GLD','TLT','SHY','XLE','IEF','XLV','TBF','XLP','EXG'),50,True,4,180,0.1)
    
#https://app.composer.trade/symphony/WvEvmKNg49DcCrqqksFP/details

class MagicInternetMoneyGainTrainStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.magic_internet_money_gain_train()
    
    def deez_gain_train_hedge(self):
        if EMA(self.algo,'UUP',42) > EMA(self.algo,'UUP',100):
            AH(self.algo,'USDU',181,1.0)
        else:
            Sort(self.algo,'STD',('BIL','SOXL','PDBC'),14,True,2,181,1.0)
    
    def curet_search(self):
        Sort(self.algo,'CumReturn',('BITO','MSTR','COIN'),21,True,1,181,1.0)

    def biti_bot(self):
        if RSI(self.algo,'BITO',14) > 60:
            AH(self.algo,'BITI',181,1.0)
        else:
            if CumReturn(self.algo, 'BITI', 1) <= -0.01:
                AH(self.algo,'MSTR',181,1.0)
            else:
                if CumReturn(self.algo,'BITO',5) >= STD(self.algo,'BITO',10):
                    AH(self.algo,'BITI',181,1.0)
                else:
                    if CumReturn(self.algo,'BITO',2) >= STD(self.algo,'BITO',5):
                        if CumReturn(self.algo,'BITO',1) > CumReturn(self.algo,'BITI',3):
                            self.curet_search()
                        else:
                            self.deez_gain_train_hedge()
                    else:
                        self.deez_gain_train_hedge()
    
    def magic_internet_money_gain_train(self):
        if GetCurrentPrice(self.algo,'BITO') <= SMA(self.algo,'BITO',62):
            self.biti_bot()
        else:
            self.deez_gain_train_hedge()

#region imports
from AlgorithmImports import *
#endregion


# Your New Python File
from AlgorithmImports import *
from indicators import *
from main import YellowCatStrat

#https://app.composer.trade/symphony/0ZmKN2022XnilEaT1lCh/details

class MaxDrawdownBlackSwanCatcherStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.max_drawdown_black_swan_catcher()
    
    def smh_pop_bot(self):
        if RSI(self.algo,'SOXL',10) < 30:
            AH(self.algo,'USD',182,0.33)
        else:
            AH(self.algo,'BIL',182,0.33)

    def qqq_pop_bot(self):
        if RSI(self.algo,'TQQQ',10) > 80:
            AH(self.algo,'UVXY',182,0.33)
        else:
            if RSI(self.algo,'TQQQ',10) < 30:
                AH(self.algo,'QLD',182,0.33)
            else:
                AH(self.algo,'BIL',182,0.33)
    
    def spy_pop_bot(self):
        if RSI(self.algo,'SPXL',10) > 80:
            AH(self.algo,'UVXY',182,0.33)
        else:
            if RSI(self.algo,'SPXL',10) < 30:
                AH(self.algo,'SSO',182,0.33)
            else:
                AH(self.algo,'BIL',182,0.33)

    def v210_pop_bots_l_can_replace_bil_with_another_symphony(self):
        self.spy_pop_bot()
        self.qqq_pop_bot()
        self.smh_pop_bot()

    def not_a_black_swan_event(self):
        self.v210_pop_bots_l_can_replace_bil_with_another_symphony()
    
    def v210_pop_bots_l_dont_replace_bil(self):
        self.spy_pop_bot()
        self.qqq_pop_bot()
        self.smh_pop_bot()
    
    def max_drawdown_black_swan_catcher(self):
        if MaxDD(self.algo, 'SPY', 10) > 0.06:
            self.v210_pop_bots_l_dont_replace_bil()
        else:
            self.not_a_black_swan_event()

#https://app.composer.trade/symphony/KJqNBGxYyyKuCcEfdHhq/details

class MeanReversionComparisontoPythonCodeStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo 

    def Execute(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if RSI(self.algo,'TQQQ',10) > 79:
                AH(self.algo,'UVXY',183,1)
            else:
                AH(self.algo,'TQQQ',183,1)
        else:
            if RSI(self.algo,'TQQQ',10) > 79:
                AH(self.algo,'SPY',183,1) 
            else:
                AH(self.algo,'TQQQ',183,1)

#https://app.composer.trade/symphony/6jwz3IVGRl5wzXT6yolX/details

class MFormula50000MillionMarketCapStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        Sort(self.algo,'SMADayRet',['ABBV','MO','AMGN','VZ','CI','SCCO','SLB','QCOM','PM','PFE','MRK','MCK','MAR','MPC','LOW','LMT','KLAC','JNJ','HD','GILD','XOM','EOG','CVS','CMCSA','CSCO','CAT','BMY','BKNG','ADP','AMAT'],21,True,5,184,1)

#https://app.composer.trade/symphony/4nRRutmlzZpacQYQCrXs/details

class NVDAorSS40dRSIStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.nvda_or_ss_40d_rsi()
    
    def ss_40d_rsi(self):
        if RSI(self.algo,'VIXM',40) > 69:
            AH(self.algo,'SPXU',185,1.0)
        else:
            Sort(self.algo,'RSI',('MSFT','NVDA','XOM'),40,True,1,185,1.0)
    
    def huge_volatility(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.13:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.06:
                AH(self.algo,'SOXS',185,1.0)
            else:
                AH(self.algo,'NVDA',185,1.0)
        else:
            self.ss_40d_rsi()
    
    def nvda_or_ss_40d_rsi(self):
        if RSI(self.algo,'TQQQ',10) > 79:
            AH(self.algo,'SOXS',185,1.0)
        else:
            self.huge_volatility()

#https://app.composer.trade/symphony/xs2tMR83iZKleF8aaPYO/details

class NVDAorLLYStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.nvda_or_lly()
    
    def huge_volatility(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.13:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.06:
                AH(self.algo,'SOXS',186,1.0)
            else:
                AH(self.algo,'NVDA',186,1.0)
        else:
            AH(self.algo,'LLY',186,1.0)
    
    def nvda_or_lly(self):
        if RSI(self.algo,'TQQQ',10) > 79:
            AH(self.algo,'SOXS',186,1.0)
        else:
            self.huge_volatility()

#https://app.composer.trade/symphony/6YuuMVqE4bVmWwVfZlpp/details

class NVDAor40dRSITop2Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.nvda_or_40d_rsi_sort_top_2()
    
    def A40d_rsi_sort_top_2(self):
        if RSI(self.algo,'VIXM',40) > 69:
            AH(self.algo,'SPXU',187,1.0)
        else:
            Sort(self.algo,'RSI',('AAPL','MSFT','NVDA','AMD','XOM','NFLX','META','TSLA','AMZN','GOOGL','COIN'),40,True,2,187,1.0)

    def huge_volatility(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.13:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.06:
                AH(self.algo,'SOXS',187,1.0)
            else:
                AH(self.algo,'NVDA',187,1.0)
        else:
            self.A40d_rsi_sort_top_2()
    
    def nvda_or_40d_rsi_sort_top_2(self):
        if RSI(self.algo,'TQQQ',10) > 79:
            AH(self.algo,'SOXS',187,1.0)
        else:
            self.huge_volatility()

#https://app.composer.trade/symphony/a7YjUZVDLDCjblAdBHyB/details

class NoRSI1Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.no_rsi_1()
    
    def A3x_fund_surfing(self):
        Sort(self.algo,'SMADayRet',('YINN','EDC','GUSH','SQQQ','TQQQ','SPXL','UDOW','TMF','TMV'),21,True,2,188,1.0)
    
    def momentum_search_battleship(self):
        Sort(self.algo,'SMADayRet',('DBC','GLD','SLV','USO','WEAT','CORN','SH','PSQ','PDBC','COMT','KOLD','BOIL'),21,True,3,188,1.0)
    
    def no_rsi_1(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.12:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                Sort(self.algo,'CumReturn',('UVXY','TECS'),5,True,1,188,1.0)
            else:
                if MaxDD(self.algo, 'TMF', 10) < 0.07:
                    Sort(self.algo,'SMADayRet',('TECL','SVXY'),5,True,1,188,1.0)
                else:
                    Sort(self.algo,'RSI',('TECS','BTAL','EUO'),10,False,1,188,1.0)
        else:
            if MaxDD(self.algo, 'QQQ', 10) > 0.06:
                Sort(self.algo,'SMADayRet',('TECS','TMF','SVXY'),5,True,1,188,1.0)
            else:
                if MaxDD(self.algo, 'TMF', 10) > 0.07:
                    if EMA(self.algo,'DBC',100) > EMA(self.algo,'DBC',400):
                        self.momentum_search_battleship()
                    else:
                        self.A3x_fund_surfing()
                else:
                    self.A3x_fund_surfing()

#https://app.composer.trade/symphony/JhxIt8cH3uBhiNIIvpdQ/details

class NormalMarketStrategyStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'SMH') > SMA(self.algo,'SMH',200):
            AH(self.algo,'SMH',189,1)
        else:
            if GetCurrentPrice(self.algo,'SMH') < SMA(self.algo,'SMH',20):
                Sort(self.algo,'RSI',('SOXS','SHY'),10,True,1,189,1) 
            else:
                AH(self.algo,'SMH',189,1)
    
#https://app.composer.trade/symphony/CDOVdD8dYy8M1OQJfWiA/details

class NOLETFVOGv12ofRiskOnRiskOffHedgefundieNoK1okhi2umoreTMFmodInvestCopyStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'VIXM',40) > 69:
            self.risk_off_market_crash()
        else:
            if CumReturn(self.algo,'BND',60) > CumReturn(self.algo,'BIL',60):
                self.risk_on_normal_market_conditions()
            else:
                if CumReturn(self.algo,'TLT',20) < CumReturn(self.algo,'BIL',20):
                    self.risk_off_rising_rates()
                else:
                    self.risk_on_falling_rates_hfea_refined()
    
    def hfea_refined_risk_off(self):
        AH(self.algo,'BIL',190,1.0)
    
    def hfea_refined_risk_on(self):
        AH(self.algo,'SPY',190,0.5)
        AH(self.algo,'TLT',190,0.5)
    
    def risk_on_falling_rates_hfea_refined(self):
        if MaxDD(self.algo, 'SPY', 10) < 0.05:
            self.hfea_refined_risk_on()
        else:
            self.hfea_refined_risk_off()
    
    def risk_off_rising_rates(self):
        AH(self.algo,'USDU',190,0.5)
        Sort(self.algo,'RSI',('TBF','SH'),20,False,1,190,0.5)
    
    def risk_on_normal_market_conditions(self):
        AH(self.algo,'SPY',190,0.33) 
        AH(self.algo,'QQQ',190,0.33)
        AH(self.algo,'TLT',190,0.33)
    
    def risk_off_market_crash(self):
        AH(self.algo,'SHY',190,1.0)

#https://app.composer.trade/symphony/A1OHxnrHaBJojCvGzTj7/details

class NOLETFVofSandysGoldenDragonV20Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        Sort(self.algo,'CumReturn',('VNM','EWJ','EIDO','INDA','EEM','EEMS'),10,True,1,191,0.25)
        Sort(self.algo,'CumReturn',('VNM','EWJ','EIDO','INDA','EEM','EEMS'),10,True,2,191,0.25)
        Sort(self.algo,'CumReturn',('VNM','EWJ','EIDO','INDA','EEM','EEMS'),10,True,3,191,0.25)
        Sort(self.algo,'CumReturn',('VNM','EWJ','EIDO','INDA','EEM','EEMS'),10,True,4,191,0.25)

#https://app.composer.trade/symphony/DmmjNJrzhTRsA1KSxK2f/details

class NoLETFSandysGoldenDragonV44volhedgeStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'QQQ',10) >= 80:
            AH(self.algo,'UVXY',192,1)
        else:
            if RSI(self.algo,'QQQ',10) <= 31:
                AH(self.algo,'TECL',192,1)
            else:
                AH(self.algo,'IEI',192,0.25)
                AH(self.algo,'GLD',192,0.25) 
                AH(self.algo,'UUP',192,0.25) 
                AH(self.algo,'SCHD',192,0.25)
    
#https://app.composer.trade/symphony/CJunzoy3dZ63Q70Edojw/details

class NoBT2VixationSVIXinVISPYUFrameworkStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.junior_gold_rat_ftlt()
    
    def junior_gold_rat_ftlt_no_tmf_check(self):
        if RSI(self.algo,'IEF',11) > RSI(self.algo,'IWM',16):
            AH(self.algo,'JNUG',193,1.0)
        else:
            AH(self.algo,'JDST',193,1.0)
    
    def junior_gold_rat_ftlt_tmf_check(self):
        if RSI(self.algo,'TMF',14) > 60:
            if RSI(self.algo,'IEF',11) < RSI(self.algo,'IWM',16):
                AH(self.algo,'JNUG',193,1.0)
            else:
                AH(self.algo,'JDST',193,1.0)
        else:
            if RSI(self.algo,'IEF',11) > RSI(self.algo,'IWM',16):
                AH(self.algo,'JNUG',193,1.0)
            else:
                AH(self.algo,'JDST',193,1.0)
    
    def junior_gold_rat_ftlt(self):
        if RSI(self.algo,'SPY',10) > 71:
            self.junior_gold_rat_ftlt_tmf_check()
        else:
            self.junior_gold_rat_ftlt_no_tmf_check()

#https://app.composer.trade/symphony/3Jmc4S1TO2gAvdYi2UHO/details

class NewLoveStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.svix_sds_412022_to_present()
        self.svxy_vixm_1112011_to_212018()
    
    def svxy_vixm_1112011_to_212018(self):
        AHIV(self.algo,('QQQ','VIXM','SVXY'),30,194,0.5)
    
    def svix_sds_412022_to_present(self):
        AHIV(self.algo,('SVIX','SPXS'),30,194,0.5)

    
#https://app.composer.trade/symphony/FCF3aIo3m6y0D4WIoHsx/details

class NeosYieldMax5dCRTop1NeedsQQQIPWNStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        Sort(self.algo,'CumReturn',('TSLY','CONY','NVDY','AMDY','APLY','AMZY','OARK','DISO','GOOY','PYPY','MSFO','JPMO','XOMO','NFLY','FBY','SQY','MRNY','SPYI','CSHI','BNDI'),5,True,1,195,1)
    
#https://app.composer.trade/symphony/pUFwgKt2gQQemjxY84EL/details

class NavonodStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if CumReturn(self.algo, 'QQQ', 5) >= 0.04:
            AH(self.algo,'PSQ',196,1)
        else:
            if CumReturn(self.algo, 'QQQ', 5) <= -0.01:
                AH(self.algo,'BIL',196,1) 
            else:
                AH(self.algo,'TQQQ',196,1)

#https://app.composer.trade/symphony/lAQj9APlLISUGOnoCGGt/details

class NaturalGasStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.natural_gas()
    
    def natural_gas(self):
        if SMA(self.algo,'FCG',100) > SMA(self.algo,'FCG',500):
            AH(self.algo,'FCG',197,0.9)
            if GetCurrentPrice(self.algo,'UNG') > SMA(self.algo,'UNG',50):
                AH(self.algo,'BOIL',197,0.1)
            else:
                AH(self.algo,'KOLD',197,0.1)
        else:
            if SMA(self.algo,'UNG',50) < SMA(self.algo,'UNG',400):
                if GetCurrentPrice(self.algo,'UNG') < SMA(self.algo,'UNG',10):
                    AH(self.algo,'KOLD',197,0.5) 
                    AH(self.algo,'BIL',197,0.5)
                else:
                    AH(self.algo,'BIL',197,1.0)
            else:
                AH(self.algo,'UNG',197,1.0)

#https://app.composer.trade/symphony/VoBzCUKzKz6mr2yQecwc/details

class NasdySoxxMachineV10Deez7JUL227Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self._soxx_rsi_machine_deez_15nov226()
    
    def v_12_nasdaqx_deetf_deez_ar_83_dd_256_1jan2019(self):
        if RSI(self.algo,'SPY',14) > 77:
            AH(self.algo,'VIXM',198,1.0)
        else:
            if RSI(self.algo,'SPY',14) < 30:
                Sort(self.algo,'CumReturn',('TECL','TNA','SPXL'),45,True,2,198,1.0)
            else:
                Sort(self.algo,'RSI',('MSFT','AAPL','GD','RTX','NOC','AMZN','GOOGL','META','PEP','MSTR','NVDA','TSLA','AMD','INTC','NFLX','AMGN','CSCO','TMUS','AVGO','SBUX'),46,True,3,198,1.0)

    def _soxx_rsi_machine_deez_15nov226(self):
        if RSI(self.algo,'SOXX',10) > 73:
            AH(self.algo,'SOXS',198,1.0)
        else:
            if RSI(self.algo,'SOXX',2) < 42:
                if RSI(self.algo,'SOXL',10) < 57:
                    AH(self.algo,'SOXL',198,1.0)
                else:
                    AH(self.algo,'SOXS',198,1.0)
            else:
                self.v_12_nasdaqx_deetf_deez_ar_83_dd_256_1jan2019()

#https://app.composer.trade/symphony/xXYkU5kiiJi4yUMxoZRx/details

class NASDAQ2LinerNewbiestolearnShortCodeStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            AH(self.algo,'QQQ',199,1)
        else:
            if GetCurrentPrice(self.algo,'QLD') > SMA(self.algo,'QLD',20):
                AH(self.algo,'QLD',199,1)
            else:
                Sort(self.algo,'RSI',('BSV','QID'),10,True,1,199,1)
    
#https://app.composer.trade/symphony/IwTEpK4XTl4VdjDDKkRo/details

class OverboughtorOversoldSPYelseUVXYNowletsmakeitweirdStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            AH(self.algo,'QQQ',200,0.5) 
            AH(self.algo,'SPYG',200,0.5)
        else:
            if RSI(self.algo,'QQQ',10) < 30:
                AH(self.algo,'XLK',200,1)
            else:
                if GetCurrentPrice(self.algo,'SPY') < SMA(self.algo,'SPY',25):
                    Sort(self.algo,'RSI',('SH','TLT'),10,True,1,200,1)
                else:
                    AH(self.algo,'SHY',200,1)
            if RSI(self.algo,'QQQ',10) < 30:
                AH(self.algo,'XLK',200,1)
            else:
                if GetCurrentPrice(self.algo,'QQQ') < SMA(self.algo,'QQQ',20):
                    if CumReturn(self.algo, 'PSQ', 10) > 0.2:
                        AH(self.algo,'BSV',200,1)
                    else:
                        Sort(self.algo,'RSI',('PSQ','IEF'),10,True,1,200,1)
                else:
                    if RSI(self.algo,'PSQ',10) < 29:
                        AH(self.algo,'PSQ',200,1) 
                    else:
                        AH(self.algo,'QQQ',200,1)

#https://app.composer.trade/symphony/C8QUEQBKayzmaSBz7MAZ/details

class OverboughtorOversoldSPYelseUVXYStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'SPY',10) > 80:
            AH(self.algo,'UVXY',201,1)
        else:
            if RSI(self.algo,'SPY',10) < 30:
                AH(self.algo,'UPRO',201,1) 
            else:
                AH(self.algo,'SPY',201,1)
    
    
#https://app.composer.trade/symphony/DbxbzPBQvE84tXYyRP84/details

class Overboughtgroupv2bestasof114228Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'QQQ',10) > 81:
            self.overbought_group_3d_ma_v2_()
        else:
            AH(self.algo,'BIL',202,1)
    
    def overbought_group_3d_ma_v2_(self):
        Sort(self.algo,'SMADayRet',('TMF','XLP','SRTY','TLT'),3,True,2,202,1) 
    
#https://app.composer.trade/symphony/UtghzmzXlL6DD3FDEKu7/details

class OptimizedSMAandRSIBasedStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if SMA(self.algo,'BLK',10) > SMA(self.algo,'BLK',50):
            AHIV(self.algo,('BLK','VOX'),10,203,1)
        else:
            if RSI(self.algo,'JPM',10) < 30:
                AHIV(self.algo,('UVXY','TQQQ'),10,203,1)
            else:
                if SMA(self.algo,'TMV',10) > SMA(self.algo,'TMV',50):
                    AH(self.algo,'TMV',203,0.5)
                    if RSI(self.algo,'TMV',14) > 30:
                        AH(self.algo,'TMV',203,0.5)
                    else:
                        AH(self.algo,'TQQQ',203,0.5)
                else:
                    if SMA(self.algo,'SPY',10) > SMA(self.algo,'SPY',50):
                        AH(self.algo,'SPY',203,1)
                    else:
                        AH(self.algo,'QQQ',203,1)

#https://app.composer.trade/symphony/rsCffOM6Ynot1cc8svgB/details

class OperationMeatShieldPlusPureBSCatcherGarenPhillipsStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_operation_meat_shield()
        self.group_pure_bs_catcher()

    def group_operation_meat_shield(self):
        if RSI(self.algo,'COST',14) < 69:
            if MaxDD(self.algo, 'SPY', 5) > 0.12:
                AH(self.algo,'BIL',204,0.1)
            else:
                AH(self.algo,'COST',204,0.1)
        else:
            AH(self.algo,'BIL',204,0.1)

        if RSI(self.algo,'UNH',14) < 79:
            if MaxDD(self.algo, 'SPY', 5) > 0.12:
                AH(self.algo,'BIL',204,0.4)
            else:
                AH(self.algo,'UNH',204,0.4)
        else:
            AH(self.algo,'BIL',204,0.4)

    def group_pure_bs_catcher(self):
        if SMA(self.algo,'SPY',200) < GetCurrentPrice(self.algo,'SPY'):
            if RSI(self.algo,'TQQQ',14) > 75:
                AH(self.algo,'UVXY',204,0.5)
            else:
                if RSI(self.algo,'SPXL',10) > 80:
                    AH(self.algo,'UVXY',204,0.5)
                else:
                    AH(self.algo,'BSV',204,0.5)
        else:
            if RSI(self.algo,'SPY',10) < 30:
                AH(self.algo,'BSV',204,0.5)
            else:
                if RSI(self.algo,'UVXY',10) > 74:
                    if RSI(self.algo,'UVXY',10) < 84:
                        AH(self.algo,'UVXY',204,0.5)
                    else:
                        AH(self.algo,'BSV',204,0.5)
                else:
                    AH(self.algo,'BSV',204,0.5)

#https://app.composer.trade/symphony/FoQrUYquL40wnSJrfax5/details

class OldTechBacktestto1990Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        Sort(self.algo,'SMADayRet',('INTC','MSFT','COHU','CGNX','AMD','ADSK','AMAT','TXN','IBM','GE','HPQ'),60,True,3,205,0.51)
        AH(self.algo,'INTC',205,0.07)
        AH(self.algo,'MSFT',205,0.07)
        AH(self.algo,'TXN',205,0.07)
        AH(self.algo,'AMD',205,0.07)
        AH(self.algo,'HPQ',205,0.07) 
        AH(self.algo,'GE',205,0.07) 
        AH(self.algo,'IBM',205,0.07)

#https://app.composer.trade/symphony/sB0QNjnVjjCQdIpptNjQ/details

class OGv12ofRiskOnRiskOffHedgefundieNoK1okhi2umoreTMFmodStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'VIXM',40) > 69:
            self.risk_off_market_crash()
        else:
            if CumReturn(self.algo,'BND',60) > CumReturn(self.algo,'BIL',60):
                self.risk_on_normal_market_conditions()
            else:
                if CumReturn(self.algo,'TLT',20) < CumReturn(self.algo,'BIL',20):
                    self.risk_off_rising_rates()
                else:
                    self.risk_on_falling_rates_hfea_refined()
        
    def hfea_refined_risk_off(self):
        AH(self.algo,'BIL',206,1.0)
    
    def hfea_refined_risk_on(self):
        AH(self.algo,'UPRO',206,0.5)
        AH(self.algo,'TMF',206,0.5)

    def risk_on_falling_rates_hfea_refined(self):
        if MaxDD(self.algo, 'SPY', 10) < 0.05:
            self.hfea_refined_risk_on()
        else:
            self.hfea_refined_risk_off()
    
    def risk_off_rising_rates(self):
        AH(self.algo,'USDU',206,0.5)
        Sort(self.algo,'RSI',('SQQQ','TBF'),20,False,1,206,0.5)

    def risk_on_normal_market_conditions(self):
        Sort(self.algo,'RSI',('TECL','SOXL','FAS','TQQQ','UPRO'),10,False,3,206,0.55)
        AH(self.algo,'TMF',206,0.45)
    
    def risk_off_market_crash(self):
        AH(self.algo,'SHY',206,1.0)

#https://app.composer.trade/symphony/RHek4bySlnk47BFqRcH7/details

class OGv11BESTTQQQforthelongrunokhi2uCOMBOcollectionsimpleeditionsonlyStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'BIL',7) < RSI(self.algo,'IEF',5):
            Sort(self.algo,'SMADayRet',('ARKK','ARKG','ARKF','TARK'),4,False,1,207,1)
        else:
            AH(self.algo,'SARK',207,0.95)
            AHIV(self.algo,('ARKX','ARKQ'),14,207,0.05)
        
#https://app.composer.trade/symphony/EWuWWsgoR2aPIy3AaKkh/details

class OGPopBots21lBrianElOct28th223okhi2ulessBILmodStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.pop_bots_21_l_briane_l_oct_28th_223_okhi2u_less_bil_mod()
    
    def combined_pop_bot(self):
        if RSI(self.algo,'TQQQ',10) > 80:
            AH(self.algo,'UVXY',208,1.0)
        else:
            if RSI(self.algo,'SPXL',10) > 80:
                AH(self.algo,'UVXY',208,1.0)
            else:
                if RSI(self.algo,'TQQQ',10) < 30:
                    AH(self.algo,'TQQQ',208,1.0)
                else:
                    if RSI(self.algo,'SOXL',10) < 30:
                        AH(self.algo,'SOXL',208,1.0)
                    else:
                        if RSI(self.algo,'SPXL',10) < 30:
                            AH(self.algo,'SPXL',208,1.0)
                        else:
                            AH(self.algo,'BIL',208,1.0)
    
    def pop_bots_21_l_briane_l_oct_28th_223_okhi2u_less_bil_mod(self):
        self.combined_pop_bot()
    
#https://app.composer.trade/symphony/FmRMEGZBD3qUvvSchwj1/details

class OG2xEditionOfV11OfRiskOnRiskOffHedgefundieNoK1Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'VIXM',40) > 69:
            self.group_risk_off_market_crash()
        else:
            if CumReturn(self.algo,'BND',60) > CumReturn(self.algo,'BIL',60):
                self.group_risk_on_normal_market_conditions()
            else:
                if CumReturn(self.algo,'TLT',20) < CumReturn(self.algo,'BIL',20):
                    self.group_risk_off_rising_rates()
                else:
                    self.group_risk_on_falling_rates_hfea_refined()

    def group_risk_off_market_crash(self):
        AH(self.algo,'SHY',209,1)

    def group_risk_on_normal_market_conditions(self):
        Sort(self.algo,'RSI',('QLD','SSO','ROM','USD','TLT','DDM'),10,False,3,209,1)

    def group_risk_off_rising_rates(self):
        AH(self.algo,'USDU',209,0.5)
        self.group_dont_use_qid_because_it_triggers_a_bug_where_the_price_spikes_incorrectly_in_may_2018_for_fake_gains()

    def group_dont_use_qid_because_it_triggers_a_bug_where_the_price_spikes_incorrectly_in_may_2018_for_fake_gains(self):
        Sort(self.algo,'RSI',('SDS','TBF'),20,False,1,209,0.5)

    def group_risk_on_falling_rates_hfea_refined(self):
        if MaxDD(self.algo, 'SPY', 10) < 0.05:
            self.group_hfea_refined_risk_on()
        else:
            self.group_hfea_refined_risk_off()

    def group_hfea_refined_risk_on(self):
        AH(self.algo,'SSO',209,0.7)
        AH(self.algo,'TMF',209,0.3)

    def group_hfea_refined_risk_off(self):
        AH(self.algo,'BIL',209,1)

#https://app.composer.trade/symphony/u9b482QOYUIVbbHbtiGN/details

class ofNewBearBotsLeveragedSafetynoK1editionStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'UUP',7) > 50:
            Sort(self.algo,'RSI',('DG','DLTR'),7,False,1,210,1)
        else:
            Sort(self.algo,'RSI',('WMT','COST'),7,False,1,210,1)

#https://app.composer.trade/symphony/LHf1bGRdyxPr9B9B5HLf/details

class o4FishsRSIbasedassetallocationStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'SPY',10) > 80:
            AH(self.algo,'UVXY',211,1)
        else:
            if RSI(self.algo,'QQQ',10) > 81:
                AH(self.algo,'UVXY',211,1)
            else:
                self.rest_rsi()
    
    def rest_rsi(self):
        if RSI(self.algo,'VOO',14) > 70:
            AH(self.algo,'CURE',211,1.0)
        else:
            if RSI(self.algo,'TQQQ',14) < 30:
                AH(self.algo,'TQQQ',211,1.0)
            else:
                if RSI(self.algo,'VOO',14) > 40:
                    if RSI(self.algo,'VOO',14) < 60:
                        AH(self.algo,'QYLD',211,1.0)
                    else:
                        if RSI(self.algo,'VOO',14) > 60:
                            if RSI(self.algo,'VOO',14) < 70:
                                AH(self.algo,'SPUU',211,1.0)
                            else:
                                AH(self.algo,'VOO',211,1.0)
                        else:
                            AH(self.algo,'VOO',211,1.0)
                else:
                    AH(self.algo,'VOO',211,1.0)

#https://app.composer.trade/symphony/3i4cick0O18qknQfXH3X/details

class RenTecPublicStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.big_dumb_sort_v2()
    
    def big_dumb_sort_v2(self):
        if RSI(self.algo,'QQQ',10) > 40:
            if RSI(self.algo,'QQQ',10) < 77:
                Sort(self.algo,'SMADayRet',('ERX','RETL','DRN','FAZ','TMV','GUSH','TQQQ','SPXL','UDOW','NAIL','WANT','DPST','WEBL','TECL','TNA','FNGU','LLY','NVDA'),10,True,4,212,0.33)
                Sort(self.algo,'STD',('ERX','RETL','DRN','FAZ','TMV','GUSH','TQQQ','SPXL','UDOW','NAIL','WANT','WEBL','DPST','TECL','TNA','FNGU','LLY','NVDA'),10,False,4,212,0.33)
                Sort(self.algo,'MaxDD',('ERX','RETL','DRN','FAZ','TMV','GUSH','TQQQ','SPXL','UDOW','NAIL','WANT','WEBL','TECL','DPST','TNA','FNGU','LLY','NVDA'),10,False,4,212,0.33)
            else:
                AH(self.algo,'VIXY',212,1) 
        else:
            AH(self.algo,'BTAL',212,1.0)
    
#https://app.composer.trade/symphony/9EJ1uTB9LTUZc6UoQF9j/details

class RRSIEtcComboofEnergyFinancialHealthcareSymphsStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
       self.ceg()
       self.vst()
       self.jpm()
       self.thc()
    
    def thc(self):
        if RSI(self.algo,'THC',14) > 50:
            if CumReturn(self.algo, 'THC', 14) > 0.0:
                if EMA(self.algo,'THC',5) > EMA(self.algo,'THC',10):
                    AH(self.algo,'THC',213,0.25)
                else:
                    AHIV(self.algo,('TMV','SVXY'),3,213,0.25)
            else:
                AHIV(self.algo,('TMV','SVXY'),3,213,0.25)
        else:
            AHIV(self.algo,('TMV','SVXY'),3,213,0.25)
    
    def jpm(self):
        if RSI(self.algo,'JPM',14) > 65:
            if CumReturn(self.algo, 'JPM', 14) > 0.0:
                if EMA(self.algo,'JPM',5) > EMA(self.algo,'JPM',10):
                    AH(self.algo,'JPM',213,0.25)
                else:
                    AHIV(self.algo,('TMV','SVXY'),3,213,0.25)
            else:
                AHIV(self.algo,('TMV','SVXY'),3,213,0.25)
        else:
            AHIV(self.algo,('TMV','SVXY'),3,213,0.25)
    
    def vst(self):
        if RSI(self.algo,'VST',14) > 55:
            if CumReturn(self.algo, 'VST', 14) > 0.0:
                if EMA(self.algo,'VST',5) > EMA(self.algo,'VST',10):
                    AH(self.algo,'VST',213,0.25)
                else:
                    AHIV(self.algo,('TMV','SVXY'),3,213,0.25)
            else:
                AHIV(self.algo,('TMV','SVXY'),3,213,0.25)
        else:
            AHIV(self.algo,('TMV','SVXY'),3,213,0.25)
    
    def ceg(self):
        if RSI(self.algo,'CEG',14) > 60:
            if CumReturn(self.algo, 'CEG', 14) > 0.0:
                if EMA(self.algo,'CEG',5) > EMA(self.algo,'CEG',10):
                    AH(self.algo,'CEG',213,0.25)
                else:
                    AHIV(self.algo,('TMV','SVXY'),3,213,0.25)
            else:
                AHIV(self.algo,('TMV','SVXY'),3,213,0.25)
        else:
            AHIV(self.algo,('TMV','SVXY'),3,213,0.25)
#https://app.composer.trade/symphony/F5CdRaqu0KDd6HeQ2W4u/details

class RV1aMonotonicMicroblobK1FreeStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.just_run_this_ftlt_every_large_cap()
    
    def just_run_this_ftlt_every_large_cap(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if RSI(self.algo,'SPY',10) > 80:
                AH(self.algo,'VIXY',214,1.0)
            else:
                if RSI(self.algo,'QQQ',10) > 79:
                    AH(self.algo,'VIXY',214,1.0)
                else:
                    if RSI(self.algo,'XLK',10) > 79:
                        AH(self.algo,'VIXY',214,1.0)
                    else:
                        if RSI(self.algo,'IYY',10) > 79:
                            AH(self.algo,'VIXY',214,1.0)
                        else:
                            if RSI(self.algo,'VTV',10) > 79:
                                AH(self.algo,'VIXY',214,1.0)
                            else:
                                if RSI(self.algo,'XLP',10) > 75:
                                    AH(self.algo,'VIXY',214,1.0)
                                else:
                                    if RSI(self.algo,'XLF',10) > 80:
                                        AH(self.algo,'VIXY',214,1.0)
                                    else:
                                        if RSI(self.algo,'VOX',10) > 79:
                                            AH(self.algo,'VIXY',214,1.0)
                                        else:
                                            AHIV(self.algo,('LLY','NVO','V','JPM','WMT','UNH','MA','PG','JNJ','HD','MRK','COST'),20,214,1.0)
        else:
            if RSI(self.algo,'SOXX',10) < 30:
                AH(self.algo,'SOXL',214,1.0)
            else:
                if RSI(self.algo,'QQQ',10) < 30:
                    AH(self.algo,'TECL',214,1.0)
                else:
                    if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',30):
                        AHIV(self.algo,('LLY','NVO','V','JPM','WMT','UNH','MA','PG','JNJ','HD','MRK','COST'),20,214,1.0)
                    else:
                        AH(self.algo,'BTAL',214,1.0)
#https://app.composer.trade/symphony/JARfIfaVc7bBy5kyIYV3/details

class SSimpleTreasuryBearSVIXDaily1yrAR139Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        AHIV(self.algo,('TMV','SVIX'),3,215,1)
    
#https://app.composer.trade/symphony/1yafb3HZWXPigdXayU2R/details

class StockSurfingwLeverageStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.stock_surfing_w_leverage()
    
    def stock_surfing_w_leverage(self):
        if STD(self.algo,'SPY',21) < 1:
            Sort(self.algo,'RSI',('MSFU','AAPU'),21,False,1,216,0.5)
        else:
            AH(self.algo,'SHY',216,0.5)
        if STD(self.algo,'SPY',21) < 2:
            Sort(self.algo,'RSI',('MSFU','SHY'),21,False,1,216,0.5)
        else:
            AH(self.algo,'SHY',216,0.5)
    
#https://app.composer.trade/symphony/FNBPlbrt8a6MCvC5DRO0/details

class sV7BWCTechRotatorComboStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        Sort(self.algo,'CumReturn',('TSLY','CONY','NVDY','AMDY','APLY','AMZY','OARK','DISO','GOOY','PYPY','MSFO','JPMO','XOMO','NFLY','FBY','SQY','MRNY','SPYI','CSHI','BNDI'),5,True,1,217,1)
    
    
#https://app.composer.trade/symphony/C2Y8TkAsTUPdl9sT0xxT/details

class TDumpsterFireSmoothCriminal420aDeez6JUN227Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1a_magic_internet_money_A2x_qqq_ftlt()
    
    def bull_market_stock_selector(self):
        Sort(self.algo,'RSI',('BSV','QLD','SSO'),20,False,1,218,1.0)
    
    def bear_market_stock_selector(self):
        Sort(self.algo,'RSI',('QID','SDS','BSV'),10,False,1,218,1.0)
    
    def market_strategy(self):
        if MaxDD(self.algo, 'SPY', 10) > 0.06:
            self.bear_market_stock_selector()
        else:
            self.bull_market_stock_selector()
    
    def A2x_qqq_ftlt(self):
        if RSI(self.algo,'TQQQ',10) > 80:
            AH(self.algo,'UVXY',218,1.0)
        else:
            if RSI(self.algo,'TQQQ',10) < 30:
                AH(self.algo,'QLD',218,1.0)
            else:
                self.market_strategy()
    
    def biti_bot(self):
        if RSI(self.algo,'BITO',14) > 60:
            AH(self.algo,'BITI',218,1.0)
        else:
            if CumReturn(self.algo, 'BITI', 1) <= -0.01:
                AH(self.algo,'MSTR',218,1.0)
            else:
                if CumReturn(self.algo,'BITO',5) >= STD(self.algo,'BITO',10):
                    AH(self.algo,'BITI',218,1.0)
                else:
                    if CumReturn(self.algo,'BITO',2) >= STD(self.algo,'BITO',5):
                        if CumReturn(self.algo,'BITO',1) > CumReturn(self.algo,'BITI',3):
                            AH(self.algo,'MSTR',218,1.0)
                        else:
                            self.A2x_qqq_ftlt()
                    else:
                        self.A2x_qqq_ftlt()
    
    def v1a_magic_internet_money_A2x_qqq_ftlt(self):
        if GetCurrentPrice(self.algo,'BITO') <= SMA(self.algo,'BITO',62):
            self.biti_bot()
        else:
            self.A2x_qqq_ftlt()
    
#https://app.composer.trade/symphony/6XfjOVLuBKNuvSEW7nFV/details

class TESTPORT034LBTSlimelMBM10411239StD4428Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v2_direxion_stock_surfing()
    
    def stock_surf_bottom_1_5d_rsi(self):
        Sort(self.algo,'RSI',('SHY','AAPU','GGLL'),5,False,1,219,1.0)
    
    def tmvtmf_selector(self):
        if MaxDD(self.algo, 'TMV', 5) < 0.1:
            if MaxDD(self.algo, 'TMF', 5) < 0.1:
                self.stock_surf_bottom_1_5d_rsi()
            else:
                Sort(self.algo,'MaxDD',('TMF','TMV'),5,True,1,219,1.0)
        else:
            Sort(self.algo,'MaxDD',('TMF','TMV'),5,True,1,219,1.0)
    
    def stock_surf_bottom_1_20d_rsi(self):
        Sort(self.algo,'RSI',('SHY','MSFU'),20,False,1,219,1.0)
    
    def v2_direxion_stock_surfing(self):
        if RSI(self.algo,'UVXY',20) < 70:
            self.stock_surf_bottom_1_20d_rsi()
        else:
            self.tmvtmf_selector()
    
#https://app.composer.trade/symphony/7MuBzjNSVZr5gLJIsjZo/details

class TheAdaptiveDragonV101aStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1a_magic_internet_money_gain_train()
    
    def deez_gain_train_hedge(self):
        if EMA(self.algo,'UUP',42) > EMA(self.algo,'UUP',100):
            AH(self.algo,'USDU',220,1.0)
        else:
            Sort(self.algo,'STD',('BIL','SOXL','PDBC'),14,True,2,220,1.0)
    
    def biti_bot(self):
        if RSI(self.algo,'BITO',14) > 60:
            AH(self.algo,'BITI',220,1.0)
        else:
            if CumReturn(self.algo, 'BITI', 1) <= -0.01:
                AH(self.algo,'MSTR',220,1.0)
            else:
                if CumReturn(self.algo,'BITO',5) >= STD(self.algo,'BITO',10):
                    AH(self.algo,'BITI',220,1.0)
                else:
                    if CumReturn(self.algo,'BITO',2) >= STD(self.algo,'BITO',5):
                        if CumReturn(self.algo,'BITO',1) > CumReturn(self.algo,'BITI',3):
                            AH(self.algo,'MSTR',220,1.0)
                        else:
                            self.deez_gain_train_hedge()
                    else:
                        self.deez_gain_train_hedge()
    
    def v1a_magic_internet_money_gain_train(self):
        if GetCurrentPrice(self.algo,'BITO') <= SMA(self.algo,'BITO',62):
            self.biti_bot()
        else:
            self.deez_gain_train_hedge()
    
#https://app.composer.trade/symphony/AgAzL6qCNxWwVVfW20zs/details

class tV101bAmoebaLowDDVariationspicyDailyBTMar3022616770AR91DDDec12226Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if RSI(self.algo,'TQQQ',10) > 80:
                AH(self.algo,'UVXY',221,1)
            else:
                if RSI(self.algo,'SPY',10) > 80:
                    AH(self.algo,'UVXY',221,1)
                else:
                    if RSI(self.algo,'TQQQ',60) > 65:
                        AH(self.algo,'QQQ',221,0.275)
                        AH(self.algo,'TMF',221,0.225)
                    else:
                        if RSI(self.algo,'TQQQ',60) < 55:
                            AH(self.algo,'TQQQ',221,0.275)
                            AH(self.algo,'TMF',221,0.225)
                        else:
                            AH(self.algo,'QLD',221,1)
        else:
            if RSI(self.algo,'TQQQ',10) < 31:
                AH(self.algo,'TECL',221,1)
            else:
                AH(self.algo,'BIL',221,0.34)
                if GetCurrentPrice(self.algo,'QQQ') < SMA(self.algo,'QQQ',20):
                    Sort(self.algo,'RSI',('SQQQ','BSV'),10,True,1,221,0.165)
                    Sort(self.algo,'RSI',('SOXS','BSV'),10,True,1,221,0.165)
                else:
                    if RSI(self.algo,'SQQQ',10) < 31:
                        AH(self.algo,'SQQQ',221,0.33)
                    else:
                        if CumReturn(self.algo, 'QQQ', 10) > 0.055:
                            AH(self.algo,'SQQQ',221,0.33)
                        else:
                            Sort(self.algo,'RSI',('TQQQ','SOXL'),10,True,1,221,0.33)
                self.cost_unh()
        
    def cost_unh(self):
        AH(self.algo,'COST',221,0.165) 
        AH(self.algo,'UNH',221,0.165)
    
    
#https://app.composer.trade/symphony/D1jaxKiHUmUyY8yW5SWp/details

class UV1BWCMinVolatilityFundxantibeta228EditionStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        AH(self.algo,'FBL',222,0.167)
        AH(self.algo,'NVDL',222,0.167)
        AH(self.algo,'AAPU',222,0.167) 
        AH(self.algo,'MSFU',222,0.167) 
        AH(self.algo,'GGLL',222,0.167) 
        AH(self.algo,'AMZU',222,0.167)

    
#https://app.composer.trade/symphony/4A7jBeSjkF1L8XunRhOC/details

class V1aABetterBuytheDipsNasdaqbyGarenPhillipswDividendsStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1a_a_better_()
    
    def v1a_a_better_(self):
        if CumReturn(self.algo, 'QQQ', 5) < -0.06:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.05:
                AH(self.algo,'SQQQ',223,1.0)
            else:
                if RSI(self.algo,'TQQQ',10) > 31:
                    AH(self.algo,'SQQQ',223,1.0)
                else:
                    AH(self.algo,'TQQQ',223,1.0)
        else:
            if RSI(self.algo,'QQQ',10) > 80:
                AH(self.algo,'SQQQ',223,1.0)
            else:
                if RSI(self.algo,'QQQ',10) < 31:
                    AH(self.algo,'TQQQ',223,1.0)
                else:
                    Sort(self.algo,'RSI',('APLY','MSFO','NVDY','TSLY'),40,True,1,223,1.0)
#https://app.composer.trade/symphony/3fckZif8mr3EdWHCDb1C/details

class V1aAllWeatherCoreV1NewSOXLBallerStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.add_your_favorite_bsc_()
    
    def kmlm_v_vti(self):
        if SMADayRet(self.algo,'VTI',20) > SMADayRet(self.algo,'KMLM',20):
            Sort(self.algo,'STD',('SVIX','TECL'),20,False,1,224,1.0)
        else:
            Sort(self.algo,'STD',('VIXM','BTAL'),20,False,1,224,1.0)
    
    def add_your_favorite_bsc_(self):
        self.kmlm_v_vti()

#https://app.composer.trade/symphony/7E1vJSF3vDbE71kz8uwM/details

class V1aMagicInternetMoneyGainTrainStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1a_magic_internet_money_gain_train()
    
    def deez_gain_train_hedge(self):
        if EMA(self.algo,'UUP',42) > EMA(self.algo,'UUP',100):
            AH(self.algo,'USDU',225,1.0)
        else:
            Sort(self.algo,'STD',('BIL','SOXL','PDBC'),14,True,2,225,1.0)
    
    def biti_bot(self):
        if RSI(self.algo,'BITO',14) > 60:
            AH(self.algo,'BITI',225,1.0)
        else:
            if CumReturn(self.algo, 'BITI', 1) <= -0.01:
                AH(self.algo,'MSTR',225,1.0)
            else:
                if CumReturn(self.algo,'BITO',5) >= STD(self.algo,'BITO',10):
                    AH(self.algo,'BITI',225,1.0)
                else:
                    if CumReturn(self.algo,'BITO',2) >= STD(self.algo,'BITO',5):
                        if CumReturn(self.algo,'BITO',1) > CumReturn(self.algo,'BITI',3):
                            AH(self.algo,'MSTR',225,1.0)
                        else:
                            self.deez_gain_train_hedge()
                    else:
                        self.deez_gain_train_hedge()
    
    def v1a_magic_internet_money_gain_train(self):
        if GetCurrentPrice(self.algo,'BITO') <= SMA(self.algo,'BITO',62):
            self.biti_bot()
        else:
            self.deez_gain_train_hedge()

#https://app.composer.trade/symphony/50WBtLuze0G1A5mQJW8h/details

class V1BWCMinVolatilityFundxantibeta228EditionStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v2c_bitcoin_strategy_dereckn()
    
    def v2c_bitcoin_strategy_dereckn(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if GetCurrentPrice(self.algo,'BITO') > SMA(self.algo,'BITO',15):
                AH(self.algo,'BITO',226,1.0)
            else:
                AH(self.algo,'USDU',226,1.0)
        else:
            if GetCurrentPrice(self.algo,'BITO') > SMA(self.algo,'BITO',200):
                AH(self.algo,'HIBL',226,1.0)
            else:
                if RSI(self.algo,'BITO',10) < 30:
                    AH(self.algo,'BITO',226,1.0)
                else:
                    if GetCurrentPrice(self.algo,'BITO') < SMA(self.algo,'BITO',15):
                        Sort(self.algo,'RSI',('BITI','TLT','BSV','TBF'),10,True,1,226,1.0)
                    else:
                        if RSI(self.algo,'BITO',10) > 59:
                            AH(self.algo,'BITI',226,1.0)
                        else:
                            AH(self.algo,'HIBL',226,1.0)

#https://app.composer.trade/symphony/82ZyW1Dt5MjciWeX5gu6/details

class V1fMonotonicMicroblobK1FreeStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.magic_internet_money_golden_baller()
    
    def golden_bear(self):
        AH(self.algo,'UGL',227,0.33)
        AH(self.algo,'PSQ',227,0.33)
        AH(self.algo,'SH',227,0.33)
    
    def extremely_oversold_sp_low_rsi_double_check_with_bond_mkt_before_going_long(self):
        if RSI(self.algo,'SHY',10) < RSI(self.algo,'VTI',10):
            AH(self.algo,'SOXS',227,1.0)
        else:
            AH(self.algo,'SOXL',227,1.0)
    
    def semis(self):
        Sort(self.algo,'MaxDD',('SOXL','SMH'),6,True,1,227,1.0)
    
    def golden_baller(self):
        if RSI(self.algo,'BIL',10) < RSI(self.algo,'IEF',10):
            if RSI(self.algo,'SPY',7) > 76:
                AH(self.algo,'UGL',227,1.0)
            else:
                self.semis()
        else:
            if RSI(self.algo,'SPY',7) < 27:
                self.extremely_oversold_sp_low_rsi_double_check_with_bond_mkt_before_going_long()
            else:
                self.golden_bear()
    
    def curet_search(self):
        Sort(self.algo,'CumReturn',('BITO','MSTR','COIN'),21,True,1,227,1.0)
    
    def biti_bot(self):
        if RSI(self.algo,'BITO',14) > 60:
            AH(self.algo,'BITI',227,1.0)
        else:
            if CumReturn(self.algo, 'BITI', 1) <= -0.01:
                AH(self.algo,'MSTR',227,1.0)
            else:
                if CumReturn(self.algo,'BITO',5) >= STD(self.algo,'BITO',10):
                    AH(self.algo,'BITI',227,1.0)
                else:
                    if CumReturn(self.algo,'BITO',2) >= STD(self.algo,'BITO',5):
                        if CumReturn(self.algo,'BITO',1) > CumReturn(self.algo,'BITI',3):
                            self.curet_search()
                        else:
                            self.golden_baller()
                    else:
                        self.golden_baller()
    
    def magic_internet_money_golden_baller(self):
        if GetCurrentPrice(self.algo,'BITO') <= SMA(self.algo,'BITO',62):
            self.biti_bot()
        else:
            self.golden_baller()

#https://app.composer.trade/symphony/7c8IjqTSKmxfMH8g9IM3/details

class V1HobbitonHedgeFundsWeeklyBig5wWeeklyJEPIJediStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1_hobbiton_hedge_funds_weekly_big_5_janmay_227_list()
        self.v131_weekly_jepi_jedi_hibl_aggressive()
    
    def v131_weekly_jepi_jedi_hibl_aggressive(self):
        if SMADayRet(self.algo,'BND',10) > SMADayRet(self.algo,'TBX',10):
            AH(self.algo,'JEPI',228,0.08)
            AH(self.algo,'DBMF',228,0.08)
            AH(self.algo,'HIBL',228,0.08)
            Sort(self.algo,'SMADayRet',('HIBL','TQQQ','TBX','SVXY'),7,True,1,228,0.25)
        else:
            AH(self.algo,'JEPI',228,0.125)
            AH(self.algo,'DBMF',228,0.125)
            Sort(self.algo,'RSI',('BTAL','UGL','USDU','TQQQ'),10,False,1,228,0.125)
            Sort(self.algo,'RSI',('DIG','VIXM','YCS','EUO','PST'),21,False,1,228,0.125)
    
    def v1_hobbiton_hedge_funds_weekly_big_5_janmay_227_list(self):
        Sort(self.algo,'RSI',('CRESY','TKC','FET','TDW','GLD','SLV','NUGT','PPLT','GGB','RIG','ARGT','NBR','PKX','BORR','XPRO','FRO','SMHI','SPY','FTI','GEOS','SPY','SPY','OIH','UGP','BTU','CEIX','ARCH','EC'),60,False,10,228,0.5)
    
#https://app.composer.trade/symphony/2O13d23cdB5z85FJ779i/details

class V2BitcoinStrategyDereckNStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v2_bitcoin_strategy_dereckn()
    
    def v2_bitcoin_strategy_dereckn(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if GetCurrentPrice(self.algo,'BITO') > SMA(self.algo,'BITO',15):
                AH(self.algo,'BITO',229,1.0)
            else:
                AH(self.algo,'SHY',229,1.0)
        else:
            if GetCurrentPrice(self.algo,'BITO') > SMA(self.algo,'BITO',200):
                AH(self.algo,'BITO',229,1.0)
            else:
                if RSI(self.algo,'BITO',10) < 30:
                    AH(self.algo,'BITO',229,1.0)
                else:
                    if GetCurrentPrice(self.algo,'BITO') < SMA(self.algo,'BITO',15):
                        Sort(self.algo,'RSI',('BITI','TLT','BSV','TBF'),10,True,1,229,1.0)
                    else:
                        if RSI(self.algo,'BITO',10) > 59:
                            AH(self.algo,'BITI',229,1.0)
                        else:
                            AH(self.algo,'BITO',229,1.0)
    
#https://app.composer.trade/symphony/4uMVWJrddMUR6zrJGg2V/details

class V2cBitcoinStrategyDereckNStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v2c_bitcoin_strategy_dereckn()
    
    def v2c_bitcoin_strategy_dereckn(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if GetCurrentPrice(self.algo,'BITO') > SMA(self.algo,'BITO',15):
                AH(self.algo,'BITO',230,1.0)
            else:
                AH(self.algo,'USDU',230,1.0)
        else:
            if GetCurrentPrice(self.algo,'BITO') > SMA(self.algo,'BITO',200):
                AH(self.algo,'HIBL',230,1.0)
            else:
                if RSI(self.algo,'BITO',10) < 30:
                    AH(self.algo,'BITO',230,1.0)
                else:
                    if GetCurrentPrice(self.algo,'BITO') < SMA(self.algo,'BITO',15):
                        Sort(self.algo,'RSI',('BITI','TLT','BSV','TBF'),10,True,1,230,1.0)
                    else:
                        if RSI(self.algo,'BITO',10) > 59:
                            AH(self.algo,'BITI',230,1.0)
                        else:
                            AH(self.algo,'HIBL',230,1.0)
    
#https://app.composer.trade/symphony/1nsDEkExoBRHVyYF2kWD/details

class V2dBitcoinStrategyDereckNStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v2d_bitcoin_strategy_dereckn()
    
    def v2d_bitcoin_strategy_dereckn(self):
        if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
            if GetCurrentPrice(self.algo,'BITO') > SMA(self.algo,'BITO',15):
                AH(self.algo,'BITO',231,1.0)
            else:
                AH(self.algo,'USDU',231,1.0)
        else:
            if GetCurrentPrice(self.algo,'BITO') > SMA(self.algo,'BITO',200):
                AH(self.algo,'HIBL',231,1.0)
            else:
                if RSI(self.algo,'BITO',10) < 30:
                    AH(self.algo,'BITO',231,1.0)
                else:
                    if GetCurrentPrice(self.algo,'BITO') < SMA(self.algo,'BITO',15):
                        Sort(self.algo,'RSI',('BITI','TMV'),10,True,1,231,1.0)
                    else:
                        if RSI(self.algo,'BITO',10) > 59:
                            AH(self.algo,'USDU',231,1.0)
                        else:
                            AH(self.algo,'HIBL',231,1.0)
    
#https://app.composer.trade/symphony/6WWFGt4yIKRaj6E9wGwZ/details

class V2DirexionStockSurfingStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v2_direxion_stock_surfing()
    
    def stock_surf_bottom_1_5d_rsi(self):
        Sort(self.algo,'RSI',('SHY','AAPU','GGLL'),5,False,1,232,1.0)
    
    def tmvtmf_selector(self):
        if MaxDD(self.algo, 'TMV', 5) < 0.1:
            if MaxDD(self.algo, 'TMF', 5) < 0.1:
                self.stock_surf_bottom_1_5d_rsi()
            else:
                Sort(self.algo,'MaxDD',('TMF','TMV'),5,True,1,232,1.0)
        else:
            Sort(self.algo,'MaxDD',('TMF','TMV'),5,True,1,232,1.0)
    
    def stock_surf_bottom_1_20d_rsi(self):
        Sort(self.algo,'RSI',('SHY','MSFU'),20,False,1,232,1.0)
    
    def v2_direxion_stock_surfing(self):
        if RSI(self.algo,'UVXY',20) < 70:
            self.stock_surf_bottom_1_20d_rsi()
        else:
            self.tmvtmf_selector()
    
#https://app.composer.trade/symphony/7hkOlDCyXyE9Dy4IJG4s/details

class V11NeoTrinityStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.magic_internet_money_A2x_qqq_ftlt()
    
    def bull_market_stock_selector(self):
        Sort(self.algo,'RSI',('BSV','QLD','SSO'),20,False,1,233,1.0)
    
    def bear_market_stock_selector(self):
        Sort(self.algo,'RSI',('QID','SDS','BSV'),10,False,1,233,1.0)
    
    def market_strategy(self):
        if MaxDD(self.algo, 'SPY', 10) > 0.06:
            self.bear_market_stock_selector()
        else:
            self.bull_market_stock_selector()
    
    def A2x_qqq_ftlt(self):
        if RSI(self.algo,'TQQQ',10) > 80:
            AH(self.algo,'UVXY',233,1.0)
        else:
            if RSI(self.algo,'TQQQ',10) < 30:
                AH(self.algo,'QLD',233,1.0)
            else:
                self.market_strategy()
    
    def curet_search(self):
        Sort(self.algo,'CumReturn',('BITO','MSTR','COIN'),21,True,1,233,1.0)
    
    def biti_bot(self):
        if RSI(self.algo,'BITO',14) > 60:
            AH(self.algo,'BITI',233,1.0)
        else:
            if CumReturn(self.algo, 'BITI', 1) <= -0.01:
                AH(self.algo,'MSTR',233,1.0)
            else:
                if CumReturn(self.algo,'BITO',5) >= STD(self.algo,'BITO',10):
                    AH(self.algo,'BITI',233,1.0)
                else:
                    if CumReturn(self.algo,'BITO',2) >= STD(self.algo,'BITO',5):
                        if CumReturn(self.algo,'BITO',1) > CumReturn(self.algo,'BITI',3):
                            self.curet_search()
                        else:
                            self.A2x_qqq_ftlt()
                    else:
                        self.A2x_qqq_ftlt()
    
    def magic_internet_money_A2x_qqq_ftlt(self):
        if GetCurrentPrice(self.algo,'BITO') <= SMA(self.algo,'BITO',62):
            self.biti_bot()
        else:
            self.A2x_qqq_ftlt()

#https://app.composer.trade/symphony/6HL8WOd2sKmzYDUKm66V/details

class v11SVXYFTLTfrontrunnerVIXYmodStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.eth()
    
    def eth(self):
        if RSI(self.algo,'TQQQ',10) < 31:
            AH(self.algo,'TECL',234,1.0)
        else:
            if RSI(self.algo,'QQQ',10) > 80:
                AH(self.algo,'UVXY',234,1.0)
            else:
                if RSI(self.algo,'SPY',10) > 80:
                    AH(self.algo,'UVXY',234,1.0)
                else:
                    if RSI(self.algo,'IEF',10) > RSI(self.algo,'PSQ',20):
                        if EMA(self.algo,'EETH',8) > SMA(self.algo,'EETH',24):
                            AH(self.algo,'EETH',234,1.0)
                        else:
                            AH(self.algo,'SHV',234,1.0)
                    else:
                        AH(self.algo,'SHV',234,1.0)
#region imports
from AlgorithmImports import *
#endregion


# Your New Python File
from AlgorithmImports import *
from indicators import *
from main import YellowCatStrat


#https://app.composer.trade/symphony/5c2tP0k505Jz3OH2XQjJ/details

class YieldMaxStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        Sort(self.algo,'SMADayRet',['TSLY','OARK','APLY','NVDY','AMZY','FBY','GOOY','NFLY','CONY','MSFO','DISO','XOMO','JPMO','AMDY','PYPY','SQY','MRNY'],21,True,4,29,1)

#https://app.composer.trade/symphony/cU4zGJ0lmQtFkcgtinPA/details

class AFourCornersv14nicomavisStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_four_corners()

    def group_four_corners(self):
        if RSI(self.algo, 'QQQ', 10) < 30:
            self.group_quick_oversold_bounce()
        else:
            if RSI(self.algo, 'XLK', 10) > 80:
                self.group_quick_overbought_pop()
            else:
                if RSI(self.algo, 'XLY', 10) > 80:
                    self.group_quick_overbought_pop()
                else:
                    self.group_core_logic_2x2()

    def group_quick_oversold_bounce(self):
        AH(self.algo, 'TQQQ', 240, 0.33)
        AH(self.algo, 'VGT', 240, 0.33)
        AH(self.algo, 'IEF', 240, 0.33)

    def group_quick_overbought_pop(self):
        AH(self.algo, 'TMF', 240, 0.25)
        AH(self.algo, 'VXX', 240, 0.25)
        AH(self.algo, 'XLU', 240, 0.25)
        AH(self.algo, 'XLP', 240, 0.25)

    def group_core_logic_2x2(self):
        if RSI(self.algo, 'QQQ', 100) > RSI(self.algo, 'VPU', 100):
            if CumReturn(self.algo, 'CORP', 60) > CumReturn(self.algo, 'BIL', 60):
                self.group_bull_market()
            else:
                self.group_hedge()
        else:
            if CumReturn(self.algo, 'CORP', 60) > CumReturn(self.algo, 'BIL', 60):
                self.group_hedge_alt()
            else:
                self.group_bear_market()

    def group_bull_market(self):
        AH(self.algo, 'UPRO', 240, 0.25)
        AH(self.algo, 'TQQQ', 240, 0.25)
        AH(self.algo, 'EEMS', 240, 0.25)
        AH(self.algo, 'EDV', 240, 0.25)

    def group_hedge(self):
        AH(self.algo, 'VT', 240, 0.25)
        self.group_yield()
        self.group_gold_mining()
        self.group_ief_vs_psq()

    def group_yield(self):
        AH(self.algo, 'VMBS', 240, 0.33*0.25)
        AH(self.algo, 'LQD', 240, 0.33*0.25)
        AH(self.algo, 'VPU', 240, 0.33*0.25)

    def group_gold_mining(self):
        AH(self.algo, 'GLD', 240, 0.5*0.25)
        AH(self.algo, 'GDX', 240, 0.5*0.25)

    def group_ief_vs_psq(self):
        if RSI(self.algo, 'IEF', 7) > RSI(self.algo, 'PSQ', 20):
            AH(self.algo, 'TQQQ', 240, 1*0.25)
        else:
            AH(self.algo, 'BTAL', 240, 1*0.25)

    def group_hedge_alt(self):
        AH(self.algo, 'VT', 240, 0.25)
        AH(self.algo, 'VWO', 240, 0.25)
        AH(self.algo, 'EDV', 240, 0.25)
        self.group_materials_mining()

    def group_materials_mining(self):
        AH(self.algo, 'VAW', 240, 0.33*0.25)
        AH(self.algo, 'PICK', 240, 0.33*0.25) 
        AH(self.algo, 'GDX', 240, 0.33*0.25)

    def group_bear_market(self):
        if RSI(self.algo, 'QQQ', 14) < 35:
            AH(self.algo, 'QQQ', 240, 0.5)
            AH(self.algo, 'VWO', 240, 0.5)
        else:
            AH(self.algo, 'BTAL', 240, 0.33) 
            AH(self.algo, 'LBAY', 240, 0.33)
            self.group_ief_vs_psq_alt()

    def group_ief_vs_psq_alt(self):
        if RSI(self.algo, 'IEF', 7) > RSI(self.algo, 'PSQ', 20):
            self.group_yield() 
        else:
            AH(self.algo, 'PSQ', 240, 0.33)
#https://app.composer.trade/symphony/iaI55QVOumI9g1ZZgF2Z/details

class AV14BentoBBGVStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1b_simple_sort_w_leverage()
    
    def bond_midterm_longterm(self):
        if RSI(self.algo, 'IEF', 200) < RSI(self.algo, 'TLT', 200):
            if RSI(self.algo, 'BND', 45) > RSI(self.algo, 'SPY', 45):
                AH(self.algo, 'TQQQ', 241, 1.0)
            else:
                AH(self.algo, 'BTAL', 241, 0.6)
                AH(self.algo, 'SQQQ', 241, 0.4)
        else:
            AH(self.algo, 'BTAL', 241, 0.6)
            AH(self.algo, 'SQQQ', 241, 0.4)
    
    def bond_stock(self):
        if RSI(self.algo, 'BND', 45) > RSI(self.algo, 'SPY', 45):
            AH(self.algo, 'TQQQ', 241, 1.0)
        else:
            AH(self.algo, 'BTAL', 241, 0.6)
            AH(self.algo, 'SQQQ', 241, 0.4)
    
    def normal_market(self):
        if MaxDD(self.algo, 'QQQ', 10) > 0.06:
            AH(self.algo, 'BTAL', 241, 0.6)
            AH(self.algo, 'SQQQ', 241, 0.4)
        else:
            if MaxDD(self.algo, 'TMF', 10) > 0.07:
                AH(self.algo, 'BTAL', 241, 0.6)
                AH(self.algo, 'SQQQ', 241, 0.4)
            else:
                if GetCurrentPrice(self.algo, 'QQQ') > SMA(self.algo, 'QQQ', 25):
                    AH(self.algo, 'TQQQ', 241, 1.0)
                else:
                    if RSI(self.algo, 'SPY', 60) > 50:
                        self.bond_stock()
                    else:
                        self.bond_midterm_longterm()
    
    def mean_rev(self):
        if RSI(self.algo, 'TQQQ', 10) < 32:
            AH(self.algo, 'SOXL', 241, 1.0)
        else:
            if MaxDD(self.algo, 'TMF', 10) < 0.07:
                AH(self.algo, 'SOXL', 241, 1.0)
            else:
                AH(self.algo, 'BTAL', 241, 0.6)
                AH(self.algo, 'SQQQ', 241, 0.4)
    
    def huge_volatility(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.13:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.06:
                AH(self.algo, 'SOXS', 241, 1.0)
            else:
                self.mean_rev()
        else:
            self.normal_market()
    
    def v1b_tqqq_or_not_blackswan_meanrev_bondsignal_replace_uvxy_w_soxs(self):
        if RSI(self.algo, 'TQQQ', 10) > 79:
            AH(self.algo, 'SOXS', 241, 1.0)
        else:
            self.huge_volatility()
    
    def v1b_tqqq_or_not_dash_of_sqqq_deez_replace_uvxy_w_soxs(self):
        self.v1b_tqqq_or_not_blackswan_meanrev_bondsignal_replace_uvxy_w_soxs()
    
    def v1b_simple_sort_w_leverage(self):
        if CumReturn(self.algo, 'SH', 10) > -0.01:
            self.v1b_tqqq_or_not_dash_of_sqqq_deez_replace_uvxy_w_soxs()
        else:
            Sort(self.algo,'RSI',('AAPU','MSFU','NVDA','TSLL','XOM'),40,True,1,241,1.0)

#https://app.composer.trade/symphony/e8es8trxGahs9TcNOlCG/details

class ALivePortfolioInvestCopyStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v21_holy_grail_wrsi_divination_without_vixen_cmp_mod_2_backtest_version()
    
    def buy_the_dips_sell_the_rips_v2_modded(self):
        if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
            Sort(self.algo,'RSI',('SQQQ','UVXY'),14,True,1,242,1.0)
        else:
            if RSI(self.algo, 'TQQQ', 10) < 30:
                AH(self.algo, 'TQQQ', 242, 1.0)
            else:
                AH(self.algo, 'BIL', 242, 1.0)
    
    def v21_holy_grail_wrsi_divination_without_vixen_cmp_mod_2_backtest_version(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            if RSI(self.algo, 'QQQ', 10) > 80:
                Sort(self.algo,'RSI',('UVXY','SQQQ'),14,True,1,242,0.5)
            else:
                if RSI(self.algo, 'QQQ', 21) < RSI(self.algo, 'BSV', 21):
                    Sort(self.algo,'SMADayRet',('BIL','TQQQ'),21,True,1,242,0.5)
                else:
                    if RSI(self.algo, 'QQQ', 10) > 65:
                        AH(self.algo, 'TQQQ', 242, 0.5)
                    else:
                        AH(self.algo, 'BIL', 242, 0.5)
            if RSI(self.algo, 'SPY', 10) > 80:
                Sort(self.algo,'RSI',('UVXY','SDOW'),14,True,1,242,0.5)
            else:
                if RSI(self.algo, 'SPY', 21) < RSI(self.algo, 'BSV', 21):
                    if RSI(self.algo, 'VIXM', 10) < 70:
                        Sort(self.algo,'MaxDD',('BIL','UPRO'),21,True,1,242,0.25)
                    else:
                        AH(self.algo, 'BIL', 242, 0.25)
                    if STD(self.algo, 'SPY', 14) < 1.5:
                        Sort(self.algo,'MaxDD',('BIL','UPRO'),21,True,1,242,0.25)
                    else:
                        AH(self.algo, 'BIL', 242, 0.25)
                else:
                    if RSI(self.algo, 'XLY', 10) > 70:
                        AH(self.algo, 'UPRO', 242, 0.5)
                    else:
                        AH(self.algo, 'BIL', 242, 0.5)
        else:
            if RSI(self.algo, 'SPY', 10) < 30:
                Sort(self.algo,'SMADayRet',('UPRO','TQQQ','BIL'),14,False,1,242,1.0)
            else:
                if CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                    self.buy_the_dips_sell_the_rips_v2_modded()
                else:
                    if GetCurrentPrice(self.algo, 'TQQQ') > SMA(self.algo, 'TQQQ', 21):
                        Sort(self.algo,'RSI',('TQQQ','AGG'),14,False,1,242,1.0)
                    else:
                        if SMADayRet(self.algo, 'AGG', 21) > SMADayRet(self.algo, 'BTAL', 21):
                            Sort(self.algo,'RSI',('AGG','SQQQ'),10,True,1,242,1.0)
                        else:
                            Sort(self.algo,'RSI',('TMF','SQQQ'),10,True,1,242,0.5)
                            Sort(self.algo,'RSI',('SQQQ','GLD','BTAL'),14,False,1,242,0.5)

#https://app.composer.trade/symphony/f0z0IUTT7HsxvHmZmSjx/details

class ALSVix3LBT22May2013InvestCopyStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.ls_vix_3_lbt_22_may_2013()
    
    def hedge(self):
        AHIV(self.algo, ('SH', 'IEF'), 30, 243, 0.33)
    
    def vixation_363a(self):
        AHIV(self.algo, ('DGRW', 'SH', 'DGRW'), 10, 243, 0.08)
    
    def shlong(self):
        AH(self.algo, 'TECL', 243, 0.04) 
        AH(self.algo, 'TQQQ', 243, 0.04)
    
    def dipsripsvix_vixation(self):
        if RSI(self.algo, 'TQQQ', 10) < 27:
            self.shlong()
        else:
            if RSI(self.algo, 'TECL', 10) < 29:
                self.shlong()
            else:
                if RSI(self.algo, 'UPRO', 10) < 29:
                    self.shlong()
                else:
                    if RSI(self.algo, 'TQQQ', 10) > 82:
                        AH(self.algo, 'UVXY', 243, 0.33)
                    else:
                        if RSI(self.algo, 'TECL', 10) > 80:
                            AH(self.algo, 'UVXY', 243, 0.33)
                        else:
                            if RSI(self.algo, 'UPRO', 10) > 78:
                                AH(self.algo, 'UVXY', 243, 0.33)
                            else:
                                self.vixation_363a()

    def ief_vs_psq(self):
        if RSI(self.algo, 'IEF', 10) > RSI(self.algo, 'PSQ', 20):
            self.shlong()
        else:
            self.vixation_363a()
    
    def tlt_vs_psq(self):
        if RSI(self.algo, 'TLT', 20) > RSI(self.algo, 'PSQ', 20):
            self.shlong()
        else:
            self.vixation_363a()
    
    def bnd_vs_qqq(self):
        if RSI(self.algo, 'BND', 15) > RSI(self.algo, 'QQQ', 15):
            self.shlong()
        else:
            self.vixation_363a()
    
    def agg_vs_qqq(self):
        if RSI(self.algo, 'AGG', 10) > RSI(self.algo, 'QQQ', 10):
            self.shlong()
        else:
            self.vixation_363a()
    
    def bvbvb(self):
        self.agg_vs_qqq()
        self.bnd_vs_qqq()
        self.tlt_vs_psq()
        self.ief_vs_psq()
    
    def bsc_logic(self):
        if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
            AH(self.algo, 'UVXY', 243, 0.33)
        else:
            self.shlong()
    
    def bsc_bvbvb(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.11:
            self.bsc_logic()
        else:
            if RSI(self.algo, 'VIXM', 10) > 70:
                self.bsc_logic()
            else:
                if STD(self.algo, 'QQQ', 10) > 3:
                    self.bsc_logic()
                else:
                    if STD(self.algo, 'SPY', 5) > 2.5:
                        self.bsc_logic()
                    else:
                        if RSI(self.algo, 'SVXY', 10) < 30:
                            self.bsc_logic()
                        else:
                            self.bvbvb()
    
    def ls_vix_3_lbt_22_may_2013(self):
        self.bsc_bvbvb()
        self.dipsripsvix_vixation()
        self.hedge()

#https://app.composer.trade/symphony/TOtApARMtmXfeejXxfNa/details

class ASSTraderSafetyOrchestrav11bStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if CumReturn(self.algo, 'XLF', 5) < 0.01:
            if EMA(self.algo, 'XLF', 2) < EMA(self.algo, 'XLF', 6):
                self.v1_xlf_bankruncatcher_k1_free()
            else:
                self.v1_xlf_bankruncatcher_k1_free()
                Sort(self.algo,'CumReturn',('BAC','HSBC','PNC','C','MS','JPM','BBVA','COF','WFC','GS','SAN','DB','BCS','MTB','RF','KEY','FITB','TFC'),10,True,1,244,0.125)
                Sort(self.algo,'STD',('BAC','HSBC','PNC','C','MS','JPM','BBVA','COF','WFC','GS','SAN','DB','BCS','MTB','RF','KEY','FITB','TFC'),200,True,3,244,0.125)
        else:
            self.v1_xlf_bankruncatcher_k1_free()
            Sort(self.algo,'CumReturn',('BAC','HSBC','PNC','C','MS','JPM','BBVA','COF','WFC','GS','SAN','DB','BCS','MTB','RF','KEY','FITB','TFC'),10,True,1,244,0.25)

    def v2_safety_mix_michael_b_uup_gld_xlp(self):
        Sort(self.algo,'CumReturn',('XLV','XLU','XLP','XLE','XLI','XLB','XLRE','GLD','USDU'),3,True,3,244,0.75)
    
    def bond_midterm_longterm(self):
        if RSI(self.algo, 'IEF', 200) < RSI(self.algo, 'TLT', 200):
            if RSI(self.algo, 'BND', 45) > RSI(self.algo, 'XLF', 45):
                AH(self.algo, 'FAS', 244, 0.75)
            else:
                self.v2_safety_mix_michael_b_uup_gld_xlp()
        else:
            self.v2_safety_mix_michael_b_uup_gld_xlp()

    def bond_stock(self):
        if RSI(self.algo, 'BND', 45) > RSI(self.algo, 'XLF', 45):
            AH(self.algo, 'FAS', 244, 0.75)
        else:
            self.v2_safety_mix_michael_b_uup_gld_xlp()
    
    def normal_market(self):
        if MaxDD(self.algo, 'XLF', 10) > 0.07:
            self.v2_safety_mix_michael_b_uup_gld_xlp()
        else:
            if MaxDD(self.algo, 'TMF', 10) > 0.07:
                self.v2_safety_mix_michael_b_uup_gld_xlp()
            else:
                if SMA(self.algo, 'XLF', 2) > EMA(self.algo, 'XLF', 7):
                    AH(self.algo, 'FAS', 244, 0.75)
                else:
                    if RSI(self.algo, 'XLF', 45) > 40:
                        self.bond_stock()
                    else:
                        self.bond_midterm_longterm()
    
    def mean_rev(self):
        if RSI(self.algo, 'FAS', 5) < 21:
            AH(self.algo, 'FAS', 244, 0.75)
        else:
            if MaxDD(self.algo, 'TMF', 10) < 0.07:
                AH(self.algo, 'FAS', 244, 0.75)
            else:
                self.v2_safety_mix_michael_b_uup_gld_xlp()
    
    def huge_volatility(self):
        if CumReturn(self.algo, 'FAS', 5) < -0.06:
            if CumReturn(self.algo, 'FAS', 1) > 0.04:
                AH(self.algo, 'FAZ', 244, 0.75)
            else:
                self.mean_rev()
        else:
            self.normal_market()
    
    def v1_xlf_bankruncatcher_k1_free(self):
        if RSI(self.algo, 'XLF', 10) > 80:
            AH(self.algo, 'FAZ', 244, 0.75)
        else:
            self.huge_volatility()
#https://app.composer.trade/symphony/QHpgMCavdogue5bR4kGL/details

class AExtendedMildFrontrunnerTLTCheck20111004Strategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.extended_mild_frontrunner_tlt_check_20111004()
    
    def tlt_tqqq(self):
        if SMA(self.algo, 'TLT', 5) < SMA(self.algo, 'TLT', 200):
            if CumReturn(self.algo, 'TLT', 10) > 0.01:
                AH(self.algo, 'TQQQ', 245,1.0)
            else:
                AH(self.algo, 'BIL', 245,1.0)
        else:
            AH(self.algo, 'XLP', 245,1.0)
    
    def extended_mild_frontrunner_tlt_check_20111004(self):
        if RSI(self.algo, 'QQQ', 10) > 79:
            AH(self.algo, 'UVXY', 245, 0.5) 
            AH(self.algo, 'XLP', 245, 0.5)
        else:
            if RSI(self.algo, 'VTV', 10) > 79:
                AH(self.algo, 'UVXY', 245, 0.5) 
                AH(self.algo, 'XLP', 245, 0.5)
            else:
                if RSI(self.algo, 'VOX', 10) > 79:
                    AH(self.algo, 'UVXY', 245, 0.5) 
                    AH(self.algo, 'XLP', 245, 0.5)
                else:
                    if MaxDD(self.algo, 'SPY', 9) <= 0.0:
                        AH(self.algo, 'UVXY', 245, 0.5) 
                        AH(self.algo, 'XLP', 245, 0.5)
                    else:
                        if RSI(self.algo, 'TECL', 10) > 79:
                            AH(self.algo, 'UVXY', 245, 0.5) 
                            AH(self.algo, 'XLP', 245, 0.5)
                        else:
                            if RSI(self.algo, 'XLP', 10) > 75:
                                AH(self.algo, 'UVXY', 245, 0.5) 
                                AH(self.algo, 'XLP', 245, 0.5)
                            else:
                                if RSI(self.algo, 'TQQQ', 10) > 79:
                                    AH(self.algo, 'UVXY', 245, 0.5) 
                                    AH(self.algo, 'XLP', 245, 0.5)
                                else:
                                    if RSI(self.algo, 'XLY', 10) > 80:
                                        AH(self.algo, 'UVXY', 245, 0.5) 
                                        AH(self.algo, 'XLP', 245, 0.5)
                                    else:
                                        if RSI(self.algo, 'FAS', 10) > 80:
                                            AH(self.algo, 'UVXY', 245, 0.5) 
                                            AH(self.algo, 'XLP', 245, 0.5)
                                        else:
                                            if RSI(self.algo, 'SPY', 10) > 80:
                                                AH(self.algo, 'UVXY', 245, 0.5)
                                                AH(self.algo, 'XLP', 245, 0.5)
                                            else:
                                                if CumReturn(self.algo, 'TQQQ', 6) < -0.12:
                                                    if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                                                        AH(self.algo, 'UVXY', 245, 0.5)
                                                        AH(self.algo, 'XLP', 245, 0.5)
                                                    else:
                                                        self.tlt_tqqq()
                                                else:
                                                    self.tlt_tqqq()

#https://app.composer.trade/symphony/XwHVpB37makJzUzQppmm/details

class Av11SVXYFTLTfrontrunnerUVXYmodStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v11_svxy_ftlt_frontrunner_uvxy_mod()
    
    def v11_svxy_ftlt_frontrunner_uvxy_mod(self):
        if RSI(self.algo, 'QQQE', 10) > 80:
            AH(self.algo, 'UVXY', 246, 1.0)
        else:
            if RSI(self.algo, 'VTV', 10) > 80:
                AH(self.algo, 'UVXY', 246, 1.0)
            else:
                if RSI(self.algo, 'VOX', 10) > 80:
                    AH(self.algo, 'UVXY', 246, 1.0)
                else:
                    if RSI(self.algo, 'TECL', 10) > 79:
                        AH(self.algo, 'UVXY', 246, 1.0)
                    else:
                        if RSI(self.algo, 'VOOG', 10) > 79:
                            AH(self.algo, 'UVXY', 246, 1.0)
                        else:
                            if RSI(self.algo, 'VOOV', 10) > 79:
                                AH(self.algo, 'UVXY', 246, 1.0)
                            else:
                                if RSI(self.algo, 'XLP', 10) > 75:
                                    AH(self.algo, 'UVXY', 246, 1.0)
                                else:
                                    if RSI(self.algo, 'TQQQ', 10) > 79:
                                        AH(self.algo, 'UVXY', 246, 1.0)
                                    else:
                                        if RSI(self.algo, 'XLY', 10) > 80:
                                            AH(self.algo, 'UVXY', 246, 1.0)
                                        else:
                                            if RSI(self.algo, 'XLC', 10) > 80:
                                                AH(self.algo, 'UVXY', 246, 1.0)
                                            else:
                                                if RSI(self.algo, 'XLE', 10) > 80:
                                                    AH(self.algo, 'UVXY', 246, 1.0)
                                                else:
                                                    if RSI(self.algo, 'FAS', 10) > 80:
                                                        AH(self.algo, 'UVXY', 246, 1.0)
                                                    else:
                                                        if RSI(self.algo, 'SPY', 10) > 80:
                                                            AH(self.algo, 'UVXY', 246, 1.0)
                                                        else:
                                                            if CumReturn(self.algo, 'TQQQ', 6) < -0.12:
                                                                if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                                                                    AH(self.algo, 'UVXY', 246, 1.0)
                                                                else:
                                                                    AH(self.algo, 'BIL', 246, 1.0)
                                                            else:
                                                                AH(self.algo, 'BIL', 246, 1.0)


#https://app.composer.trade/symphony/UZ8FUkCn6a4NCvzOXNeo/details

class AExtendedMildFrontrunnerTLTCheckStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.extended_mild_frontrunner_tlt_check()
    
    def tlt_tqqq(self):
        if SMA(self.algo, 'TLT', 5) < SMA(self.algo, 'TLT', 200):
            if CumReturn(self.algo, 'TLT', 10) > 0.01:
                AH(self.algo, 'TQQQ', 247, 1)
            else:
                AH(self.algo, 'BIL', 247, 1)
        else:
            AH(self.algo, 'XLP', 247, 1)
    
    def extended_mild_frontrunner_tlt_check(self):
        if RSI(self.algo, 'QQQ', 10) > 79:
            AH(self.algo, 'UVXY', 247, 0.5) 
            AH(self.algo, 'XLP', 247, 0.5)
        else:
            if RSI(self.algo, 'VTV', 10) > 79:
                AH(self.algo, 'UVXY', 247, 0.5) 
                AH(self.algo, 'XLP', 247, 0.5)
            else:
                if RSI(self.algo, 'VOX', 10) > 79:
                    AH(self.algo, 'UVXY', 247, 0.5) 
                    AH(self.algo, 'XLP', 247, 0.5)
                else:
                    if MaxDD(self.algo, 'SPY', 9) <= 0.0:
                        AH(self.algo, 'UVXY', 247, 0.5) 
                        AH(self.algo, 'XLP', 247, 0.5)
                    else:
                        if RSI(self.algo, 'TECL', 10) > 79:
                            AH(self.algo, 'UVXY', 247, 0.5) 
                            AH(self.algo, 'XLP', 247, 0.5)
                        else:
                            if RSI(self.algo, 'XLP', 10) > 75:
                                AH(self.algo, 'UVXY', 247, 0.5) 
                                AH(self.algo, 'XLP', 247, 0.5)
                            else:
                                if RSI(self.algo, 'TQQQ', 10) > 79:
                                    AH(self.algo, 'UVXY', 247, 0.5) 
                                    AH(self.algo, 'XLP', 247, 0.5)
                                else:
                                    if RSI(self.algo, 'XLY', 10) > 80:
                                        AH(self.algo, 'UVXY', 247, 0.5) 
                                        AH(self.algo, 'XLP', 247, 0.5)
                                    else:
                                        if RSI(self.algo, 'FAS', 10) > 80:
                                            AH(self.algo, 'UVXY', 247, 0.5) 
                                            AH(self.algo, 'XLP', 247, 0.5)
                                        else:
                                            if RSI(self.algo, 'SPY', 10) > 80:
                                                AH(self.algo, 'UVXY', 247, 0.5)
                                                AH(self.algo, 'XLP', 247, 0.5)
                                            else:
                                                if RSI(self.algo, 'SPY', 10) < 25:
                                                    AH(self.algo, 'SH', 247, 1)
                                                else:
                                                    if CumReturn(self.algo, 'TQQQ', 6) < -0.12:
                                                        if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                                                            AH(self.algo, 'UVXY', 247, 0.5)
                                                            AH(self.algo, 'XLP', 247, 0.5)
                                                        else:
                                                            self.tlt_tqqq()
                                                    else:
                                                        self.tlt_tqqq()
    
#https://app.composer.trade/symphony/bwEfC4JbjulJuH0uQhyT/details

class AHedgedRegimeSwitchingRSIHedgeStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.hedged_regime_switching_rsi_hedge()
    
    def layer_4_standard_volatility_hedge_bil(self):
        AH(self.algo, 'UUP', 248, 1.0)
    
    def layer_3_bear_strategy_fund_surf_wo_hedge(self):
        Sort(self.algo,'RSI',('SQQQ','SPXU'),10,False,1,248,1.0)
    
    def layer_3_bull_strategy_fund_surf_w_hedge(self):
        Sort(self.algo,'RSI',('BSV','TQQQ','SPXL'),20,False,1,248,1.0)
    
    def layer_2_bear_market_fund_surf(self):
        if GetCurrentPrice(self.algo, 'SPY') <= EMA(self.algo, 'SPY', 10):
            if RSI(self.algo, 'SPY', 60) < 55:
                if RSI(self.algo, 'SPY', 60) < 45:
                    self.layer_3_bull_strategy_fund_surf_w_hedge()
                else:
                    if RSI(self.algo, 'SPY', 10) < 45:
                        self.layer_3_bear_strategy_fund_surf_wo_hedge()
                    else:
                        self.layer_4_standard_volatility_hedge_bil()
            else:
                self.layer_4_standard_volatility_hedge_bil()
        else:
            self.layer_4_standard_volatility_hedge_bil()

    def fund_surf_bottom_1_20d_rsi(self):
        Sort(self.algo,'RSI',('SHY','QLD','SSO','SPY','QQQ'),20,False,1,248,1.0)
    
    def bullish_side(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            self.fund_surf_bottom_1_20d_rsi()
        else:
            if SMA(self.algo, 'SPY', 200) > SMA(self.algo, 'SPY', 50):
                if SMA(self.algo, 'TLT', 200) > SMA(self.algo, 'TLT', 50):
                    AH(self.algo, 'UUP', 248, 1.0)
                else:
                    AH(self.algo, 'TLT', 248, 1.0)
            else:
                if RSI(self.algo, 'SPY', 10) < 30:
                    AH(self.algo, 'QLD', 248, 1.0)
                else:
                    AH(self.algo, 'QID', 248, 0.5)
                    AH(self.algo, 'XLP', 248, 0.5)
    
    def total_market_strategy(self):
        if RSI(self.algo, 'SPY', 100) > 50:
            self.bullish_side()
        else:
            self.layer_2_bear_market_fund_surf()
    
    def short_fund_surf_hedged_an_attempt_to_profit_from_short_term_bear_market_sentiment(self):
        Sort(self.algo,'RSI',('BSV','PSQ'),10,False,1,248,1.0)
    
    def _this_is_an_attempt_to_create_an_indicator_that_scans_for_black_swan_events(self):
        self.short_fund_surf_hedged_an_attempt_to_profit_from_short_term_bear_market_sentiment()
    
    def _this_is_an_attempt_to_hedge_against_extreme_market_volatility_(self):
        AH(self.algo, 'UVXY', 248, 1.0)
    
    def layer_1_broad_market_hedges(self):
        if RSI(self.algo, 'SPY', 10) >= 80:
            self._this_is_an_attempt_to_hedge_against_extreme_market_volatility_()
        else:
            if RSI(self.algo, 'QQQ', 10) >= 80:
                self._this_is_an_attempt_to_hedge_against_extreme_market_volatility_()
            else:
                if RSI(self.algo, 'UVXY', 10) > 70:
                    self._this_is_an_attempt_to_create_an_indicator_that_scans_for_black_swan_events()
                else:
                    self.total_market_strategy()
    
    def hedged_regime_switching_rsi_hedge(self):
        self.layer_1_broad_market_hedges()
    
#https://app.composer.trade/symphony/umpFivCYDkYWf1KaqSXf/details
class A2CombinedTSLANVDAapproachesBT23Aug2213Dec23AR14558DD128TH9Strategy(YellowCatStrat):

    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.tqqq_for_the_long_term_v42_with_only_nvdlnvds_bt_13dec22()
        self.tsla_longshort_10d_ma_tsll_and_tsls()
    def tsla_longshort_10d_ma_tsll_and_tsls(self):
        if SMA(self.algo, 'TSLA', 10) < GetCurrentPrice(self.algo, 'TSLA'):
            AH(self.algo, 'TSLL', 249, 0.5) 
        else:
            AH(self.algo, 'TSLS', 249, 0.5)
    def a_better_(self):
        if CumReturn(self.algo, 'QQQ', 5) < -0.06:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.05:
                AH(self.algo, 'NVDS', 249, 0.5)
            else:
                if RSI(self.algo, 'TQQQ', 10) > 31:
                    AH(self.algo, 'NVDS', 249, 0.5)
                else:
                    AH(self.algo, 'NVDL', 249, 0.5)
        else:
            if RSI(self.algo, 'QQQ', 10) > 80:
                AH(self.algo, 'NVDS', 249,0.5)
            else:
                AH(self.algo, 'NVDL', 249,0.5)
    def tqqq_for_the_long_term_v42_with_only_nvdlnvds_bt_13dec22(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            if RSI(self.algo, 'TQQQ', 14) > 75:
                AH(self.algo, 'NVDS', 249, 0.5)
            else:
                if RSI(self.algo, 'SPXL', 10) > 80:
                    AH(self.algo, 'NVDS', 249, 0.5)
                else:
                    self.a_better_()
        else:
            if RSI(self.algo, 'TQQQ', 9) < 32:
                if CumReturn(self.algo, 'TQQQ', 2) >= CumReturn(self.algo, 'TQQQ', 5):
                    AH(self.algo, 'NVDL', 249, 0.5)
                else:
                    if RSI(self.algo, 'SPY', 10) < 30:
                        AH(self.algo, 'NVDA', 249, 0.5)
                    else:
                        if RSI(self.algo, 'UVXY', 10) > 74:
                            if RSI(self.algo, 'UVXY', 10) > 84:
                                AH(self.algo, 'NVDS', 249, 0.5)
                            else:
                                AH(self.algo, 'NVDL', 249, 0.5)
                        else:
                            if GetCurrentPrice(self.algo, 'TQQQ') > SMA(self.algo, 'TQQQ', 20):
                                if RSI(self.algo, 'SQQQ', 10) < 31:
                                    AH(self.algo, 'NVDS', 249, 0.5)
                                else:
                                    AH(self.algo, 'NVDL', 249, 0.5)
                            else:
                                AH(self.algo, 'NVDS', 249, 0.5)
            else:
                if RSI(self.algo, 'SPY', 10) < 30:
                    AH(self.algo, 'NVDL', 249, 0.5)
                else:
                    if RSI(self.algo, 'UVXY', 10) > 74:
                        if RSI(self.algo, 'UVXY', 10) > 84:
                            AH(self.algo, 'NVDS', 249, 0.5)
                        else:
                            AH(self.algo, 'NVDL', 249, 0.5)
                    else:
                        if GetCurrentPrice(self.algo, 'TQQQ') > SMA(self.algo, 'TQQQ', 20):
                            if RSI(self.algo, 'SQQQ', 10) < 31:
                                AH(self.algo, 'NVDS', 249, 0.5)
                            else:
                                AH(self.algo, 'NVDL', 249, 0.5)
                        else:
                            AH(self.algo, 'NVDS', 249, 0.5)

#https://app.composer.trade/symphony/E4DDtJu7CXgdcHGrZnvN/details

class AV1aAllWeatherCoreBBV3042aMergedwithNeoSOXXandV1NewSOXLBallerStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.pop_bots_adaptive_asset_allocation_l_giantstepsbriane_l_nov_2nd_2011()
    
    def adaptive_asset_allocation_tech_gold_bonds_dbc_usdu(self):
        if CumReturn(self.algo, 'SPY', 126) >= CumReturn(self.algo, 'UUP', 126):
            if CumReturn(self.algo, 'SPY', 126) >= CumReturn(self.algo, 'DBC', 126):
                if CumReturn(self.algo, 'TLT', 126) >= CumReturn(self.algo, 'UUP', 126):
                    if CumReturn(self.algo, 'TLT', 126) >= CumReturn(self.algo, 'DBC', 126):
                        AHIV(self.algo, ('TQQQ', 'TMF'), 21, 250, 0.16)
                    else:
                        AHIV(self.algo, ('TQQQ', 'DBC'), 21, 250, 0.16)
                else:
                    if CumReturn(self.algo, 'UUP', 126) >= CumReturn(self.algo, 'DBC', 126):
                        AHIV(self.algo, ('TQQQ', 'USDU'), 21, 250, 0.16)
                    else:
                        AHIV(self.algo, ('DBC', 'JNUG'), 21, 250, 0.16)
            else:
                if CumReturn(self.algo, 'SPY', 126) >= CumReturn(self.algo, 'TLT', 126):
                    AHIV(self.algo, ('TQQQ', 'DBC'), 21, 250, 0.16)
                else:
                    AHIV(self.algo, ('TMF', 'DBC'), 21, 250, 0.16)
        else:
            if CumReturn(self.algo, 'DBC', 126) >= CumReturn(self.algo, 'SPY', 126):
                if CumReturn(self.algo, 'UUP', 126) >= CumReturn(self.algo, 'TLT', 126):
                    if CumReturn(self.algo, 'DBC', 126) >= CumReturn(self.algo, 'TLT', 126):
                        AHIV(self.algo, ('TMV', 'USDU'), 21, 250, 0.16)
                    else:
                        AHIV(self.algo, ('TMF', 'USDU'), 21, 250, 0.16)
                else:
                    if CumReturn(self.algo, 'DBC', 126) >= CumReturn(self.algo, 'UUP', 126):
                        AHIV(self.algo, ('TMF', 'DBC'), 21, 250, 0.16)
                    else:
                        AHIV(self.algo, ('JNUG', 'TMF'), 21, 250, 0.16)
            else:
                if CumReturn(self.algo, 'TLT', 126) >= CumReturn(self.algo, 'SPY', 126):
                    AHIV(self.algo, ('TMF', 'JNUG'), 21, 250, 0.16)
                else:
                    AHIV(self.algo, ('TQQQ', 'USDU'), 21, 250, 0.16)
    
    def soxl_pop(self):
        if RSI(self.algo, 'SOXL', 10) < 30:
            AH(self.algo, 'SOXL', 250, 0.16)
        else:
            self.adaptive_asset_allocation_tech_gold_bonds_dbc_usdu()

    def spxl_pop(self):
        if RSI(self.algo, 'SPXL', 10) < 30:
            AH(self.algo, 'SPXL', 250, 0.16)
        else:
            self.adaptive_asset_allocation_tech_gold_bonds_dbc_usdu()
    
    def tqqq_pop(self):
        if RSI(self.algo, 'TQQQ', 10) < 30:
            AH(self.algo, 'TQQQ', 250, 0.16)
        else:
            self.adaptive_asset_allocation_tech_gold_bonds_dbc_usdu()
    
    def pop_bots(self):
        self.tqqq_pop()
        self.spxl_pop()
        self.soxl_pop()
    
    def uvxy_spy_pops(self):
        if RSI(self.algo, 'SPXL', 10) > 80:
            AH(self.algo, 'UVXY', 250, 0.16)
        else:
            self.pop_bots()
    
    def uvxy_qqq_pops(self):
        if RSI(self.algo, 'TQQQ', 10) > 80:
            AH(self.algo, 'UVXY', 250, 0.16)
        else:
            self.pop_bots()
    
    def pop_bots_adaptive_asset_allocation_l_giantstepsbriane_l_nov_2nd_2011(self):
        self.uvxy_qqq_pops()
        self.uvxy_spy_pops()
    
#https://app.composer.trade/symphony/VM2wMBvaJLtso60f266Z/details

class AThePowerofHedgingV2Strategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_the_power_of_hedging_v2()

    def group_the_power_of_hedging_v2(self):
        self.group_btal_dbmf()
        self.group_qld_ftlt()

    def group_btal_dbmf(self):
        AH(self.algo, 'BTAL', 251, 0.3)
        AH(self.algo, 'DBMF', 251, 0.3)

    def group_qld_ftlt(self):
        if RSI(self.algo, 'SPY', 60) > 60:
            self.group_tlt_gld_bsv_10d_rsi_t1()
        else:
            if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
                if RSI(self.algo, 'QQQ', 10) > 80:
                    AH(self.algo, 'VIXM', 251, 0.4)
                else:
                    if RSI(self.algo, 'SPY', 10) > 80:
                        AH(self.algo, 'VIXM', 251, 0.4)
                    else:
                        self.group_longs()
            else:
                if RSI(self.algo, 'TQQQ', 10) < 31:
                    AH(self.algo, 'TECL', 251, 0.4)
                else:
                    if RSI(self.algo, 'SMH', 10) < 30:
                        AH(self.algo, 'SOXL', 251, 0.4) 
                    else:
                        if RSI(self.algo, 'SPY', 10) < 30:
                            AH(self.algo, 'UPRO', 251, 0.4)
                        else:
                            self.group_bear_market_sideways_protection()

    def group_tlt_gld_bsv_10d_rsi_t1(self):
        Sort(self.algo, 'RSI', ('TLT', 'BSV', 'GLD'), 10, True, 1, 251, 0.4)

    def group_longs(self):
        Sort(self.algo, 'STD', ('QLD', 'SSO', 'USD'), 10, True, 2, 251, 0.2)

    def group_bear_market_sideways_protection(self):
        self.group_1_year_cr_leverage_or_deleverage()
        self.group_current_price_vs_20d_ma_leverage_or_deleverage()
        
    def group_1_year_cr_leverage_or_deleverage(self):
        if CumReturn(self.algo, 'QQQ', 252) > -0.2:
            self.group_leverage()
        else:
            self.group_deleverage()

    def group_current_price_vs_20d_ma_leverage_or_deleverage(self):
        if GetCurrentPrice(self.algo, 'QQQ') > SMA(self.algo, 'QQQ', 20):
            if RSI(self.algo, 'SQQQ', 10) < 31:
                AH(self.algo, 'QID', 251, 0.2)
            else:
                if CumReturn(self.algo, 'QQQ', 10) > 0.055:
                    AH(self.algo, 'QID', 251, 0.2)
                else:
                    Sort(self.algo, 'RSI', ('QLD', 'USD'), 10, True, 1, 251, 0.1)
        else:
            self.group_10d_tlt_vs_10d_sqqq_leverage_or_deleverage()

    def group_leverage(self):
        if GetCurrentPrice(self.algo, 'QQQ') > SMA(self.algo, 'QQQ', 20):
            if RSI(self.algo, 'SQQQ', 10) < 31:
                AH(self.algo, 'QID', 251, 0.2)
            else:
                if CumReturn(self.algo, 'QQQ', 10) > 0.055:
                    AH(self.algo, 'QID', 251, 0.2)
                else:
                    Sort(self.algo, 'RSI', ('QLD', 'USD'), 10, True, 1, 251, 0.2)
        else:
            self.group_10d_tlt_vs_10d_sqqq_leverage()

    def group_deleverage(self):
        if GetCurrentPrice(self.algo, 'QQQ') > SMA(self.algo, 'QQQ', 20):
            if RSI(self.algo, 'SQQQ', 10) < 31:
                AH(self.algo, 'PSQ', 251, 0.2)
            else:
                if CumReturn(self.algo, 'QQQ', 10) > 0.055:
                    AH(self.algo, 'PSQ', 251, 0.2)
                else:
                    Sort(self.algo, 'RSI', ('QQQ', 'SMH'), 10, True, 1, 251, 0.2)
        else:
            self.group_10d_tlt_vs_10d_sqqq_leverage_or_deleverage()

    def group_10d_tlt_vs_10d_sqqq_leverage_or_deleverage(self):
        if CumReturn(self.algo, 'QQQ', 60) <= -0.12:
            self.group_10d_tlt_vs_10d_sqqq_deleverage()
        else:
            self.group_10d_tlt_vs_10d_sqqq_leverage()

    def group_10d_tlt_vs_10d_sqqq_leverage(self):
        if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'SQQQ', 10):
            AH(self.algo, 'QLD', 251, 0.2)
        else:
            AH(self.algo, 'QID', 251, 0.2)

    def group_10d_tlt_vs_10d_sqqq_deleverage(self):
        if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'SQQQ', 10):
            AH(self.algo, 'QQQ', 251, 0.2)
        else:
            AH(self.algo, 'PSQ', 251, 0.2)
    
    
#https://app.composer.trade/symphony/OK2kPAdrnFL6fEWZVQeN/details

class ANeoTrinityDippyAAAHnLStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1a_wammer_time_strychnine_k1_free()
    
    def bond_midterm_longterm(self):
        if RSI(self.algo, 'IEF', 200) < RSI(self.algo, 'TLT', 200):
            if RSI(self.algo, 'BND', 45) > RSI(self.algo, 'SPY', 45):
                AH(self.algo, 'TQQQ', 252,0.5)
            else:
                AH(self.algo, 'PSQ', 252,0.5)
        else:
            AH(self.algo, 'PSQ', 252,0.5)
    
    def bond_stock(self):
        if RSI(self.algo, 'BND', 45) > RSI(self.algo, 'SPY', 45):
            AH(self.algo, 'TQQQ', 252,0.5)
        else:
            AH(self.algo, 'PSQ', 252,0.5)
    
    def normal_market(self):
        if MaxDD(self.algo, 'QQQ', 10) > 0.06:
            AH(self.algo, 'PSQ', 252,0.5)
        else:
            if MaxDD(self.algo, 'TMF', 10) > 0.07:
                AH(self.algo, 'PSQ', 252,0.5)
            else:
                if GetCurrentPrice(self.algo, 'QQQ') > SMA(self.algo, 'QQQ', 25):
                    AH(self.algo, 'TQQQ', 252,0.5)
                else:
                    if RSI(self.algo, 'SPY', 60) > 50:
                        self.bond_stock()
                    else:
                        self.bond_midterm_longterm()
    
    def mean_rev(self):
        if RSI(self.algo, 'TQQQ', 10) < 32:
            AH(self.algo, 'SOXL', 252,0.5)
        else:
            if MaxDD(self.algo, 'TMF', 10) < 0.07:
                AH(self.algo, 'SOXL', 252,0.5)
            else:
                AH(self.algo, 'PSQ', 252,0.5)
    
    def huge_volatility(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.13:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.06:
                AH(self.algo, 'SOXS', 252,0.5)
            else:
                self.mean_rev()
        else:
            self.normal_market()
    
    def v1a_tqqq_or_not_blackswan_meanrev_bondsignal_replace_uvxy_k1_free(self):
        if RSI(self.algo, 'TQQQ', 10) > 79:
            AH(self.algo, 'VXX', 252,0.5)
        else:
            self.huge_volatility()
    
    def wam_ftlt_short_backtest(self):
        if SMADayRet(self.algo, 'SHY', 575) < 0:
            if RSI(self.algo, 'IEF', 11) > RSI(self.algo, 'IWM', 16):
                Sort(self.algo,'SMADayRet',('TECL','TQQQ','DRN','HIBL','TARK','URTY','TMF','SPXL'),4,False,2,252,0.5)
            else:
                Sort(self.algo,'SMADayRet',('PSQ','TYO','HIBS','DRV','TMV','SH','SPXS'),4,False,2,252,0.5)
        else:
            self.v1a_tqqq_or_not_blackswan_meanrev_bondsignal_replace_uvxy_k1_free()
    
    def wam_ftlt_long_backtest(self):
        if SMADayRet(self.algo, 'SHY', 575) < 0:
            if RSI(self.algo, 'IEF', 11) > RSI(self.algo, 'IWM', 16):
                Sort(self.algo,'SMADayRet',('TECL','TQQQ','DRN','URTY','TMF','SPXL'),4,False,2,252,0.5)
            else:
                Sort(self.algo,'SMADayRet',('PSQ','TYO','DRV','TMV','SH','SPXS'),4,False,2,252,0.5)
        else:
            self.v1a_tqqq_or_not_blackswan_meanrev_bondsignal_replace_uvxy_k1_free()
    
    def wam_ftlt_no_tmf_check_k1_free(self):
        self.wam_ftlt_long_backtest()
        self.wam_ftlt_short_backtest()
    
    def wam_ftlt_tmf_check_k1_free(self):
        self.wam_ftlt_long_backtest()
        self.wam_ftlt_short_backtest()
    
    def v1a_wammer_time_strychnine_k1_free(self):
        if RSI(self.algo, 'SPY', 10) > 65:
            self.wam_ftlt_tmf_check_k1_free()
        else:
            self.wam_ftlt_no_tmf_check_k1_free()
    
#https://app.composer.trade/symphony/x8Fl4ZAIflwR2HmPiWWa/details

class ABWCBILLBTStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1a_latest_hedged_leveraged_bonds_stocks_v42_replace_upro_with_tecl_tqqq_and_soxl_k1_free()
    
    def risk_off(self):
        AH(self.algo, 'TMV', 253, 0.5) 
        AH(self.algo, 'UDOW', 253, 0.5)
    
    def bond_midterm_longterm(self):
        if RSI(self.algo, 'IEF', 200) < RSI(self.algo, 'TLT', 200):
            if RSI(self.algo, 'BND', 45) > RSI(self.algo, 'SPY', 45):
                AH(self.algo, 'TQQQ', 253, 1.0)
            else:
                AH(self.algo, 'BIL', 253, 0.6)
                AH(self.algo, 'SQQQ', 253, 0.4)
        else:
            AH(self.algo, 'BIL', 253, 0.6)
            AH(self.algo, 'SQQQ', 253, 0.4)
    
    def bond_stock(self):
        if RSI(self.algo, 'BND', 45) > RSI(self.algo, 'SPY', 45):
            AH(self.algo, 'TQQQ', 253, 1.0)
        else:
            AH(self.algo, 'BIL', 253, 0.6)
            AH(self.algo, 'SQQQ', 253, 0.4)
    
    def normal_market(self):
        if MaxDD(self.algo, 'QQQ', 10) > 0.06:
            AH(self.algo, 'BIL', 253, 0.6)
            AH(self.algo, 'SQQQ', 253, 0.4)
        else:
            if MaxDD(self.algo, 'TMF', 10) > 0.07:
                AH(self.algo, 'BIL', 253, 0.6)
                AH(self.algo, 'SQQQ', 253, 0.4)
            else:
                if GetCurrentPrice(self.algo, 'QQQ') > SMA(self.algo, 'QQQ', 25):
                    AH(self.algo, 'TQQQ', 253, 1.0)
                else:
                    if RSI(self.algo, 'SPY', 60) > 50:
                        self.bond_stock()
                    else:
                        self.bond_midterm_longterm()
    
    def mean_rev(self):
        if RSI(self.algo, 'TQQQ', 10) < 32:
            AH(self.algo, 'SOXL', 253, 1.0)
        else:
            if MaxDD(self.algo, 'TMF', 10) < 0.07:
                AH(self.algo, 'SOXL', 253, 1.0)
            else:
                AH(self.algo, 'BIL', 253, 0.6)
                AH(self.algo, 'SQQQ', 253, 0.4)
    
    def huge_volatility(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.13:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.06:
                AH(self.algo, 'SOXS', 253, 1.0)
            else:
                self.mean_rev()
        else:
            self.normal_market()
    
    def v1a_tqqq_or_not_blackswan_meanrev_bondsignal_replace_uvxy_w_soxs(self):
        if RSI(self.algo, 'TQQQ', 10) > 79:
            AH(self.algo, 'SOXS', 253, 1.0)
        else:
            self.huge_volatility()
    
    def v1a_tqqq_or_not_dash_of_sqqq_deez_replace_uvxy_w_soxs(self):
        self.v1a_tqqq_or_not_blackswan_meanrev_bondsignal_replace_uvxy_w_soxs()
    
    def v1a_latest_hedged_leveraged_bonds_stocks_v42_replace_upro_with_tecl_tqqq_and_soxl_k1_free(self):
        if STD(self.algo, 'SPY', 10) > 3:
            self.v1a_tqqq_or_not_dash_of_sqqq_deez_replace_uvxy_w_soxs()
        else:
            if GetCurrentPrice(self.algo, 'TLT') > SMA(self.algo, 'TLT', 150):
                AH(self.algo, 'TECL', 253, 0.2)
                AH(self.algo, 'TQQQ', 253, 0.2)
                AH(self.algo, 'SOXL', 253, 0.2)
                AH(self.algo, 'TMF', 253, 0.2)
                AH(self.algo, 'PHDG', 253, 0.2)
            else:
                if GetCurrentPrice(self.algo, 'TLT') < SMA(self.algo, 'TLT', 23):
                    self.risk_off()
                else:
                    Sort(self.algo,'CumReturn',('TMF','UPRO','TMV','MOAT','BRK/B','USMV','TYO'),30,True,1,253,1.0)

#https://app.composer.trade/symphony/vRJuEbuNRZo7wYMi7Ott/details

class AJEPQSince2022Strategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.jepq_since_2022()
    
    def sideways_market_deleverage(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 20):
            AH(self.algo, 'JEPI', 254, 0.5)
        else:
            if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'PSQ', 10):
                AH(self.algo, 'JEPQ', 254, 0.5)
            else:
                AH(self.algo, 'PSQ', 254, 0.5)
        if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'PSQ', 10):
            AH(self.algo, 'JEPQ', 254, 0.5)
        else:
            AH(self.algo, 'PSQ', 254, 0.5)
    
    def nasdaq_in_crash_territory_time_to_deleverage(self):
        if GetCurrentPrice(self.algo, 'QQQ') < SMA(self.algo, 'QQQ', 20):
            if CumReturn(self.algo, 'QQQ', 60) <= -0.12:
                self.sideways_market_deleverage()
            else:
                if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'PSQ', 10):
                    AH(self.algo, 'QLD', 254, 0.5)
                else:
                    AH(self.algo, 'QID', 254, 0.5)
        else:
            if RSI(self.algo, 'PSQ', 10) < 31:
                AH(self.algo, 'PSQ', 254, 0.5)
            else:
                if CumReturn(self.algo, 'QQQ', 10) > 0.055:
                    AH(self.algo, 'PSQ', 254, 0.5)
                else:
                    Sort(self.algo,'RSI',('JEPQ','SMH'),10,True,1,254,1.0)
    
    def bear_market_sideways_protection_2008_edition(self):
        if CumReturn(self.algo, 'QQQ', 252) < -0.2:
            self.nasdaq_in_crash_territory_time_to_deleverage()
        else:
            if GetCurrentPrice(self.algo, 'QQQ') < SMA(self.algo, 'QQQ', 20):
                if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'PSQ', 10):
                    AH(self.algo, 'QLD', 254, 0.5)
                else:
                    AH(self.algo, 'QID', 254, 0.5)
            else:
                if RSI(self.algo, 'PSQ', 10) < 31:
                    AH(self.algo, 'QID', 254, 0.5)
                else:
                    if CumReturn(self.algo, 'QQQ', 10) > 0.055:
                        AH(self.algo, 'QID', 254, 0.5)
                    else:
                        Sort(self.algo,'RSI',('QLD','USD'),10,True,1,254,0.5)
    
    def jepq_since_2022(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            if RSI(self.algo, 'QQQ', 10) > 80:
                AH(self.algo, 'TLT', 254, 1)
            else:
                if RSI(self.algo, 'SPY', 10) > 80:
                    AH(self.algo, 'TLT', 254, 1)
                else:
                    if RSI(self.algo, 'SPY', 60) > 60:
                        AH(self.algo, 'TLT', 254, 1)
                    else:
                        AH(self.algo, 'JEPQ', 254, 1)
        else:
            if RSI(self.algo, 'QQQ', 10) < 30:
                AH(self.algo, 'QLD', 254, 1)
            else:
                if GetCurrentPrice(self.algo, 'QQQ') > SMA(self.algo, 'QQQ', 20):
                    if RSI(self.algo, 'PSQ', 10) < 30:
                        AH(self.algo, 'PSQ', 254, 0.5)
                    else:
                        if CumReturn(self.algo, 'QQQ', 10) > 0.055:
                            AH(self.algo, 'SHV', 254, 0.5)
                        else:
                            AH(self.algo, 'JEPQ', 254, 0.5)
                else:
                    Sort(self.algo,'RSI',('IEF','PSQ'),10,True,1,254,0.5)
                self.bear_market_sideways_protection_2008_edition()
    

#https://app.composer.trade/symphony/J6fEBib50uKh0nmaWJAf/details

class AQQQ1508RR214DDNov2013currentREPLACESQQQwithGOLDv11Strategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.tqqq_for_the_long_term_v3_298_rr33_max_dd()
    
    def AAABBCC(self):
        Sort(self.algo,'RSI',('CCRD','CHKP','CRUS','CSCO','DQ','ECOM','ELTK','ERIC','HCKT','INFY','JKHY','LOGI','MNDO','MSFT','NSYS','QLYS','SIMO','TSM','TQQQ','WSTG'),40,False,4,255,1)
    
    def a_better_(self):
        if CumReturn(self.algo, 'QQQ', 5) < -0.06:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.05:
                AH(self.algo, 'GLD', 255, 1.0)
            else:
                if RSI(self.algo, 'TQQQ', 10) > 31:
                    AH(self.algo, 'GLD', 255, 1.0)
                else:
                    AH(self.algo, 'QQQ', 255, 1.0)
        else:
            if RSI(self.algo, 'QQQ', 10) > 80:
                AH(self.algo, 'GLD', 255, 1.0)
            else:
                if RSI(self.algo, 'QQQ', 10) < 31:
                    AH(self.algo, 'QQQ', 255, 1.0)
                else:
                    self.AAABBCC()
    
    def tqqq_for_the_long_term_v3_298_rr33_max_dd(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            if RSI(self.algo, 'TQQQ', 14) > 75:
                AH(self.algo, 'UVXY', 255, 1.0)
            else:
                if RSI(self.algo, 'SPXL', 10) > 80:
                    AH(self.algo, 'UVXY', 255, 1.0)
                else:
                    self.a_better_()
        else:
            if RSI(self.algo, 'TQQQ', 9) < 32:
                if CumReturn(self.algo, 'TQQQ', 2) >= CumReturn(self.algo, 'TQQQ', 5):
                    Sort(self.algo,'RSI',('QQQ','SOXX','SHY'),10,False,1,255,0.5)
                    Sort(self.algo,'RSI',('SOXX','SHY'),10,False,1,255,0.5)
                else:
                    if RSI(self.algo, 'SPY', 10) < 30:
                        Sort(self.algo,'RSI',('SPY','SHY'),10,False,1,255,1.0)
                    else:
                        if RSI(self.algo, 'UVXY', 10) > 74:
                            if RSI(self.algo, 'UVXY', 10) > 84:
                                Sort(self.algo,'RSI',('BSV','GLD'),10,True,1,255,1.0)
                            else:
                                AH(self.algo, 'UVXY', 255, 1.0)
                        else:
                            if GetCurrentPrice(self.algo, 'TQQQ') > SMA(self.algo, 'TQQQ', 20):
                                if RSI(self.algo, 'SQQQ', 10) < 31:
                                    AH(self.algo, 'GLD', 255, 1.0)
                                else:
                                    AH(self.algo, 'QQQ', 255, 1.0)
                            else:
                                Sort(self.algo,'RSI',('BSV','GLD'),10,True,1,255,1.0)
            else:
                if RSI(self.algo, 'SPY', 10) < 30:
                    Sort(self.algo,'RSI',('SPY','SHY'),10,False,1,255,1.0)
                else:
                    if RSI(self.algo, 'UVXY', 10) > 74:
                        if RSI(self.algo, 'UVXY', 10) > 84:
                            Sort(self.algo,'RSI',('BSV','GLD'),10,True,1,255,1.0)
                        else:
                            AH(self.algo, 'UVXY', 255, 1.0)
                    else:
                        if GetCurrentPrice(self.algo, 'TQQQ') > SMA(self.algo, 'TQQQ', 20):
                            if RSI(self.algo, 'SQQQ', 10) < 31:
                                AH(self.algo, 'GLD', 255, 1.0)
                            else:
                                AH(self.algo, 'QQQ', 255, 1.0)
                        else:
                            Sort(self.algo,'RSI',('BSV','GLD'),10,True,1,255,1.0)

#https://app.composer.trade/symphony/XezBPHJAaya0iijGjNvM/details

class AV11MagicInternetMoneyMIMDeezAR137139DD194BT29JUN2022Strategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if GetCurrentPrice(self.algo, 'BITO') <= SMA(self.algo, 'BITO', 62):
            if RSI(self.algo, 'BITO', 14) < 60:
                if CumReturn(self.algo, 'BITI', 1) <= -0.01:
                    if CumReturn(self.algo, 'BITO', 1) <= -0.02:
                        AH(self.algo, 'BIL', 256, 1)
                    else:
                        AHIV(self.algo, ('MSTR', 'COIN', 'BITO', 'SOXL'), 14, 256, 1)
                else:
                    if CumReturn(self.algo, 'BITO', 5) >= STD(self.algo, 'BITO', 10):
                        if STD(self.algo, 'BITO', 2) >= STD(self.algo, 'BITO', 5):
                            AH(self.algo, 'BITI', 256, 1)
                        else:
                            if CumReturn(self.algo, 'BITI', 2) <= -0.03:
                                AH(self.algo, 'BIL', 256, 1)
                            else:
                                AH(self.algo, 'BITI', 256, 1)
                    else:
                        if CumReturn(self.algo, 'BITO', 2) >= STD(self.algo, 'BITO', 5):
                            if CumReturn(self.algo, 'BITO', 1) > CumReturn(self.algo, 'BITI', 3):
                                Sort(self.algo,'CumReturn',('BITO','MSTR','COIN'),21,True,1,256,1)
                            else:
                                AH(self.algo, 'UNH', 256, 0.5) 
                                AH(self.algo, 'COST', 256, 0.5)
                        else:
                            AH(self.algo, 'UNH', 256, 0.5) 
                            AH(self.algo, 'COST', 256, 0.5)
            else:
                if RSI(self.algo, 'BITO', 14) >= 85:
                    if CumReturn(self.algo, 'BITO', 3) >= 0.05:
                        if CumReturn(self.algo, 'BITO', 1) > CumReturn(self.algo, 'BITO', 3):
                            AH(self.algo, 'BITI', 256, 1)
                        else:
                            if CumReturn(self.algo, 'BITI', 1) <= -0.03:
                                if CumReturn(self.algo, 'UUP', 2) >= CumReturn(self.algo, 'BITI', 2):
                                    AH(self.algo, 'BIL', 256, 1)
                                else:
                                    AH(self.algo, 'BITI', 256, 1)
                            else:
                                if CumReturn(self.algo, 'UUP', 2) >= CumReturn(self.algo, 'BITI', 2):
                                    AH(self.algo, 'BIL', 256, 1)
                                else:
                                    AH(self.algo, 'BITI', 256, 1)
                    else:
                        if CumReturn(self.algo, 'BITI', 1) <= -0.03:
                            if CumReturn(self.algo, 'UUP', 2) >= CumReturn(self.algo, 'BITI', 2):
                                AH(self.algo, 'BIL', 256, 1)
                            else:
                                AH(self.algo, 'BITI', 256, 1)
                        else:
                            if CumReturn(self.algo, 'UUP', 2) >= CumReturn(self.algo, 'BITI', 2):
                                AH(self.algo, 'BIL', 256, 1)
                            else:
                                AH(self.algo, 'BITI', 256, 1)
                else:
                    if CumReturn(self.algo, 'BITI', 1) <= -0.03:
                        if CumReturn(self.algo, 'UUP', 2) >= CumReturn(self.algo, 'BITI', 2):
                            AH(self.algo, 'BIL', 256, 1)
                        else:
                            AH(self.algo, 'BITI', 256, 1)
                    else:
                        if CumReturn(self.algo, 'UUP', 2) >= CumReturn(self.algo, 'BITI', 2):
                            AH(self.algo, 'UUP', 256, 1)
                        else:
                            AH(self.algo, 'BITI', 256, 1)
        else:
            AH(self.algo, 'UNH', 256, 0.5) 
            AH(self.algo, 'COST', 256, 0.5)
    
from AlgorithmImports import *
import math
import pandas as pd
from cmath import sqrt
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Data.Custom import *
from QuantConnect.Python import PythonData

class IntelligentSkyRodent(QCAlgorithm):
    def Initialize(self):
        self.cash = 80000
        self.buffer_pct = 0.03
        self.SetStartDate(2023, 6, 1)
        self.SetEndDate(2024, 6, 5)
        self.SetCash(self.cash)
        self.equities = ['FNGS','SPLV','TMV', 'VCIT', 'XLY', 'HIBL', 'XLK', 'XLP', 'SVXY', 'QID', 'TBF', 'TSLA', 'LQD', 'VTIP', 'EDV', 'STIP', 'SPTL', 'IEI', 'USDU', 'SQQQ', 'VIXM', 'SPXU', 'QQQ', 'BSV', 'TQQQ', 'SPY', 'DBC', 'SHV', 'IAU', 'VEA', 'UTSL', 'UVXY', 'UPRO', 'EFA', 'EEM', 'TLT', 'SHY', 'GLD', 'SLV', 'USO', 'WEAT', 'CORN', 'SH', 'DRN', 'PDBC', 'COMT', 'KOLD', 'BOIL', 'ESPO', 'PEJ', 'UGL', 'URE', 'VXX', 'UUP', 'BND', 'DUST', 'JDST', 'JNUG', 'GUSH', 'DBA', 'DBB', 'COM', 'PALL', 'AGQ', 'BAL', 'WOOD', 'URA', 'SCO', 'UCO', 'DBO', 'TAGS', 'CANE', 'REMX', 'COPX', 'IEF', 'SPDN', 'CHAD', 'DRIP', 'SPUU', 'INDL', 'BRZU', 'ERX', 'ERY', 'CWEB', 'CHAU', 'KORU', 'MEXX', 'EDZ', 'EURL', 'YINN', 'YANG', 'TNA', 'TZA', 'SPXL', 'SPXS', 'MIDU', 'TYD', 'TYO', 'TMF', 'TECL', 'TECS', 'SOXL', 'SOXS', 'LABU', 'LABD', 'RETL', 'DPST', 'DRV', 'PILL', 'CURE', 'FAZ', 'FAS', 'EWA', 'EWGS', 'EWG', 'EWP', 'EWQ', 'EWU', 'EWJ', 'EWI', 'EWN', 'ECC', 'NURE', 'VNQI', 'VNQ', 'VDC', 'VIS', 'VGT', 'VAW', 'VPU', 'VOX', 'VFH', 'VHT', 'VDE', 'SMH', 'DIA', 'UDOW', 'PSQ', 'SOXX', 'VTI', 'COST', 'UNH', 'SPHB', 'BTAL', 'VIXY', 'WEBL', 'WEBS', 'UBT', 'PST', 'TLH', 'QLD', 'SQM', 'SSO', 'SD', 'DGRO', 'SCHD', 'SGOL', 'TIP', 'DUG', 'EWZ', 'TBX', 'VGI', 'XLU', 'XLV', 'EUO', 'YCS', 'MVV', 'USD', 'BIL', 'TMF', 'EPI', 'IYK', 'DIG', 'AGG', 'PUI', 'UDN', 'QQQE', 'VTV', 'VOOG', 'VOOV']

        self.MKT = self.AddEquity("SPY",Resolution.Daily).Symbol
        self.mkt = []
        for equity in self.equities:
            self.AddEquity(equity,Resolution.Minute)
            self.Securities[equity].SetDataNormalizationMode(DataNormalizationMode.Adjusted)
        self.AddEquity('BIL',Resolution.Minute)
        self.Securities['BIL'].SetDataNormalizationMode(DataNormalizationMode.TotalReturn)
       
        self.PT1 = 0.94

        self.HT1 = {str(i).zfill(2): 0 for i in range(1,10)}
        self.HTS1 = {str(i).zfill(2): [] for i in range(1,10)}
        self.HT2 = {str(i).zfill(2): 0 for i in range(1,10)}
        self.HTS2 = {str(i).zfill(2): [] for i in range(1,10)}
        self.HT3 = {str(i).zfill(2): 0 for i in range(1,10)}
        self.HTS3 = {str(i).zfill(2): [] for i in range(1,10)}

        self.Schedule.On(self.DateRules.EveryDay("SPY"),
                self.TimeRules.BeforeMarketClose("SPY", 2),
                self.FunctionBeforeMarketClose)
    def RSI(self,equity,period):
        extension = min(period*5,250)
        r_w = RollingWindow[float](extension)
        history = self.History(equity,extension - 1,Resolution.Daily)
        for historical_bar in history:
            r_w.Add(historical_bar.Close)
        while r_w.Count < extension:
            current_price = self.Securities[equity].Price
            r_w.Add(current_price)
        if r_w.IsReady:
            average_gain = 0
            average_loss = 0
            gain = 0
            loss = 0
            for i in range(extension - 1,extension - period -1,-1):
                gain += max(r_w[i-1] - r_w[i],0)
                loss += abs(min(r_w[i-1] - r_w[i],0))
            average_gain = gain/period
            average_loss = loss/period
            for i in range(extension - period - 1,0,-1):
                average_gain = (average_gain*(period-1) + max(r_w[i-1] - r_w[i],0))/period
                average_loss = (average_loss*(period-1) + abs(min(r_w[i-1] - r_w[i],0)))/period
            if average_loss == 0:
                return 100
            else:
                rsi = 100 - (100/(1 + average_gain / average_loss))
                return rsi
        else:
            return None

    def CumReturn(self,equity,period):

        history = self.History(equity, period, Resolution.Daily)
        closing_prices = pd.Series([bar.Close for bar in history])
        current_price = self.Securities[equity].Price
        # Convert current_price to a Series and use pd.concat to append it to closing_prices
        closing_prices = pd.concat([closing_prices, pd.Series([current_price])]).reset_index(drop=True)
        first_price = closing_prices.iloc[0]
        if first_price == 0:
            return None
        else:
            return_val = (current_price / first_price) - 1
            return return_val
    def STD(self,equity,period):
        r_w = RollingWindow[float](period + 1)
        r_w_return = RollingWindow[float](period)
        history = self.History(equity,period,Resolution.Daily)
        for historical_bar in history:
            r_w.Add(historical_bar.Close)
        while r_w.Count < period + 1:
            current_price = self.Securities[equity].Price
            r_w.Add(current_price)
        for i in range (period,0,-1):
            daily_return = (r_w[i-1]/r_w[i] - 1)
            r_w_return.Add(daily_return)
        dfstd = pd.DataFrame({'r_w_return':r_w_return})
        if r_w.IsReady:
            std = dfstd['r_w_return'].std()
            if std == 0:
                return 0
            else:
                return std
        else:
            return 0

    def MaxDD(self,equity,period):
        history = self.History(equity,period - 1,Resolution.Daily)
        closing_prices = pd.Series([bar.Close for bar in history])
        current_price = self.Securities[equity].Price
        closing_prices = closing_prices.append(pd.Series([current_price]))
        rolling_max = closing_prices.cummax()
        drawdowns = (rolling_max - closing_prices) / rolling_max
        max_dd = drawdowns.min()
        return max_dd

    def SMA(self,equity,period):
        r_w = RollingWindow[float](period)
        history = self.History(equity,period - 1,Resolution.Daily)
        for historical_bar in history:
            r_w.Add(historical_bar.Close)
        while r_w.Count < period:
            current_price = self.Securities[equity].Price
            r_w.Add(current_price)        
        if r_w.IsReady:
            sma = sum(r_w) / period
            return sma
        else:
            return 0

    def IV(self,equity,period):
        r_w = RollingWindow[float](period + 1)
        r_w_return = RollingWindow[float](period)
        history = self.History(equity,period,Resolution.Daily)
        for historical_bar in history:
            r_w.Add(historical_bar.Close)
        while r_w.Count < period + 1:
            current_price = self.Securities[equity].Price
            r_w.Add(current_price)
        for i in range (period,0,-1):
            if r_w[i] == 0:
                return 0
            else:
                daily_return = (r_w[i-1]/r_w[i] - 1)
                r_w_return.Add(daily_return)
        dfinverse = pd.DataFrame({'r_w_return':r_w_return})       
        if r_w.IsReady:
            std = dfinverse['r_w_return'].std()
            if std == 0:
                return 0
            else:
                inv_vol = 1 / std
                return inv_vol
        else:
            return 0

    def SMADayRet(self,equity,period):
        r_w = RollingWindow[float](period + 1)
        r_w_return = RollingWindow[float](period)
        history = self.History(equity,period,Resolution.Daily)
        for historical_bar in history:
            r_w.Add(historical_bar.Close)
        while r_w.Count < period + 1:
            current_price = self.Securities[equity].Price
            r_w.Add(current_price)
        for i in range (period,0,-1):
            if r_w[i] == 0:
                return None
            daily_return = (r_w[i-1]/r_w[i] - 1)
            r_w_return.Add(daily_return)
        if r_w.IsReady:
            smareturn = sum(r_w_return) / period
            return smareturn
        else:
            return 0
            
    def EMA(self,equity,period):
        extension = period + 50
        r_w = RollingWindow[float](extension)
        history = self.History(equity,extension - 1,Resolution.Daily)
        for historical_bar in history:
            r_w.Add(historical_bar.Close)
        while r_w.Count < extension:
            current_price = self.Securities[equity].Price
            r_w.Add(current_price)
        if r_w.IsReady:
            total_price = 0
            for i in range(extension - 1,extension - period - 2,-1):
                total_price += r_w[i]
            average_price = total_price/period
            for i in range(extension - period - 2,-1,-1):
                average_price = r_w[i]*2/(period+1) + average_price*(1-2/(period+1))
            return average_price
        else:
            return None
    def Sort(self,sort_type,equities,period,reverse,number,multiplier,holdings=1):
        self.PT = getattr(self,f"PT{number}") * multiplier /  holdings
        returns = {}
        for equity in equities:
            returns[equity] = getattr(self,sort_type)(equity,period)
        s_e = sorted([item for item in returns.items() if item[1] is not None],key = lambda x: x[1],reverse = reverse)
        t3e = s_e[:holdings]
        ht = getattr(self,f"HT{number}")
        hts = getattr(self,f"HTS{number}")
        for ticker in t3e:
            for i in ht.keys():
                if ht[i] == 0:
                    ht[i] = self.PT
                    hts[i].append(ticker[0])
                    break
        setattr(self,f"HT{number}",ht)
        setattr(self,f"HTS{number}",hts)

    def AH(self, equities, PTnumber, multiplier): #AppendHolding
        if not isinstance(equities, list):
            equities = [equities]
        
        HT = getattr(self, f"HT{PTnumber}")
        HTS = getattr(self, f"HTS{PTnumber}")
        PT = getattr(self, f"PT{PTnumber}") * multiplier
        
        for equity in equities:
            for i in HT.keys():
                if HT[i] == 0:
                    HT[i] = PT
                    HTS[i].append(equity)
                    break

    def OnData (self,data):
        pass

    def FunctionBeforeMarketClose(self):
        mkt_price = self.History(self.MKT,2,Resolution.Daily)['close'].unstack(level= 0).iloc[-1]
        self.mkt.append(mkt_price)
        mkt_perf = self.cash * self.mkt[-1] / self.mkt[0]
        self.Plot('Strategy Equity',self.MKT,mkt_perf)
        self.tqqq_ftlt()
        self.ExecuteTrade()

    
    def sideways_market_deleverage(self):
            if self.Securities['SPY'].Price > self.SMA('SPY', 20):
                self.AH('SPY', 1, 1.0)
            else:
                if self.RSI('TLT', 10) > self.RSI('SQQQ', 10):
                    self.AH('QQQ', 1, 1.0)
                else:
                    self.AH('PSQ', 1, 1.0)
            if self.RSI('TLT', 10) > self.RSI('SQQQ', 10):
                self.AH('QQQ', 1, 1.0)
            else:
                self.AH('PSQ', 1, 1.0)
    
    def nasdaq_in_crash_territory_time_to_deleverage(self):
        if self.Securities['QQQ'].Price < self.SMA('QQQ', 20):
            if self.CumReturn('QQQ', 60) <= -12:
                self.sideways_market_deleverage()
            else:
                if self.RSI('TLT', 10) > self.RSI('SQQQ', 10):
                    self.AH('TQQQ', 1, 1.0)
                else:
                    self.AH('SQQQ', 1, 1.0)
        else:
            if self.RSI('SQQQ', 10) < 31:
                self.AH('PSQ', 1, 1.0)
            else:
                if self.CumReturn('QQQ', 10) > 5.5:
                    self.AH('PSQ', 1, 1.0)
                else:
                    self.Sort('RSI',('QQQ','SMH'),10,True,1,1.0)
    
    def bear_market_sideways_protection(self):
        if self.CumReturn('QQQ', 252) < -20:
            self.nasdaq_in_crash_territory_time_to_deleverage()
        else:
            if self.Securities['QQQ'].Price < self.SMA('QQQ', 20):
                if self.RSI('TLT', 10) > self.RSI('SQQQ', 10):
                    self.AH('TQQQ', 1, 1.0)
                else:
                    self.AH('SQQQ', 1, 1.0)
            else:
                if self.RSI('SQQQ', 10) < 31:
                    self.AH('SQQQ', 1, 1.0)
                else:
                    if self.CumReturn('QQQ', 10) > 5.5:
                        self.AH('SQQQ', 1, 1.0)
                    else:
                        self.Sort('RSI',('TQQQ','SOXL'),10,True,1,1.0)
        if self.Securities['QQQ'].Price < self.SMA('QQQ', 20):
            if self.CumReturn('QQQ', 60) <= -12:
                self.sideways_market_deleverage()
            else:
                if self.RSI('TLT', 10) > self.RSI('SQQQ', 10):
                    self.AH('TQQQ', 1, 1.0)
                else:
                    self.AH('SQQQ', 1, 1.0)
        else:
            if self.RSI('SQQQ', 10) < 31:
                self.AH('SQQQ', 1, 1.0)
            else:
                if self.CumReturn('QQQ', 70) < -15:
                    self.Sort('RSI',('TQQQ','SOXL'),10,True,1,1.0)
                else:
                    self.Sort('CumReturn',('SPY','QQQ','DIA','XLP'),15,True,1,1.0)
    
    def dip_buy_strategy(self):
        if self.RSI('TQQQ', 10) < 31:
            self.AH('TECL', 1, 1.0)
        else:
            if self.RSI('SMH', 10) < 30:
                self.AH('SOXL', 1, 1.0)
            else:
                if self.RSI('SPY', 10) < 30:
                    self.AH('UPRO', 1, 1.0)
                else:
                    self.bear_market_sideways_protection()
    
    def svxy_ftlt(self):
        if self.RSI('QQQ', 10) > 80:
            self.AH('VIXY', 1, 0.33)
        else:
            if self.RSI('SPY', 10) > 80:
                self.AH('VIXY', 1, 0.33)
            else:
                if self.RSI('QQQ', 10) < 30:
                    self.AH('XLK', 1, 0.33)
                else:
                    if self.Securities['SVXY'].Price > self.SMA('SVXY', 24):
                        self.Sort('SMADayRet',('SVXY','SPY'),20,True,1,0.33)
                    else:
                        self.AH('BTAL', 1, 0.33)
    
    def spy_cooloff_period(self):
        self.AH('SHV', 1, 1.0)
    
    def bull_market(self):
            if self.RSI('QQQ', 10) > 80:
                self.AH('UVXY', 1, 1.0)
            else:
                if self.RSI('SPY', 10) > 80:
                    self.AH('UVXY', 1, 1.0)
                else:
                    if self.RSI('SPY', 60) > 60:
                        self.spy_cooloff_period()
                    else:
                        self.Sort('SMADayRet',('TQQQ','TECL','UDOW','UPRO'),21,True,1,0.67, 2)
                        self.svxy_ftlt()
    
    def tqqq_ftlt(self):
        if self.Securities['SPY'].Price > self.SMA('SPY', 200):
            self.bull_market()
        else:
            self.dip_buy_strategy()

    def ExecuteTrade(self):
        group1 = {
            'HTS': [self.HTS1[i][0] if len(self.HTS1[i]) == 1 else self.HTS1[i] for i in self.HTS1],
            'HT': [self.HT1[i] for i in self.HT1]
        }
        df1 = pd.DataFrame(group1)
        group2 = {
            'HTS': [self.HTS2[i][0] if len(self.HTS2[i]) == 1 else self.HTS2[i] for i in self.HTS2],
            'HT': [self.HT2[i] for i in self.HT2]
        }
        df2 = pd.DataFrame(group2)


        group3 = {
            'HTS': [self.HTS3[i][0] if len(self.HTS3[i]) == 1 else self.HTS3[i] for i in self.HTS3],
            'HT': [self.HT3[i] for i in self.HT3]
        }
        df3 = pd.DataFrame(group3)

        df = pd.concat([df1, df2, df3])
        df['HTS'] = df['HTS'].astype(str)
        result = df.groupby(['HTS']).sum().reset_index()
        for equity in self.equities:
            if all(not pd.isnull(result.iloc[i,0]) and not equity == result.iloc[i,0] for i in range(len(result))):
                if self.Portfolio[equity].HoldStock:
                    self.Liquidate(equity)
        output = "*****"
        for i in range(len(result)):
            if result.iloc[i,0]:
                percentage = round(result.iloc[i,1] * 100,2)
                output += "{}: {}% - ".format(result.iloc[i,0],percentage)
        output = output.rstrip(" - ")
        self.Log(output)
        for i in range(len(result)):
            if not result.iloc[i,1] == 0 and not result.iloc[i,0] == 'BIL':
                percentage_equity = self.Portfolio[result.iloc[i,0]].HoldingsValue / self.Portfolio.TotalPortfolioValue
                if result.iloc[i,1] < percentage_equity and abs(result.iloc[i,1] / percentage_equity - 1) > self.buffer_pct:
                    self.SetHoldings(result.iloc[i,0],result.iloc[i,1])
                else:
                    pass
        for i in range(len(result)):
            if not result.iloc[i,1] == 0 and not result.iloc[i,0] == 'BIL':
                percentage_equity = self.Portfolio[result.iloc[i,0]].HoldingsValue / self.Portfolio.TotalPortfolioValue
                if result.iloc[i,1] > percentage_equity and abs(percentage_equity / result.iloc[i,1] - 1) > self.buffer_pct:
                    self.SetHoldings(result.iloc[i,0],result.iloc[i,1])
                else:
                    pass

        self.HT1 = {str(i).zfill(2): 0 for i in range(1,10)}
        self.HTS1 = {str(i).zfill(2): [] for i in range(1,10)}
        self.HT2 = {str(i).zfill(2): 0 for i in range(1,10)}
        self.HTS2 = {str(i).zfill(2): [] for i in range(1,10)}
        self.HT3 = {str(i).zfill(2): 0 for i in range(1,10)}
        self.HTS3 = {str(i).zfill(2): [] for i in range(1,10)}
from AlgorithmImports import *
from indicators import *
from main import YellowCatStrat

#https://app.composer.trade/symphony/55MOoMbflnJSsyf7QACE/details

class WarTimeStrategywYieldMax20Strategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        AH(self.algo,'XAR',237,0.2)
        Sort(self.algo,'CumReturn',('TSLY','CONY','NVDY','AMDY','APLY','AMZY','OARK','DISO','GOOY','PYPY','MSFO','JPMO','XOMO','NFLY','FBY','SQY','MRNY'),4,True,2,237,0.8)


#https://app.composer.trade/symphony/IDiDD9n9bs6c4gRcfwkt/details

class WLBTFrameworkRotatorStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo,'BND',10) > RSI(self.algo,'SPHB',10):
            AH(self.algo,'ARKK',238,1)
        else:
            if GetCurrentPrice(self.algo,'ARKK') < SMA(self.algo,'ARKK',200):
                if RSI(self.algo,'ARKK',10) < 31:
                    AH(self.algo,'TARK',238,1) 
                else:
                    AH(self.algo,'SARK',238,1) 
            else:
                AH(self.algo,'SHV',238,1.0)
    
#https://app.composer.trade/symphony/CiqPIRWCU9zGCxW7KMeu/details

class xHEDGEDLEVERAGEDBONDSSTOCKSV211BT126224ReplaceUPROwithTECLTQQQandSOXLStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.hedged_leveraged_bonds_stocks_v211_bt_126224_replace_upro_with_tecl_tqqq_and_soxl()
    
    def hedged_leveraged_bonds_stocks_v211_bt_126224_replace_upro_with_tecl_tqqq_and_soxl(self):
        if GetCurrentPrice(self.algo,'TLT') > SMA(self.algo,'TLT',150):
            if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
                AH(self.algo,'TECL',239,0.2)
                AH(self.algo,'TQQQ',239,0.2)
                AH(self.algo,'SOXL',239,0.2)
                AH(self.algo,'TMF',239,0.2)
                AH(self.algo,'PHDG',239,0.2)
            else:
                AH(self.algo,'TLT',239,1.0)
        else:
            if GetCurrentPrice(self.algo,'TLT') < SMA(self.algo,'TLT',23):
                Sort(self.algo,'CumReturn',('TMV','UDOW','BIL'),5,True,2,239,1.0)
            else:
                Sort(self.algo,'CumReturn',('TMF','UPRO','TMV','MOAT','BRK/B','USMV'),30,True,1,239,1.0)

#https://app.composer.trade/symphony/74FHpgXjiu6TMEYDW7fQ/details

class V101dAmoebaLowDDVariationxxxDailyBTMar3022632160AR115DDDec12226InvestCopyStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
       if GetCurrentPrice(self.algo,'SPY') > SMA(self.algo,'SPY',200):
           if RSI(self.algo,'QQQ',10) > 79:
               AH(self.algo,'SOXS',235,0.2)
           else:
               if RSI(self.algo,'SPY',10) > 80:
                   AH(self.algo,'SOXS',235,0.2)
               else:
                   AH(self.algo,'TQQQ',235,0.2)
       else:
           if RSI(self.algo,'QQQ',10) < 31:
               AH(self.algo,'TECL',235,0.2)
           else:
               if RSI(self.algo,'SPY',10) < 30:
                   AH(self.algo,'UPRO',235,0.2)
               else:
                   if GetCurrentPrice(self.algo,'QQQ') < SMA(self.algo,'QQQ',20):
                       Sort(self.algo,'RSI',('SQQQ','TLT'),10,True,1,235,0.2)
                   else:
                       if RSI(self.algo,'PSQ',10) < 31:
                           AH(self.algo,'SQQQ',235,0.2)
                       else:
                           AH(self.algo,'TQQQ',235,0.2)
       if RSI(self.algo,'QQQ',10) > 79:
           AH(self.algo,'SOXS',235,0.8)
       else:
           if RSI(self.algo,'SPY',10) > 80:
               AH(self.algo,'SOXS',235,0.8)
           else:
               if RSI(self.algo,'QQQ',10) < 31:
                   AH(self.algo,'TQQQ',235,0.8)
               else:
                   if RSI(self.algo,'IEF',10) > RSI(self.algo,'PSQ',20):
                       AH(self.algo,'FNGU',235,0.25) 
                       AH(self.algo,'SOXL',235,0.25) 
                       AH(self.algo,'SVOL',235,0.25)
                   else:
                       AH(self.algo,'PSQ',235,0.8)
    
#https://app.composer.trade/symphony/4BcMMSL17xKrTJoDynju/details

class WAMlessStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1a_a_better_()
    
    def v1a_a_better_(self):
        if CumReturn(self.algo, 'QQQ', 5) < -0.06:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.05:
                AH(self.algo,'SQQQ',236,1.0)
            else:
                if RSI(self.algo,'TQQQ',10) > 31:
                    AH(self.algo,'SQQQ',236,1.0)
                else:
                    AH(self.algo,'TQQQ',236,1.0)
        else:
            if RSI(self.algo,'QQQ',10) > 80:
                AH(self.algo,'SQQQ',236,1.0)
            else:
                if RSI(self.algo,'QQQ',10) < 31:
                    AH(self.algo,'TQQQ',236,1.0)
                else:
                    Sort(self.algo,'RSI',('APLY','MSFO','NVDY','TSLY'),40,True,1,236,1.0)

#https://app.composer.trade/symphony/ADmWNa8WqwVGUwTyadBC/details

class LV144aProteusSlimeDividendsl1000BBV3042AMergedwithMagicInternetMoneyCONSandV1NewSOXLBallerStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.yieldmax_ss_sd()
    
    def yieldmax_ss_sd(self):
        if RSI(self.algo,'VIXM',40) > 69:
            AH(self.algo,'SPXU',135,1.0)
        else:
            Sort(self.algo,'STD',('APLY','MSFO','NVDY','AMDY'),10,False,2,135,1.0)
    
#https://app.composer.trade/symphony/7gKYUtcB39mqAEfo2j2i/details

class MagicInternetMoney2xQQQFTLTStrategy(YellowCatStrat):
    def __init__(self,algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1_hobbiton_hedge_funds_weekly_big_5_janmay_2023_list()
        self.v131_weekly_jepi_jedi_hibl_aggressive()
    
    def v131_weekly_jepi_jedi_hibl_aggressive(self):
        if SMADayRet(self.algo,'BND',10) > SMADayRet(self.algo,'TBX',10):
            AH(self.algo,'JEPI',136,0.08)
            AH(self.algo,'DBMF',136,0.08)
            AH(self.algo,'HIBL',136,0.08)
            Sort(self.algo,'SMADayRet',('HIBL','TQQQ','TBX','SVXY'),7,True,1,136,0.25)
        else:
            AH(self.algo,'JEPI',136,0.12)
            AH(self.algo,'DBMF',136,0.12)
            Sort(self.algo,'RSI',('BTAL','UGL','USDU','TQQQ'),10,False,1,136,0.12)
            Sort(self.algo,'RSI',('DIG','VIXM','YCS','EUO','PST'),21,False,1,136,0.12)

    def v1_hobbiton_hedge_funds_weekly_big_5_janmay_2023_list(self):
        Sort(self.algo,'RSI',('CRESY','TKC','FET','TDW','GLD','SLV','NUGT','PPLT','GGB','RIG','ARGT','NBR','PKX','BORR','XPRO','FRO','SMHI','SPY','FTI','GEOS','SPY','SPY','OIH','UGP','BTU','CEIX','ARCH','EC'),60,False,10,136,0.5)
    

#https://app.composer.trade/symphony/0lY4zupz0QNv0CeICL49/details

class V10AnansiPortfolio5050Split20121025Strategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v4002e_beta_baller_wrapper_wmdyn_anansi_bwc_whsmacon_eric()
    
    def short_rotator_sqqq(self):
        Sort(self.algo,'RSI',('SQQQ','BND'),10,True,1,257,1.0)
    
    def branch_from_tqqq_or_not_modified(self):
        if RSI(self.algo, 'SPY', 60) > 50:
            self.short_rotator_sqqq()
        else:
            if RSI(self.algo, 'IEF', 200) < RSI(self.algo, 'TLT', 200):
                self.short_rotator_sqqq()
            else:
                AH(self.algo, 'BIL', 257, 1.0)
    
    def what_more_do_you_need_modded(self):
        if RSI(self.algo, 'TQQQ', 10) < 31:
            AH(self.algo, 'FNGU', 257, 1.0)
        else:
            if RSI(self.algo, 'IEF', 10) > RSI(self.algo, 'PSQ', 20):
                AH(self.algo, 'FNGU', 257, 1.0)
            else:
                if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
                    AH(self.algo, 'XLP', 257, 0.5)
                    AH(self.algo, 'PDBC', 257, 0.5)
                else:
                    self.branch_from_tqqq_or_not_modified()
    
    def rotator_tqqqtlt_15d_ma_t1(self):
        Sort(self.algo,'SMADayRet',('TQQQ','TLT'),15,True,1,257,1.0)
    
    def safety_rotator_5d_rsi_t1(self):
        Sort(self.algo,'RSI',('VIXY','TLT','SH'),5,True,1,257,1.0)
    
    def tqqq_or_safety(self):
        if STD(self.algo, 'SPY', 10) > 3:
            self.safety_rotator_5d_rsi_t1()
        else:
            self.rotator_tqqqtlt_15d_ma_t1()
    
    def vegan_tccc_wrapper_modded(self):
        if SMADayRet(self.algo, 'BIL', 100) < SMADayRet(self.algo, 'TLT', 100):
            if CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                    AH(self.algo, 'UVXY', 257, 1.0)
                else:
                    self.tqqq_or_safety()
            else:
                self.tqqq_or_safety()
        else:
            self.what_more_do_you_need_modded()
    
    def beta_baller_wrapper_modded(self):
        if RSI(self.algo, 'BOXX', 10) < RSI(self.algo, 'TLT', 10):
            if RSI(self.algo, 'SPY', 10) > 75:
                AH(self.algo, 'UVXY', 257, 1.0)
            else:
                if RSI(self.algo, 'SOXX', 5) > 80:
                    AH(self.algo, 'SOXS', 257, 1.0)
                else:
                    AH(self.algo, 'SOXL', 257, 1.0)
        else:
            if RSI(self.algo, 'SPY', 5) < 25:
                if RSI(self.algo, 'SPHB', 10) < 48:
                    AH(self.algo, 'FNGU', 257, 1.0)
                else:
                    AH(self.algo, 'FNGD', 257, 1.0)
            else:
                self.vegan_tccc_wrapper_modded()
    
    def v4002e_beta_baller_wrapper_wmdyn_anansi_bwc_whsmacon_eric(self):
        if RSI(self.algo, 'TQQQ', 10) > 79:
            AH(self.algo, 'UVXY', 257, 1.0)
        else:
            if RSI(self.algo, 'XLK', 10) > 79:
                AH(self.algo, 'UVXY', 257, 1.0)
            else:
                if RSI(self.algo, 'VOX', 10) > 79:
                    AH(self.algo, 'UVXY', 257, 1.0)
                else:
                    if RSI(self.algo, 'VTV', 10) > 79:
                        AH(self.algo, 'UVXY', 257, 1.0)
                    else:
                        if RSI(self.algo, 'TQQQ', 14) < 30:
                            AH(self.algo, 'TQQQ', 257, 1.0)
                        else:
                            if RSI(self.algo, 'SMH', 14) < 30:
                                AH(self.algo, 'SOXL', 257, 1.0)
                            else:
                                self.beta_baller_wrapper_modded()

#https://app.composer.trade/symphony/0jL16xcw2J63Vzg8UCly/details

class V4002eBetaBallerWrapperWMDYNAnansiBWCWHSmaconEricStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v4002e_beta_baller_wrapper_wmdyn_anansi_bwc_whsmacon_eric()
    
    def short_rotator_sqqq(self):
        Sort(self.algo,'RSI',('SQQQ','BND'),10,True,1,258,1.0)
    
    def branch_from_tqqq_or_not_modified(self):
        if RSI(self.algo, 'SPY', 60) > 50:
            self.short_rotator_sqqq()
        else:
            if RSI(self.algo, 'IEF', 200) < RSI(self.algo, 'TLT', 200):
                self.short_rotator_sqqq()
            else:
                AH(self.algo, 'BIL', 258, 1.0)
    
    def what_more_do_you_need_modded(self):
        if RSI(self.algo, 'TQQQ', 10) < 31:
            AH(self.algo, 'FNGU', 258, 1.0)
        else:
            if RSI(self.algo, 'IEF', 10) > RSI(self.algo, 'PSQ', 20):
                AH(self.algo, 'FNGU', 258, 1.0)
            else:
                if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
                    AH(self.algo, 'XLP', 258, 0.5)
                    AH(self.algo, 'PDBC', 258, 0.5)
                else:
                    self.branch_from_tqqq_or_not_modified()
    
    def rotator_tqqqtlt_15d_ma_t1(self):
        Sort(self.algo,'SMADayRet',('TQQQ','TLT'),15,True,1,258,1.0)
    
    def safety_rotator_5d_rsi_t1(self):
        Sort(self.algo,'RSI',('VIXY','TLT','SH'),5,True,1,258,1.0)
    
    def tqqq_or_safety(self):
        if STD(self.algo, 'SPY', 10) > 3:
            self.safety_rotator_5d_rsi_t1()
        else:
            self.rotator_tqqqtlt_15d_ma_t1()
    
    def vegan_tccc_wrapper_modded(self):
        if SMADayRet(self.algo, 'BIL', 100) < SMADayRet(self.algo, 'TLT', 100):
            if CumReturn(self.algo, 'TQQQ', 6) < -0.1:
                if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                    AH(self.algo, 'UVXY', 258, 1.0)
                else:
                    self.tqqq_or_safety()
            else:
                self.tqqq_or_safety()
        else:
            self.what_more_do_you_need_modded()
    
    def beta_baller_wrapper_modded(self):
        if RSI(self.algo, 'BOXX', 10) < RSI(self.algo, 'TLT', 10):
            if RSI(self.algo, 'SPY', 10) > 75:
                AH(self.algo, 'UVXY', 258, 1.0)
            else:
                if RSI(self.algo, 'SOXX', 5) > 80:
                    AH(self.algo, 'SOXS', 258, 1.0)
                else:
                    AH(self.algo, 'SOXL', 258, 1.0)
        else:
            if RSI(self.algo, 'SPY', 5) < 25:
                if RSI(self.algo, 'SPHB', 10) < 48:
                    AH(self.algo, 'FNGU', 258, 1.0)
                else:
                    AH(self.algo, 'FNGD', 258, 1.0)
            else:
                self.vegan_tccc_wrapper_modded()
    
    def v4002e_beta_baller_wrapper_wmdyn_anansi_bwc_whsmacon_eric(self):
        if RSI(self.algo, 'TQQQ', 10) > 79:
            AH(self.algo, 'UVXY', 258, 1.0)
        else:
            if RSI(self.algo, 'XLK', 10) > 79:
                AH(self.algo, 'UVXY', 258, 1.0)
            else:
                if RSI(self.algo, 'VOX', 10) > 79:
                    AH(self.algo, 'UVXY', 258, 1.0)
                else:
                    if RSI(self.algo, 'VTV', 10) > 79:
                        AH(self.algo, 'UVXY', 258, 1.0)
                    else:
                        if RSI(self.algo, 'TQQQ', 14) < 30:
                            AH(self.algo, 'TQQQ', 258, 1.0)
                        else:
                            if RSI(self.algo, 'SMH', 14) < 30:
                                AH(self.algo, 'SOXL', 258, 1.0)
                            else:
                                self.beta_baller_wrapper_modded()

#https://app.composer.trade/symphony/q4bmyjbVIT0eCKACg8YG/details

class Av6SymphonySorterStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.qld_ftlt()
    
    def sideways_market_deleverage(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 20):
            AH(self.algo, 'SPY', 259, 0.5)
        else:
            if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'PSQ', 10):
                AH(self.algo, 'QQQ', 259, 0.5)
            else:
                AH(self.algo, 'PSQ', 259, 0.5)
        if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'PSQ', 10):
            AH(self.algo, 'QQQ', 259, 0.5)
        else:
            AH(self.algo, 'PSQ', 259, 0.5)
    
    def nasdaq_in_crash_territory_time_to_deleverage(self):
        if GetCurrentPrice(self.algo, 'QQQ') < SMA(self.algo, 'QQQ', 20):
            if CumReturn(self.algo, 'QQQ', 60) <= -0.12:
                self.sideways_market_deleverage()
            else:
                if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'PSQ', 10):
                    AH(self.algo, 'QLD', 259, 1.0)
                else:
                    AH(self.algo, 'QID', 259, 1.0)
        else:
            if RSI(self.algo, 'PSQ', 10) < 31:
                AH(self.algo, 'PSQ', 259, 1.0)
            else:
                if CumReturn(self.algo, 'QQQ', 10) > 0.055:
                    AH(self.algo, 'PSQ', 259, 1.0)
                else:
                    Sort(self.algo,'RSI',('QQQ','SMH'),10,True,1,259,1.0)
    
    def bear_market_sideways_protection_2008_edition(self):
        if CumReturn(self.algo, 'QQQ', 252) < -0.2:
            self.nasdaq_in_crash_territory_time_to_deleverage()
        else:
            if GetCurrentPrice(self.algo, 'QQQ') < SMA(self.algo, 'QQQ', 20):
                if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'PSQ', 10):
                    AH(self.algo, 'QLD', 259,0.5)
                else:
                    AH(self.algo, 'QID', 259,0.5)
            else:
                if RSI(self.algo, 'PSQ', 10) < 31:
                    AH(self.algo, 'QID', 259,0.5)
                else:
                    if CumReturn(self.algo, 'QQQ', 10) > 0.055:
                        AH(self.algo, 'QID', 259,0.5)
                    else:
                        Sort(self.algo,'RSI',('QLD','USD'),10,True,1,259,0.5)
        if GetCurrentPrice(self.algo, 'QQQ') > SMA(self.algo, 'QQQ', 20):
            if RSI(self.algo, 'PSQ', 10) < 30:
                AH(self.algo, 'PSQ', 259,0.5)
            else:
                if CumReturn(self.algo, 'QQQ', 10) > 0.055:
                    AH(self.algo, 'SHV', 259,0.5)
                else:
                    AH(self.algo, 'QQQ', 259,0.5)
        else:
            Sort(self.algo,'RSI',('IEF','PSQ'),10,True,1,259,0.5)
    
    def to_test_back_to_2008_use_tlt_in_place_of_uvxy(self):
        AH(self.algo, 'TLT', 259, 1.0)
    
    def qld_ftlt(self):
        if RSI(self.algo, 'QQQ', 10) < 30:
            AH(self.algo, 'ROM', 259, 1.0)
        else:
            if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
                if RSI(self.algo, 'QQQ', 10) > 80:
                    self.to_test_back_to_2008_use_tlt_in_place_of_uvxy()
                else:
                    if RSI(self.algo, 'SPY', 10) > 80:
                        self.to_test_back_to_2008_use_tlt_in_place_of_uvxy()
                    else:
                        if RSI(self.algo, 'SPY', 60) > 60:
                            AH(self.algo, 'TLT', 259, 1.0)
                        else:
                            AH(self.algo, 'QLD', 259, 1.0)
            else:
                self.bear_market_sideways_protection_2008_edition()
    
#https://app.composer.trade/symphony/9PzLly9uidYy5U05NB6D/details

class LTESTPORT061DWGMultiSymphony2Strategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.safety_town_v14_w_pop_bots_v10()
    
    def vixm_btal(self):
        AH(self.algo, 'BTAL', 260, 0.005)
        AH(self.algo, 'VIXM', 260, 0.005)
    
    def vix_hack(self):
        if RSI(self.algo, 'SPY', 10) >= 70:
            AH(self.algo, 'UVXY', 260, 0.01)
            AH(self.algo, 'VIXM', 260, 0.01)
        else:
            AH(self.algo, 'SVXY', 260, 0.01)
            self.vixm_btal()
        if RSI(self.algo, 'SPY', 14) >= 65:
            AH(self.algo, 'UVXY', 260, 0.01)
            AH(self.algo, 'VIXM', 260, 0.01)
        else:
            AH(self.algo, 'SVXY', 260, 0.01)
            self.vixm_btal()
        if RSI(self.algo, 'SPY', 14) >= 65:
            AH(self.algo, 'UVXY', 260, 0.01)
            AH(self.algo, 'VIXM', 260, 0.01)
        else:
            Sort(self.algo,'STD',('SVXY','VIXM','BTAL'),21,True,2,260,0.02)
        if RSI(self.algo, 'SPY', 10) >= 70:
            AH(self.algo, 'UVXY', 260, 0.01)
            AH(self.algo, 'VIXM', 260, 0.01)
        else:
            Sort(self.algo,'STD',('SVXY','VIXM','BTAL'),21,True,2,260,0.02)
    
    def safe_haven(self):
            AH(self.algo, 'GLD', 260,0.005)
            AH(self.algo, 'XLP', 260,0.005)
            AH(self.algo, 'DBMF', 260,0.005)
            AHIV(self.algo, ('UUP', 'SHY', 'SHV'), 30, 260,0.005)
    
    def _safety_town_v14(self):
        self.safe_haven()
        self.vix_hack()
    
    def soxl_pop(self):
        if RSI(self.algo, 'SOXL', 10) < 30:
            AH(self.algo, 'SOXL', 260, 0.04)
        else:
            self._safety_town_v14()
    
    def spxl_pop(self):
        if RSI(self.algo, 'SPXL', 10) < 30:
            AH(self.algo, 'SPXL', 260, 0.04)
        else:
            self._safety_town_v14()
    
    def tqqq_pop(self):
        if RSI(self.algo, 'TQQQ', 10) < 30:
            AH(self.algo, 'TQQQ', 260, 0.04)
        else:
            self._safety_town_v14()
    
    def pop_bots(self):
        self.tqqq_pop()
        self.spxl_pop()
        self.soxl_pop()
    
    def uvxy_10x76_is_best_level(self):
        if RSI(self.algo, 'TQQQ', 10) > 76:
            AH(self.algo, 'UVXY', 260, 0.125)
        else:
            self.pop_bots()
    
    def uvxy_7x8587_is_best_level(self):
        if RSI(self.algo, 'TQQQ', 7) > 85:
            AH(self.algo, 'UVXY', 260, 0.125)
        else:
            self.pop_bots()
    
    def uvxy_5x8991_is_best_level(self):
        if RSI(self.algo, 'TQQQ', 5) > 90:
            AH(self.algo, 'UVXY', 260, 0.125)
        else:
            self.pop_bots()
    
    def uvxy_3x95_is_best_level(self):
        if RSI(self.algo, 'TQQQ', 3) > 95:
            AH(self.algo, 'UVXY', 260, 0.125)
        else:
            self.pop_bots()
    
    def qqq(self):
        self.uvxy_3x95_is_best_level()
        self.uvxy_5x8991_is_best_level()
        self.uvxy_7x8587_is_best_level()
        self.uvxy_10x76_is_best_level()
    
    def uvxy_10x80_or_higher_is_best_level(self):
        if RSI(self.algo, 'SPXL', 10) > 80:
            AH(self.algo, 'UVXY', 260, 0.16)
        else:
            self.pop_bots()
    
    def uvxy_7x85_is_best_level(self):
        if RSI(self.algo, 'SPXL', 7) > 85:
            AH(self.algo, 'UVXY', 260, 0.16)
        else:
            self.pop_bots()
    
    def uvxy_4x88_is_best_level(self):
        if RSI(self.algo, 'SPXL', 4) > 88:
            AH(self.algo, 'UVXY', 260, 0.16)
        else:
            self.pop_bots()
    
    def spy(self):
        self.uvxy_4x88_is_best_level()
        self.uvxy_7x85_is_best_level()
        self.uvxy_10x80_or_higher_is_best_level()
    
    def safety_town_v14_w_pop_bots_v10(self):
        self.spy()
        self.qqq()
    
#https://app.composer.trade/symphony/JA4UiNuABnjhhhw3A4Xj/details
    
#https://app.composer.trade/symphony/JTv1bOWI9eounzInSrBt/details

class AVolmageddon20Strategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.volmageddon_20()
    
    def normal_logic(self):
         AH(self.algo, 'SVIX', 262, 1.0)
    
    def dropping_fast_lets_defend(self):
        if STD(self.algo, 'UVXY', 5) < STD(self.algo, 'UVXY', 10):
            if RSI(self.algo, 'SPY', 14) > 50:
                AH(self.algo, 'SVXY', 262, 1.0)
            else:
                if SMADayRet(self.algo, 'UVXY', 3) > SMADayRet(self.algo, 'VIXM', 3):
                    if RSI(self.algo, 'UVXY', 10) > 70:
                        Sort(self.algo,'SMADayRet',('UVXY','VIXY'),5,True,1,262,1.0)
                    else:
                        AH(self.algo, 'SVXY', 262, 1.0)
                else:
                    AH(self.algo, 'SVXY', 262, 1.0)
        else:
            Sort(self.algo,'SMADayRet',('SPY','BIL'),14,True,1,262,1.0)
    
    def volatility_bsc_10a(self):
        if STD(self.algo, 'UVXY', 10) > 10:
            self.dropping_fast_lets_defend()
        else:
            self.normal_logic()
    
    def volmageddon_20(self):
        if RSI(self.algo, 'QQQE', 10) > 80:
            AH(self.algo, 'UVXY', 262, 1.0)
        else:
            if RSI(self.algo, 'VTV', 10) > 80:
                AH(self.algo, 'BIL', 262, 1.0)
            else:
                if RSI(self.algo, 'VOX', 10) > 80:
                    AH(self.algo, 'BIL', 262, 1.0)
                else:
                    if RSI(self.algo, 'TECL', 10) > 79:
                        AH(self.algo, 'UVXY', 262, 1.0)
                    else:
                        if RSI(self.algo, 'VOOG', 10) > 79:
                            AH(self.algo, 'UVXY', 262, 1.0)
                        else:
                            if RSI(self.algo, 'VOOV', 10) > 79:
                                AH(self.algo, 'BIL', 262, 1.0)
                            else:
                                if RSI(self.algo, 'XLP', 10) > 75:
                                    AH(self.algo, 'BIL', 262, 1.0)
                                else:
                                    if RSI(self.algo, 'TQQQ', 10) > 79:
                                        AH(self.algo, 'UVXY', 262, 1.0)
                                    else:
                                        if RSI(self.algo, 'XLY', 10) > 80:
                                            AH(self.algo, 'UVXY', 262, 1.0)
                                        else:
                                            if RSI(self.algo, 'XLC', 10) > 80:
                                                AH(self.algo, 'UVXY', 262, 1.0)
                                            else:
                                                if RSI(self.algo, 'XLE', 10) > 80:
                                                    AH(self.algo, 'BIL', 262, 1.0)
                                                else:
                                                    if RSI(self.algo, 'FAS', 10) > 80:
                                                        AH(self.algo, 'VIXY', 262, 0.5)
                                                        AH(self.algo, 'BIL', 262, 0.5)
                                                    else:
                                                        if RSI(self.algo, 'SPY', 10) > 80:
                                                            AH(self.algo, 'UVXY', 262, 1.0)
                                                        else:
                                                            if CumReturn(self.algo, 'TQQQ', 6) < -0.12:
                                                                if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                                                                    AH(self.algo, 'UVXY', 262, 1.0)
                                                                else:
                                                                    AH(self.algo, 'BIL', 262, 1.0)
                                                            else:
                                                                self.volatility_bsc_10a()
    

#https://app.composer.trade/symphony/p5sfa3E10lBvid1Nadv0/details


class AV1aQQQSince2010Strategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.v1a_qqq_since_2010()
    
    def sideways_market_deleverage(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 20):
            AH(self.algo, 'SPY', 263, 0.5)
        else:
            if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'PSQ', 10):
                AH(self.algo, 'QQQ', 263, 0.5)
            else:
                AH(self.algo, 'PSQ', 263, 0.5)
        if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'PSQ', 10):
            AH(self.algo, 'QQQ', 263, 0.5)
        else:
            AH(self.algo, 'PSQ', 263, 0.5)

    def nasdaq_in_crash_territory_time_to_deleverage(self):
        if GetCurrentPrice(self.algo, 'QQQ') < SMA(self.algo, 'QQQ', 20):
            if CumReturn(self.algo, 'QQQ', 60) <= -0.12:
                self.sideways_market_deleverage()
            else:
                if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'PSQ', 10):
                    AH(self.algo, 'QLD', 263, 0.5)
                else:
                    AH(self.algo, 'QID', 263, 0.5)
        else:
            if RSI(self.algo, 'PSQ', 10) < 31:
                AH(self.algo, 'PSQ', 263, 0.5)
            else:
                if CumReturn(self.algo, 'QQQ', 10) > 0.055:
                    AH(self.algo, 'PSQ', 263, 0.5)
                else:
                    Sort(self.algo,'RSI',('QQQ','SMH'),10,True,1,263,0.5)
    
    def bear_market_sideways_protection_2008_edition(self):
        if CumReturn(self.algo, 'QQQ', 252) < -0.2:
            self.nasdaq_in_crash_territory_time_to_deleverage()
        else:
            if GetCurrentPrice(self.algo, 'QQQ') < SMA(self.algo, 'QQQ', 20):
                if RSI(self.algo, 'TLT', 10) > RSI(self.algo, 'PSQ', 10):
                    AH(self.algo, 'QLD', 263, 0.5)
                else:
                    AH(self.algo, 'QID', 263, 0.5)
            else:
                if RSI(self.algo, 'PSQ', 10) < 31:
                    AH(self.algo, 'QID', 263, 0.5)
                else:
                    if CumReturn(self.algo, 'QQQ', 10) > 0.055:
                        AH(self.algo, 'QID', 263, 0.5)
                    else:
                        Sort(self.algo,'RSI',('QLD','USD'),10,True,1,263,0.5)
    
    def qqq_since_2007(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            if RSI(self.algo, 'QQQ', 10) > 80:
                AH(self.algo, 'TLT', 263, 1)
            else:
                if RSI(self.algo, 'SPY', 10) > 80:
                    AH(self.algo, 'TLT', 263, 1)
                else:
                    if RSI(self.algo, 'SPY', 60) > 60:
                        AH(self.algo, 'TLT', 263, 1)
                    else:
                        AH(self.algo, 'QQQ', 263, 1)
        else:
            if RSI(self.algo, 'QQQ', 10) < 30:
                AH(self.algo, 'QLD', 263, 1)
            else:
                if GetCurrentPrice(self.algo, 'QQQ') > SMA(self.algo, 'QQQ', 20):
                    if RSI(self.algo, 'PSQ', 10) < 30:
                        AH(self.algo, 'PSQ', 263, 1)
                    else:
                        if CumReturn(self.algo, 'QQQ', 10) > 0.055:
                            AH(self.algo, 'SHV', 263, 1)
                        else:
                            AH(self.algo, 'QQQ', 263, 1)
                else:
                    Sort(self.algo,'RSI',('IEF','PSQ'),10,True,1,263,0.5)
                    self.bear_market_sideways_protection_2008_edition()
    
    def huge_volatility(self):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.13:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.06:
                AH(self.algo, 'SOXS', 263, 1)
            else:
                self.qqq_since_2007()
        else:
            self.qqq_since_2007()
    
    def v1a_qqq_since_2010(self):
        if RSI(self.algo, 'TQQQ', 10) > 79:
            AH(self.algo, 'SOXS', 263, 1)
        else:
            self.huge_volatility()

#https://app.composer.trade/symphony/TNFj6kgWRBLUMyRieBLl/details
class FrontrunnerPlanetsMixStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo, 'SPY', 10) > 80:
            self.group_vix_blend_plus_plus()
        else:
            if RSI(self.algo, 'IOO', 10) > 80:
                self.scale_in_vix_plus_to_plus_plus_IOO()
            else:
                if RSI(self.algo, 'QQQ', 10) > 79:
                    self.scale_in_vix_plus_to_plus_plus_QQQ()
                else:
                    if RSI(self.algo, 'VTV', 10) > 79:
                        self.group_vix_blend()
                    else:
                        if RSI(self.algo, 'XLP', 10) > 77:
                            self.group_vix_blend()
                        else:
                            if RSI(self.algo, 'XLF', 10) > 81:
                                self.group_vix_blend()
                            else:
                                if RSI(self.algo, 'SPY', 70) > 62:
                                    self.group_overbought()
                                else:
                                    if CumReturn(self.algo, 'VIXY', 9) > 0.2:
                                        self.group_high_vix()
                                    else:
                                        self.group_strats_go_here()

    def group_vix_blend_plus_plus(self):
        AH(self.algo, 'UVXY', 264, 1/3)
        AH(self.algo, 'UVXY', 264, 1/3)
        AH(self.algo, 'VIXM', 264, 1/3)

    def scale_in_vix_plus_to_plus_plus_IOO(self):
        if RSI(self.algo, 'IOO', 10) > 82.5:
            self.group_vix_blend_plus_plus()
        else:
            self.group_vix_blend_plus()

    def scale_in_vix_plus_to_plus_plus_QQQ(self):
        if RSI(self.algo, 'QQQ', 10) > 82.5:
            self.group_vix_blend_plus_plus()
        else:
            self.group_vix_blend_plus()

    def group_vix_blend_plus(self):
        AH(self.algo, 'UVXY', 264, 1/3)
        AH(self.algo, 'VXX', 264, 1/3)
        AH(self.algo, 'VIXM', 264, 1/3)

    def group_vix_blend(self):
        AH(self.algo, 'VIXY', 264, 1/3)
        AH(self.algo, 'VXX', 264, 1/3)
        AH(self.algo, 'VIXM', 264, 1/3)

    def group_overbought(self):
        if RSI(self.algo, 'AGG', 15) > RSI(self.algo, 'QQQ', 15):
            self.group_ticker_mixer()
        else:
            self.group_gld_slv_dbc()
        self.group_vix_stuff()

    def group_ticker_mixer(self):
        Sort(self.algo, 'SMADayRet', ('SPXL', 'TQQQ', 'TECL', 'SOXL', 'FNGU'), 15, True, 3, 264, 0.25)
        AH(self.algo, 'TQQQ', 264, 0.25)

    def group_gld_slv_dbc(self):
        AH(self.algo, 'GLD', 264, 0.25)
        AH(self.algo, 'SLV', 264, 0.125)
        AH(self.algo, 'DBC', 264, 0.125)

    def group_vix_stuff(self):
        if RSI(self.algo, 'QQQ', 90) > 60:
            AH(self.algo, 'VIXY', 264, 0.5)
        else:
            if RSI(self.algo, 'QQQ', 14) > 80:
                AH(self.algo, 'VIXY', 264, 0.5)
            else:
                if RSI(self.algo, 'QQQ', 5) > 90:
                    AH(self.algo, 'VIXY', 264, 0.5)
                else:
                    if RSI(self.algo, 'QQQ', 3) > 95:
                        AH(self.algo, 'VIXY', 264, 0.5)
                    else:
                        if RSI(self.algo, 'IEF', 10) > RSI(self.algo, 'PSQ', 20):
                            AH(self.algo, 'SVXY', 264, 0.5)
                        else:
                            AH(self.algo, 'SLV', 264, 0.5)

    def group_high_vix(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            if RSI(self.algo, 'UVXY', 21) > 65:
                self.group_bsc_31_rsi()
            else:
                self.group_svxy()
        else:
            if RSI(self.algo, 'TQQQ', 10) < 31:
                self.group_pick_bottom_3_1_5x()
            else:
                if CumReturn(self.algo, 'VIXY', 10) > 0.25:
                    self.group_volmageddon_protection()
                else:
                    self.group_inverse_vix_mix()

    def group_bsc_31_rsi(self):
        if RSI(self.algo, 'SPY', 10) > 31:
            if MaxDD(self.algo, 'SVXY', 5) > 0.15:
                self.group_uvix_volatility()
            else:
                self.group_uvxy_volatility()
        else:
            self.group_svxy()

    def group_uvix_volatility(self):
        AH(self.algo, 'UVXY', 264, 0.1)
        AH(self.algo, 'BTAL', 264, 0.9)

    def group_uvxy_volatility(self):
        AH(self.algo, 'UVXY', 264, 0.1)
        self.group_vix_mix(0.3)
        AH(self.algo, 'BTAL', 264, 0.6)

    def group_vix_mix(self, weight):
        Sort(self.algo, 'SMADayRet', ('SOXS', 'TECS', 'SQQQ', 'OILD', 'TMV', 'FAZ', 'DRV', 'EDZ', 'DXD', 'SPXS', 'SDOW', 'FNGD'), 10, False, 2, 264, weight)

    def group_svxy(self):
        if MaxDD(self.algo, 'SVXY', 3) > 0.2:
            self.group_volmageddon_protection()
        else:
            if CumReturn(self.algo, 'VIXY', 5) > 0.45:
                AH(self.algo, 'SVIX', 264, 1)
            else:
                AH(self.algo, 'SVXY', 264, 0.5)
                self.group_inverse_vix_mix(0.5)

    def group_volmageddon_protection(self):
        AH(self.algo, 'BTAL', 264, 1/3)
        AH(self.algo, 'USMV', 264, 1/3)
        if CumReturn(self.algo, 'SVXY', 1) > 0.05:
            AH(self.algo, 'SVIX', 264, 1/3)
        else:
            AH(self.algo, 'SVXY', 264, 1/3)

    def group_inverse_vix_mix(self, weight=1):
        Sort(self.algo, 'SMADayRet', ('QLD', 'UYG', 'SAA', 'EFO', 'SSO', 'UDOW', 'UWM', 'ROM', 'ERX'), 10, False, 2, 264, weight)

    def group_pick_bottom_3_1_5x(self):
        Sort(self.algo, 'SMADayRet', ('SPXL', 'TQQQ', 'TECL', 'SOXL'), 10, False, 3, 264, 0.5)
        Sort(self.algo, 'SMADayRet', ('SPY', 'QQQ', 'XLK', 'SOXX'), 10, False, 3, 264, 0.5)

    def group_strats_go_here(self):
        AH(self.algo, 'BIL', 264, 1)

#https://app.composer.trade/symphony/eVz7RjuM6eVimfb2xMSA/details
class BestLeverageV31TrimAnansiParthStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo
        # Track allocated weight to ensure we don't exceed maximum
        self.allocated_weight = 0
        
    def Execute(self):
        # Reset allocated weight at the start of each execution
        self.allocated_weight = 0
        self.scale_in_frontrunner_anansi()

    def scale_in_frontrunner_anansi(self):
        if RSI(self.algo, 'SPY', 10) > 80:
            self.scale_in_vix_plus_to_vix_plus_plus('SPY', 82.5)
        elif RSI(self.algo, 'QQQ', 10) > 79:
            self.scale_in_vix_plus_to_vix_plus_plus('QQQ', 82.5)
        elif RSI(self.algo, 'XLP', 10) > 77:
            self.scale_in_vix_to_vix_plus('XLP', 85)
        elif RSI(self.algo, 'VTV', 10) > 79:
            self.scale_in_vix_to_vix_plus('VTV', 85)
        elif RSI(self.algo, 'XLF', 10) > 81:
            self.scale_in_vix_to_vix_plus('XLF', 85)
        elif RSI(self.algo, 'VOX', 10) > 79:
            self.scale_in_btal_to_vix('VOX', 85)
        elif RSI(self.algo, 'CURE', 10) > 82:
            self.scale_in_btal_to_vix('CURE', 85)
        elif RSI(self.algo, 'RETL', 10) > 82:
            self.scale_in_btal_to_vix('RETL', 85)
        else:
            self.high_vix_strategy()

    def allocate_position(self, symbol, max_weight, weight_fraction):
        """Helper method to safely allocate position weight"""
        weight = max_weight * weight_fraction
        if self.allocated_weight + weight <= 1.0:  # Ensure we don't exceed 100%
            AH(self.algo, symbol, 265, weight)
            self.allocated_weight += weight
            return True
        return False

    def scale_in_vix_plus_to_vix_plus_plus(self, asset, threshold):
        if RSI(self.algo, asset, 10) > threshold:
            self.vix_blend_plus_plus()
        else:
            self.vix_blend_plus()

    def scale_in_vix_to_vix_plus(self, asset, threshold):
        if RSI(self.algo, asset, 10) > threshold:
            self.vix_blend_plus()
        else:
            self.vix_blend()

    def scale_in_btal_to_vix(self, asset, threshold):
        if RSI(self.algo, asset, 10) > threshold:
            self.vix_blend()
        else:
            self.allocate_position('BTAL', 1.0, 1.0)

    def vix_blend_plus_plus(self):
        for symbol in ['UVXY', 'UVXY', 'VIXM']:
            self.allocate_position(symbol, 1.0, 1/3)

    def vix_blend_plus(self):
        for symbol in ['UVXY', 'VXX', 'VIXM']:
            self.allocate_position(symbol, 1.0, 1/3)

    def vix_blend(self):
        for symbol in ['VIXY', 'VXX', 'VIXM']:
            self.allocate_position(symbol, 1.0, 1/3)

    def high_vix_strategy(self):
        if CumReturn(self.algo, 'VIXY', 10) > 0.2:
            self.high_vix_conditions()
        else:
            self.strategies()

    def high_vix_conditions(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            if CumReturn(self.algo, 'VIXY', 10) > 0.275:
                self.allocate_position('BTAL', 1.0, 0.5)
                remaining_weight = 1.0 - self.allocated_weight
                if remaining_weight > 0:
                    self.ticker_mixer(remaining_weight)
            else:
                self.ticker_mixer(1.0)
        else:
            if RSI(self.algo, 'TQQQ', 10) < 30:
                self.pick_bottom_3(['SPXL', 'TQQQ', 'TECL', 'SOXL'], 1.0)
            elif CumReturn(self.algo, 'VIXY', 10) > 0.25:
                self.allocate_position('BTAL', 1.0, 1.0)
            else:
                self.ticker_mixer(1.0)

    def strategies(self):
        # Divide total weight among strategies
        self.caesars_tqqq_modified(0.5)
        remaining_weight = 1.0 - self.allocated_weight
        if remaining_weight > 0:
            weight_per_strategy = remaining_weight / 2
            self.foreign_rat(weight_per_strategy)
            self.ftlt_bull_bonds(weight_per_strategy)

    def caesars_tqqq_modified(self, total_weight):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            if SMA(self.algo, 'SPY', 3) < SMA(self.algo, 'SPY', 200):
                self.bull_cross(total_weight)
            else:
                self.caesars_long_blend(total_weight)
        else:
            if SMA(self.algo, 'SPY', 3) > SMA(self.algo, 'SPY', 200):
                self.bear_cross(total_weight)
            else:
                self.jrt_bear_plus(total_weight)

    def bull_cross(self, total_weight):
        if self.allocated_weight + total_weight <= 1.0:
            Sort(self.algo, 'RSI', ('TQQQ', 'SPXL', 'TMF'), 10, True, 2, 265, total_weight)
            self.allocated_weight += total_weight

    def caesars_long_blend(self, total_weight):
        # Distribute weight proportionally
        self.long_or_jrt(total_weight * 0.4)
        remaining_weight = total_weight - self.allocated_weight
        if remaining_weight > 0:
            self.long_top_1(remaining_weight * 0.583)  # 0.35/0.6 of remaining
            self.allocate_position('SVXY', remaining_weight, 0.417)  # 0.25/0.6 of remaining

    def long_or_jrt(self, weight):
        if CumReturn(self.algo, 'TBT', 60) < 0.1:
            self.long_top_1(weight)
        else:
            self.jrt_20_60(weight)

    def long_top_1(self, weight):
        if self.allocated_weight + weight <= 1.0:
            Sort(self.algo, 'SMADayRet', ('SOXL', 'TQQQ', 'FNGU', 'GUSH', 'DIG'), 252, True, 1, 265, weight)
            self.allocated_weight += weight

    def jrt_20_60(self, weight):
        if RSI(self.algo, 'AGG', 20) > RSI(self.algo, 'SH', 60):
            self.jrt(weight)
        else:
            self.allocate_position('PSQ', weight, 1.0)

    def jrt(self, weight):
        if self.allocated_weight + weight <= 1.0:
            weight_high_iv = weight * 0.75
            AHIV(self.algo, ('LLY', 'NVO', 'COST'), 10, 265, weight_high_iv)
            self.allocated_weight += weight_high_iv
            
            remaining_weight = weight * 0.25
            if self.allocated_weight + remaining_weight <= 1.0:
                Sort(self.algo, 'SMADayRet', ('PGR', 'GE'), 60, True, 1, 265, remaining_weight)
                self.allocated_weight += remaining_weight

    def bear_cross(self, weight):
        if self.allocated_weight + weight <= 1.0:
            Sort(self.algo, 'RSI', ('SQQQ', 'SPXU', 'TMF', 'TMV'), 10, True, 2, 265, weight)
            self.allocated_weight += weight

    def jrt_bear_plus(self, weight):
        if RSI(self.algo, 'QQQ', 10) < 31 or \
           RSI(self.algo, 'SPY', 10) < 30 or \
           RSI(self.algo, 'SOXL', 10) < 30 or \
           RSI(self.algo, 'FNGU', 10) < 30:
            self.pick_bottom_3(['SPXL', 'TQQQ', 'TECL', 'SOXL', 'FNGU'], weight)
        elif CumReturn(self.algo, 'QQQ', 60) < -0.12:
            self.jrt_10_20(weight)
        else:
            self.tqqq_conditions(weight)

    def pick_bottom_3(self, assets, total_weight):
        if self.allocated_weight + total_weight <= 1.0:
            Sort(self.algo, 'SMADayRet', assets, 10, False, 3, 265, total_weight)
            self.allocated_weight += total_weight

    def jrt_10_20(self, weight):
        if RSI(self.algo, 'IEF', 10) > RSI(self.algo, 'PSQ', 20):
            self.jrt(weight)
        else:
            self.allocate_position('PSQ', weight, 1.0)

    def tqqq_conditions(self, weight):
        if GetCurrentPrice(self.algo, 'TQQQ') > SMA(self.algo, 'TQQQ', 20):
            if RSI(self.algo, 'PSQ', 10) < 32.5:
                self.allocate_position('SQQQ', weight, 1.0)
            else:
                self.jrt_10_20_cr(weight)
        else:
            self.jrt_10_20(weight)

    def jrt_10_20_cr(self, weight):
        if RSI(self.algo, 'IEF', 10) > RSI(self.algo, 'PSQ', 20):
            self.jrt(weight)
        elif CumReturn(self.algo, 'TQQQ', 10) > 0.15:
            self.allocate_position('SQQQ', weight, 1.0)
        else:
            self.allocate_position('PSQ', weight, 1.0)

    def foreign_rat(self, weight):
        if GetCurrentPrice(self.algo, 'EEM') > SMA(self.algo, 'EEM', 200):
            if RSI(self.algo, 'IEI', 11) > RSI(self.algo, 'IWM', 16):
                self.allocate_position('EDC', weight, 1.0)
            else:
                self.allocate_position('EDZ', weight, 1.0)
        else:
            if RSI(self.algo, 'IEI', 11) > RSI(self.algo, 'EEM', 16):
                self.allocate_position('EDC', weight, 1.0)
            else:
                self.allocate_position('EDZ', weight, 1.0)

    def ftlt_bull_bonds(self, weight):
        if CumReturn(self.algo, 'TQQQ', 6) < -0.12:
            if CumReturn(self.algo, 'TQQQ', 1) > 0.055:
                self.vix_blend_plus()
            else:
                self.mean_reversion(weight)
        else:
            self.bull_or_bonds(weight)

    def mean_reversion(self, weight):
        if RSI(self.algo, 'SOXL', 10) < 30:
            self.pick_bottom_3(['SPXL', 'TQQQ', 'TECL', 'SOXL', 'FNGU'], weight)
        elif RSI(self.algo, 'SPXL', 10) < 32.5:
            self.allocate_position('BIL', weight, 1.0)
        elif RSI(self.algo, 'TQQQ', 10) < 32.5:
            self.pick_bottom_3(['SPXL', 'TQQQ', 'TECL', 'SOXL', 'FNGU'], weight)
        else:
            self.jrt_15_15(weight)

    def jrt_15_15(self, weight):
        if RSI(self.algo, 'AGG', 15) > RSI(self.algo, 'QQQ', 15):
            self.ticker_mixer(weight)
        else:
            self.allocate_position('PSQ', weight, 1.0)

    def bull_or_bonds(self, weight):
        if RSI(self.algo, 'XLU', 126) < RSI(self.algo, 'XLK', 126):
            self.compares(weight)
        else:
            self.tmf_or_xlp(weight)

    def compares(self, weight):
        if self.allocated_weight + weight <= 1.0:
            AHIV(self.algo, ('group_15_15', 'group_10_20', 'group_20_60', 'group_all'), 45, 265, weight)
            self.allocated_weight += weight

    def group_15_15(self):
        self.jrt_15_15(1.0)

    def group_10_20(self):
        self.jrt_10_20(1.0)

    def group_20_60(self):
        if RSI(self.algo, 'AGG', 20) > RSI(self.algo, 'SH', 60):
            self.ticker_mixer(1.0)
        else:
            self.allocate_position('PSQ', 1.0, 1.0)

    def group_all(self):
        if RSI(self.algo, 'AGG', 15) > RSI(self.algo, 'QQQ', 15) or \
           RSI(self.algo, 'AGG', 20) > RSI(self.algo, 'SH', 60) or \
           RSI(self.algo, 'IEF', 10) > RSI(self.algo, 'IEF', 10) > RSI(self.algo, 'PSQ', 20):
            self.ticker_mixer(1.0)
        else:
            self.allocate_position('PSQ', 1.0, 1.0)

    def tmf_or_xlp(self, weight):
        if RSI(self.algo, 'TLT', 126) < 50:
            self.jrt_15_15(weight)
        else:
            if self.allocated_weight + weight <= 1.0:
                Sort(self.algo, 'RSI', ('TMF', 'XLP'), 20, False, 1, 265, weight)
                self.allocated_weight += weight

    def ticker_mixer(self, total_weight):
        # Allocate 75% to top 3 performers
        if self.allocated_weight + (total_weight * 0.75) <= 1.0:
            Sort(self.algo, 'SMADayRet', ('SPXL', 'TQQQ', 'TECL', 'SOXL', 'FNGU'), 15, True, 3, 265, total_weight * 0.75)
            self.allocated_weight += total_weight * 0.75
        
            # Allocate remaining 25% to TQQQ if possible
            remaining_weight = total_weight * 0.25
            if self.allocated_weight + remaining_weight <= 1.0:
                self.allocate_position('TQQQ', remaining_weight, 1.0)

#https://app.composer.trade/symphony/HMtU9wQtOQex2HQZcOMf/details

class FourCornersNicoMavisStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_four_corners()

    def group_four_corners(self):
        if STD(self.algo, 'QQQ', 10) > 0.03:
            self.high_volatility_allocation()
        else:
            self.low_volatility_allocation()

    def high_volatility_allocation(self):
        self.group_qqq_or_psq()
        self.group_ballast()

    def group_qqq_or_psq(self):
        if RSI(self.algo, 'IEF', 7) > RSI(self.algo, 'PSQ', 20):
            AH(self.algo, 'QQQ', 281, 0.5)
        else:
            AH(self.algo, 'PSQ', 281, 0.5)

    def group_ballast(self):
        AH(self.algo, 'TLT', 281, 0.25)
        AH(self.algo, 'GLD', 281, 0.25)

    def low_volatility_allocation(self):
        if RSI(self.algo, 'QQQ', 10) < 31:
            self.group_3x_long()
            self.group_ballast()
        elif RSI(self.algo, 'QQQ', 10) > 79:
            AH(self.algo, 'UVXY', 281, 0.25)
            AH(self.algo, 'XLP', 281, 0.25)
        elif RSI(self.algo, 'VTV', 10) > 79:
            AH(self.algo, 'UVXY', 281, 0.25)
            AH(self.algo, 'XLP', 281, 0.25)
        else:
            self.complex_allocation()

    def group_3x_long(self):
        AH(self.algo, 'TECL', 281, 0.25)
        AH(self.algo, 'SOXL', 281, 0.25)

    def complex_allocation(self):
        if RSI(self.algo, 'QQQ', 100) > RSI(self.algo, 'VPU', 100):
            self.qqq_dominant_allocation()
        else:
            self.vpu_dominant_allocation()

    def qqq_dominant_allocation(self):
        if CumReturn(self.algo, 'CORP', 60) > CumReturn(self.algo, 'BIL', 60):
            self.group_3x_long_tqqq_upro()
        else:
            self.defensive_allocation()

    def group_3x_long_tqqq_upro(self):
        AH(self.algo, 'TQQQ', 281, 0.5)
        AH(self.algo, 'UPRO', 281, 0.5)

    def defensive_allocation(self):
        AH(self.algo, 'BTAL', 281, 0.33)
        self.group_tqqq_or_psq()
        self.group_utilities_vs_gold()

    def group_tqqq_or_psq(self):
        if RSI(self.algo, 'IEF', 7) > RSI(self.algo, 'PSQ', 20):
            AH(self.algo, 'TQQQ', 281, 0.33)
        else:
            AH(self.algo, 'PSQ', 281, 0.33)

    def group_utilities_vs_gold(self):
        GroupSort(self.algo, 'RSI', ('VPU', 'group_gold_mining'), 60, False, 1, 281, 0.33)

    def group_gold_mining(self):
        AH(self.algo, 'GLD', 281, 0.5)
        AH(self.algo, 'GDX', 281, 0.5)

    def vpu_dominant_allocation(self):
        if CumReturn(self.algo, 'CORP', 60) > CumReturn(self.algo, 'BIL', 60):
            AH(self.algo, 'QQQ', 281, 0.5)
            AH(self.algo, 'TLT', 281, 0.5)
        else:
            AH(self.algo, 'BTAL', 281, 0.33)
            self.group_tlt_or_psq()
            self.group_utilities_vs_gold()

    def group_tlt_or_psq(self):
        if RSI(self.algo, 'IEF', 7) > RSI(self.algo, 'PSQ', 20):
            AH(self.algo, 'TLT', 281, 0.33)
        else:
            AH(self.algo, 'PSQ', 281, 0.33)

#https://app.composer.trade/symphony/0HtsuysJQd8rLyiWoTaI/details
#https://app.composer.trade/symphony/3QZTLfI7ZgpZdCe33N4V/details

#https://app.composer.trade/symphony/lqceelxzw0jOtpV6pL9A/details
class JustRunThisFTLTDIAStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_just_run_this_ftlt_dia()

    def group_just_run_this_ftlt_dia(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            self.check_rsi_conditions()
        else:
            self.check_tqqq_condition()

    def check_rsi_conditions(self):
        conditions = [
            ('SPY', 80),
            ('QQQ', 79),
            ('XLK', 79),
            ('IYY', 79),
            ('VTV', 79),
            ('XLP', 75),
            ('XLF', 80),
            ('VOX', 79)
        ]
        
        for symbol, threshold in conditions:
            if RSI(self.algo, symbol, 10) > threshold:
                AH(self.algo, 'VIXY', 280, 1)
                return
        
        AH(self.algo, 'DIA', 280, 1)

    def check_tqqq_condition(self):
        if RSI(self.algo, 'TQQQ', 10) < 30:
            AH(self.algo, 'TECL', 280, 1)
        elif GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 30):
            AH(self.algo, 'DIA', 280, 1)
        else:
            AH(self.algo, 'BTAL', 280, 1)
from AlgorithmImports import *
import math
import pandas as pd
from cmath import sqrt
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Data.Custom import *
from QuantConnect.Python import PythonData

class IntelligentSkyRodent(QCAlgorithm):
    def Initialize(self):
        self.cash = 80000
        self.buffer_pct = 0.03
        self.SetStartDate(2023, 6, 1)
        self.SetEndDate(2024, 6, 5)
        self.SetCash(self.cash)
        self.equities = ['FNGS','SPLV','TMV', 'VCIT', 'XLY', 'HIBL', 'XLK', 'XLP', 'SVXY', 'QID', 'TBF', 'TSLA', 'LQD', 'VTIP', 'EDV', 'STIP', 'SPTL', 'IEI', 'USDU', 'SQQQ', 'VIXM', 'SPXU', 'QQQ', 'BSV', 'TQQQ', 'SPY', 'DBC', 'SHV', 'IAU', 'VEA', 'UTSL', 'UVXY', 'UPRO', 'EFA', 'EEM', 'TLT', 'SHY', 'GLD', 'SLV', 'USO', 'WEAT', 'CORN', 'SH', 'DRN', 'PDBC', 'COMT', 'KOLD', 'BOIL', 'ESPO', 'PEJ', 'UGL', 'URE', 'VXX', 'UUP', 'BND', 'DUST', 'JDST', 'JNUG', 'GUSH', 'DBA', 'DBB', 'COM', 'PALL', 'AGQ', 'BAL', 'WOOD', 'URA', 'SCO', 'UCO', 'DBO', 'TAGS', 'CANE', 'REMX', 'COPX', 'IEF', 'SPDN', 'CHAD', 'DRIP', 'SPUU', 'INDL', 'BRZU', 'ERX', 'ERY', 'CWEB', 'CHAU', 'KORU', 'MEXX', 'EDZ', 'EURL', 'YINN', 'YANG', 'TNA', 'TZA', 'SPXL', 'SPXS', 'MIDU', 'TYD', 'TYO', 'TMF', 'TECL', 'TECS', 'SOXL', 'SOXS', 'LABU', 'LABD', 'RETL', 'DPST', 'DRV', 'PILL', 'CURE', 'FAZ', 'FAS', 'EWA', 'EWGS', 'EWG', 'EWP', 'EWQ', 'EWU', 'EWJ', 'EWI', 'EWN', 'ECC', 'NURE', 'VNQI', 'VNQ', 'VDC', 'VIS', 'VGT', 'VAW', 'VPU', 'VOX', 'VFH', 'VHT', 'VDE', 'SMH', 'DIA', 'UDOW', 'PSQ', 'SOXX', 'VTI', 'COST', 'UNH', 'SPHB', 'BTAL', 'VIXY', 'WEBL', 'WEBS', 'UBT', 'PST', 'TLH', 'QLD', 'SQM', 'SSO', 'SD', 'DGRO', 'SCHD', 'SGOL', 'TIP', 'DUG', 'EWZ', 'TBX', 'VGI', 'XLU', 'XLV', 'EUO', 'YCS', 'MVV', 'USD', 'BIL', 'TMF', 'EPI', 'IYK', 'DIG', 'AGG', 'PUI', 'UDN', 'QQQE', 'VTV', 'VOOG', 'VOOV']

        self.MKT = self.AddEquity("SPY",Resolution.Daily).Symbol
        self.mkt = []
        for equity in self.equities:
            self.AddEquity(equity,Resolution.Minute)
            self.Securities[equity].SetDataNormalizationMode(DataNormalizationMode.Adjusted)
        self.AddEquity('BIL',Resolution.Minute)
        self.Securities['BIL'].SetDataNormalizationMode(DataNormalizationMode.TotalReturn)
       
        self.PT1 = 0.94

        self.HT1 = {str(i).zfill(2): 0 for i in range(1,10)}
        self.HTS1 = {str(i).zfill(2): [] for i in range(1,10)}
        self.HT2 = {str(i).zfill(2): 0 for i in range(1,10)}
        self.HTS2 = {str(i).zfill(2): [] for i in range(1,10)}
        self.HT3 = {str(i).zfill(2): 0 for i in range(1,10)}
        self.HTS3 = {str(i).zfill(2): [] for i in range(1,10)}

        self.Schedule.On(self.DateRules.EveryDay("SPY"),
                self.TimeRules.BeforeMarketClose("SPY", 2),
                self.FunctionBeforeMarketClose)
    def RSI(self,equity,period):
        extension = min(period*5,250)
        r_w = RollingWindow[float](extension)
        history = self.History(equity,extension - 1,Resolution.Daily)
        for historical_bar in history:
            r_w.Add(historical_bar.Close)
        while r_w.Count < extension:
            current_price = self.Securities[equity].Price
            r_w.Add(current_price)
        if r_w.IsReady:
            average_gain = 0
            average_loss = 0
            gain = 0
            loss = 0
            for i in range(extension - 1,extension - period -1,-1):
                gain += max(r_w[i-1] - r_w[i],0)
                loss += abs(min(r_w[i-1] - r_w[i],0))
            average_gain = gain/period
            average_loss = loss/period
            for i in range(extension - period - 1,0,-1):
                average_gain = (average_gain*(period-1) + max(r_w[i-1] - r_w[i],0))/period
                average_loss = (average_loss*(period-1) + abs(min(r_w[i-1] - r_w[i],0)))/period
            if average_loss == 0:
                return 100
            else:
                rsi = 100 - (100/(1 + average_gain / average_loss))
                return rsi
        else:
            return None

    def CumReturn(self,equity,period):

        history = self.History(equity, period, Resolution.Daily)
        closing_prices = pd.Series([bar.Close for bar in history])
        current_price = self.Securities[equity].Price
        # Convert current_price to a Series and use pd.concat to append it to closing_prices
        closing_prices = pd.concat([closing_prices, pd.Series([current_price])]).reset_index(drop=True)
        first_price = closing_prices.iloc[0]
        if first_price == 0:
            return None
        else:
            return_val = (current_price / first_price) - 1
            return return_val
    def STD(self,equity,period):
        r_w = RollingWindow[float](period + 1)
        r_w_return = RollingWindow[float](period)
        history = self.History(equity,period,Resolution.Daily)
        for historical_bar in history:
            r_w.Add(historical_bar.Close)
        while r_w.Count < period + 1:
            current_price = self.Securities[equity].Price
            r_w.Add(current_price)
        for i in range (period,0,-1):
            daily_return = (r_w[i-1]/r_w[i] - 1)
            r_w_return.Add(daily_return)
        dfstd = pd.DataFrame({'r_w_return':r_w_return})
        if r_w.IsReady:
            std = dfstd['r_w_return'].std()
            if std == 0:
                return 0
            else:
                return std
        else:
            return 0

    def MaxDD(self,equity,period):
        history = self.History(equity,period - 1,Resolution.Daily)
        closing_prices = pd.Series([bar.Close for bar in history])
        current_price = self.Securities[equity].Price
        closing_prices = closing_prices.append(pd.Series([current_price]))
        rolling_max = closing_prices.cummax()
        drawdowns = (rolling_max - closing_prices) / rolling_max
        max_dd = drawdowns.min()
        return max_dd

    def SMA(self,equity,period):
        r_w = RollingWindow[float](period)
        history = self.History(equity,period - 1,Resolution.Daily)
        for historical_bar in history:
            r_w.Add(historical_bar.Close)
        while r_w.Count < period:
            current_price = self.Securities[equity].Price
            r_w.Add(current_price)        
        if r_w.IsReady:
            sma = sum(r_w) / period
            return sma
        else:
            return 0

    def IV(self,equity,period):
        r_w = RollingWindow[float](period + 1)
        r_w_return = RollingWindow[float](period)
        history = self.History(equity,period,Resolution.Daily)
        for historical_bar in history:
            r_w.Add(historical_bar.Close)
        while r_w.Count < period + 1:
            current_price = self.Securities[equity].Price
            r_w.Add(current_price)
        for i in range (period,0,-1):
            if r_w[i] == 0:
                return 0
            else:
                daily_return = (r_w[i-1]/r_w[i] - 1)
                r_w_return.Add(daily_return)
        dfinverse = pd.DataFrame({'r_w_return':r_w_return})       
        if r_w.IsReady:
            std = dfinverse['r_w_return'].std()
            if std == 0:
                return 0
            else:
                inv_vol = 1 / std
                return inv_vol
        else:
            return 0

    def SMADayRet(self,equity,period):
        r_w = RollingWindow[float](period + 1)
        r_w_return = RollingWindow[float](period)
        history = self.History(equity,period,Resolution.Daily)
        for historical_bar in history:
            r_w.Add(historical_bar.Close)
        while r_w.Count < period + 1:
            current_price = self.Securities[equity].Price
            r_w.Add(current_price)
        for i in range (period,0,-1):
            if r_w[i] == 0:
                return None
            daily_return = (r_w[i-1]/r_w[i] - 1)
            r_w_return.Add(daily_return)
        if r_w.IsReady:
            smareturn = sum(r_w_return) / period
            return smareturn
        else:
            return 0
            
    def EMA(self,equity,period):
        extension = period + 50
        r_w = RollingWindow[float](extension)
        history = self.History(equity,extension - 1,Resolution.Daily)
        for historical_bar in history:
            r_w.Add(historical_bar.Close)
        while r_w.Count < extension:
            current_price = self.Securities[equity].Price
            r_w.Add(current_price)
        if r_w.IsReady:
            total_price = 0
            for i in range(extension - 1,extension - period - 2,-1):
                total_price += r_w[i]
            average_price = total_price/period
            for i in range(extension - period - 2,-1,-1):
                average_price = r_w[i]*2/(period+1) + average_price*(1-2/(period+1))
            return average_price
        else:
            return None
    def Sort(self,sort_type,equities,period,reverse,number,multiplier,holdings=1):
        self.PT = getattr(self,f"PT{number}") * multiplier /  holdings
        returns = {}
        for equity in equities:
            returns[equity] = getattr(self,sort_type)(equity,period)
        s_e = sorted([item for item in returns.items() if item[1] is not None],key = lambda x: x[1],reverse = reverse)
        t3e = s_e[:holdings]
        ht = getattr(self,f"HT{number}")
        hts = getattr(self,f"HTS{number}")
        for ticker in t3e:
            for i in ht.keys():
                if ht[i] == 0:
                    ht[i] = self.PT
                    hts[i].append(ticker[0])
                    break
        setattr(self,f"HT{number}",ht)
        setattr(self,f"HTS{number}",hts)

    def AH(self, equities, PTnumber, multiplier): #AppendHolding
        if not isinstance(equities, list):
            equities = [equities]
        
        HT = getattr(self, f"HT{PTnumber}")
        HTS = getattr(self, f"HTS{PTnumber}")
        PT = getattr(self, f"PT{PTnumber}") * multiplier
        
        for equity in equities:
            for i in HT.keys():
                if HT[i] == 0:
                    HT[i] = PT
                    HTS[i].append(equity)
                    break

    def OnData (self,data):
        pass

    def FunctionBeforeMarketClose(self):
        mkt_price = self.History(self.MKT,2,Resolution.Daily)['close'].unstack(level= 0).iloc[-1]
        self.mkt.append(mkt_price)
        mkt_perf = self.cash * self.mkt[-1] / self.mkt[0]
        self.Plot('Strategy Equity',self.MKT,mkt_perf)
        self.tqqq_ftlt()
        self.ExecuteTrade()

    
    def sideways_market_deleverage(self):
            if self.Securities['SPY'].Price > self.SMA('SPY', 20):
                self.AH('SPY', 1, 1.0)
            else:
                if self.RSI('TLT', 10) > self.RSI('SQQQ', 10):
                    self.AH('QQQ', 1, 1.0)
                else:
                    self.AH('PSQ', 1, 1.0)
            if self.RSI('TLT', 10) > self.RSI('SQQQ', 10):
                self.AH('QQQ', 1, 1.0)
            else:
                self.AH('PSQ', 1, 1.0)
    
    def nasdaq_in_crash_territory_time_to_deleverage(self):
        if self.Securities['QQQ'].Price < self.SMA('QQQ', 20):
            if self.CumReturn('QQQ', 60) <= -12:
                self.sideways_market_deleverage()
            else:
                if self.RSI('TLT', 10) > self.RSI('SQQQ', 10):
                    self.AH('TQQQ', 1, 1.0)
                else:
                    self.AH('SQQQ', 1, 1.0)
        else:
            if self.RSI('SQQQ', 10) < 31:
                self.AH('PSQ', 1, 1.0)
            else:
                if self.CumReturn('QQQ', 10) > 5.5:
                    self.AH('PSQ', 1, 1.0)
                else:
                    self.Sort('RSI',('QQQ','SMH'),10,True,1,1.0)
    
    def bear_market_sideways_protection(self):
        if self.CumReturn('QQQ', 252) < -20:
            self.nasdaq_in_crash_territory_time_to_deleverage()
        else:
            if self.Securities['QQQ'].Price < self.SMA('QQQ', 20):
                if self.RSI('TLT', 10) > self.RSI('SQQQ', 10):
                    self.AH('TQQQ', 1, 1.0)
                else:
                    self.AH('SQQQ', 1, 1.0)
            else:
                if self.RSI('SQQQ', 10) < 31:
                    self.AH('SQQQ', 1, 1.0)
                else:
                    if self.CumReturn('QQQ', 10) > 5.5:
                        self.AH('SQQQ', 1, 1.0)
                    else:
                        self.Sort('RSI',('TQQQ','SOXL'),10,True,1,1.0)
        if self.Securities['QQQ'].Price < self.SMA('QQQ', 20):
            if self.CumReturn('QQQ', 60) <= -12:
                self.sideways_market_deleverage()
            else:
                if self.RSI('TLT', 10) > self.RSI('SQQQ', 10):
                    self.AH('TQQQ', 1, 1.0)
                else:
                    self.AH('SQQQ', 1, 1.0)
        else:
            if self.RSI('SQQQ', 10) < 31:
                self.AH('SQQQ', 1, 1.0)
            else:
                if self.CumReturn('QQQ', 70) < -15:
                    self.Sort('RSI',('TQQQ','SOXL'),10,True,1,1.0)
                else:
                    self.Sort('CumReturn',('SPY','QQQ','DIA','XLP'),15,True,1,1.0)
    
    def dip_buy_strategy(self):
        if self.RSI('TQQQ', 10) < 31:
            self.AH('TECL', 1, 1.0)
        else:
            if self.RSI('SMH', 10) < 30:
                self.AH('SOXL', 1, 1.0)
            else:
                if self.RSI('SPY', 10) < 30:
                    self.AH('UPRO', 1, 1.0)
                else:
                    self.bear_market_sideways_protection()
    
    def svxy_ftlt(self):
        if self.RSI('QQQ', 10) > 80:
            self.AH('VIXY', 1, 0.33)
        else:
            if self.RSI('SPY', 10) > 80:
                self.AH('VIXY', 1, 0.33)
            else:
                if self.RSI('QQQ', 10) < 30:
                    self.AH('XLK', 1, 0.33)
                else:
                    if self.Securities['SVXY'].Price > self.SMA('SVXY', 24):
                        self.Sort('SMADayRet',('SVXY','SPY'),20,True,1,0.33)
                    else:
                        self.AH('BTAL', 1, 0.33)
    
    def spy_cooloff_period(self):
        self.AH('SHV', 1, 1.0)
    
    def bull_market(self):
            if self.RSI('QQQ', 10) > 80:
                self.AH('UVXY', 1, 1.0)
            else:
                if self.RSI('SPY', 10) > 80:
                    self.AH('UVXY', 1, 1.0)
                else:
                    if self.RSI('SPY', 60) > 60:
                        self.spy_cooloff_period()
                    else:
                        self.Sort('SMADayRet',('TQQQ','TECL','UDOW','UPRO'),21,True,1,0.67, 2)
                        self.svxy_ftlt()
    
    def tqqq_ftlt(self):
        if self.Securities['SPY'].Price > self.SMA('SPY', 200):
            self.bull_market()
        else:
            self.dip_buy_strategy()

    def ExecuteTrade(self):
        group1 = {
            'HTS': [self.HTS1[i][0] if len(self.HTS1[i]) == 1 else self.HTS1[i] for i in self.HTS1],
            'HT': [self.HT1[i] for i in self.HT1]
        }
        df1 = pd.DataFrame(group1)
        group2 = {
            'HTS': [self.HTS2[i][0] if len(self.HTS2[i]) == 1 else self.HTS2[i] for i in self.HTS2],
            'HT': [self.HT2[i] for i in self.HT2]
        }
        df2 = pd.DataFrame(group2)


        group3 = {
            'HTS': [self.HTS3[i][0] if len(self.HTS3[i]) == 1 else self.HTS3[i] for i in self.HTS3],
            'HT': [self.HT3[i] for i in self.HT3]
        }
        df3 = pd.DataFrame(group3)

        df = pd.concat([df1, df2, df3])
        df['HTS'] = df['HTS'].astype(str)
        result = df.groupby(['HTS']).sum().reset_index()
        for equity in self.equities:
            if all(not pd.isnull(result.iloc[i,0]) and not equity == result.iloc[i,0] for i in range(len(result))):
                if self.Portfolio[equity].HoldStock:
                    self.Liquidate(equity)
        output = "*****"
        for i in range(len(result)):
            if result.iloc[i,0]:
                percentage = round(result.iloc[i,1] * 100,2)
                output += "{}: {}% - ".format(result.iloc[i,0],percentage)
        output = output.rstrip(" - ")
        self.Log(output)
        for i in range(len(result)):
            if not result.iloc[i,1] == 0 and not result.iloc[i,0] == 'BIL':
                percentage_equity = self.Portfolio[result.iloc[i,0]].HoldingsValue / self.Portfolio.TotalPortfolioValue
                if result.iloc[i,1] < percentage_equity and abs(result.iloc[i,1] / percentage_equity - 1) > self.buffer_pct:
                    self.SetHoldings(result.iloc[i,0],result.iloc[i,1])
                else:
                    pass
        for i in range(len(result)):
            if not result.iloc[i,1] == 0 and not result.iloc[i,0] == 'BIL':
                percentage_equity = self.Portfolio[result.iloc[i,0]].HoldingsValue / self.Portfolio.TotalPortfolioValue
                if result.iloc[i,1] > percentage_equity and abs(percentage_equity / result.iloc[i,1] - 1) > self.buffer_pct:
                    self.SetHoldings(result.iloc[i,0],result.iloc[i,1])
                else:
                    pass

        self.HT1 = {str(i).zfill(2): 0 for i in range(1,10)}
        self.HTS1 = {str(i).zfill(2): [] for i in range(1,10)}
        self.HT2 = {str(i).zfill(2): 0 for i in range(1,10)}
        self.HTS2 = {str(i).zfill(2): [] for i in range(1,10)}
        self.HT3 = {str(i).zfill(2): 0 for i in range(1,10)}
        self.HTS3 = {str(i).zfill(2): [] for i in range(1,10)}
from AlgorithmImports import *
from indicators import *
from main import YellowCatStrat
#https://app.composer.trade/symphony/iJzUFJ6CMGzIlLaPYBCq/details
class HWRT30Strategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo, 'IOO', 10) > 80:
            AH(self.algo, 'UVXY', 266, 1)
        else:
            if RSI(self.algo, 'TQQQ', 10) > 81:
                if RSI(self.algo, 'UVXY', 60) > 40:
                    AH(self.algo, 'UVXY', 266, 1)
                else:
                    if RSI(self.algo, 'RETL', 10) > 82:
                        self.scale_in_btal_to_vix()
                    else:
                        if RSI(self.algo, 'XLF', 10) > 81:
                            self.scale_in_vix_to_vix_plus()
                        else:
                            AH(self.algo, 'SHV', 266, 1)
            else:
                if RSI(self.algo, 'SPY', 10) > 80:
                    if RSI(self.algo, 'UVXY', 60) > 40:
                        AH(self.algo, 'UVXY', 266, 1)
                    else:
                        if RSI(self.algo, 'RETL', 10) > 82:
                            self.scale_in_btal_to_vix()
                        else:
                            if RSI(self.algo, 'XLF', 10) > 81:
                                self.scale_in_vix_to_vix_plus()
                            else:
                                AH(self.algo, 'SHV', 266, 1)
                else:
                    self.check_oversold_conditions()

    def scale_in_btal_to_vix(self):
        if RSI(self.algo, 'RETL', 10) > 85:
            self.vix_blend_group()
        else:
            self.btal_bil_group()

    def scale_in_vix_to_vix_plus(self):
        if RSI(self.algo, 'XLF', 10) > 85:
            self.vix_blend_plus_group()
        else:
            self.vix_blend_group()

    def vix_blend_group(self):
        AH(self.algo, 'VIXY', 266, 0.33)
        AH(self.algo, 'VXX', 266, 0.33)
        AH(self.algo, 'VIXM', 266, 0.33)

    def vix_blend_plus_group(self):
        AH(self.algo, 'UVXY', 266, 0.33)
        AH(self.algo, 'VXX', 266, 0.33)
        AH(self.algo, 'VIXM', 266, 0.33)

    def btal_bil_group(self):
        AH(self.algo, 'BTAL', 266, 0.5)
        AH(self.algo, 'SHV', 266, 0.5)

    def check_oversold_conditions(self):
        if RSI(self.algo, 'SOXL', 14) < 30:
            AH(self.algo, 'SOXL', 266, 1)
        else:
            if RSI(self.algo, 'TECL', 14) < 30:
                AH(self.algo, 'TECL', 266, 1)
            else:
                if RSI(self.algo, 'LABU', 10) < 22:
                    Sort(self.algo, 'CumReturn', ('LABU', 'SOXL'), 1, False, 1, 266, 1)
                else:
                    if RSI(self.algo, 'QQQ', 14) < 30:
                        AH(self.algo, 'TECL', 266, 1)
                    else:
                        if RSI(self.algo, 'SMH', 10) < 25:
                            AH(self.algo, 'SOXL', 266, 1)
                        else:
                            self.check_overbought_conditions()

    def check_overbought_conditions(self):
        if RSI(self.algo, 'TQQQ', 14) > 80:
            AH(self.algo, 'TECS', 266, 1)
        else:
            if RSI(self.algo, 'SOXL', 14) > 80:
                AH(self.algo, 'SOXS', 266, 1)
            else:
                if RSI(self.algo, 'TMV', 14) > 80:
                    AH(self.algo, 'TMF', 266, 1)
                else:
                    if RSI(self.algo, 'SMH', 10) > 80:
                        AH(self.algo, 'SOXS', 266, 1)
                    else:
                        self.bwc_ultimate_frontrunner()

    def bwc_ultimate_frontrunner(self):
        if RSI(self.algo, 'QQQ', 10) > 79:
            self.bwc_scale_in_vix_with_vixy_check()
        else:
            if RSI(self.algo, 'SPY', 10) > 79:
                self.bwc_scale_in_vix_with_vixy_check()
            else:
                self.check_additional_conditions()

    def bwc_scale_in_vix_with_vixy_check(self):
        if RSI(self.algo, 'VIXY', 60) > 40:
            self.vix_1_5x_group()
        else:
            if RSI(self.algo, 'QQQ', 10) > 82.5:
                self.vix_1_5x_group()
            else:
                self.vix_blend_weighted()

    def vix_1_5x_group(self):
        AH(self.algo, 'VXX', 266, 0.5)
        AH(self.algo, 'UVIX', 266, 0.5)

    def vix_blend_weighted(self):
        AH(self.algo, 'VXX', 266, 0.45)
        AH(self.algo, 'VIXM', 266, 0.2)
        AH(self.algo, 'UVIX', 266, 0.35)

    def check_additional_conditions(self):
        if RSI(self.algo, 'IOO', 10) > 80:
            self.bwc_scale_in_vix_with_vixy_check()
        else:
            self.check_xlp_conditions()

    def check_xlp_conditions(self):
        if RSI(self.algo, 'XLP', 10) > 77:
            self.bwc_scale_in_vix_simple()
        else:
            self.check_vtv_conditions()

    def bwc_scale_in_vix_simple(self):
        if RSI(self.algo, 'XLP', 10) > 82.5:
            self.vix_1_5x_group()
        else:
            AH(self.algo, 'VIXY', 266, 1)

    def check_vtv_conditions(self):
        if RSI(self.algo, 'VTV', 10) > 79:
            if RSI(self.algo, 'VTV', 10) > 82.5:
                self.vix_1_5x_group()
            else:
                AH(self.algo, 'VIXY', 266, 1)
        else:
            self.check_final_conditions()

    def check_final_conditions(self):
        if RSI(self.algo, 'XLF', 10) > 81:
            if RSI(self.algo, 'XLF', 10) > 85:
                self.vix_1_5x_group()
            else:
                AH(self.algo, 'VIXY', 266, 1)
        else:
            if RSI(self.algo, 'VOX', 10) > 79:
                if RSI(self.algo, 'VOX', 10) > 82.5:
                    self.vix_1_5x_group()
                else:
                    AH(self.algo, 'VIXY', 266, 1)
            else:
                self.check_cure_conditions()

    def check_cure_conditions(self):
        if RSI(self.algo, 'CURE', 10) > 82:
            if RSI(self.algo, 'CURE', 10) > 85:
                self.vix_1_5x_group()
            else:
                AH(self.algo, 'VIXY', 266, 1)
        else:
            self.check_retl_conditions()

    def check_retl_conditions(self):
        if RSI(self.algo, 'RETL', 10) > 82:
            if RSI(self.algo, 'RETL', 10) > 85:
                self.vix_1_5x_group()
            else:
                AH(self.algo, 'VIXY', 266, 1)
        else:
            self.final_checks()

    def final_checks(self):
        if RSI(self.algo, 'LABU', 10) > 79:
            AH(self.algo, 'LABD', 266, 1)
        else:
            if RSI(self.algo, 'SPY', 70) > 62:
                self.check_agg_vs_qqq()
            else:
                self.check_oversold_tech()

    def check_agg_vs_qqq(self):
        if RSI(self.algo, 'AGG', 15) > RSI(self.algo, 'QQQ', 15):
            self.all_3x_tech_group()
        else:
            self.gld_slv_pdbc_group()

    def all_3x_tech_group(self):
        AH(self.algo, 'TQQQ', 266, 0.2)
        AH(self.algo, 'SPXL', 266, 0.2)
        AH(self.algo, 'SOXL', 266, 0.2)
        AH(self.algo, 'FNGU', 266, 0.2)
        AH(self.algo, 'ERX', 266, 0.2)

    def gld_slv_pdbc_group(self):
        AH(self.algo, 'GLD', 266, 0.5)
        AH(self.algo, 'SLV', 266, 0.25)
        AH(self.algo, 'PDBC', 266, 0.25)

    def check_oversold_tech(self):
        if RSI(self.algo, 'SOXL', 10) < 25:
            AH(self.algo, 'SOXL', 266, 1)
        else:
            if RSI(self.algo, 'FNGU', 10) < 25:
                AH(self.algo, 'FNGU', 266, 1)
            else:
                if RSI(self.algo, 'TQQQ', 10) < 28:
                    Sort(self.algo, 'RSI', ('SOXL', 'TECL', 'TQQQ', 'FNGU'), 10, False, 2, 266, 1)
                else:
                    self.check_final_tech_conditions()

    def check_final_tech_conditions(self):
        if RSI(self.algo, 'TECL', 14) < 25:
            AH(self.algo, 'TECL', 266, 1)
        else:
            if RSI(self.algo, 'UPRO', 10) < 25:
                AH(self.algo, 'UPRO', 266, 1)
            else:
                AH(self.algo, 'BIL', 266, 1)

#https://app.composer.trade/symphony/ByLY0PDXmpr3WJ5kt1JP/details
class FBBJRTAnansiStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_fbb_jrt_anansi()

    def group_fbb_jrt_anansi(self):
        if RSI(self.algo, 'SPY', 10) > 80:
            self.group_vix_blend_plus()
        else:
            self.check_ioo()

    def group_vix_blend_plus(self):
        AH(self.algo, 'VIXY', 267, 0.75)
        self.group_alternate_tlt_btal(0.25)

    def group_alternate_tlt_btal(self, weight):
        AH(self.algo, 'TLT', 267, weight * 0.5)
        AH(self.algo, 'BTAL', 267, weight * 0.5)

    def check_ioo(self):
        if RSI(self.algo, 'IOO', 10) > 80:
            self.scale_in_vix_to_vix_plus_ioo()
        else:
            self.check_qqq()

    def scale_in_vix_to_vix_plus_ioo(self):
        if RSI(self.algo, 'IOO', 10) > 82.5:
            self.group_vix_blend_plus()
        else:
            self.group_vix_blend()

    def group_vix_blend(self):
        AH(self.algo, 'VIXY', 267, 0.5)
        self.group_alternate_tlt_btal(0.5)

    def check_qqq(self):
        if RSI(self.algo, 'QQQ', 10) > 79:
            self.scale_in_vix_to_vix_plus_qqq()
        else:
            self.check_vtv()

    def scale_in_vix_to_vix_plus_qqq(self):
        if RSI(self.algo, 'QQQ', 10) > 82.5:
            self.group_vix_blend_plus()
        else:
            self.group_vix_blend()

    def check_vtv(self):
        if RSI(self.algo, 'VTV', 10) > 79:
            self.group_vix_blend()
        else:
            self.check_vox()

    def check_vox(self):
        if RSI(self.algo, 'VOX', 10) > 79:
            self.group_vix_blend()
        else:
            self.check_xlp()

    def check_xlp(self):
        if RSI(self.algo, 'XLP', 10) > 77:
            self.group_vix_blend()
        else:
            self.check_xlf()

    def check_xlf(self):
        if RSI(self.algo, 'XLF', 10) > 81:
            self.group_vix_blend()
        else:
            self.check_spy_overbought()

    def check_spy_overbought(self):
        if RSI(self.algo, 'SPY', 65) > 63:
            self.group_overbought_blend()
        else:
            self.check_qqq_drawdown()

    def group_overbought_blend(self):
        self.group_anti_beta()
        self.group_bond_signals()

    def group_anti_beta(self):
        AHIV(self.algo, ('DBC', 'GLD'), 5, 267, 0.25)

    def group_bond_signals(self):
        self.group_10d_ief_vs_15d_psq()
        self.group_15d_agg_vs_15d_qqq()
        self.group_20d_agg_vs_60d_sh()

    def group_10d_ief_vs_15d_psq(self):
        if RSI(self.algo, 'IEF', 10) > RSI(self.algo, 'PSQ', 20):
            self.group_svxy_or_safety()
        else:
            AH(self.algo, 'PSQ', 267, 0.25/3)

    def group_15d_agg_vs_15d_qqq(self):
        if RSI(self.algo, 'AGG', 15) > RSI(self.algo, 'QQQ', 15):
            self.group_svxy_or_safety()
        else:
            AH(self.algo, 'PSQ', 267, 0.25/3)

    def group_20d_agg_vs_60d_sh(self):
        if RSI(self.algo, 'AGG', 20) > RSI(self.algo, 'SH', 60):
            self.group_svxy_or_safety()
        else:
            AH(self.algo, 'PSQ', 267, 0.25/3)

    def group_svxy_or_safety(self):
        if GetCurrentPrice(self.algo, 'SVXY') > SMA(self.algo, 'SVXY', 24):
            Sort(self.algo, 'SMADayRet', ('SVXY', 'QQQ'), 20, True, 1, 267, 0.25/3)
        else:
            AH(self.algo, 'SPY', 267, 0.25/3)

    def check_qqq_drawdown(self):
        if CumReturn(self.algo, 'QQQ', 6) < -0.04:
            self.check_qqq_rebound()
        else:
            self.group_ftlt_bull_bonds()

    def check_qqq_rebound(self):
        if CumReturn(self.algo, 'QQQ', 1) > 0.02:
            self.group_vix_blend()
        else:
            self.group_mr()

    def group_mr(self):
        if RSI(self.algo, 'SOXX', 10) < 30:
            AH(self.algo, 'SOXX', 267, 0.5)
        else:
            self.check_qqq_low_rsi()

    def check_qqq_low_rsi(self):
        if RSI(self.algo, 'QQQ', 10) < 31:
            AH(self.algo, 'XLK', 267, 0.5)
        else:
            self.group_svxy_or_safety_mr()

    def group_svxy_or_safety_mr(self):
        if GetCurrentPrice(self.algo, 'SVXY') > SMA(self.algo, 'SVXY', 24):
            Sort(self.algo, 'SMADayRet', ('SVXY', 'QQQ'), 20, True, 1, 267, 0.5)
        else:
            AH(self.algo, 'BTAL', 267, 0.5)

    def group_ftlt_bull_bonds(self):
        self.group_ftlt_bull_bonds_v3()
        self.group_jrt()

    def group_ftlt_bull_bonds_v3(self):
        if RSI(self.algo, 'XLU', 126) < RSI(self.algo, 'SPY', 126):
            self.group_20_60_agg_vs_sphb()
        else:
            self.check_tlt_rsi()

    def group_20_60_agg_vs_sphb(self):
        if RSI(self.algo, 'AGG', 20) > RSI(self.algo, 'SH', 60):
            AH(self.algo, 'XLK', 267, 0.25)
        else:
            self.check_agg_vs_sphb()

    def check_agg_vs_sphb(self):
        if RSI(self.algo, 'AGG', 21) > RSI(self.algo, 'SPHB', 21):
            AH(self.algo, 'XLK', 267, 0.25)
        else:
            AH(self.algo, 'PSQ', 267, 0.25)

    def check_tlt_rsi(self):
        if RSI(self.algo, 'TLT', 126) < 50:
            self.group_20_60_agg_vs_sphb()
        else:
            self.group_tmf_or_xlp()

    def group_tmf_or_xlp(self):
        Sort(self.algo, 'RSI', ('TMF', 'XLP'), 20, False, 1, 267, 0.25)

    def group_jrt(self):
        AHIV(self.algo, ('LLY', 'NVO', 'COST'), 10, 267, 0.75/2)
        self.group_pgr_or_ge()

    def group_pgr_or_ge(self):
        Sort(self.algo, 'SMADayRet', ('PGR', 'GE'), 60, True, 1, 267, 0.25/2)

#https://app.composer.trade/symphony/KBjhuv2Fq8HO9Fn4NbwP/details
class HydraNoLeverageTacoStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_v020_no_leverage()
        self.group_crypto_block()

    def group_v020_no_leverage(self):
        self.group_v002_if_else_into_every_sector(0.9)

    def group_crypto_block(self):
        if EMA(self.algo, 'GBTC', 50) < GetCurrentPrice(self.algo, 'GBTC'):
            AH(self.algo, 'GBTC', 268, 0.1)
        else:
            self.group_v002_if_else_into_every_sector(0.1)

    def group_v002_if_else_into_every_sector(self, weight_multiplier):
        if RSI(self.algo, 'TQQQ', 10) > 79:
            AH(self.algo, 'VXX', 268, weight_multiplier)
        else:
            self.check_qqq(weight_multiplier)

    def check_qqq(self, weight_multiplier):
        if MaxDD(self.algo, 'QQQ', 20) < 0.05:
            AH(self.algo, 'QQQ', 268, weight_multiplier)
        else:
            self.check_xly(weight_multiplier)

    def check_xly(self, weight_multiplier):
        if MaxDD(self.algo, 'XLY', 20) < 0.05:
            AH(self.algo, 'XLY', 268, weight_multiplier)
        else:
            self.check_ixp(weight_multiplier)

    def check_ixp(self, weight_multiplier):
        if MaxDD(self.algo, 'IXP', 20) < 0.05:
            AH(self.algo, 'IXP', 268, weight_multiplier)
        else:
            self.check_xli(weight_multiplier)

    def check_xli(self, weight_multiplier):
        if MaxDD(self.algo, 'XLI', 20) < 0.05:
            AH(self.algo, 'XLI', 268, weight_multiplier)
        else:
            self.check_xlb(weight_multiplier)

    def check_xlb(self, weight_multiplier):
        if MaxDD(self.algo, 'XLB', 20) < 0.05:
            AH(self.algo, 'XLB', 268, weight_multiplier)
        else:
            self.check_xle(weight_multiplier)

    def check_xle(self, weight_multiplier):
        if MaxDD(self.algo, 'XLE', 20) < 0.05:
            AH(self.algo, 'XLE', 268, weight_multiplier)
        else:
            self.check_xlp(weight_multiplier)

    def check_xlp(self, weight_multiplier):
        if MaxDD(self.algo, 'XLP', 20) < 0.05:
            AH(self.algo, 'XLP', 268, weight_multiplier)
        else:
            self.check_xlv(weight_multiplier)

    def check_xlv(self, weight_multiplier):
        if MaxDD(self.algo, 'XLV', 20) < 0.05:
            AH(self.algo, 'XLV', 268, weight_multiplier)
        else:
            self.check_xlu(weight_multiplier)

    def check_xlu(self, weight_multiplier):
        if MaxDD(self.algo, 'XLU', 20) < 0.05:
            AH(self.algo, 'XLU', 268, weight_multiplier)
        else:
            self.check_xlf(weight_multiplier)

    def check_xlf(self, weight_multiplier):
        if MaxDD(self.algo, 'XLF', 20) < 0.05:
            AH(self.algo, 'XLF', 268, weight_multiplier)
        else:
            self.check_xlre(weight_multiplier)

    def check_xlre(self, weight_multiplier):
        if MaxDD(self.algo, 'XLRE', 20) < 0.05:
            AH(self.algo, 'XLRE', 268, weight_multiplier)
        else:
            self.fallback_bonds(weight_multiplier)

    def fallback_bonds(self, weight_multiplier):
        AH(self.algo, 'SHY', 268, weight_multiplier / 3)
        AH(self.algo, 'AGG', 268, weight_multiplier / 3)
        AH(self.algo, 'BND', 268, weight_multiplier / 3)

class SuperQQQStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo, 'QQQ', 20) < 35:
            AH(self.algo, 'TECL', 269, 1)
        elif RSI(self.algo, 'SQQQ', 20) < 30:
            AH(self.algo, 'SQQQ', 269, 1)
        else:
            if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
                if RSI(self.algo, 'QQQ', 14) > 75:
                    AH(self.algo, 'SQQQ', 269, 1)
                elif RSI(self.algo, 'QQQ', 10) > 65:
                    AH(self.algo, 'TQQQ', 269, 1)
                else:
                    AH(self.algo, 'QQQ', 269, 1)
            else:
                if RSI(self.algo, 'SQQQ', 10) < 31:
                    AH(self.algo, 'SQQQ', 269, 1)
                else:
                    Sort(self.algo, 'RSI', ('TLT', 'PSQ'), 10, True, 1, 269, 1)

#https://app.composer.trade/symphony/HgzmHmJVEf54f8rqSaqB/details
class KMLMSwitcherSimplyGreenRSIBuySellInvestCopyStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_4x_up_3x_down()
        self.group_3x_tec()
        self.group_3x_qqq()

    def group_4x_up_3x_down(self):
        if RSI(self.algo, 'SPY', 10) > RSI(self.algo, 'KMLM', 10):
            if RSI(self.algo, 'SPY', 10) > 80:
                AH(self.algo, 'SPXU', 270, 0.33333)
            else:
                AH(self.algo, 'SPYU', 270, 0.33333)
        else:
            if RSI(self.algo, 'SPY', 10) < 30:
                AH(self.algo, 'SPYU', 270, 0.33333)
            else:
                AH(self.algo, 'SPXU', 270, 0.33333)

    def group_3x_tec(self):
        if RSI(self.algo, 'XLK', 10) > RSI(self.algo, 'KMLM', 10):
            if RSI(self.algo, 'XLK', 10) > 81:
                AH(self.algo, 'TECS', 270, 0.33333)
            else:
                AH(self.algo, 'TECL', 270, 0.33333)
        else:
            if RSI(self.algo, 'XLK', 10) < 29:
                AH(self.algo, 'TECL', 270, 0.33333)
            else:
                AH(self.algo, 'TECS', 270, 0.33333)

    def group_3x_qqq(self):
        if RSI(self.algo, 'QQQ', 10) > RSI(self.algo, 'KMLM', 10):
            if RSI(self.algo, 'QQQ', 10) > 81:
                AH(self.algo, 'SQQQ', 270, 0.33333)
            else:
                AH(self.algo, 'TQQQ', 270, 0.33333)
        else:
            if RSI(self.algo, 'QQQ', 10) < 29:
                AH(self.algo, 'TQQQ', 270, 0.33333)
            else:
                AH(self.algo, 'SQQQ', 270, 0.33333)

#https://app.composer.trade/symphony/8BLpfj467VXjLMLDs078/details

class JustFrontrunThisStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.just_frontrun_this()

    def just_frontrun_this(self):
        if RSI(self.algo, 'SPY', 10) > 80:
            self.vix_blend_plus(0.75, 0.25)
        elif RSI(self.algo, 'IOO', 10) > 80:
            self.vix_blend_plus(0.75, 0.25)
        elif RSI(self.algo, 'QQQ', 10) > 79:
            self.vix_blend(0.5, 0.5)
        elif RSI(self.algo, 'VTV', 10) > 79:
            self.vix_blend(0.5, 0.5)
        elif RSI(self.algo, 'VOX', 10) > 79:
            self.vix_blend(0.5, 0.5)
        elif RSI(self.algo, 'XLP', 10) > 77:
            self.vix_blend(0.5, 0.5)
        elif RSI(self.algo, 'XLF', 10) > 81:
            self.vix_blend(0.5, 0.5)
        elif CumReturn(self.algo, 'VIXY', 10) > 0.2:
            self.high_vol_strat()
        elif RSI(self.algo, 'SPY', 70) > 62:
            self.overbought()
        else:
            self.jrt()

    def vix_blend_plus(self, vixy_weight, alt_weight):
        AH(self.algo, 'VIXY', 271, vixy_weight)
        AH(self.algo, 'TLT', 271, alt_weight * 0.5)
        AH(self.algo, 'BTAL', 271, alt_weight * 0.5)

    def vix_blend(self, vixy_weight, alt_weight):
        AH(self.algo, 'VIXY', 271, vixy_weight)
        AH(self.algo, 'TLT', 271, alt_weight * 0.5)
        AH(self.algo, 'BTAL', 271, alt_weight * 0.5)

    def high_vol_strat(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            self.jrt()
            self.ticker_mixer()
        elif RSI(self.algo, 'TQQQ', 10) < 30:
            AH(self.algo, 'TQQQ', 271, 0.25 * 0.5)
            AH(self.algo, 'QQQ', 271, 0.75 * 0.5)
            AH(self.algo, 'TECL', 271, 0.25 * 0.5)
            AH(self.algo, 'XLK', 271, 0.75 * 0.5)
        elif CumReturn(self.algo, 'VIXY', 10) > 0.25:
            AH(self.algo, 'BTAL', 271, 0.5)
            AH(self.algo, 'BIL', 271, 0.5)
        else:
            self.jrt()
            self.ticker_mixer()

    def overbought(self):
        AH(self.algo, 'GLD', 271, 0.4)
        AH(self.algo, 'SLV', 271, 0.2)
        AH(self.algo, 'DBC', 271, 0.2)
        self.vix_stuff(0.2)

    def vix_stuff(self, weight):
        if RSI(self.algo, 'QQQ', 90) > 60:
            AH(self.algo, 'VIXY', 271, weight)
        elif RSI(self.algo, 'QQQ', 15) > 80:
            AH(self.algo, 'VIXY', 271, weight)
        elif RSI(self.algo, 'QQQ', 5) > 90:
            AH(self.algo, 'VIXY', 271, weight)
        elif RSI(self.algo, 'QQQ', 3) > 95:
            AH(self.algo, 'VIXY', 271, weight)
        else:
            AH(self.algo, 'SLV', 271, weight * 0.5)
            AH(self.algo, 'XME', 271, weight * 0.5)

    def jrt(self):
        AHIV(self.algo, ('LLY', 'NVO', 'COST', 'PGR'), 10, 271, 1)

    def ticker_mixer(self):
        Sort(self.algo, 'SMADayRet', ('SPY', 'QQQ', 'IWM', 'VWO', 'XLE', 'XHB', 'XLP'), 20, False, 3, 271, 1)

#https://app.composer.trade/symphony/vJhxZPu93No0odspLXAo/details

class HedgedFTLTStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.group_hedged_ftlt()

    def group_hedged_ftlt(self):
        if RSI(self.algo, 'SPY', 10) > 80:
            self.group_vix_blend_plus()
        elif RSI(self.algo, 'IOO', 10) > 80:
            self.group_vix_blend_plus()
        elif RSI(self.algo, 'QQQ', 10) > 79:
            self.group_scale_in_vix_to_vix_plus()
        elif RSI(self.algo, 'VTV', 10) > 79:
            self.group_vix_blend()
        elif RSI(self.algo, 'VOX', 10) > 79:
            self.group_vix_blend()
        elif RSI(self.algo, 'XLP', 10) > 77:
            self.group_vix_blend()
        elif RSI(self.algo, 'XLF', 10) > 81:
            self.group_vix_blend()
        else:
            self.group_strats()

    def group_vix_blend_plus(self):
        AH(self.algo, 'VIXY', 272, 0.75)
        self.group_alternate(0.25)

    def group_vix_blend(self):
        AH(self.algo, 'VIXY', 272, 0.5)
        self.group_alternate(0.5)

    def group_alternate(self, weight):
        AH(self.algo, 'TLT', 272, weight * 0.5)
        AH(self.algo, 'BTAL', 272, weight * 0.5)

    def group_scale_in_vix_to_vix_plus(self):
        if RSI(self.algo, 'QQQ', 10) > 82.5:
            self.group_vix_blend_plus()
        else:
            self.group_vix_blend()

    def group_strats(self):
        self.group_ftlt(0.3)
        self.group_hedge(0.7)

    def group_ftlt(self, weight):
        self.group_spy_ftlt(weight * 0.5)
        self.group_tqqq_ftlt(weight * 0.5)

    def group_spy_ftlt(self, weight):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            if RSI(self.algo, 'SPY', 60) > 60:
                AH(self.algo, 'GLD', 272, weight * 0.5)
                AH(self.algo, 'SHY', 272, weight * 0.5)
            else:
                AH(self.algo, 'SPY', 272, weight)
        elif RSI(self.algo, 'QQQ', 10) < 30:
            AH(self.algo, 'QLD', 272, weight)
        elif RSI(self.algo, 'SPY', 10) < 30:
            AH(self.algo, 'SSO', 272, weight)
        elif GetCurrentPrice(self.algo, 'QQQ') > SMA(self.algo, 'QQQ', 20):
            if RSI(self.algo, 'PSQ', 10) < 32.5:
                AH(self.algo, 'PSQ', 272, weight)
            else:
                AH(self.algo, 'QQQ', 272, weight)
        else:
            Sort(self.algo, 'RSI', ('PSQ', 'BSV'), 10, True, 1, 272, weight)

    def group_tqqq_ftlt(self, weight):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            AH(self.algo, 'TQQQ', 272, weight)
        elif RSI(self.algo, 'TQQQ', 10) < 31:
            AH(self.algo, 'TECL', 272, weight)
        elif RSI(self.algo, 'SPY', 10) < 30:
            AH(self.algo, 'UPRO', 272, weight)
        elif GetCurrentPrice(self.algo, 'TQQQ') > SMA(self.algo, 'TQQQ', 20):
            if RSI(self.algo, 'SQQQ', 10) < 31:
                AH(self.algo, 'SQQQ', 272, weight)
            else:
                AH(self.algo, 'TQQQ', 272, weight)
        else:
            Sort(self.algo, 'RSI', ('SQQQ', 'TLT'), 10, True, 1, 272, weight)

    def group_hedge(self, weight):
        self.group_tmv_simplified_momentum(weight * 0.2)
        self.group_tmf_simplified_momentum(weight * 0.2)
        self.group_tina(weight * 0.2)
        self.group_shorting_spy(weight * 0.2)
        self.group_svxy_ftlt(weight * 0.2)

    def group_tmv_simplified_momentum(self, weight):
        if SMA(self.algo, 'TMV', 15) > SMA(self.algo, 'TMV', 50):
            if RSI(self.algo, 'TMV', 10) < 70:
                if STD(self.algo, 'TMV', 10) < 0.03:
                    AH(self.algo, 'TMV', 272, weight)
                else:
                    AH(self.algo, 'BIL', 272, weight)
            else:
                AH(self.algo, 'BIL', 272, weight)
        else:
            AH(self.algo, 'BIL', 272, weight)

    def group_tmf_simplified_momentum(self, weight):
        if RSI(self.algo, 'TMF', 10) < 32:
            AH(self.algo, 'TMF', 272, weight)
        elif SMA(self.algo, 'TMF', 15) > SMA(self.algo, 'TMF', 50):
            if RSI(self.algo, 'TMF', 10) < 75:
                AH(self.algo, 'TMF', 272, weight * 0.5)
                AH(self.algo, 'BIL', 272, weight * 0.5)
            else:
                AH(self.algo, 'BIL', 272, weight)
        else:
            AH(self.algo, 'BIL', 272, weight)

    def group_tina(self, weight):
        if GetCurrentPrice(self.algo, 'QQQ') > SMA(self.algo, 'QQQ', 20):
            if CumReturn(self.algo, 'QQQ', 10) > 0.055:
                AH(self.algo, 'PSQ', 272, weight)
            elif CumReturn(self.algo, 'TQQQ', 62) < -0.33:
                AH(self.algo, 'TQQQ', 272, weight)
            else:
                AH(self.algo, 'SHV', 272, weight)
        elif RSI(self.algo, 'QQQ', 10) < 30:
            AH(self.algo, 'TECL', 272, weight)
        elif CumReturn(self.algo, 'TQQQ', 62) < -0.33:
            AH(self.algo, 'TQQQ', 272, weight)
        else:
            Sort(self.algo, 'RSI', ('PSQ', 'BSV', 'TLT'), 20, True, 1, 272, weight)

    def group_shorting_spy(self, weight):
        if RSI(self.algo, 'BND', 20) > RSI(self.algo, 'SH', 60):
            if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
                AH(self.algo, 'SHV', 272, weight)
            elif RSI(self.algo, 'QQQ', 10) < 30:
                AH(self.algo, 'XLK', 272, weight)
            else:
                AH(self.algo, 'SHV', 272, weight)
        elif RSI(self.algo, 'QQQ', 10) < 30:
            AH(self.algo, 'XLK', 272, weight)
        elif EMA(self.algo, 'SPY', 10) < SMA(self.algo, 'SPY', 10):
            AH(self.algo, 'SH', 272, weight)
        else:
            AH(self.algo, 'SHV', 272, weight)

    def group_svxy_ftlt(self, weight):
        if RSI(self.algo, 'QQQ', 10) < 30:
            AH(self.algo, 'XLK', 272, weight)
        elif GetCurrentPrice(self.algo, 'SVXY') > SMA(self.algo, 'SVXY', 24):
            Sort(self.algo, 'SMADayRet', ('SVXY', 'VTI'), 20, True, 1, 272, weight)
        else:
            AH(self.algo, 'BTAL', 272, weight)

#https://app.composer.trade/symphony/xM0BoiOzcaQBqVkE5ish/details
class VIXBallerV12Strategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        self.volatility_bomb_block()

    def volatility_bomb_block(self):
        if RSI(self.algo, 'UVXY', 21) > 65:
            if RSI(self.algo, 'UVXY', 10) > 74:
                if RSI(self.algo, 'UVXY', 10) < 84:
                    AH(self.algo, 'UVXY', 273, 1)
                else:
                    AH(self.algo, 'BIL', 273, 1)
            else:
                AH(self.algo, 'BIL', 273, 1)
        else:
            self.vix_baller_v1()

    def vix_baller_v1(self):
        if RSI(self.algo, 'IOO', 10) > 80:
            AH(self.algo, 'UVXY', 273, 1)
        elif RSI(self.algo, 'TQQQ', 10) > 81:
            if RSI(self.algo, 'UVXY', 60) > 40:
                AH(self.algo, 'UVXY', 273, 1)
            else:
                self.retl_check()
        else:
            self.spy_check()

    def retl_check(self):
        if RSI(self.algo, 'RETL', 10) > 82:
            self.scale_in_btal_vix()
        else:
            self.xlf_check()

    def scale_in_btal_vix(self):
        if RSI(self.algo, 'RETL', 10) > 85:
            AH(self.algo, 'UVXY', 273, 1)
        else:
            self.btal_bil()

    def btal_bil(self):
        AH(self.algo, 'BTAL', 273, 0.5)
        AH(self.algo, 'SHV', 273, 0.5)

    def xlf_check(self):
        if RSI(self.algo, 'XLF', 10) > 81:
            self.scale_in_vix_vix_plus()
        else:
            AH(self.algo, 'SHV', 273, 1)

    def scale_in_vix_vix_plus(self):
        if RSI(self.algo, 'XLF', 10) > 85:
            AH(self.algo, 'UVXY', 273, 1)
        else:
            AH(self.algo, 'UVXY', 273, 1)

    def spy_check(self):
        if RSI(self.algo, 'SPY', 10) > 80:
            if RSI(self.algo, 'UVXY', 60) > 40:
                AH(self.algo, 'UVXY', 273, 1)
            else:
                self.retl_check()
        else:
            self.soxl_check()

    def soxl_check(self):
        if RSI(self.algo, 'SOXL', 14) < 30:
            AH(self.algo, 'SOXL', 273, 1)
        else:
            self.tecl_check()

    def tecl_check(self):
        if RSI(self.algo, 'TECL', 14) < 30:
            AH(self.algo, 'TECL', 273, 1)
        else:
            self.upro_check()

    def upro_check(self):
        if RSI(self.algo, 'UPRO', 10) < 25:
            AH(self.algo, 'UPRO', 273, 1)
        else:
            self.upleveraged_anansi_scale_in()

    def upleveraged_anansi_scale_in(self):
        if RSI(self.algo, 'SPY', 10) > 80:
            AH(self.algo, 'UVXY', 273, 1)
        else:
            self.ioo_check()

    def ioo_check(self):
        if RSI(self.algo, 'IOO', 10) > 80:
            self.scale_in_vix_plus_vix_plus_plus()
        else:
            self.qqq_check()

    def scale_in_vix_plus_vix_plus_plus(self):
        if RSI(self.algo, 'IOO', 10) > 82.5:
            AH(self.algo, 'UVXY', 273, 1)
        else:
            AH(self.algo, 'UVXY', 273, 1)

    def qqq_check(self):
        if RSI(self.algo, 'QQQ', 10) > 79:
            self.scale_in_vix_plus_vix_plus_plus()
        else:
            self.vtv_check()

    def vtv_check(self):
        if RSI(self.algo, 'VTV', 10) > 79:
            AH(self.algo, 'UVXY', 273, 1)
        else:
            self.xlp_check()

    def xlp_check(self):
        if RSI(self.algo, 'XLP', 10) > 77:
            AH(self.algo, 'UVXY', 273, 1)
        else:
            self.xlf_check_2()

    def xlf_check_2(self):
        if RSI(self.algo, 'XLF', 10) > 81:
            AH(self.algo, 'UVXY', 273, 1)
        else:
            self.fngu_check()

    def fngu_check(self):
        if RSI(self.algo, 'FNGU', 10) > 83:
            AH(self.algo, 'UVXY', 273, 1)
        else:
            self.spy_overbought_check()

    def spy_overbought_check(self):
        if RSI(self.algo, 'SPY', 70) > 62:
            self.overbought_strategy()
        else:
            self.vixy_check()

    def overbought_strategy(self):
        if RSI(self.algo, 'AGG', 15) > RSI(self.algo, 'QQQ', 15):
            self.ticker_mixer()
        else:
            self.gld_slv_dbc()

    def ticker_mixer(self):
        Sort(self.algo, 'SMADayRet', ('SPXL', 'TQQQ', 'TECL', 'SOXL', 'FNGU'), 15, True, 3, 273, 0.75)
        AH(self.algo, 'TQQQ', 273, 0.25)

    def gld_slv_dbc(self):
        AH(self.algo, 'GLD', 273, 0.5)
        AH(self.algo, 'SLV', 273, 0.25)
        AH(self.algo, 'DBC', 273, 0.25)

    def vixy_check(self):
        if CumReturn(self.algo, 'VIXY', 10) > 0.2:
            self.high_vix_strategy()
        else:
            self.tqqq_oversold_check()

    def high_vix_strategy(self):
        if GetCurrentPrice(self.algo, 'SPY') > SMA(self.algo, 'SPY', 200):
            if CumReturn(self.algo, 'VIXY', 10) > 0.275:
                AH(self.algo, 'BTAL', 273, 0.5)
                self.ticker_mixer_2()
            else:
                self.ticker_mixer_2()
        else:
            self.tqqq_oversold_check()

    def ticker_mixer_2(self):
        Sort(self.algo, 'SMADayRet', ('SPY', 'IWM', 'EFA', 'XLF', 'XHB', 'XLE'), 10, False, 3, 273, 1)

    def tqqq_oversold_check(self):
        if RSI(self.algo, 'TQQQ', 10) < 30:
            self.pick_bottom_3()
        else:
            self.vixy_check_2()

    def pick_bottom_3(self):
        Sort(self.algo, 'SMADayRet', ('SPXL', 'TQQQ', 'TECL', 'SOXL'), 10, False, 3, 273, 0.5)
        Sort(self.algo, 'SMADayRet', ('SPY', 'QQQ', 'XLK', 'SOXX'), 10, False, 3, 273, 0.5)

    def vixy_check_2(self):
        if CumReturn(self.algo, 'VIXY', 10) > 0.25:
            AH(self.algo, 'BTAL', 273, 1)
        else:
            self.ticker_mixer_2()


#https://app.composer.trade/symphony/hrOhrq5vnOGoCnJsDNJ4/details
class Cactus36CMPStrategy(YellowCatStrat):
    def __init__(self, algo):
        super().__init__()
        self.algo = algo

    def Execute(self):
        if RSI(self.algo, 'VIXM', 5) > 55:
            self.high_volatility_strategy()
        else:
            self.low_volatility_strategy()

    def high_volatility_strategy(self):
        self.core_logic()
        self.dip_buy_logic()

    def low_volatility_strategy(self):
        if RSI(self.algo, 'VIXM', 21) > 60:
            self.abnormal_market_check()
        else:
            self.qqq_logic()
            self.rsi_logic()

    def core_logic(self):
        if RSI(self.algo, 'XLU', 21) < RSI(self.algo, 'QQQ', 21):
            AH(self.algo, 'TQQQ', 277, 0.25)
        else:
            self.sqqq_btal_filter(0.25)

        if RSI(self.algo, 'JNK', 21) > RSI(self.algo, 'QQQ', 21):
            AH(self.algo, 'TQQQ', 277, 0.25)
        else:
            self.sqqq_btal_filter(0.25)

    def dip_buy_logic(self):
        if RSI(self.algo, 'QYLD', 14) < 35:
            AH(self.algo, 'TQQQ', 277, 0.25)
        else:
            AH(self.algo, 'BTAL', 277, 0.25)

        if RSI(self.algo, 'TQQQ', 10) < 30:
            AH(self.algo, 'TQQQ', 277, 0.25)
        else:
            AH(self.algo, 'BTAL', 277, 0.25)

    def abnormal_market_check(self):
        if RSI(self.algo, 'GLD', 3) < 70:
            AH(self.algo, 'BTAL', 277, 1)
        else:
            AH(self.algo, 'TQQQ', 277, 1)

    def qqq_logic(self):
        if STD(self.algo, 'QQQ', 21) < 0.02:
            AH(self.algo, 'TQQQ', 277, 0.25)
        else:
            self.sqqq_btal_filter(0.25)

        if CumReturn(self.algo, 'TQQQ', 5) < 0.1:
            AH(self.algo, 'TQQQ', 277, 0.25)
        else:
            self.sqqq_btal_filter(0.25)

    def rsi_logic(self):
        if RSI(self.algo, 'XLP', 30) < RSI(self.algo, 'QYLD', 30):
            AH(self.algo, 'TQQQ', 277, 0.25)
        else:
            AH(self.algo, 'BTAL', 277, 0.25)

        if RSI(self.algo, 'BND', 10) > RSI(self.algo, 'BTAL', 10):
            AH(self.algo, 'TQQQ', 277, 0.25)
        else:
            AH(self.algo, 'BIL', 277, 0.25)

    def sqqq_btal_filter(self, weight):
        Sort(self.algo, 'RSI', ('SQQQ', 'BTAL'), 10, False, 1, 277, weight * 0.5)
        Sort(self.algo, 'SMADayRet', ('SQQQ', 'BTAL'), 10, True, 1, 277, weight * 0.5)
#region imports
from AlgorithmImports import *
#endregion
import os
import re

def find_duplicates(project_dir):
    # Regular expression pattern to match the class definition
    class_pattern = r"class\s+(\w+)Strategy\(YellowCatStrat\):"
    
    # Regular expression pattern to match symphony IDs
    symphony_pattern = r"symphony/([^/]+)/details"

    # Dictionaries to store the class names, symphony IDs, and their locations
    classes = {}
    symphony_ids = {}

    # Traverse through all subdirectories in the project directory
    for root, dirs, files in os.walk(project_dir):
        for file in files:
            if file == "version1.py":
                file_path = os.path.join(root, file)
                with open(file_path, "r") as f:
                    content = f.read()
                    
                    # Find class names
                    class_matches = re.findall(class_pattern, content)
                    for match in class_matches:
                        class_name = match
                        if class_name in classes:
                            classes[class_name].append(file_path)
                        else:
                            classes[class_name] = [file_path]
                    
                    # Find symphony IDs
                    symphony_matches = re.findall(symphony_pattern, content)
                    for match in symphony_matches:
                        symphony_id = match
                        if symphony_id in symphony_ids:
                            symphony_ids[symphony_id].append(file_path)
                        else:
                            symphony_ids[symphony_id] = [file_path]

    # Print the duplicate class names and their locations
    print("Duplicate Class Names:")
    for class_name, locations in classes.items():
        if len(locations) > 1:
            print(f"Duplicate found: class {class_name}Strategy(YellowCatStrat) in:")
            for location in locations:
                print(f"  - {location}")
    
    # Print the duplicate symphony IDs and their locations
    print("\nDuplicate Symphony IDs:")
    for symphony_id, locations in symphony_ids.items():
        if len(locations) > 1:
            print(f"Duplicate found: Symphony ID {symphony_id} in:")
            for location in locations:
                print(f"  - {location}")

# Provide the path to your project directory
project_directory = "E:/Quantconnect/Yellow Cat On Fire/Strategies"

find_duplicates(project_directory)
 #indicators.py
from AlgorithmImports import *
from AlgorithmImports import *
import math
import pandas as pd
from cmath import sqrt
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Data.Custom import *
from QuantConnect.Python import PythonData
import csv
import io
import time
import json
import random
import re
import inspect

def RSI(self, equity, period):
    extension = min(period * 5, 250)
    r_w = RollingWindow[float](extension)
    history = self.History(equity, extension - 1, Resolution.Daily)
    for historical_bar in history:
        r_w.Add(historical_bar.Close)
    while r_w.Count < extension:
        current_price = self.Securities[equity].Price
        r_w.Add(current_price)
    if r_w.IsReady:
        average_gain = 0
        average_loss = 0
        gain = 0
        loss = 0
        for i in range(extension - 1, extension - period - 1, -1):
            if i - 1 < 0:
                diff = random.randint(0, 99)
            else:
                diff = r_w[i - 1] - r_w[i]
            gain += max(diff, 0)
            loss += abs(min(diff, 0))
        average_gain = gain / period
        average_loss = loss / period
        for i in range(extension - period - 1, 0, -1):
            if i - 1 < 0:
                diff = random.randint(0, 99)
            else:
                diff = r_w[i - 1] - r_w[i]
            average_gain = (average_gain * (period - 1) + max(diff, 0)) / period
            average_loss = (average_loss * (period - 1) + abs(min(diff, 0))) / period
        if average_loss == 0:
            return 100
        else:
            rsi = 100 - (100 / (1 + average_gain / average_loss))
            return rsi
    else:
        return None
def CumReturn(self,equity,period):
    history = self.History(equity,period,Resolution.Daily)
    closing_prices = pd.Series([bar.Close for bar in history])
    current_price = self.Securities[equity].Price
    closing_prices = pd.concat([closing_prices, pd.Series([current_price])])
    first_price = closing_prices.iloc[0]
    if first_price == 0:
        return 0
    else:
        return_val = (current_price/first_price) - 1
        return return_val
def STD(self, equity, period):
    r_w = RollingWindow[float](period + 1)
    r_w_return = RollingWindow[float](period)
    history = self.History(equity, period, Resolution.Daily)
    
    for historical_bar in history:
        r_w.Add(historical_bar.Close)
    
    while r_w.Count < period + 1:
        current_price = self.Securities[equity].Price
        r_w.Add(current_price)
    
    for i in range(period, 0, -1):
        if r_w[i] != 0:
            daily_return = (r_w[i-1] / r_w[i] - 1)
        else:
            daily_return = 0  # or any other appropriate value
        r_w_return.Add(daily_return)
    
    dfstd = pd.DataFrame({'r_w_return': r_w_return})
    
    if r_w.IsReady:
        std = dfstd['r_w_return'].std()
        if std == 0:
            return 0
        else:
            return std
    else:
        return 0
def MaxDD(self, equity, period):
        history = self.History(equity,period - 1,Resolution.Daily)
        closing_prices = pd.Series([bar.Close for bar in history])
        current_price = self.Securities[equity].Price
        closing_prices = pd.concat([closing_prices, pd.Series([current_price])])
        rolling_max = closing_prices.cummax()
        drawdowns = (rolling_max - closing_prices)/rolling_max
        max_dd = drawdowns.max()
        return max_dd
def SMA(self,equity,period):

    r_w = RollingWindow[float](period)
    history = self.History(equity,period - 1,Resolution.Daily)
    for historical_bar in history:
        r_w.Add(historical_bar.Close)
    while r_w.Count < period:
        current_price = self.Securities[equity].Price
        r_w.Add(current_price)
    if r_w.IsReady:
        sma = sum(r_w)/period
        return sma
    else:
        return 0
def IV(self,equity,period):
    r_w = RollingWindow[float](period + 1)
    r_w_return = RollingWindow[float](period)
    history = self.History(equity,period,Resolution.Daily)
    for historical_bar in history:
        r_w.Add(historical_bar.Close)
    while r_w.Count < period + 1:
        current_price = self.Securities[equity].Price
        r_w.Add(current_price)
    for i in range (period,0,-1):
        if r_w[i] == 0:
            return 0
        else:
            daily_return = (r_w[i-1]/r_w[i] - 1)
            r_w_return.Add(daily_return)
    dfinverse = pd.DataFrame({'r_w_return':r_w_return})
    if r_w.IsReady:
        std = dfinverse['r_w_return'].std()
        if std == 0:
            return 0
        else:
            inv_vol = 1/std
            return inv_vol
    else:
        return 0
def SMADayRet(self, equity, period):
    r_w = RollingWindow[float](period + 1)
    r_w_return = RollingWindow[float](period)
    history = self.History(equity, period, Resolution.Daily)
    for historical_bar in history:
        r_w.Add(historical_bar.Close)
    while r_w.Count < period + 1:
        current_price = self.Securities[equity].Price
        r_w.Add(current_price)
    for i in range(period, 0, -1):
        if r_w[i] == 0:
            return 0  # Return 0 instead of None
        daily_return = (r_w[i-1] / r_w[i] - 1)
        r_w_return.Add(daily_return)
    if r_w.IsReady:
        smareturn = sum(r_w_return) / period
        return smareturn
    else:
        return 0
def EMA(self,equity,period):
    extension = period + 50
    r_w = RollingWindow[float](extension)
    history = self.History(equity,extension - 1,Resolution.Daily)
    for historical_bar in history:
        r_w.Add(historical_bar.Close)
    while r_w.Count < extension:
        current_price = self.Securities[equity].Price
        r_w.Add(current_price)
    if r_w.IsReady:
        total_price = 0
        for i in range(extension - 1,extension - period - 2,-1):
            total_price += r_w[i]
        average_price = total_price/period
        for i in range(extension - period - 2,-1,-1):
            average_price = r_w[i]*2/(period+1) + average_price*(1-2/(period+1))
        return average_price
    else:
        return None

def Sort(self, sort_type, equities, period, reverse, num_assets, number, multiplier):
    # Update the PT value for the given strategy number
    PT = getattr(self, f"PT{number}") * multiplier

    # Define a dictionary to map sort types to functions
    indicator_functions = {
        'EMA': EMA,
        'RSI': RSI,
        'CumReturn': CumReturn,
        'STD': STD,
        'MaxDD': MaxDD,
        'SMA': SMA,
        'IV': IV,
        'SMADayRet': SMADayRet,
        # Add other indicators here as needed
    }

    # Compute the indicator value for each equity
    returns = {}
    for equity in equities:
        indicator_function = indicator_functions.get(sort_type, None)
        if callable(indicator_function):
            indicator_value = indicator_function(self, equity, period)
            if indicator_value is not None:
                returns[equity] = indicator_value

    # Sort the equities based on the indicator values
    sorted_equities = sorted(returns.items(), key=lambda x: x[1], reverse=reverse)

    # Select the top 'num_assets' from the sorted list
    top_equities = sorted_equities[:num_assets]

    # Get the current HT and HTS attributes for the strategy
    HT = getattr(self, f"HT{number}")
    HTS = getattr(self, f"HTS{number}")

    # Assign each of the top equities to the next available slot in HT and HTS
    for equity, value in top_equities:
        for i in HT.keys():
            if HT[i] == 0:
                HT[i] = PT / num_assets  # Distribute PT evenly among the assets
                HTS[i].append(equity)  # Append the asset symbol
                break  # Move to the next asset after appending

    # Update the HT and HTS attributes for the strategy
    setattr(self, f"HT{number}", HT)
    setattr(self, f"HTS{number}", HTS)


def AH(self,equities,PTnumber,multiplier): #AppendHolding
    if not isinstance(equities,list):
        equities = [equities]
    HT = getattr(self,f"HT{PTnumber}")
    HTS = getattr(self,f"HTS{PTnumber}")
    PT = getattr(self,f"PT{PTnumber}") * multiplier
    
    for equity in equities:
        for i in HT.keys():
            if HT[i] == 0:
                HT[i] = PT
                HTS[i].append(equity)
                break

def GetCurrentPrice(self, symbol):
    """
    Gets the current price of a security.

    :param self: The self instance containing the securities.
    :param symbol: The symbol of the security.
    :return: The current price of the security or None if not available.
    """
    if symbol in self.Securities:
        return self.Securities[symbol].Price
    else:
        self.Debug(f"Symbol {symbol} not found in securities.")
        return None
    
def AHIV(self, assets, period, PTnumber, multiplier):
    if isinstance(assets, str):
        assets = [assets]
    elif isinstance(assets, tuple):
        assets = list(assets)

    HT = getattr(self, f"HT{PTnumber}")
    HTS = getattr(self, f"HTS{PTnumber}")
    PT = getattr(self, f"PT{PTnumber}") * multiplier

    tickers_IV = []
    processed_assets = []

    for asset in assets:
        if isinstance(asset, tuple):
            asset_name, weight = asset
        else:
            asset_name, weight = asset, 1

        if is_valid_ticker(asset_name):
            # It's a valid ticker symbol
            try:
                IV_value = IV(self, asset_name, period)
                if IV_value is not None and IV_value != 0:
                    tickers_IV.append((asset_name, IV_value, weight))
                    processed_assets.append(asset_name)
                #else:
                    #self.Log(f"IV value is None or 0 for ticker: {asset_name}")
            except Exception as e:
                self.Log(f"Error calculating IV for ticker: {asset_name}. Error: {str(e)}")
        else:
            # It's a group method, execute it
            try:
                group_method = getattr(self, asset_name, None)
                if group_method is None:
                    group_method = getattr(self.algo, asset_name, None)
                if group_method is None:
                    for strategy in self.algo.strategies.values():
                        if hasattr(strategy, asset_name):
                            group_method = getattr(strategy, asset_name)
                            break
                
                if group_method is None:
                    self.Log(f"Group method not found: {asset_name}")
                    continue

                # Execute the group method
                result = group_method()
                if isinstance(result, tuple) and len(result) == 2:
                    group_tickers, group_weights = result
                    for ticker, ticker_weight in zip(group_tickers, group_weights):
                        if is_valid_ticker(ticker):
                            try:
                                IV_value = IV(self, ticker, period)
                                if IV_value is not None and IV_value != 0:
                                    tickers_IV.append((ticker, IV_value, weight * ticker_weight))
                                    processed_assets.append(ticker)
                                #else:
                                    #self.Log(f"IV value is None or 0 for ticker: {ticker} in group {asset_name}")
                            except Exception as e:
                                self.Log(f"Error calculating IV for ticker: {ticker} in group {asset_name}. Error: {str(e)}")
            except Exception as e:
                self.Log(f"Error executing group method: {asset_name}. Error: {str(e)}")

    if not tickers_IV:
        self.Log("No valid IV values calculated. Exiting AHIV function.")
        return

    # Calculate total weighted IV
    total_weighted_IV = sum(iv * weight for _, iv, weight in tickers_IV)

    # Allocate for each asset
    for ticker, iv, weight in tickers_IV:
        try:
            portion = (iv * weight) / total_weighted_IV if total_weighted_IV != 0 else 0
            allocation = portion * PT
            
            for i in HT.keys():
                if HT[i] == 0:
                    HT[i] = allocation
                    HTS[i].append(ticker)
                    break
        except Exception as e:
            self.Log(f"Error allocating for asset: {ticker}. Error: {str(e)}")

def is_valid_ticker(symbol):
    pattern = r'^[A-Z]{1,5}(\.[A-Z]{1,2})?$'
    return re.match(pattern, symbol) is not None

def get_strategy_number(self, group_method):
    for strategy_name, strategy_instance in self.algo.strategies.items():
        strategy_module_source = inspect.getsource(strategy_instance.__class__)
        strategy_numbers = re.findall(r'AH\(self(?:\.algo)?,\s*[\'\w\(\)\s,]+,\s*(\d+)\s*,', strategy_module_source)
        strategy_numbers.extend(re.findall(r'Sort\(self(?:\.algo)?,\s*[\'\w]+,\s*[\'\w\(\)\s,]+,\s*\d+\s*,\s*\w+\s*,\s*\d+\s*,\s*(\d+)', strategy_module_source))
        strategy_numbers.extend(re.findall(r'AHIV\(self(?:\.algo)?,\s*[\'\w\(\)\s,]+,\s*\d+\s*,\s*(\d+)\s*,\s*[\d\.]+\)', strategy_module_source))
        strategy_numbers.extend(re.findall(r'GroupSort\(self(?:\.algo)?,\s*[\'\w]+,\s*[\'\w\(\)\s,]+,\s*\d+\s*,\s*\w+\s*,\s*\d+\s*,\s*(\d+)', strategy_module_source))
        
        if group_method in strategy_module_source:
            return strategy_numbers[0] if strategy_numbers else None
    
    return None

def SandboxGroupSort(self, filter_type, group_methods, window, select_type, num_assets):
    indicator_functions = {
        'EMA': EMA,
        'RSI': RSI,
        'CumReturn': CumReturn,
        'STD': STD,
        'MaxDD': MaxDD,
        'SMA': SMA,
        'IV': IV,
        'SMADayRet': SMADayRet,
    }

    group_indicator_values = {}
    for group_item in group_methods:
        group_method, weight = group_item if isinstance(group_item, tuple) else (group_item, 1)
        if group_method is None:
            continue

        strategy_number = get_strategy_number(self, group_method)
        if strategy_number is None:
            self.algo.Debug(f"Strategy number not found for {group_method}")
            continue

        # Create temporary HT and HTS for this group
        temp_HT = {str(j).zfill(2): 0 for j in range(1, 10)}
        temp_HTS = {str(j).zfill(2): [] for j in range(1, 10)}

        # Check if group_method is a valid ticker symbol
        if isinstance(group_method, str) and is_valid_ticker(group_method):
            # It's a ticker symbol
            temp_HT['01'] = 1
            temp_HTS['01'] = [group_method]
        else:
            # It's a group method
            if hasattr(self, group_method):
                group_method_func = getattr(self, group_method)
            elif hasattr(self.algo, group_method):
                group_method_func = getattr(self.algo, group_method)
            else:
                for strategy in self.algo.strategies.values():
                    if hasattr(strategy, group_method):
                        group_method_func = getattr(strategy, group_method)
                        break
                else:
                    self.algo.Debug(f"Method '{group_method}' not found in any strategy")
                    continue

            # Execute the group method in the sandbox
            original_HT = getattr(self.algo, f'HT{strategy_number}')
            original_HTS = getattr(self.algo, f'HTS{strategy_number}')
            setattr(self.algo, f'HT{strategy_number}', temp_HT)
            setattr(self.algo, f'HTS{strategy_number}', temp_HTS)
            group_method_func()

        # Calculate the weighted indicator value for the group
        weighted_indicator_value = 0
        total_weight = sum(temp_HT.values())
        for i, (equities, allocation) in enumerate(zip(temp_HTS.values(), temp_HT.values())):
            if not equities or allocation == 0:
                continue
            if isinstance(equities, list):
                for equity in equities:
                    if is_valid_ticker(equity):
                        indicator_value = indicator_functions[filter_type](self.algo, equity, window)
                        if indicator_value is not None:
                            weighted_indicator_value += (allocation / total_weight) * indicator_value
                    else:
                        self.algo.Debug(f"Invalid ticker: {equity}")
            elif is_valid_ticker(equities):
                indicator_value = indicator_functions[filter_type](self.algo, equities, window)
                if indicator_value is not None:
                    weighted_indicator_value += (allocation / total_weight) * indicator_value
            else:
                self.algo.Debug(f"Invalid ticker: {equities}")

        group_indicator_values[group_method] = weighted_indicator_value * weight

        # Restore original HT and HTS if they were changed
        if not (isinstance(group_method, str) and is_valid_ticker(group_method)):
            setattr(self.algo, f'HT{strategy_number}', original_HT)
            setattr(self.algo, f'HTS{strategy_number}', original_HTS)

    # Sort groups based on the weighted indicator values
    reverse = select_type == 'Top'
    sorted_groups = sorted(group_indicator_values.items(), key=lambda x: x[1], reverse=reverse)[:num_assets]

    return [group for group, _ in sorted_groups]

def GroupSort(self, filter_type, group_methods, window, select_type, num_assets, number, multiplier):
    # Use SandboxGroupSort to evaluate and sort the groups
    selected_groups = SandboxGroupSort(self, filter_type, group_methods, window, select_type, num_assets)
    
    #self.algo.Debug(f"GroupSort: Selected groups/assets: {selected_groups}")
    # Get the current HT and HTS attributes for the strategy
    HT = getattr(self.algo, f"HT{number}")
    HTS = getattr(self.algo, f"HTS{number}")

    # Execute the selected groups and update HT and HTS
    PT = getattr(self.algo, f"PT{number}") * multiplier
    allocated_pt = 0

    for group_method in selected_groups:
        strategy_number = get_strategy_number(self, group_method)
        if strategy_number is None:
            self.algo.Debug(f"Strategy number not found for {group_method}")
            continue

        if isinstance(group_method, str) and is_valid_ticker(group_method):
            # It's a ticker symbol
            allocation = PT / num_assets
            if allocated_pt + allocation <= PT:
                for i in range(1, 10):
                    key = str(i).zfill(2)
                    if HT[key] == 0:
                        HT[key] = allocation
                        HTS[key] = [group_method]
                        allocated_pt += allocation
                        break
        else:
            # It's a group method
            if hasattr(self, group_method):
                group_method_func = getattr(self, group_method)
            elif hasattr(self.algo, group_method):
                group_method_func = getattr(self.algo, group_method)
            else:
                for strategy in self.algo.strategies.values():
                    if hasattr(strategy, group_method):
                        group_method_func = getattr(strategy, group_method)
                        break
                else:
                    self.algo.Debug(f"Method '{group_method}' not found in any strategy")
                    continue

            original_HT = getattr(self.algo, f'HT{strategy_number}')
            original_HTS = getattr(self.algo, f'HTS{strategy_number}')
            
            # Create temporary HT and HTS for this group
            temp_HT = {str(j).zfill(2): 0 for j in range(1, 10)}
            temp_HTS = {str(j).zfill(2): [] for j in range(1, 10)}
            setattr(self.algo, f'HT{strategy_number}', temp_HT)
            setattr(self.algo, f'HTS{strategy_number}', temp_HTS)
            
            # Execute the group method
            group_method_func()
            
            # Update the actual HT and HTS based on the temporary ones
            for i in range(1, 10):
                key = str(i).zfill(2)
                if temp_HT[key] != 0:
                    allocation = (PT / num_assets) * (temp_HT[key] / sum(temp_HT.values()))
                    if allocated_pt + allocation <= PT:
                        HT[key] = allocation
                        HTS[key] = temp_HTS[key]
                        allocated_pt += allocation
                    else:
                        break
            
            # Restore original HT and HTS
            setattr(self.algo, f'HT{strategy_number}', original_HT)
            setattr(self.algo, f'HTS{strategy_number}', original_HTS)

        if allocated_pt >= PT:
            break

    # Update the HT and HTS attributes for the strategy
    setattr(self.algo, f"HT{number}", HT)
    setattr(self.algo, f"HTS{number}", HTS)
# main.py
from AlgorithmImports import *
import math
import pandas as pd
from cmath import sqrt
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Data.Custom import *
from QuantConnect.Python import PythonData
import csv
import io
import time
import json
import os
import importlib
import inspect
import re
import numpy as np
import types
from indicators import *
from datetime import datetime, timedelta


class YellowCatStrat(QCAlgorithm):

    def Initialize(self):
        self.cash = 1000000
        
        self.SetStartDate(2024,12,10)
        self.SetEndDate(2025,1,14)
        self.SetCash(self.cash)
        self.equities = ['BRK/B','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','Q','R','S','T','U','V','W','X','Y','Z','GOOGL',
'AA','AAPB','AAPD','AAPL','AAPU','AAPX','ABBV','ACIO','ACWV','ADBE','ADP','ADSK','AGG','AGQ','AIA','AIYY','AKAM','AMAT','AMD','AMDY','AMGN','AMZA','AMZN','AMZU','AMZY','APLY','ARCH','ARGT','ARKF','ARKG','ARKK','ARKQ','ARKX','ARM','ASML','AVAV','AVGO','AXP','BA','BAC','BAL','BBVA','BCS','BEEZ','BFLY','BIL','BIRD','BITB','BITI','BITO','BITX','BKNG','BLK','BLOK','BLV','BMY','BND','BNDI','BNDW','BNKD','BOIL','BORR','BOTZ','BOXX','BRZU','BSV','BTAL','BTU','BUCK','BUG','BUL','BULZ','BWX','CALF','CANE','CAT','CCJ','CCRD','CEG','CEIX','CEW','CGNX','CHAD','CHAU','CHKP','CI','CII','CLF','CMCSA','CNI','COF','COHU','COIN','COM','COMT','CONL','CONY','COPX','CORN','CORP','COST','COWS','COWZ','CQQQ','CRESY','CRM','CROX','CRUS','CRWD','CSCO','CSHI','CURE','CVS','CWEB','CYBR','DB','DBA','DBB','DBC','DBMF','DBO','DDM','DE','DFEN','DG','DGRO','DGRW','DHS','DIA','DIG','DIS','DISO','DIVO','DLTR','DNN','DOG','DOGZ','DPST','DQ','DRIP','DRN','DRQ','DRV','DUG','DUK','DUSL','DUST','DVYA','DVYE','DXD','EC','ECC','ECH','ECL','ECNS','ECOM','EDC','EDEN','EDV','EDZ','EEM','EEMA','EEMS','EEMV','EETH','EFA','EFAV','EFG','EFNL','EFO','EFV','EIDO','EIRL','EIS','ELTK','EMA','EMB','EMIF','ENOR','ENPH','ENZL','EOG','EPHE','EPI','EPOL','EPP','EPU','ERET','ERIC','ERX','ERY','ES','ESGD','ESGE','ESPO','EUFN','EUO','EURL','EWA','EWC','EWD','EWG','EWGS','EWH','EWI','EWJ','EWJV','EWK','EWL','EWM','EWN','EWO','EWP','EWQ','EWS','EWT','EWU','EWUS','EWW','EWY','EWZ','EWZS','EXG','EXI','EZA','EZU','FAAR','FAS','FAZ','FBL','FBND','FBY','FCG','FEPI','FET','FILL','FITB','FLNG','FLYD','FLYU','FM','FMF','FNGD','FNGS','FNGU','FRDM','FRO','FROG','FTGC','FTI','FTLS','FTNT','FTQI','FXI','GBTC','GD','GDX','GDXD','GDXU','GE','GEOS','GGB','GGLL','GGLS','GILD','GLD','GOOG','GOOGL','GOOS','GOOY','GS','GUSH','HCKT','HD','HDGE','HEEM','HIBL','HIBS','HIVE','HKND','HOG','HON','HPQ','HSBC','HT','HTGC','HTS','HYEM','IAU','IAUM','IBIT','IBM','ICLN','ICSH','IDV','IEF','IEI','IEO','IEV','IGF','IGRO','ILF','IMOM','IMTM','INDA','INDL','INDY','INFY','INTC','INTF','IOO','IQLT','IVAL','IVEG','IVLU','IWB','IWM','IXC','IXG','IXJ','IXN','IXP','IYK','IYY','JDST','JEPI','JEPQ','JKHY','JNJ','JNK','JNUG','JPM','JPMO','JPXN','JXI','KEY','KLAC','KMLM','KNSL','KO','KOLD','KORU','KSA','KWT','KXI','LABD','LABU','LBAY','LCTD','LDEM','LEU','LLY','LMT','LOGI','LOW','LQD','LQDW','LRCX','LTPZ','MA','MAR','MARA','MCD','MCK','META','MEXX','MIDU','MNDO','MNST','MO','MOAT','MOO','MPC','MRK','MRNA','MRNY','MS','MSFO','MSFT','MSFU','MSFX','MSTR','MSTY','MT','MTB','MU','MVV','MXI','NAIL','NBR','NFLX','NFLY','NLR','NOBL','NOC','NRGD','NSYS','NU','NUE','NUGT','NURE','NUSI','NVDA','NVDL','NVDS','NVDU','NVDY','NVO','OARK','OEF','OIH','OILD','OILK','OKTA','OTTR','OWL','PAK','PALL','PANW','PAWZ','PDBC','PEJ','PEP','PETS','PEY','PFE','PG','PGR','PHDG','PICK','PILL','PKX','PLTR','PM','PNC','PPLT','PSQ','PST','PUI','PUTW','PYPY','QAT','QCOM','QDTE','QID','QLD','QLYS','QQQ','QQQE','QQQY','QYLD','REMX','RETL','RF','RIG','RINF','RING','RIOT','ROM','RSI','RTX','RXI','RYLD','SAA','SAN','SARK','SBUX','SCCO','SCHD','SCO','SD','SDG','SDOW','SDS','SDY','SGML','SGOL','SH','SHV','SHY','SHYG','SIMO','SJB','SLB','SLV','SLVP','SLX','SMA','SMCI','SMDD','SMH','SMHI','SMIN','SMR','SNAL','SOF','SOXL','SOXS','SOXX','SPDN','SPHB','SPHD','SPLG','SPLV','SPTL','SPUU','SPXL','SPXS','SPXU','SPY','SPYG','SPYI','SPYU','SQM','SQQQ','SQY','SRTY','SSO','STD','STIP','STLD','SVIX','SVOL','SVXY','SWAN','TAGS','TAIL','TARK','TBF','TBT','TBX','TCHI','TDW','TECB','TECL','TECS','TFC','TFLO','THC','THD','TIGR','TIP','TKC','TLH','TLT','TLTW','TMF','TMUS','TMV','TNA','TNP','TQQQ','TRV','TS','TSLA','TSLL','TSLQ','TSLS','TSLY','TSM','TTT','TUR','TXN','TYD','TYO','TZA','UAE','UBOT','UBT','UCO','UDN','UDOW','UEC','UGE','UGL','UGP','ULTA','ULTY','UNG','UNH','UPRO','URA','URE','URNJ','URNM','UROY','URTY','USD','USDU','USFR','USMV','USO','UTSL','UTWO','UUP','UUUU','UVIX','UVXY','UWM','UYG','VALE','VAW','VCIT','VCLT','VDC','VDE','VEA','VEGI','VEU','VFH','VGI','VGLT','VGT','VHT','VIG','VIS','VIXM','VIXY','VMBS','VNM','VNQ','VNQI','VOO','VOOG','VOOV','VOX','VPU','VSAT','VST','VT','VTI','VTIP','VTV','VUG','VV','VWO','VXX','VYM','VZ','WANT','WEAT','WEBL','WEBS','WEIX','WFC','WGMI','WM','WMT','WOLF','WOOD','WOOF','WSTG','WTID','XAR','XDTE','XHB','XLB','XLC','XLE','XLF','XLI','XLK','XLP','XLRE','XLU','XLV','XLY','XME','XOM','XOMO','XPRO','XT','XYLD','YANG','YCS','YINN','YMAG','YMAX','ZBRA','ZS']
          
        for equity in self.equities:
            self.AddEquity(equity,Resolution.Minute)
            self.Securities[equity].SetDataNormalizationMode(DataNormalizationMode.Adjusted)

        # Set up the risk-free rate model with a constant 2% rate
        self.set_risk_free_interest_rate_model(ConstantRiskFreeRateInterestRateModel(0.02))

        self.exclude_symbols = ['BIL','BOXX','BSV','BUCK','CSHI','ICSH','IEI','MINT','SHV','SHY','SOF','TFLO','USFR','UTWO','STIP','VCIT','LQD','VTIP','TLT','BND','IEF','TIP','VGIT','IYK','USFR']
        # Base directory for strategies
        strategy_base_dir = "Strategies"
        
        # List of strategy names (you would populate this list dynamically)
        self.strategy_names = [
            "CombinedStrategy1",
            "CombinedStrategy2",
            "CombinedStrategy3",
            "CombinedStrategy4",
            "CombinedStrategy5",
            "CombinedStrategy6",
            "CombinedStrategy7",
            "CombinedStrategy8",
            "CombinedStrategy9",
            "CombinedStrategy10",
            # Add other strategy names here...
        ]

        # Get the absolute path of the current file (main.py)
        current_file_path = os.path.abspath(__file__)

        # Get the directory of the current file
        current_directory = os.path.dirname(current_file_path)

        # Construct the path to the Strategies folder
        strategies_directory = os.path.join(current_directory, "Strategies")

        # Dynamically import strategies and create instances
        self.strategies = {}

        # Generate setattr(self, f'HT...') from 1 to 1000
        for i in range(1, 500):
            setattr(self, f'HT{i}', {str(j).zfill(2): 0 for j in range(1, 30)})
            setattr(self, f'HTS{i}', {str(j).zfill(2): [] for j in range(1, 30)})

        for strategy_name in self.strategy_names:
            strategy_module_name = f"Strategies.{strategy_name}.version1"
            strategy_module = importlib.import_module(strategy_module_name)

            # Get the source code of the strategy module
            strategy_module_source = inspect.getsource(strategy_module)

            # Find all occurrences of "class ...Strategy" in the source code
            strategy_class_names = re.findall(r'class\s+(\w+Strategy)', strategy_module_source)

            for strategy_class_name in strategy_class_names:
                # Get the strategy class from the module
                strategy_class = getattr(strategy_module, strategy_class_name)

                # Extract the assigned number from the strategy class name if available
                assigned_numbers = re.findall(r'\d+', strategy_class_name)
                if assigned_numbers:
                    assigned_number = int(assigned_numbers[0])
                else:
                    assigned_number = None

                # Create an instance of the strategy class, passing 'self' as the 'context' argument
                strategy_instance = strategy_class(self)

                # Store the strategy instance in the dictionary
                self.strategies[strategy_class_name] = strategy_instance

        self.PTMaster = 1

        self.days_history = 20
        self.number_to_pick = 8
        self.correlation_number = 0.01 #not used
        self.filter_value = 0.003
        self.buffer_pct = 0.05 #Rebalance
        self.number_of_PT = len(self.strategies) + 100

        self.initializePrevDayVariables(self.number_of_PT, self.days_history)
        self.initializePrevDayReturnVariables(self.number_of_PT, self.days_history)
        self.previously_logged_strategies = set()

        # Fixed strategies and their percentages
        self.fixed_strategies = {
            1: 0.15,  # Strategy 1 with 15%
            2: 0.10,  # Strategy 2 with 10%
            #3: 0.07   # Strategy 3 with 7%
        }

        # Calculate the percentage for each dynamic strategy
        self.dynamic_strategy_percentage = (0.97 - sum(self.fixed_strategies.values())) / self.number_to_pick

        # Initialize PT variables for each strategy
        for i in range(1, self.number_of_PT + 1):
            if i in self.fixed_strategies:
                setattr(self, f'PT{i}', self.fixed_strategies[i] * self.PTMaster)
            else:
                setattr(self, f'PT{i}', self.dynamic_strategy_percentage * self.PTMaster)

        # Assign self.algo to self
        self.algo = self

        # Dictionary to store group definitions
        self.group_definitions = {}

        # Iterate over the strategies
        for strategy_name, strategy in self.strategies.items():
            # Get the source code of the strategy module
            strategy_module_source = inspect.getsource(strategy.__class__)

            # Find all occurrences of "GroupSort(" and "Sort(" in the source code
            group_sort_calls = re.findall(r"GroupSort\(.*?\)", strategy_module_source)

            # Extract the group names from the GroupSort and Sort calls and add them to the dictionary
            for call in group_sort_calls:
                group_names = re.findall(r"'(.*?)'", call)
                for group_name in group_names:
                    if group_name not in self.group_definitions:
                        # Add the group name to the dictionary with a default definition
                        self.group_definitions[group_name] = f"""
            def {group_name}(self):
                # Define the logic for the {group_name} method
                # Return a tuple of equities and weights
                equities = []
                weights = []
                return equities, weights
            """.lstrip()  # Remove leading whitespace

        # Dynamically generate the group methods in the YellowCatStrat instance
        for group_name, group_def in self.group_definitions.items():
            exec(group_def, globals(), locals())
            setattr(self, group_name, types.MethodType(locals()[group_name], self))

        # Load the previous day returns from the ObjectStore
        self.loadPrevDayReturnsFromObjectStore()


        self.Schedule.On(self.DateRules.EveryDay("SPY"),
                self.TimeRules.BeforeMarketClose("SPY",15),
                self.FunctionBeforeMarketClose)

    def initializePrevDayVariables(self, strategy_count, days_history):
        for i in range(1, strategy_count + 1):
            for day in range(1, days_history + 1):
                setattr(self, f'prev_day_HT{i}_{day}', {'data': {str(j).zfill(2): 0 for j in range(1, 30)}, 'timestamp': None})
                setattr(self, f'prev_day_HTS{i}_{day}', {'data': {str(j).zfill(2): [] for j in range(1, 30)}, 'timestamp': None})

    def initializePrevDayReturnVariables(self, strategy_count, days_history):
        for i in range(1, strategy_count + 1):
            for day in range(1, days_history + 1):
                setattr(self, f'prev_day_return{i}_{day}', {'value': 0.0, 'timestamp': None})

    def CumReturnStrategy(self, equity, days):
        history = self.History(equity, days, Resolution.Daily)
        closing_prices = pd.Series([bar.Close for bar in history])
        
        if closing_prices.empty:
            return None  # Return None if there is no historical data
        
        first_price = closing_prices.iloc[-1]  # Use -1 index to get the last price from historical data
        
        current_price = self.Securities[equity].Price
        
        if first_price == 0:
            return None
        else:
            return_val = (current_price / first_price) - 1
            
            # Add safeguard for extreme returns
            if abs(return_val) > 1.5:
                self.Log(f"Warning: Extreme return detected for {equity}. Value: {return_val}. Setting to 0.")
                return_val = 0
            
            return return_val
            
    def OnData(self, data):
        pass

    def FunctionBeforeMarketClose(self):
        # Execute all strategies stored in the dictionary
        for strategy_name, strategy in self.strategies.items():
            strategy.Execute()
        self.updatePrevDayVariables()
        self.CalculateAndLogTopStrategies()
        self.ExecuteTrade()
        self.SetVarToZero()

    def ExecuteTrade(self):
        if not self.is_market_open("SPY"):
            return
        df_list = []

        # Process each top-performing strategy
        for strategy_number in self.FinalTickers:
            HTS_attr = getattr(self, f'HTS{strategy_number}')
            HT_attr = getattr(self, f'HT{strategy_number}')

            group = {
                'HTS': [HTS_attr[i][0] if len(HTS_attr[i]) == 1 else HTS_attr[i] for i in HTS_attr],
                'HT': [HT_attr[i]/1 for i in HT_attr]
            }
            df = pd.DataFrame(group)
            df_list.append(df)

        # Combine all dataframes
        df_combined = pd.concat(df_list)
        df_combined['HTS'] = df_combined['HTS'].astype(str)
        result = df_combined.groupby(['HTS']).sum().reset_index()
        # Dictionary with pairs
        pairs_dict = {
            'SOXL': 'SOXS',
            'TQQQ': 'SQQQ',
            'SPXL': 'SPXU',
            'WEBL': 'WEBS',
            'TECL': 'TECS',
            'UPRO': 'SPXU',
            'QQQ': 'PSQ',
            'SPY': 'SH',
            'TMV': 'TMF',
            'HIBL': 'HIBS',
            'BITO': 'BITI',
            'TSLL': 'TSLQ',
            'AAPU': 'AAPD',
            'ERX': 'ERY',
            'BOIL': 'KOLD',
            'LABU': 'LABD',
            'JNUG': 'JDST',
            'ARKK': 'SARK',
            'IBIT': 'BITI',
            'TNA': 'TZA',
            'UCO': 'SCO',
            'FAS': 'FAZ',
            'NRGU': 'NRGD',
            'DDM': 'SDOW',
            'GUSH': 'DRIP',
            'TYD': 'TYO',
            'UGL': 'GLL',
            'DRN': 'DRV',
            'BITX': 'BITI',
            'MSFU': 'MSFD',
            'GGLL': 'GGLS',
            'SVIX': 'UVXY'
        }
        pairs_dict.update({v: k for k,v in pairs_dict.items()}) #ensure both directions are covered

        # Define leverage multipliers for each ETF
        leverage_multipliers = {
            'SOXL': 3, 'SOXS': 3,
            'TQQQ': 3, 'SQQQ': 3,
            'SPXL': 3, 'SPXU': 3,
            'WEBL': 3, 'WEBS': 3,
            'TECL': 3, 'TECS': 3,
            'UPRO': 3, 'SPXU': 3,
            'QQQ': 1, 'PSQ': 1,
            'SPY': 1, 'SH': 1,
            'TMV': 3, 'TMF': 3,
            'HIBL': 3, 'HIBS': 3,
            'BITO': 1, 'BITI': 1,
            'TSLL': 1, 'TSLQ': 1,
            'AAPU': 2, 'AAPD': 1,
            'ERX': 2, 'ERY': 2,
            'BOIL': 2, 'KOLD': 2,
            'LABU': 3, 'LABD': 3,
            'JNUG': 2, 'JDST': 2,
            'TARK': 1, 'SARK': 1,
            'IBIT': 1, 'BITI': 1,
            'TNA': 3, 'TZA': 3,
            'UCO': 2, 'SCO': 2,
            'FAS': 3, 'FAZ': 3,
            'NRGU': 3, 'NRGD': 3,
            'DDM': 2, 'SDOW': 2,
            'GUSH': 2, 'DRIP': 2,
            'TYD': 3, 'TYO': 3,
            'UGL': 2, 'GLL': 2,
            'DRN': 3, 'DRV': 3,
            'GGLL': 2, 'GGLS': 1,
            'BITX': 2, 'BITI': 1,
            'MSFU': 2, 'MSFD': 1,
            'SVIX': 1, 'UVXY': 2
        }
        # Track selling and buying
        processed_pairs_selling = set()
        processed_pairs_buying = set()
        liquidated_equities = set()
        # Exclude symbols
        
        # dictionary
        symbol_dict = dict(zip(result.iloc[:,0],result.iloc[:,1]))
        # Log output
        output = "*****"

        for symbol, percentage in symbol_dict.items():
            output += "{}: {}% - ".format(symbol, round(percentage*100, 2))

        output = output.rstrip(" - ")
        self.Log(output)
        # Symbols to be transformed
        transform_symbols = ['PSQ','SH','USDU','SPXS','UPRO','QLD','QID','TSLS','ARKK','FNGU','GBTC','IBIT','SDS','NUGT','DUST','SPYU','NVDU','SSO','AAPB','AAPL','MSFT','NVDA','TSLA','AMZN','QQQ','SPY','SVXY','SVOL','VIXM','VXX','VIXY','BITO','BITB','MSFX','GOOG','GOOGL','TSLY','OARK','APLY','NVDY','AMZY','FBY','GOOY','CONY','NFLY','DISO','MSFO','XOMO','JPMO','AMDY','MRNY','MSTY']
        transform_mapping = {'PSQ':'SQQQ','SH':'SPXU','USDU':'UUP','SPXS':'SPXU','UPRO':'SPXL','QLD':'TQQQ','QID':'SQQQ','TSLS':'TSLQ','ARKK':'TARK','FNGU':'SOXL','GBTC':'BITX','IBIT':'BITX','SDS':'SPXU','NUGT':'JNUG','DUST':'JDST','SPYU':'SPXL','NVDU':'NVDL','SSO':'SPXL','AAPB':'AAPU','AAPL':'AAPU','MSFT':'MSFU','NVDA':'NVDL','TSLA':'TSLL','AMZN':'AMZU','QQQ':'TQQQ','SPY':'SPXL','SVXY':'SVIX','SVOL':'SVIX','VIXM':'UVXY','VXX':'UVXY','VIXY':'UVXY','BITO':'BITX','BITB':'BITX','MSFX':'MSFU','GOOG':'GGLL','GOOGL':'GGLL','TSLY':'TSLL','OARK':'TARK','APLY':'AAPU','NVDY':'NVDL','AMZY':'AMZU','FBY':'FBL','GOOY':'GGLL','CONY':'CONL','NFLY':'NFLX','DISO':'DIS','MSFO':'MSFU','XOMO':'XOM','JPMO':'JPM','AMDY':'AMD','MRNY':'MRNA','MSTY':'MSTR'}
        transform_ratios = {'PSQ':3,'SH':3,'USDU':1,'SPXS':1,'UPRO':1,'QLD':1.5,'QID':1.5,'TSLS':1,'ARKK':2,'FNGU':1,'GBTC':2,'IBIT':2,'SDS':1.5,'NUGT':1,'DUST':1,'SPYU':0.75,'NVDU':1,'SSO':1.5,'AAPB':1,'AAPL':2,'MSFT':2,'NVDA':2,'TSLA':2,'AMZN':2,'QQQ':3,'SPY':3,'SVXY':2,'SVOL':4,'VIXM':1.5,'VXX':1.5,'VIXY':1.5,'BITO':2,'BITB':2,'MSFX':1,'GOOG':2,'GOOGL':2,'TSLY':3,'OARK':3,'APLY':3,'NVDY':3,'AMZY':3,'FBY':3,'GOOY':3,'CONY':3,'NFLY':1.5,'DISO':1.5,'MSFO':3,'XOMO':1.5,'JPMO':1.5,'AMDY':1.5,'MRNY':1.5,'MSTY':1.5}
        # Transform symbols
        for symbol in transform_symbols:
            if symbol in symbol_dict:
                new_symbol = transform_mapping[symbol]
                ratio = transform_ratios[symbol]
                new_percentage = symbol_dict[symbol]/ratio 
                # Adjust percentage allocation
                if new_symbol in symbol_dict:
                    new_percentage += symbol_dict[new_symbol]
                symbol_dict[new_symbol] = new_percentage
                # Remove transformed
                symbol_dict.pop(symbol, None)
        # Ensure updated equities list
        updated_equities = set(symbol_dict.keys())
        # Liquidate equities
        for equity in self.equities:
            if equity not in updated_equities and self.Portfolio[equity].HoldStock and equity not in liquidated_equities:
                self.Liquidate(equity)
                liquidated_equities.add(equity)
        # Iterate pairs selling
        for symbol1, symbol2 in pairs_dict.items():
            if symbol1 in symbol_dict and symbol2 in symbol_dict:
                # Get leverage multipliers for both symbols
                mult1 = leverage_multipliers.get(symbol1, 1)
                mult2 = leverage_multipliers.get(symbol2, 1)
                
                # Calculate leveraged positions
                pos1 = symbol_dict[symbol1] * mult1
                pos2 = symbol_dict[symbol2] * mult2
                
                if pos1 >= pos2:
                    offset_value = (pos1 - pos2) / mult1
                    if self.Portfolio[symbol2].HoldStock:
                        self.Liquidate(symbol2)
                    if offset_value > self.filter_value:
                        self.SetHoldings(symbol1, offset_value)
                else:
                    offset_value = (pos2 - pos1) / mult2
                    if self.Portfolio[symbol1].HoldStock:
                        self.Liquidate(symbol1)
                    if offset_value > self.filter_value:
                        self.SetHoldings(symbol2, offset_value)
                        
                # Mark processed selling
                processed_pairs_selling.add(symbol1)
                processed_pairs_selling.add(symbol2)
        # Iterate remaining selling
        for symbol,value in symbol_dict.items():
            if symbol not in processed_pairs_selling and not value == 0 and symbol not in self.exclude_symbols:
                if isinstance(symbol, str) and symbol.startswith("['") and symbol.endswith("']"):
                    symbol_list = eval(symbol)
                    percentage_equity = sum(self.Portfolio[s].HoldingsValue for s in symbol_list) / self.Portfolio.TotalPortfolioValue
                else:
                    percentage_equity = self.Portfolio[symbol].HoldingsValue/self.Portfolio.TotalPortfolioValue
                if value < percentage_equity and abs(value/percentage_equity - 1) > self.buffer_pct:
                    if isinstance(symbol, str) and symbol.startswith("['") and symbol.endswith("']"):
                        symbol_list = eval(symbol)
                        for s in symbol_list:
                            self.SetHoldings(s, value / len(symbol_list))
                    else:
                        self.SetHoldings(symbol,value)
        # Iterate pairs buying
        for symbol1,symbol2 in pairs_dict.items():
            if symbol1 in symbol_dict and symbol2 in symbol_dict and symbol1 not in processed_pairs_buying and symbol2 not in processed_pairs_buying:
                offset_value = abs(symbol_dict[symbol1] - symbol_dict[symbol2])
                if offset_value > self.filter_value:
                    if symbol_dict[symbol1] > symbol_dict[symbol2]:
                        if isinstance(symbol1, list):
                            for s in symbol1:
                                self.SetHoldings(s, offset_value / len(symbol1))
                        else:
                            self.SetHoldings(symbol1,offset_value)
                    else:
                        if isinstance(symbol2, list):
                            for s in symbol2:
                                self.SetHoldings(s, offset_value / len(symbol2))
                        else:
                            self.SetHoldings(symbol2,offset_value)
                else:
                    if isinstance(symbol1, list):
                        for s in symbol1:
                            if self.Portfolio[s].HoldStock:
                                self.Liquidate(s)
                    else:
                        if self.Portfolio[symbol1].HoldStock:
                            self.Liquidate(symbol1)
                    if isinstance(symbol2, list):
                        for s in symbol2:
                            if self.Portfolio[s].HoldStock:
                                self.Liquidate(s)
                    else:
                        if self.Portfolio[symbol2].HoldStock:
                            self.Liquidate(symbol2)
                # Mark as processed buying
                processed_pairs_buying.add(symbol1)
                processed_pairs_buying.add(symbol2)
        # Filter less than 1%
        updated_equities = {symbol for symbol, value in symbol_dict.items() if value >= self.filter_value}
        # Iterate remaining symbol_dict for buying
        for symbol,value in symbol_dict.items():
            if (symbol in updated_equities and 
                symbol not in processed_pairs_buying and 
                symbol not in self.exclude_symbols):
                if isinstance(symbol, str) and symbol.startswith("['") and symbol.endswith("']"):
                    symbol_list = eval(symbol)
                    percentage_equity = sum(self.Portfolio[s].HoldingsValue for s in symbol_list) / self.Portfolio.TotalPortfolioValue
                else:
                    percentage_equity = (self.Portfolio[symbol].HoldingsValue /
                                        self.Portfolio.TotalPortfolioValue)
                if value > percentage_equity and abs(percentage_equity/value - 1) > self.buffer_pct:
                    if isinstance(symbol, str) and symbol.startswith("['") and symbol.endswith("']"):
                        symbol_list = eval(symbol)
                        for s in symbol_list:
                            self.SetHoldings(s, value / len(symbol_list))
                    else:
                        self.SetHoldings(symbol,value)

    def SetVarToZero(self):
        for strategy_number in range(1, self.number_of_PT + 1):
            setattr(self, f'HT{strategy_number}', {str(j).zfill(2): 0 for j in range(1, 30)})
            setattr(self, f'HTS{strategy_number}', {str(j).zfill(2): [] for j in range(1, 30)})

    def CalculateDailyReturn(self, strategy_number, days_since_last_update, day_number):
        current_date = self.Time.date()
        
        # Check if it's the first run after reset
        is_first_run = all(getattr(self, f'prev_day_HT{strategy_number}_{day}')['timestamp'] is None for day in range(1, self.days_history + 1))
        

        if is_first_run:
            # Load data from the file
            file_data = self.loadPrevDayReturnsFromObjectStore()
            
            # Find the most recent data in the file with timestamp < current_date
            most_recent_data = None
            most_recent_timestamp = None
            for key, value in file_data.items():
                if key.startswith(f'HT_{strategy_number}_') and value['timestamp'] is not None:
                    file_timestamp = value['timestamp']
                    if file_timestamp.date() < current_date:
                        if most_recent_timestamp is None or file_timestamp > most_recent_timestamp:
                            most_recent_timestamp = file_timestamp
                            most_recent_data = value['data']
                            most_recent_day = int(key.split('_')[-1])

            if most_recent_data is not None:
                #self.Debug(f"Found most recent data in file: timestamp={most_recent_timestamp}")
                current_HT = most_recent_data
                current_HTS = file_data[f'HTS_{strategy_number}_{most_recent_day}']['data']
                days_since_last_update = (current_date - most_recent_timestamp.date()).days
            else:
                #self.Debug("No suitable data found in file for first run, returning 0")
                return 0
        else:
            #self.Debug("Entering subsequent run logic")
            # Use the data from the previous trading day
            prev_day_data = getattr(self, f'prev_day_HT{strategy_number}_{day_number}')
            
            if prev_day_data['timestamp'] is not None and prev_day_data['timestamp'].date() < current_date:
                #self.Debug(f"Using previous day data: timestamp={prev_day_data['timestamp']}")
                current_HT = prev_day_data['data']
                current_HTS = getattr(self, f'prev_day_HTS{strategy_number}_{day_number}')['data']
            else:
                #self.Debug("No valid previous day data, returning 0")
                return 0

        return_value = self.CalculateReturnFromData(current_HT, current_HTS, days_since_last_update)
        #self.Debug(f"Calculated return value: {return_value}")
        return return_value

    def CalculateReturnFromData(self, HT, HTS, days):
        total_return = 0
        total_weight = 0
        for key in HTS:
            tickers = HTS[key]
            weight = HT[key]
            if tickers and weight != 0:
                if isinstance(tickers, list):
                    tickers_return = sum([self.CumReturnStrategy(ticker, days) if self.CumReturnStrategy(ticker, days) is not None and ticker not in self.exclude_symbols else 0 for ticker in tickers])
                else:
                    if tickers in self.exclude_symbols:
                        tickers_return = 0
                    else:
                        tickers_return = self.CumReturnStrategy(tickers, days) if self.CumReturnStrategy(tickers, days) is not None else 0
                total_return += tickers_return * weight
                total_weight += weight
        # Normalize the return by the total weight
        final_return = total_return / total_weight if total_weight != 0 else 0
        
        # Add safeguard for extreme returns
        if abs(final_return) > 1.5:
            self.Log(f"Warning: Extreme return detected. Value: {final_return}. Setting to 0.")
            final_return = 0
        
        return final_return
    
    def loadPrevDayReturnsFromObjectStore(self):
        if self.ObjectStore.ContainsKey("BlackCatReturns"):
            prev_day_returns_json = self.ObjectStore.Read("BlackCatReturns")
            
            #self.Debug(f"Loaded daily returns: {prev_day_returns_json[:1000]}...")  # Debug print (truncated for brevity)
            
            try:
                prev_day_returns = json.loads(prev_day_returns_json)
            except json.JSONDecodeError:
                #self.Debug("Error decoding JSON from ObjectStore. Returning empty dict.")
                return {}

            processed_returns = {}
            for key, value in prev_day_returns.items():
                if isinstance(value, dict):
                    if 'value' in value and 'timestamp' in value:
                        processed_value = {
                            'value': float(value['value']),
                            'timestamp': datetime.strptime(value['timestamp'], "%Y-%m-%d %H:%M:%S") if value['timestamp'] else None
                        }
                    elif 'data' in value and 'timestamp' in value:
                        processed_value = {
                            'data': value['data'],
                            'timestamp': datetime.strptime(value['timestamp'], "%Y-%m-%d %H:%M:%S") if value['timestamp'] else None
                        }
                    else:
                        #self.Debug(f"Unexpected dict structure for key {key}: {value}")
                        processed_value = {'value': 0, 'timestamp': None}
                elif isinstance(value, (int, float)):
                    processed_value = {'value': float(value), 'timestamp': None}
                else:
                    #self.Debug(f"Unexpected value type for key {key}: {type(value)}")
                    processed_value = {'value': 0, 'timestamp': None}
                
                processed_returns[key] = processed_value

            #self.Debug(f"Processed {len(processed_returns)} items from ObjectStore")
            return processed_returns
        else:
            #self.Debug("No data found in ObjectStore")
            return {}

        
    def updatePrevDayVariables(self):
        # Load existing data from the ObjectStore
        prev_day_returns = self.loadPrevDayReturnsFromObjectStore()

        current_time = self.Time
        today = current_time.date()

        # Shift data for each strategy
        for i in range(1, self.number_of_PT + 1):
            # Find the most recent trading day
            most_recent_trading_day = None
            for day in range(1, self.days_history + 1):
                prev_day_data = getattr(self, f'prev_day_HT{i}_{day}')
                if prev_day_data['timestamp'] is not None and prev_day_data['timestamp'].date() < today:
                    most_recent_trading_day = prev_day_data['timestamp'].date()
                    break

            if most_recent_trading_day is not None:
                days_since_last_update = (today - most_recent_trading_day).days
            else:
                days_since_last_update = 1

            # Shift existing data only if it's a new trading day
            if days_since_last_update >= 1:
                for day in range(self.days_history, 1, -1):
                    setattr(self, f'prev_day_HT{i}_{day}', getattr(self, f'prev_day_HT{i}_{day-1}'))
                    setattr(self, f'prev_day_HTS{i}_{day}', getattr(self, f'prev_day_HTS{i}_{day-1}'))
                    prev_data = prev_day_returns.get(f'ret_{i}_{day-1}', {'value': 0, 'timestamp': None})
                    setattr(self, f'prev_day_return{i}_{day}', prev_data)
                    prev_day_returns[f'ret_{i}_{day}'] = prev_data

                # Calculate the return for day 1 using the latest data before today
                prev_return = self.CalculateDailyReturn(i, days_since_last_update, 1)

                # Set the new return, HT, and HTS for day 1
                new_return_data = {'value': prev_return, 'timestamp': current_time}
                setattr(self, f'prev_day_return{i}_1', new_return_data)
                prev_day_returns[f'ret_{i}_1'] = {'value': prev_return, 'timestamp': current_time.strftime("%Y-%m-%d %H:%M:%S")}
                
                setattr(self, f'prev_day_HT{i}_1', {'data': getattr(self, f'HT{i}', {}).copy(), 'timestamp': current_time})
                setattr(self, f'prev_day_HTS{i}_1', {'data': {k: v.copy() for k, v in getattr(self, f'HTS{i}', {}).items()}, 'timestamp': current_time})

        self.storeDailyReturns()

    def storeDailyReturns(self):
        prev_day_returns = {}
        for i in range(1, self.number_of_PT + 1):
            for day in range(1, self.days_history + 1):
                return_data = getattr(self, f'prev_day_return{i}_{day}')
                prev_day_returns[f'ret_{i}_{day}'] = {
                    'value': return_data['value'],
                    'timestamp': return_data['timestamp'].strftime("%Y-%m-%d %H:%M:%S") if return_data['timestamp'] else None
                }
                
                # Also store HT and HTS data
                ht_data = getattr(self, f'prev_day_HT{i}_{day}')
                hts_data = getattr(self, f'prev_day_HTS{i}_{day}')
                prev_day_returns[f'HT_{i}_{day}'] = {
                    'data': ht_data['data'],
                    'timestamp': ht_data['timestamp'].strftime("%Y-%m-%d %H:%M:%S") if ht_data['timestamp'] else None
                }
                prev_day_returns[f'HTS_{i}_{day}'] = {
                    'data': hts_data['data'],
                    'timestamp': hts_data['timestamp'].strftime("%Y-%m-%d %H:%M:%S") if hts_data['timestamp'] else None
                }

        # Convert the dictionary to JSON string
        prev_day_returns_json = json.dumps(prev_day_returns)

        # Save the JSON string to the Object Store
        self.ObjectStore.Save("BlackCatReturns", prev_day_returns_json)
        
        #self.Debug(f"Stored daily returns: {prev_day_returns_json[:1000]}...")  # Debug print (truncated for brevity)

    def CalculateAndLogTopStrategies(self):
        # Initialize dictionaries to store strategy metrics
        self.strategy_eps = {}
        self.strategy_total_return = {}

        # Get the current risk-free rate
        risk_free_rate = self.risk_free_interest_rate_model.get_interest_rate(self.time)

        # Calculate metrics for each strategy
        for strategy_number in range(1, self.number_of_PT + 1):
            daily_returns = [getattr(self, f'prev_day_return{strategy_number}_{day}', {'value': 0})['value'] for day in range(1, self.days_history+1)]
            total_return = sum(daily_returns)
            eps = self.calculate_eps(daily_returns, risk_free_rate, self.days_history)
            self.strategy_eps[strategy_number] = eps
            self.strategy_total_return[strategy_number] = total_return

        # Exclude fixed strategies from the dynamic selection
        dynamic_strategies = [i for i in range(1, self.number_of_PT + 1) if i not in self.fixed_strategies]

        # Select the best strategies based on EPS
        self.DynamicTickers = sorted(dynamic_strategies, key=lambda x: self.strategy_eps[x], reverse=True)[:self.number_to_pick*2]

        # Apply risk management to limit the number of highly correlated strategies
        self.DynamicTickers = self.apply_risk_management(self.DynamicTickers)

        self.DynamicTickers = list(set(self.DynamicTickers))

        # Combine fixed and dynamic strategies
        self.FinalTickers = list(self.fixed_strategies.keys()) + self.DynamicTickers

        # Create a set of current strategies
        current_strategies = set(self.FinalTickers)

        self.Log("Strategies, Percentages, Holdings, and Metrics:")
        for index, strategy_number in enumerate(self.FinalTickers, start=1):
            if strategy_number in self.fixed_strategies:
                percentage = self.fixed_strategies[strategy_number] * 100
            else:
                percentage = self.dynamic_strategy_percentage * 100

            strategy_name, current_holdings_info = self.get_strategy_name_and_holdings(strategy_number)
            eps = self.strategy_eps[strategy_number]
            total_return = self.strategy_total_return[strategy_number]

            # Calculate total percentage from current holdings
            current_holdings_total = 0
            if current_holdings_info:
                # Split the holdings info and sum up the percentages
                holdings_parts = current_holdings_info.split(', ')
                for part in holdings_parts:
                    try:
                        current_holdings_total += float(part.split(': ')[1].rstrip('%'))
                    except (IndexError, ValueError):
                        self.Log(f"Warning: Could not parse percentage from {part}")
                        continue

            # Get daily returns
            daily_returns = [getattr(self, f'prev_day_return{strategy_number}_{day}', {'value': 0})['value'] 
                            for day in range(1, self.days_history+1)]
            daily_returns_str = ', '.join([f"{day}: {return_val:.4f}" 
                                        for day, return_val in enumerate(daily_returns, start=1)])

            # Get previous day's holdings
            prev_day_HT = getattr(self, f'prev_day_HT{strategy_number}_2')['data']
            prev_day_HTS = getattr(self, f'prev_day_HTS{strategy_number}_2')['data']

            prev_holdings_info = ', '.join([f"{ticker}: {round(prev_day_HT[key] * 100, 2)}%"
                                        for key, tickers in prev_day_HTS.items()
                                        if tickers
                                        for ticker in (tickers if isinstance(tickers, list) else [tickers])])

            # Check if the difference between target and actual percentage is significant
            warning_message = ""
            if current_holdings_total > 0 and abs(current_holdings_total/percentage - 1) > 0.05:
                warning_message = f" [WARNING: Target allocation ({percentage:.2f}%) differs significantly from actual allocation ({current_holdings_total:.2f}%)]"

            self.Log(f"Strategy {strategy_number}: {strategy_name}, Percentage: {round(percentage, 2)}%, "
                    f"Current Holdings: {current_holdings_info}, "
                    f"Previous Holdings: {prev_holdings_info}, "
                    f"EPS: {eps:.4f}, Total Return: {total_return:.4f}, Return Day {daily_returns_str}"
                    f"{warning_message}")

        self.Log(self.FinalTickers)
        self.Log("-" * 50)

    def apply_risk_management(self, strategies):
        def correlation(strategy1, strategy2):
            returns1 = [getattr(self, f'prev_day_return{strategy1}_{day}', {'value': 0})['value'] for day in range(1, self.days_history + 1)]
            returns2 = [getattr(self, f'prev_day_return{strategy2}_{day}', {'value': 0})['value'] for day in range(1, self.days_history + 1)]
            
            if returns1 == returns2:
                return 1.0
            
            if len(set(returns1)) == 1 and len(set(returns2)) == 1:
                return 1.0
            
            mean1, mean2 = sum(returns1) / len(returns1), sum(returns2) / len(returns2)
            diff1, diff2 = [r - mean1 for r in returns1], [r - mean2 for r in returns2]
            
            numerator = sum(d1 * d2 for d1, d2 in zip(diff1, diff2))
            denominator = (sum(d1 ** 2 for d1 in diff1) * sum(d2 ** 2 for d2 in diff2)) ** 0.5
            
            if denominator == 0:
                return 0.0
            
            return numerator / denominator

        MAX_CORRELATION = 0.999999
        INITIAL_SELECTION_SIZE = self.number_to_pick*2
        
        # Ensure we're not trying to select more strategies than available
        initial_selection = strategies[:min(len(strategies), INITIAL_SELECTION_SIZE)]
        #self.Debug(f"Initial selection size: {len(initial_selection)}")
        #self.Debug(f"Initial selection: {initial_selection}")

        if len(initial_selection) < self.number_to_pick:
            self.Debug(f"Warning: Not enough strategies available. Only {len(initial_selection)} strategies found.")
            return initial_selection  # Return all available strategies if we have fewer than required

        correlation_matrix = {(s1, s2): correlation(s1, s2) for s1 in initial_selection for s2 in initial_selection if s1 < s2}

        selected_strategies = []
        remaining_strategies = initial_selection.copy()

        while len(selected_strategies) < self.number_to_pick and remaining_strategies:
            if not selected_strategies:
                strategy = max(remaining_strategies, key=lambda s: self.strategy_eps[s])
                selected_strategies.append(strategy)
                remaining_strategies.remove(strategy)
            else:
                best_strategy = None
                max_eps = float('-inf')

                for strategy in remaining_strategies:
                    correlations = [correlation_matrix.get((min(strategy, s), max(strategy, s)), 0) for s in selected_strategies]
                    max_correlation = max(correlations)

                    if max_correlation < MAX_CORRELATION and self.strategy_eps[strategy] > max_eps:
                        max_eps = self.strategy_eps[strategy]
                        best_strategy = strategy

                if best_strategy:
                    selected_strategies.append(best_strategy)
                    remaining_strategies.remove(best_strategy)
                else:
                    self.Debug("No suitable strategy found below correlation threshold.")
                    break

        # If we don't have enough strategies, log a warning
        if len(selected_strategies) < self.number_to_pick:
            self.Debug(f"Warning: Only able to select {len(selected_strategies)} strategies below the correlation threshold.")

        return selected_strategies

    def get_strategy_name_and_holdings(self, strategy_number):
        for strategy_name, strategy_instance in self.strategies.items():
            strategy_module_source = inspect.getsource(strategy_instance.__class__)
            strategy_numbers = re.findall(r'AH\(self(?:\.algo)?,\s*[\'\w\(\)\s,]+,\s*(\d+)\s*,', strategy_module_source)
            strategy_numbers.extend(re.findall(r'Sort\(self(?:\.algo)?,\s*[\'\w]+,\s*[\'\w\(\)\s,]+,\s*\d+\s*,\s*\w+\s*,\s*\d+\s*,\s*(\d+)', strategy_module_source))
            strategy_numbers.extend(re.findall(r'AHIV\(self(?:\.algo)?,\s*[\'\w\(\)\s,]+,\s*\d+\s*,\s*(\d+)\s*,\s*[\d\.]+\)', strategy_module_source))
            strategy_numbers.extend(re.findall(r'GroupSort\(self(?:\.algo)?,\s*[\'\w]+,\s*[\'\w\(\)\s,]+,\s*\d+\s*,\s*\w+\s*,\s*\d+\s*,\s*(\d+)', strategy_module_source))

            #self.Log(f"Strategy: {strategy_name}, Numbers: {strategy_numbers}")  # Debugging log

            if str(strategy_number) in strategy_numbers:
                HT_attr = getattr(self, f'HT{strategy_number}')
                HTS_attr = getattr(self, f'HTS{strategy_number}')

                holdings_info = ', '.join([f"{ticker}: {round(HT_attr[key] * 100, 2)}%"
                                        for key, tickers in HTS_attr.items()
                                        if tickers
                                        for ticker in (tickers if isinstance(tickers, list) else [tickers])])

                return type(strategy_instance).__name__, holdings_info

        return "", ""

    def calculate_downside_deviation(self, returns):
        negative_returns = [r for r in returns if r < 0]
        return np.std(negative_returns) if negative_returns else 0

    def calculate_msr(self, total_return, risk_free_rate, downside_deviation, T):
        return (total_return - risk_free_rate) / (downside_deviation * np.sqrt(T)) if downside_deviation != 0 else 0

    def calculate_rm(self, total_return, T):
        return (1 + total_return) ** (1 / np.sqrt(T))

    def calculate_eps(self, returns, risk_free_rate, T):
        total_return = sum(returns)
        
        # Calculate downside deviation
        negative_returns = [r for r in returns if r < 0]
        downside_deviation = np.std(negative_returns) if negative_returns else 0
        
        # Calculate upside volatility
        positive_returns = [r for r in returns if r > 0]
        upside_volatility = np.std(positive_returns) if positive_returns else 0
        
        # Calculate MSR and RM
        msr = self.calculate_msr(total_return, risk_free_rate, downside_deviation, T)
        rm = self.calculate_rm(total_return, T)
        
        # Calculate volatility ratio
        volatility_ratio = upside_volatility / (downside_deviation + 0.0001)  # Avoid division by zero
        
        return msr * rm * (1 + volatility_ratio)