Learn Algo Trading with Python | Codes | Youtube Series

Hi @Rajashekhar_Rangappa

I am not clear on the question, please elaborate

as per my question understanding on high level
RSI will be applied on each candles, and this will for done for every candle that we get in chart variable

Hi @babji3
Hourly rate limits is the maximum no of time we can call the api in 1 hour

see : Learn Algo Trading with Python | Codes | Youtube Series - #860 by Tradehull_Imran

1 Like

With updated Dhan_Tradehull_V2 I am getting following error while fetching index intraday_data
not sure how it showing GMRINFRA

(dhan-test) mohan@mhn-acer:~/Dhan-Alog-Trading/examples$ python multi_index_strategy.py
Codebase Version 2.3 : Solved - ATM issues
2024-12-13 09:41:03,940 - multi_index_strategy.py - INFO - Current file name: multi_index_strategy.py
2024-12-13 09:41:03,940 - multi_index_strategy.py - INFO - This is an info message
2024-12-13 09:41:03,940 - root - INFO - Dhan.py  started system
2024-12-13 09:41:03,940 - root - INFO - STARTED THE PROGRAM
-----Logged into Dhan-----
This BOT Is Picking New File From Dhan
Got the instrument file
2024-12-13 09:41:11,165 - root - ERROR - Error processing GMRINFRA: No expiry date found for GMRINFRA
Traceback (most recent call last):
  File "/home/mohan/Dhan-Alog-Trading/examples/Dhan_Tradehull_V2.py", line 127, in correct_step_df_creation
    raise ValueError(f"No expiry date found for {name}")
ValueError: No expiry date found for GMRINFRA
Traceback (most recent call last):
  File "/home/mohan/Dhan-Alog-Trading/examples/multi_index_strategy.py", line 727, in <module>
    main()
  File "/home/mohan/Dhan-Alog-Trading/examples/multi_index_strategy.py", line 721, in main
    trading_symbols = trading_symbols
                      ^^^^^^^^^^^^^^^

@Tradehull_Imran Sir, please ek baar live me check karo na sl modify nahi ho raha he
orderid for modifying ko mene slorderid likha abhi .
tsl.modify_order( slorderid=stoploss_orderid,
modifiedOrderType=‘STOPLIMIT’,
modifiedOrderQuantity=qty,
modifiedLimitPrice=modified_sl - 1,
modifiedStopPrice=modified_sl,
trade_type=‘SELL’

error:
Order Status: PENDING
Order Status: TRADED
Stop Loss Order Placed. Order ID: 9224121368808
Buy Price: 230.5, Current Price: 231.3, Target: 262.5
Buy Price: 230.5, Current Price: 233.25, Target: 262.5
Error during monitoring: Traceback (most recent call last):
File “C:\Users\DELL\AppData\Local\Temp\ipykernel_5068\4082178065.py”, line 72, in
tsl.modify_order(
TypeError: modify_order() got an unexpected keyword argument ‘orderid’

Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: {‘data’: {‘805’: ‘Too many requests. Further requests may result in the user being blocked.’}, ‘status’: ‘failed’}}
Error during monitoring: Traceback (most recent call last):
File “C:\Users\DELL\AppData\Local\Temp\ipykernel_5068\4082178065.py”, line 55, in
current_market_price = current_market_price_dict[trading_symbol]
KeyError: ‘NIFTY 19 DEC 24500 PUT’

Buy Price: 230.5, Current Price: 234.3, Target: 262.5
Buy Price: 230.5, Current Price: 233.65, Target: 262.5
Buy Price: 230.5, Current Price: 232.7, Target: 262.5
Buy Price: 230.5, Current Price: 234.25, Target: 262.5
Buy Price: 230.5, Current Price: 234.2, Target: 262.5
Error during monitoring: Traceback (most recent call last):
File “C:\Users\DELL\AppData\Local\Temp\ipykernel_5068\4082178065.py”, line 72, in
tsl.modify_order(
TypeError: modify_order() got an unexpected keyword argument ‘orderid’

Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: {‘data’: {‘805’: ‘Too many requests. Further requests may result in the user being blocked.’}, ‘status’: ‘failed’}}
Error during monitoring: Traceback (most recent call last):
File “C:\Users\DELL\AppData\Local\Temp\ipykernel_5068\4082178065.py”, line 55, in
current_market_price = current_market_price_dict[trading_symbol]
KeyError: ‘NIFTY 19 DEC 24500 PUT’

Error during monitoring: Traceback (most recent call last):
File “C:\Users\DELL\AppData\Local\Temp\ipykernel_5068\4082178065.py”, line 72, in
tsl.modify_order(
TypeError: modify_order() got an unexpected keyword argument ‘orderid’

Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: {‘data’: {‘805’: ‘Too many requests. Further requests may result in the user being blocked.’}, ‘status’: ‘failed’}}
Error during monitoring: Traceback (most recent call last):
File “C:\Users\DELL\AppData\Local\Temp\ipykernel_5068\4082178065.py”, line 55, in
current_market_price = current_market_price_dict[trading_symbol]
KeyError: ‘NIFTY 19 DEC 24500 PUT’

Buy Price: 230.5, Current Price: 234.3, Target: 262.5
Error during monitoring: Traceback (most recent call last):
File “C:\Users\DELL\AppData\Local\Temp\ipykernel_5068\4082178065.py”, line 72, in
tsl.modify_order(
TypeError: modify_order() got an unexpected keyword argument ‘orderid’

Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: {‘data’: {‘805’: ‘Too many requests. Further requests may result in the user being blocked.’}, ‘status’: ‘failed’}}
Error during monitoring: Traceback (most recent call last):
File “C:\Users\DELL\AppData\Local\Temp\ipykernel_5068\4082178065.py”, line 55, in
current_market_price = current_market_price_dict[trading_symbol]
KeyError: ‘NIFTY 19 DEC 24500 PUT’

Error during monitoring: Traceback (most recent call last):
File “C:\Users\DELL\AppData\Local\Temp\ipykernel_5068\4082178065.py”, line 72, in
tsl.modify_order(
TypeError: modify_order() got an unexpected keyword argument ‘orderid’

Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: {‘data’: {‘805’: ‘Too many requests. Further requests may result in the user being blocked.’}, ‘status’: ‘failed’}}
Error during monitoring: Traceback (most recent call last):
File “C:\Users\DELL\AppData\Local\Temp\ipykernel_5068\4082178065.py”, line 55, in
current_market_price = current_market_price_dict[trading_symbol]
KeyError: 'NIFTY 19 DEC 24500 PUT

import time
import traceback
from Dhan_Tradehull_V2 import Tradehull

# Constants
client_code = "1100578034"
token_id    =
# Initialize Tradehull
tsl = Tradehull(client_code, token_id)
# Example Inputs
trading_symbol      = "NIFTY 19 DEC 24500 PUT"
qty                 = 25
buying_trigger      = 230
buying_limit_price  = buying_trigger + 0.50
stop_loss_offset    = 210
target_offset       = 32
sltrail             = 4
exchange            = "NFO"
ordertype           = "STOPLIMIT"

try:
    # Place buy order
    buy_entry_orderid = tsl.order_placement(
        trading_symbol, exchange, qty, buying_limit_price, buying_trigger, ordertype, 'BUY', 'MIS'
    )
    print(f"Buy Order Placed. Order ID: {buy_entry_orderid}")
    time.sleep(0.2)

    while True:
        try:
            # Fetch order status
            order_status = tsl.get_order_status(orderid=buy_entry_orderid)
            print(f"Order Status: {order_status}")
            time.sleep(1)

            if order_status == "PENDING":
                # Monitor stop-loss offset
                current_market_price_dict = tsl.get_ltp_data(names=[trading_symbol])
                current_market_price = current_market_price_dict[trading_symbol]

                if current_market_price <= stop_loss_offset:
                    print(f"Market price {current_market_price} is below stop-loss offset {stop_loss_offset}. Canceling order.")
                    tsl.Dhan.cancel_order(buy_entry_orderid)
                    print(f"Order {buy_entry_orderid} canceled. Stopping algorithm.")
                    break

            elif order_status == "TRADED":
                buy_price = tsl.get_order_detail(orderid=buy_entry_orderid)['price']
                target_price = buy_price + target_offset
                stop_loss_price = stop_loss_offset
                sl_limit_price = stop_loss_price - 1

                # Place stop-loss order
                stoploss_orderid = tsl.order_placement(
                    trading_symbol, exchange, qty, sl_limit_price, stop_loss_price, 'STOPLIMIT', 'SELL', 'MIS'
                )
                print(f"Stop Loss Order Placed. Order ID: {stoploss_orderid}")
                time.sleep(0.2)

                # Monitor for target price and modify stop-loss dynamically
                while True:
                    try:
                        current_market_price_dict = tsl.get_ltp_data(names=[trading_symbol])
                        current_market_price = current_market_price_dict[trading_symbol]

                        if current_market_price >= target_price:
                            # Cancel stop-loss order
                            tsl.Dhan.cancel_order(stoploss_orderid)
                            print(f"Stop Loss Order {stoploss_orderid} canceled.")

                            # Place sell order
                            sell_entry_orderid = tsl.order_placement(
                                trading_symbol, exchange, qty, 0, 0, 'MARKET', 'SELL', 'MIS'
                            )
                            print(f"Target reached. Selling {trading_symbol} at market price. Sell Order ID: {sell_entry_orderid}")
                            break

                        elif current_market_price >= buy_price + sltrail:
                            # Modify stop-loss order
                            modified_sl = current_market_price - sltrail
                            tsl.modify_order(
                                orderid=stoploss_orderid,
                                modifiedOrderType='STOPLIMIT',
                                modifiedOrderQuantity=qty,
                                modifiedLimitPrice=modified_sl - 1,
                                modifiedStopPrice=modified_sl,
                                trade_type='SELL'
                            )
                            print(f"Stop Loss modified to {modified_sl}")

                        print(f"Buy Price: {buy_price}, Current Price: {current_market_price}, Target: {target_price}")
                        time.sleep(0.2)

                    except Exception as inner_e:
                        print(f"Error during monitoring: {traceback.format_exc()}")

                break

        except Exception as e:
            print(f"Error in fetching order details or status: {traceback.format_exc()}")
            time.sleep(0.2)

except Exception as e:
    print(f"Unexpected error: {traceback.format_exc()}")

Good morning @Tradehull_Imran Sir
please help

Traceback (most recent call last):
  File "c:/Users/VINAY/Desktop/Smart traders/Nifty-Bank nifty code base.py", line 191, in <module>
    if sc1 and sc2 and sc3 and sc4 and sc5 and sc6 and sc7 and sc8 and sc9 and sc10 and sc11 and sc12 and sc13 and sc14 and sc15 and sc16 and sc17:
  File "C:\Users\VINAY\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\generic.py", line 1466, in __nonzero__
    raise ValueError(
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Who all of you are from Mumbai?

chart['ADX'] = talib.ADX(chart['high'], chart['low'], chart['close'], timeperiod=14) #pandas

ADX is returning nan always. not sure what’s wrong :thinking:

one more, how to implement VWAP & VWMA :smile: ? I don’t see ta-lib support for the same :frowning_face:

seems you are accessing the list directly… instead, should be like list[0], list[1]… etc

Hello @Tradehull_Imran
Can we print the data in excel file. If so what is the code to export the data we derived (for example, historical data for nifty) in excel.

topic on VWAMP & VWMA, please

@Rajashekhar_Rangappa , Check this video , for VWAP & VWMA

2 Likes

Thanks a ton @Kishore007. :clap:

Please provide a sections for MacOS Users. I am unable to begin as I don’t have a Windows machine. Thanks for advising.

Please help with Mac OS support for this

Any update on how to install it on MacBook?

1 Like

Hi@ Imran sir,
Please provide an algorithm code that will implement both a Call Buy strategy and a Put Buy strategy simultaneously. When a Call Buy signal is received, the algorithm should execute a call buy, and when a Put Buy signal is received, it should execute a put buy and simultaneously SL, TG, will work and both will work in intraday."

Oh! That’s Great. Congratulations sir.

Oh! That’s a very good idea.