CYCLE_LENGTH := 20;

CYCLE_PEAK := BARSLAST(HHV(HIGH, CYCLE_LENGTH) = HIGH);

CYCLE_TROUGH := BARSLAST(LLV(LOW, CYCLE_LENGTH) = LOW);

IS_TROUGH := CYCLE_TROUGH <= CYCLE_LENGTH AND CYCLE_TROUGH > 0;

IS_PEAK := CYCLE_PEAK <= CYCLE_LENGTH AND CYCLE_PEAK > 0;

SMA_CLOSE := SMA(CLOSE, CYCLE_LENGTH, 1);

BUY_SIGNAL := IS_TROUGH AND CLOSE > SMA_CLOSE;

STICKLINE(BUY_SIGNAL AND TIME <= 0935, LOW, HIGH, 2, 0), COLORGREEN;