Forum Replies Created

Check out all your contributions and responses across the community.

Viewing 15 posts - 16 through 30 (of 54 total)
  • Author
    Posts
  • You just need to assign a static IP on the Dhan broker’s end.

    If you want to know in detail, you can follow this blog:

    Copy Trading with Dhan

    Yes sir, if you are using IIFL, Groww, Kotak, or JainamLite, then the PNL is not showing from the API side for these brokers. Therefore, you will not be able to see the PNL for those brokers.

    Yes, this happens because of candle instability at market open.

    At 9:15 the volatility is very high, candles move very fast, ATR is not stable initially that’s why this happens.

    So, the main fix is using only closed candles, wait for enough candles like 20 candles minimum and use proper ATR smoothing/alignment.

    After first few candles your super trend will be working great.

    Can refer the below code:

    def compute_supertrend(candles, period=10, multiplier=3):
        if len(candles) < period + 2:
            return []
        trs = []
        for i in range(1, len(candles)):
            h = candles[i]["high"]
            l = candles[i]["low"]
            pc = candles[i - 1]["close"]
            tr = max(
                h - l,
                abs(h - pc),
                abs(l - pc)
            )
            trs.append(tr)
        if len(trs) < period:
            return []
        atr_vals = [sum(trs[:period]) / period]
    
        for i in range(period, len(trs)):
            atr = (
                (atr_vals[-1] * (period - 1)) + trs[i]
            ) / period
            atr_vals.append(atr)
        atr = [None] * period + atr_vals
    
        final_upper = [None] * len(candles)
        final_lower = [None] * len(candles)
        supertrend = [None] * len(candles)
        direction = [None] * len(candles)
    
        result = []
        for i in range(len(candles)):
            if atr[i] is None:
                result.append(None)
                continue
            h = candles[i]["high"]
            l = candles[i]["low"]
            c = candles[i]["close"]
            hl2 = (h + l) / 2
            upper_band = hl2 + (multiplier * atr[i])
            lower_band = hl2 - (multiplier * atr[i])
            if final_upper[i - 1] is None:
                final_upper[i] = upper_band
                final_lower[i] = lower_band
            else:
                prev_upper = final_upper[i - 1]
                prev_lower = final_lower[i - 1]
                prev_close = candles[i - 1]["close"]
                final_upper[i] = (
                    upper_band
                    if upper_band < prev_upper or prev_close > prev_upper
                    else prev_upper
                )
                final_lower[i] = (
                    lower_band
                    if lower_band > prev_lower or prev_close < prev_lower
                    else prev_lower
                )
    
            if supertrend[i - 1] is None:
                if c <= final_upper[i]:
                    supertrend[i] = final_upper[i]
                    direction[i] = "SELL"
                else:
                    supertrend[i] = final_lower[i]
                    direction[i] = "BUY"
            elif supertrend[i - 1] == final_upper[i - 1]:
    
                if c <= final_upper[i]:
                    supertrend[i] = final_upper[i]
                    direction[i] = "SELL"
                else:
                    supertrend[i] = final_lower[i]
                    direction[i] = "BUY"
            else:
    
                if c >= final_lower[i]:
                    supertrend[i] = final_lower[i]
                    direction[i] = "BUY"
                else:
                    supertrend[i] = final_upper[i]
                    direction[i] = "SELL"
    
            result.append({
                "supertrend": round(supertrend[i], 2),
                "signal": direction[i]
            })
    
        return result
    
    # Sample candles - reolace thsi with actual live candle data
    candles = [
        {"high": 101, "low": 99, "close": 100},
        {"high": 102, "low": 100, "close": 101},
        {"high": 103, "low": 101, "close": 102},
        {"high": 104, "low": 102, "close": 103},
        {"high": 105, "low": 103, "close": 104},
        {"high": 106, "low": 104, "close": 105},
        {"high": 107, "low": 105, "close": 106},
        {"high": 108, "low": 106, "close": 107},
        {"high": 109, "low": 107, "close": 108},
        {"high": 110, "low": 108, "close": 109},
        {"high": 111, "low": 109, "close": 110},
        {"high": 112, "low": 110, "close": 111},
        {"high": 113, "low": 111, "close": 112},
    ]
    
    result = compute_supertrend(candles)
    
    for row in result:
        print(row)

    Yes, Zerodha’s WebSocket provides the tick-tick data, we will have to aggregate the ticks and convert that into candle of different timeframes whatever you want.

    To do that can refer below code:

    from datetime import datetime
    
    CANDLE_STATE = {}
    
    def build_candle(symbol, tick, timeframe=1):
        ts = tick["timestamp"]
        price = tick["price"]
    
        # Adject timeframe
        minute = (ts.minute // timeframe) * timeframe
        bucket = ts.replace(minute=minute, second=0, microsecond=0)
    
        if symbol not in CANDLE_STATE:
            CANDLE_STATE[symbol] = {}
    
        candles = CANDLE_STATE[symbol]
    
        # Create new candle
        if bucket not in candles:
            candles[bucket] = {
                "open": price,
                "high": price,
                "low": price,
                "close": price
            }
        else:
            c = candles[bucket]
            c["high"] = max(c["high"], price)
            c["low"] = min(c["low"], price)
            c["close"] = price
    
        return candles
    # Replace the tick's static data with the live feed
    ticks = [
        {"timestamp": datetime(2026, 4, 24, 9, 15, 5), "price": 100},
        {"timestamp": datetime(2026, 4, 24, 9, 15, 20), "price": 102},
        {"timestamp": datetime(2026, 4, 24, 9, 15, 40), "price": 99},
        {"timestamp": datetime(2026, 4, 24, 9, 16, 10), "price": 105},
    ]
    
    symbol = "TEST"
    
    for t in ticks:
        candles = build_candle(symbol, t, timeframe=1)
    
    # Print result
    for time, candle in candles.items():
        print(time, candle)

    Yes, this may be the issue of data consistency.

    See may be the problem because of these factors:
    Calculation on incomplete candles
    Missing initial historical data.
    Candle mismatch because of timing
    See we need the both the live and historical data to get the accurate values in EMA and SMA.

    Below is the code that you can refer:

    def calculate_ema(prices, period=5):
        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
    
    # This prices should be have the both live nad historical data
    prices = [100, 102, 101, 105, 107, 110]
    
    ema_values = calculate_ema(prices, period=3)
    print(ema_values)

    Yes, Bollinger Bands are simple, but small mistakes in data or calculation make them mismatch.

    So, if you are using Bb on less candles data then also this happens, usually you should use the 20 period by default if anything else, values won’t match.

    May be another reason is standard deviation – if even small variation in how std dev is calculated → visible difference in bands.

    If you start with less data, then also this happens so if you are testing this in morning at market starts then it also gives inaccurate values, so you also need to feed some historical data + live candle data (after-market start).

    Below is the code you can refer:

    import math
    
    def calculate_bollinger_bands(candles, period=20):
        # Use only closed candles (skip last running candle)
        candles = candles[:-1]
    
        if len(candles) < period:
            return None
    
        closes = [c["close"] for c in candles]
        recent = closes[-period:]
    
        sma = sum(recent) / period
    
        std_dev = math.sqrt(
            sum((price - sma) ** 2 for price in recent) / period
        )
    
        upper = sma + (2 * std_dev)
        lower = sma - (2 * std_dev)
    
        return {
            "upper": round(upper, 2),
            "middle": round(sma, 2),
            "lower": round(lower, 2),
        }
    
    candles = [
        {"close": 100}, {"close": 101}, {"close": 102}, {"close": 103}, {"close": 104},
        {"close": 105}, {"close": 106}, {"close": 107}, {"close": 108}, {"close": 109},
        {"close": 110}, {"close": 111}, {"close": 112}, {"close": 113}, {"close": 114},
        {"close": 115}, {"close": 116}, {"close": 117}, {"close": 118}, {"close": 119},
        {"close": 120}  # last candle (running → will be ignored)
    ]
    
    bb = calculate_bollinger_bands(candles)
    print(bb)

    No, this problem does not come if you use the algodelta because we have “Multi account trading system”.

    So how it’s actually works like the order will not place one by one manually, it happens in parallel and your all orders execute almost simultaneously.

    In our case, the execution latency is around 0.04 seconds. So, this problem never happens in algodelta.

    No, nothing breaks. You’re safe because AlgoDelta is always synced with the broker’s real-time position book.

    So, if you or your client manually closes a trade the Quantity becomes 0 on broker. So, algo detects that instantly and algo won’t try to close it again or no error, no duplicate order nothing. It simply updates and treats the trade as closed.

    More info you can contact our support team.

    Yes, your worrying is right, but in algodelta this problem never happens.

    So, now with our new upgrade we will move to the distributed execution setup, where each child account operates through separate IP routes means each child account have separate IP.

    So now each account handle independently because of this the latency is minimum and execution very fast.

    Not at all! AlgoDelta gives you individual Control within a group.

    So, if you want to remove 2 positions you can simply square off the position for those 2 clients.

    The remaining 3 accounts will stay in the trade and continue to follow your Master account’s next signal. You get the power of a “Group” with the flexibility of “Individual” management.

    Yes, Bollinger Bands are simple, but small mistakes in data or calculation make them mismatch.

    Let break it properly:

    So if you are using Bb on less candles data then also this happnes, usally you should use the 20 period by default if anything else, values won’t match.

    May be the another reason is standard deviation – if even small variation in how std dev is calculated → visible difference in bands.

    If you start with less data, then also this happens so if you are testing this in morning at market starts then it also gives inaccurate values, so you also need to feed some historical data + live candle data (aftermarket start).

    Below is the code you can refer:

    import math
    
    def calculate_bollinger_bands(candles, period=20):
        # Use only closed candles (skip last running candle)
        candles = candles[:-1]
    
        if len(candles) < period:
            return None
    
        closes = [c["close"] for c in candles]
        recent = closes[-period:]
    
        sma = sum(recent) / period
    
        std_dev = math.sqrt(
            sum((price - sma) ** 2 for price in recent) / period
        )
    
        upper = sma + (2 * std_dev)
        lower = sma - (2 * std_dev)
    
        return {
            "upper": round(upper, 2),
            "middle": round(sma, 2),
            "lower": round(lower, 2),
        }
    
    candles = [
        {"close": 100}, {"close": 101}, {"close": 102}, {"close": 103}, {"close": 104},
        {"close": 105}, {"close": 106}, {"close": 107}, {"close": 108}, {"close": 109},
        {"close": 110}, {"close": 111}, {"close": 112}, {"close": 113}, {"close": 114},
        {"close": 115}, {"close": 116}, {"close": 117}, {"close": 118}, {"close": 119},
        {"close": 120}  # last candle (running → will be ignored)
    ]
    
    bb = calculate_bollinger_bands(candles)
    print(bb)

    Yes, in algodelta you don’t need to handle all that manually.

    So, while setting you just select something like ATM, when signal comes system checks live price.

    It finds the nearest strike automatically, picks the current weekly expiry, places the correct CE/PE order.

    So even if your signal is simple, execution is handled fully by our system.

    So you don’t have to worry about strike or expiry selection.

    To fetch the historical data from zerodha’s api below is the sample code that you can refer and modify it accordingg to your requirenment.

    
    def fetch_historical(kite, token, interval="minute", days=7):
        try:
            to_date   = datetime.now()
            from_date = to_date - timedelta(days=days)
            data = kite.historical_data(
                instrument_token=token,
                from_date=from_date,
                to_date=to_date,
                interval=interval
            )
            # FIX: strip timezone from all historical candle dates for consistent comparison
            for c in data:
                if c.get("date") and hasattr(c["date"], "tzinfo") and c["date"].tzinfo:
                    c["date"] = c["date"].replace(tzinfo=None)
            return data
        except Exception as error:
            print(f"Historical fetch failed for token {token}: {error}")
            return []
    
    fetch_historical(kite = kite,token=209604 , interval="minute", days=5)
    

    Since the from_date and to_date are necessary parameters gives the candle data between this 2 dates in format datetime.

    There are the 2 more parametrs we can pass to the kite.historical_data that is IO ( for IO data ) and continuous ( for continuous data ), but they are optional also sees thatin offical documentation https://www.kite.trade/docs/.

    Yes, they are 100% safe. This is because AlgoDelta is a Cloud-Based System.

    Once you add the demat accounts and once you made the groups of the master and child’s the platform handles by it’s on no need to worry after that.

    Yes, see you don’t have to check 10 apps. AlgoDelta provides a Unified Order History with real-time rejection reasons.

    See in our app we have order history if an order fails in a child account, AlgoDelta shows you exactly why (e.g., “Margin Shortfall” or “Invalid Token”) right on your main dashboard.

Viewing 15 posts - 16 through 30 (of 54 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