Posts

Showing posts from July, 2024

Python Date and time based entry each symbol seperate

  EntryTime = params [ 'EntryTime' ] EntryTime = datetime.strptime( EntryTime , "%H:%M" ).time() EntryDate = params [ 'EntryDate' ] EntryDate = datetime.strptime( EntryDate , "%d-%b-%y" ) current_date = datetime.now().date() current_time = datetime.now().time() if current_date == EntryDate .date() and current_time .strftime( "%H:%M" ) == EntryTime .strftime( "%H:%M" ) \ and params [ 'InitialTrade' ] is None :

Python strike selection based on premium

  def finc_closest_Ce ( price_dict , target_premium ): closest_ce_symbol = None closest_ce_premium = float ( '-inf' ) for price in price_dict : ce_premium = price_dict [ price ][ "CEPREMIUM" ] if ce_premium < target_premium and ce_premium > closest_ce_premium : closest_ce_premium = ce_premium closest_ce_symbol = price_dict [ price ][ "CESymbol" ] return closest_ce_symbol def generatepricedictce_buy ( price , step , distance , BaseSymbol , formatted_date ): start_price = price end_price = price + ( step * distance ) price_list = [ start_price + i * distance for i in range (( end_price - start_price ) // distance + 1 )] print ( "price_list: " , price_list ) price_dict = { price : { "CESymbol" : f" { BaseSymbol }{ formatted_date }{ price } CE" , "CEPREMIUM" : "PRE" } for price in price_list } for price in price_dict : c...

Python stock devloper multiclient integration (login order placement )

client_dict={} def get_client_detail (): global client_dict try : csv_path = 'clientdetails.csv' df = pd.read_csv( csv_path ) df .columns = df .columns.str.strip() for index , row in df .iterrows(): # Create a nested dictionary for each symbol symbol_dict = { 'Title' : row [ 'Title' ] , 'Value' : row [ 'Value' ] , 'QtyMultiplier' : row [ 'QtyMultiplier' ] , 'autotrader' : None , } client_dict[ row [ 'Title' ]] = symbol_dict # print("client_dict: ", client_dict) except Exception as e : print ( "Error happened in fetching symbol" , str ( e )) get_client_detail()   def stock_dev_login_multiclient ( client_dict ): for value , daram in client_dict .items(): Title = daram [ 'Title' ] if isinstance ( Title...

Python run code after particular interval of time (Mimic candles)

  def round_down_to_interval ( dt , interval_minutes ): remainder = dt .minute % interval_minutes minutes_to_current_boundary = remainder rounded_dt = dt - timedelta( minutes = minutes_to_current_boundary ) rounded_dt = rounded_dt .replace( second = 0 , microsecond = 0 ) return rounded_dt def determine_min ( minstr ): min = 0 if minstr == "1" : min = 1 if minstr == "3" : min = 3 if minstr == "5" : min = 5 if minstr == "15" : min = 15 if minstr == "30" : min = 30 return min Function calling if current_time > EntryTime and current_time < ExitTime and datetime.now() >= params [ "runtime" ]: try : time.sleep( int ( 1 )) presentDay = FyresIntegration.fetchOHLC( symbol = formatedsymbol , resolution = params [ 'TimeFrame' ] , atrperiod = params [ 'Atr_Period' ]) previousBar = presentDay .iloc[- ...

Python round to nearest (ATM strike for every instrument )

  def round_to_nearest ( number , nearest ): return round ( number / nearest ) * nearest

Python Option delta calculation

  from py_vollib.black_scholes.implied_volatility import implied_volatility from py_vollib.black_scholes.greeks.analytical import delta # for buy trade itm means 55400,55300....call # for sell trade itm means 55400, 55500...put def getstrikes_put ( ltp , step , strikestep ): result = {} result [ int ( ltp )] = None for i in range ( step ): result [ int ( ltp + strikestep * ( i + 1 ))] = None return result def getstrikes_call ( ltp , step , strikestep ): result = {} result [ int ( ltp )] = None for i in range ( step ): result [ int ( ltp - strikestep * ( i + 1 ))] = None return result def fetchcorrectstrike ( strikelist ): target_value = 0.6 closest_key = None min_difference = float ( 'inf' ) for key , value in strikelist .items(): if value > target_value and value - target_value < min_difference : min_difference = value - target_value closest_key = key return closest_key de...

MT5 all candlestick pack

 //+------------------------------------------------------------------+ //|                                   Compleate Candlestick Pack.mq5 | //|                                  Copyright 2023, MetaQuotes Ltd. | //|                                             https://www.mql5.com | //+------------------------------------------------------------------+ #include <Trade\Trade.mqh> CTrade trade; #property copyright "Copyright 2023, MetaQuotes Ltd." #property link      "https://www.mql5.com" #property version   "1.00" input int MagicNumber=12345; input double lotsize=0.01; input double TargetMultiplier=0.01; input bool invertedHammer=true; input bool Hammer=true; input ...