Forum Replies Created

Check out all your contributions and responses across the community.

Viewing 3 posts - 91 through 93 (of 93 total)
  • Author
    Posts
  • Yes, we have the exactly the same feature that solves your problem even it can square off the trades in group also.

    So, we have the end time feature so for any trade you can set the end time (e.g. 3:00), so even if your Target or Stop Loss hasn’t been hit, AlgoDelta will force-exit the position at exactly 3:00 PM.

    Ans you can also set the start time – it’s like you are tell it to Start looking for entries only after a certain time (like 10:00 AM) to avoid morning volatility.

    Yes, so MACD is depending on many factors to be correct.

    So, to make it super accurate you need the right live candle data along with the sufficient historical data of that script.

    And may be sometimes the calculation mismatch is also there. Things to remember use the closed candles only, preload enough data (e.g. at least 200 candles) and maintain EMA continuity.

    Below is the code you can refer:

    def calculate_ema(prices, period):
        ema = []
        k = 2 / (period + 1)
    
        for i, price in enumerate(prices):
            if i == 0:
                ema.append(price)
            else:
                ema.append(price * k + ema[-1] * (1 - k))
    
        return ema
    
    def calculate_macd(prices):
        ema12 = calculate_ema(prices, 12)
        ema26 = calculate_ema(prices, 26)
    
        macd_line = [e12 - e26 for e12, e26 in zip(ema12, ema26)]
        signal_line = calculate_ema(macd_line, 9)
        histogram = [m - s for m, s in zip(macd_line, signal_line)]
    
        return macd_line, signal_line, histogram
    
    # Sample
    prices = [100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120]
    
    macd, signal, hist = calculate_macd(prices)
    
    print("MACD:", macd[-5:])
    print("Signal:", signal[-5:])
    print("Histogram:", hist[-5:])

    Supertrend depends on <strong data-start=”1096″ data-end=”1103″>ATR, and ATR needs historical candles.

    So, you have to pass both the historical and live data.

    Aggregate the data first and then pass in Supertrend function you will get the accurate value.
    Eg code below:

    def get_supertrend_input(symbol, live_candles):
        # Fetch historical 
        query = "GET HISTORICAL DATA"
        values = [symbol, "minute"]
        historical_candles = fetch_historical_data(query, values)
        # Merge
        all_candles = historical_candles + live_candles
        # Safety check
        if len(all_candles) < 15:  # minimum for ATR(10)
            return []
        return all_candles
    
    def run_supertrend(symbol, live_candles):
        candles = get_supertrend_input(symbol, live_candles)
        if not candles:
            return None
        result = compute_supertrend(candles, period=10, multiplier=3)
        if not result:
            return None
        return result[-1]  # latest signal
Viewing 3 posts - 91 through 93 (of 93 total)
×

Start a Discussion

Get help from the AlgoDelta community.

×

Welcome Back!

Enter your email to sign in or create an account. No passwords needed.

Pending Approval

⚠️

Delete This?

Are you sure you want to delete this? This action is permanent and cannot be undone.

Scroll to Top