rocketpoweryul / TradeTronic

1 stars 0 forks source link

MMYT Consolidation Error #3

Closed rocketpoweryul closed 4 months ago

rocketpoweryul commented 4 months ago

Excursion not detected, likely due to peak non-detection.

image

rocketpoweryul commented 4 months ago

Description

Peak not detected at true left hand side candidate, leading to it being ignored by the consolidation detection.

Root Cause

Missed high Peak Detection on Apr 8, 2024. Likely find_swing_high_and_lows function in TATools module, because since there is no arrow, this means it doesn't consider this day a swing high.

As you can see the Apr 8 high is actually also a swing low. In these cases, the code in find_swing_high_and_lows at fault is:

# Check for outside day condition
        if is_swing_high and is_swing_low:
            # Neutralize the signal for outside days
            df.at[df.index[i], 'SwHL'] = 0

However this mutes important peaks. Mitigation will need consider both needs.

rocketpoweryul commented 4 months ago

Corrective action:

There is no reason for the tiebreaker. The fact one bar can be both doesn't affect anything. Therefore the condition is removed.

for i in range(1, len(df) - 1):
        curr_high = df['High'].iloc[i    ]
        next_high = df['High'].iloc[i + 1]
        prev_high = df['High'].iloc[i - 1]
        is_swing_high = curr_high > next_high and curr_high > prev_high

        curr_low = df['Low'].iloc[i    ]
        next_low = df['Low'].iloc[i + 1]
        prev_low = df['Low'].iloc[i - 1]
        is_swing_low = curr_low < next_low and curr_low < prev_low

        # Check for outside day condition
        #if is_swing_high and is_swing_low:
        #    # Neutralize the signal for outside days
        #    df.at[df.index[i], 'SwHL'] = 0
        if is_swing_high:
            df.at[df.index[i], 'SwHL'] = 1
        elif is_swing_low:
            df.at[df.index[i], 'SwHL'] = -1
rocketpoweryul commented 4 months ago

When commented out the consolidation now looks correct: image

Code is now deleted, rearranged to make more sense and better commented.

for i in range(1, len(df) - 1):
        # determine current high and low values
        curr_high = df['High'].iloc[i    ]
        next_high = df['High'].iloc[i + 1]
        prev_high = df['High'].iloc[i - 1]

        curr_low = df['Low'].iloc[i    ]
        next_low = df['Low'].iloc[i + 1]
        prev_low = df['Low'].iloc[i - 1]

        # detect swing high
        is_swing_high = curr_high > next_high and curr_high > prev_high

        # detect swing low
        is_swing_low = curr_low < next_low and curr_low < prev_low

        # add detection results to dataframe
        if is_swing_high:
            df.at[df.index[i], 'SwHL'] = 1
        elif is_swing_low:
            df.at[df.index[i], 'SwHL'] = -1