{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Stock_Screener (GUPPY)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What is a Stock Screener?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A stock screener is a tool to shortlist few companies from a pool of all the listed companies on a stock exchange using filters on the basis of indicator result (RSI,GUPPY,SMA,).shows the result of buy and sell stocks, which one is better option for buy or sell . \n", "The investors specify the filters and the stock screener gives the results accordingly.\n", "Stock screeners are very useful as it can save you a lot of time. \n", "You do not need to go through all the listed companies to shortlist few good ones. You can just apply the basic filter to get the list of few good ones that you want to investigate further.\n", "Overall, the stock screener will help you to find good performing stocks according to your specifications with a single click." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " * Import All libraries required for BOT" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import time\n", "import secrets \n", "import threading\n", "import webbrowser\n", "import numpy as np\n", "import pandas as pd\n", "from pytz import timezone\n", "from math import modf\n", "from pprint import pprint\n", "from datetime import datetime\n", "from time import gmtime, strftime\n", "from kiteconnect import KiteTicker \n", "from kiteconnect import KiteConnect\n", "from IPython.display import clear_output" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# LOGIN TO ZERODHA" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Enter api key & api secret" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Enter Api key and api sectet \n", "api_key='******************* @@enter your api key here@@@**************' \n", "api_secret='**********************@@enter your api key here****************'\n", "\n", "webbrowser.open_new_tab(KiteConnect(api_key,api_secret).login_url())\n", "kite = KiteConnect(api_key=api_key)\n", "data = kite.generate_session(((str(input(\"ENTER full link generated in URL :- \")).split(\"request_token=\")[1]).split(\"&action\"))[0],api_secret)\n", "kite.set_access_token(data[\"access_token\"])\n", "print(\" \\n \")\n", "display(data)\n", "print(\" \\t \\t \\t \\t \\t WELCOME TO BACKTESTING \")\n", "print(\"\\n\" )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Implementation of Coding" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " \n", " \n", " \t \t \t \t Zerodha GUPPY SCREENER for 30 minute Data\n", " \t \t \t \t 30 minute Program Start time is 2019-07-25 _ 14:11:16 \n", "\n", "\n", "\t \t \t \n", " Current Token checking 975873\n", "\n", "\n", " \t \t \t \n", " Current Colour on this token is none\n", "Buy stock found for 30 minute are := []\n", "Sell stocks found for 30 minute are:= [415745, 633601]\n", "SCANNING COMPLETE\n", " \n", " \n", "5 ,15 and 30 are completed ! Results are \n", "\n", " BUY/SELL 5 minute frame\n", " \t \t \t \t 5 minute Program Start time is 2019-07-25 _ 14:06:33 \n", " \t \t \t \t 15 minute Program Start time is 2019-07-25 _ 14:09:54 \n", " \t \t \t \t 30 minute Program Start time is 2019-07-25 _ 14:11:16 \n", " \n", " \n", "\n", " BUY/SELL 5 minute frame\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SYMBOLS_BUYTOKENS_BUYPrice
\n", "
" ], "text/plain": [ "Empty DataFrame\n", "Columns: [SYMBOLS_BUY, TOKENS_BUY, Price]\n", "Index: []" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SYMBOLS_SELLTOKENS_SELLPrice
0BAJFINANCE811533053.15
\n", "
" ], "text/plain": [ " SYMBOLS_SELL TOKENS_SELL Price\n", "0 BAJFINANCE 81153 3053.15" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", " BUY/SELL 15 minute frame\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SYMBOLS_BUYTOKENS_BUYPrice
\n", "
" ], "text/plain": [ "Empty DataFrame\n", "Columns: [SYMBOLS_BUY, TOKENS_BUY, Price]\n", "Index: []" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SYMBOLS_SELLTOKENS_SELLPrice
\n", "
" ], "text/plain": [ "Empty DataFrame\n", "Columns: [SYMBOLS_SELL, TOKENS_SELL, Price]\n", "Index: []" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "\n", " BUY/SELL 30 minute frame\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SYMBOLS_BUYTOKENS_BUYPrice
\n", "
" ], "text/plain": [ "Empty DataFrame\n", "Columns: [SYMBOLS_BUY, TOKENS_BUY, Price]\n", "Index: []" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SYMBOLS_SELLTOKENS_SELLPrice
0IOC415745147.35
1ONGC633601143.70
\n", "
" ], "text/plain": [ " SYMBOLS_SELL TOKENS_SELL Price\n", "0 IOC 415745 147.35\n", "1 ONGC 633601 143.70" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", " \t \t \t \t \t ALL ' BUY | SELL ' - Neglecting Common\n", "\n", "\n", "BUY from ALL set()\n", "SELL From ALL {81153, 415745, 633601}\n", "\n", "\n", " \t \t \t \t \t COMMON ' BUY & SELL ' \n", "\n", "\n", "BUY from ALL set()\n", "SELL From ALL set()\n", "\n", "\n", "BUY sell COMMON STOCK\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
BUY_common_symbolBUY_common_Token
\n", "
" ], "text/plain": [ "Empty DataFrame\n", "Columns: [BUY_common_symbol, BUY_common_Token]\n", "Index: []" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SELL_common_symbolSELL_common_Token
\n", "
" ], "text/plain": [ "Empty DataFrame\n", "Columns: [SELL_common_symbol, SELL_common_Token]\n", "Index: []" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\t \t \t \t \t !! ALL COMPLETED !!\n", " \n", " \n" ] } ], "source": [ "print(\" \\t \\t \\t \\t \\t \\n WELCOME TO SCREENER \")\n", "print(\"\\n\" )\n", "scan=str(input(\"DO you want Scanning ? YES/NO :-\"))\n", "if \"YES\"==scan or \"yes\"==scan:\n", " print(\"SCANNING START\")\n", " #z=list(pd.read_csv(\"list.csv\")[\"Symbol\"])\n", " z=['ADANIPORTS', 'ASIANPAINT', 'AXISBANK', 'BAJAJ-AUTO', 'BAJFINANCE', 'BAJAJFINSV', 'BPCL', 'BHARTIARTL', 'INFRATEL', 'BRITANNIA', 'CIPLA', 'COALINDIA', 'DRREDDY', 'EICHERMOT', 'GAIL', 'GRASIM', 'HCLTECH', 'HDFCBANK', 'HEROMOTOCO', 'HINDALCO', 'HINDUNILVR', 'HDFC', 'ICICIBANK', 'ITC', 'IBULHSGFIN', 'IOC', 'INDUSINDBK', 'INFY', 'JSWSTEEL', 'KOTAKBANK', 'LT', 'M&M', 'MARUTI', 'NTPC', 'ONGC', 'POWERGRID', 'RELIANCE', 'SBIN', 'SUNPHARMA', 'TCS', 'TATAMOTORS', 'TATASTEEL', 'TECHM', 'TITAN', 'UPL', 'ULTRACEMCO', 'VEDL', 'WIPRO', 'YESBANK', 'ZEEL']\n", " eexchange=\"NSE\"\n", " time_frame =\"5minute\" ###\n", " sdate =\"2019-07-02\"\n", " todate =\"2019-10-02\"\n", " tokenall=[]\n", " aa=0\n", " print(\" \\t \\t \\t \\n Getting All tokens for processing BUY SELL \")\n", " while(True):\n", " ttoken=int(pd.DataFrame(kite.ltp(eexchange+\":\"+z[aa])).iloc[-2,0])\n", " tokenall.append(ttoken)\n", " aa=aa+1\n", " if aa==50:\n", " print(\" \\t \\t \\t \\n Complete ! All tokens are fetched from file \")\n", " print(\"\\n\" )\n", " print(tokenall)\n", " break\n", " print(\" Now checking Condition of BUY sell of GUPPY \")\n", " #Variables\n", " eduu=[]\n", " eduu2=[]\n", " eduu3=[]\n", " buy5minute=[]\n", " sell5minute=[]\n", " buy10minute=[]\n", " sell10minute=[]\n", " buy15minute=[]\n", " sell15minute=[]\n", " ##\n", " lst_candle=[]\n", " lst_heikin_nor=[]\n", " lst_heikin=[]\n", " lst_cand=[]\n", " lst_c=[]\n", " anchor=0\n", " countstart=0\n", " #programe start\n", " a=0\n", " BUY_listindicator=[]\n", " SELL_listindicator=[]\n", " sell5minutesym=[]\n", " buy5minutesym=[]\n", " buy10minutesym=[]\n", " sell10minutesym=[]\n", " buy15minutesym=[]\n", " sell15minutesym=[]\n", " #\n", " #price\n", " price5min_buy=[]\n", " price5min_sell=[]\n", " price15min_buy=[]\n", " price15min_sell=[]\n", " price30min_buy=[]\n", " price30min_sell=[]\n", " priceedit=[]\n", " print(a)\n", " def ashi():\n", " global a\n", " global BUY_listindicator\n", " global SELL_listindicator\n", " while(True):\n", " print(\"\\n\" )\n", " print(\"Current Token Number which is processing is\",a)\n", " #km=datetime.now().minute\n", " #ks=datetime.now().second\n", " #if km%1==0 and ks==1:\n", " clear_output(wait=True) \n", " now_utc = datetime.now(timezone('UTC'))\n", " now_asia = now_utc.astimezone(timezone('Asia/Kolkata'))\n", " #now_asia = now_asia.strftime(\"%S \")\n", " now_asia = now_asia.strftime(\"%Y-%m-%d _ %H:%M:%S \")\n", " edu=now_asia\n", " eduu.append(edu)\n", " dff=kite.historical_data(tokenall[a],sdate,todate,time_frame,0)\n", " dfw=pd.DataFrame(dff)[:-1]\n", " df=pd.DataFrame(dfw[['date','open','high','low','close']])\n", " slow_ema = [3,5,7,9,11,13,15,17,19,21,23]\n", " fast_ema = [25,28,31,34,37,40,43,46,49,52,55,58,61,64,67,70,200]\n", " def EMA(df, base, target, period, alpha=False):\n", " con = pd.concat([df[:period][base].rolling(window=period).mean(), df[period:][base]])\n", " if (alpha == True):\n", " # (1 - alpha) * previous_val + alpha * current_val where alpha = 1 / period\n", " df[target] = con.ewm(alpha=1 / period, adjust=False).mean()\n", " else:\n", " # ((current_val - previous_val) * coeff) + previous_val where coeff = 2 / (period + 1)\n", " df[target] = con.ewm(span=period, adjust=False).mean()\n", " df.fillna(0,inplace = True)\n", " # return df\n", " for j in slow_ema:\n", " val = \"ema\"+\"_\"+str(j)\n", " EMA(df,\"close\",val,j)\n", " for k in fast_ema:\n", " val = \"ema\"+\"_\"+str(k)\n", " EMA(df,\"close\",val,k)\n", " def super_guppy(interval,df,anchor=0):\n", " anchor = 0\n", " ShowBreak = True\n", " ShowSwing = True\n", " ShowCon = False\n", " uOCCswing = False\n", " Lookback = 6\n", " emaFilter = False\n", " mult = 0\n", " buybreak = 0\n", " sellbreak = 0\n", " buy_barssince_var = 0\n", " sell_barssince_var = 0\n", " buybreak_barssince_var = 0\n", " sellbreak_barssince_var = 0\n", " barssince_lst = list()\n", " barssince_var = 0\n", " bar_count_var = 0\n", " buy1 = list()\n", " sell1 = list()\n", " buy2 = list()\n", " sell2 = list()\n", " buybreak1 = list()\n", " sellbreak1 = list()\n", " def barssince(b,barssince_var):\n", " barssince_lst = []\n", " barssince_var = 0 \n", " new_var = len(b)\n", " for i in b[::-1]:\n", " if i == 1:\n", " break\n", " barssince_lst.append(i)\n", " barssince_var = len(barssince_lst)\n", " return barssince_var\n", " barssince_lst.clear()\n", " #isIntraday\n", " if interval < 1441 :\n", " if (anchor==0 or interval <= 0 or interval >= anchor or anchor > 1441 ):\n", " mult = 1\n", " else:\n", " if round(anchor/interval) > 1:\n", " mult = round(anchor/interval)\n", " else:\n", " mult = 1\n", " else:\n", " mult = 1\n", " #isIntraday Not\n", " if interval > 1441:\n", " if (anchor==0 or interval <= 0 or interval >= anchor or anchor < 52 ):\n", " mult = mult\n", " else:\n", " if round(anchor/interval) > 1:\n", " mult = round(anchor/interval)\n", " else:\n", " mult = 1\n", " else:\n", " mult = mult\n", " mult = 1\n", " for i in range(len(df)):\n", " emaF1 = df.loc[i,'ema_3']\n", " emaF2 = df.loc[i,'ema_5']\n", " emaF3 = df.loc[i,'ema_7']\n", " emaF4 = df.loc[i,'ema_9']\n", " emaF5 = df.loc[i,'ema_11']\n", " emaF6 = df.loc[i,'ema_13']\n", " emaF7 = df.loc[i,'ema_15']\n", " emaF8 = df.loc[i,'ema_17']\n", " emaF9 = df.loc[i,'ema_19']\n", " emaF10 = df.loc[i,'ema_21']\n", " emaF11 = df.loc[i,'ema_23']\n", " emaS1 = df.loc[i,'ema_25']\n", " emaS2 = df.loc[i,'ema_28']\n", " emaS3 = df.loc[i,'ema_31']\n", " emaS4 = df.loc[i,'ema_34']\n", " emaS5 = df.loc[i,'ema_37']\n", " emaS6 = df.loc[i,'ema_40']\n", " emaS7 = df.loc[i,'ema_43']\n", " emaS8 = df.loc[i,'ema_46']\n", " emaS9 = df.loc[i,'ema_49']\n", " emaS10 = df.loc[i,'ema_52']\n", " emaS11 = df.loc[i,'ema_55']\n", " emaS12 = df.loc[i,'ema_58']\n", " emaS13 = df.loc[i,'ema_61']\n", " emaS14 = df.loc[i,'ema_64']\n", " emaS15 = df.loc[i,'ema_67']\n", " emaS16 = df.loc[i,'ema_70']\n", " ema200 = df.loc[i,'ema_200'] \n", " emafast = (emaF1 + emaF2 + emaF3 + emaF4 + emaF5 + emaF6 + emaF7 + emaF8 + emaF9 + emaF10 + emaF11)/11\n", " emaslow = (emaS1 + emaS2 + emaS3 + emaS4 + emaS5 + emaS6 + emaS7 + emaS8 + emaS9 + emaS10 + emaS11 + emaS12 + emaS13 + emaS14 + emaS15 + emaS16)/16\n", " #Fast EMA Color Rules\n", " colfastL = (emaF1>emaF2 and emaF2>emaF3 and emaF3>emaF4 and emaF4>emaF5 and emaF5>emaF6 and emaF6>emaF7 and emaF7>emaF8 and emaF8>emaF9 and emaF9>emaF10 and emaF10>emaF11)\n", " colfastS = (emaF1emaS2 and emaS2>emaS3 and emaS3>emaS4 and emaS4>emaS5 and emaS5>emaS6 and emaS6>emaS7 and emaS7>emaS8) and (emaS8>emaS9 and emaS9>emaS10 and emaS10>emaS11 and emaS11>emaS12 and emaS12>emaS13 and emaS13>emaS14 and emaS14>emaS15 and emaS15>emaS16)\n", " colslowS = (emaS1 emaslow and not colslowS and colfastL and (not ShowCon or colslowL) and (not emaFilter or emafast>ema200):\n", " if int(buy1[-1]) > 0:\n", " buy = buy1[-1] + 1\n", " else:\n", " buy = 1\n", " else:\n", " buy = 0\n", " buy1.append(buy)\n", " if emafast < emaslow and not colslowL and colfastS and (not ShowCon or colslowS) and (not emaFilter or emafast 0:\n", " sell = sell1[-1] + 1\n", " else:\n", " sell = 1\n", " else:\n", " sell = 0\n", " sell1.append(sell)\n", " #buy\n", " if buy>1 and colfastL and (uOCCswing and ((df.loc[i-1,'close']df.loc[i,'open']))):\n", " buy3 = 1\n", " else:\n", " buy3 = buy\n", " buy2.append(buy3)\n", " #sell \n", " if sell>1 and colfastS and (uOCCswing and ((df.loc[i-1,'close']df.loc[i,'open']))):\n", " sell3 = 1\n", " else:\n", " sell3 = sell\n", " sell2.append(sell3)\n", " #buybreak\n", " if emafast > emaslow and not colslowS and (not emaFilter or emafast>ema200):\n", " if buybreak1[-1] > 0:\n", " buybreak = buybreak1[-1] + 1\n", " else:\n", " buybreak = 1\n", " else:\n", " buybreak = 0\n", " buybreak1.append(buybreak)\n", " if emafast < emaslow and not colslowL and (not emaFilter or emafast 0:\n", " sellbreak = sellbreak1[-1]+1\n", " else:\n", " sellbreak = 1\n", " else:\n", " sellbreak = 0\n", " sellbreak1.append(sellbreak)\n", " #arrow plotting\n", " #buy_arrow\n", " buy_barssince_var = barssince(buy2[:-1],barssince_var)\n", " if (ShowSwing and buy3==1)and buy_barssince_var > 6:\n", " buy_arrow = 1\n", " else:\n", " buy_arrow = 0\n", " #sell arrow\n", " sell_barssince_var = barssince(sell2[:-1],barssince_var)\n", " if ShowSwing and (sell3==1 and sell_barssince_var > 6):\n", " sell_arrow = 1\n", " else:\n", " sell_arrow = 0\n", " #buybreak_arrow\n", " buybreak_barssince_var = barssince(buybreak1[:-1],barssince_var)\n", " sellbreak_barssince_var = barssince(sellbreak1[:-1],barssince_var)\n", "\n", " if ShowBreak and buybreak==1 and (sellbreak_barssince_var>Lookback) and (buybreak_barssince_var>Lookback):\n", " buybreak_arrow = 1\n", " else:\n", " buybreak_arrow = 0\n", " #sellbreak_arrow\n", " if ShowBreak and sellbreak==1 and (buybreak_barssince_var>Lookback) and (sellbreak_barssince_var>Lookback):\n", " sellbreak_arrow = 1\n", " else:\n", " sellbreak_arrow = 0\n", " if buy_arrow==1 and sell_arrow==0 and buybreak_arrow==0 and sellbreak_arrow==0:\n", " arrow_color = 'green'\n", " elif buy_arrow==0 and sell_arrow==1 and buybreak_arrow==0 and sellbreak_arrow==0:\n", " arrow_color = 'red'\n", " elif sell_arrow==0 and (buy_arrow==0 or buy_arrow==1) and buybreak_arrow==1 and sellbreak_arrow==0:\n", " arrow_color = 'aqua'\n", " elif buy_arrow==0 and (sell_arrow==1 or sell_arrow==0) and buybreak_arrow==0 and sellbreak_arrow==1:\n", " arrow_color = 'blue'\n", " else:\n", " arrow_color = 'none'\n", " df.loc[i,'arrow_color'] = arrow_color\n", " df = df[['date','open','high','low','close','arrow_color']]\n", " return df\n", " df=super_guppy(15,df)\n", " gup=df\n", " print(\" \\n \")\n", " print(\" \\t \\t \\t \\t Zerodha GUPPY SCREENER on 5 minute Data \")\n", " print(\" \\t \\t \\t \\t 5 minute Program Start time is \", eduu[0])\n", " print(\"\\t \\t \\t \\n Current Token checking \" , tokenall[a])\n", " print(\"\\n\" )\n", " print(\" \\t \\t \\t \\n Current Colour on this token is \" , gup.iloc[-1,5])\n", " if \"green\" in gup.iloc[-1,5]:\n", " print(\" BUY stock found \")\n", " buy5minute.append((tokenall[a]))\n", " buy5minutesym.append((z[a]))\n", " price5min_buy.append(gup.iloc[-1,2])\n", " if \"red\" in gup.iloc[-1,5]:\n", " print(\" SELL stock found \")\n", " sell5minute.append((tokenall[a]))\n", " sell5minutesym.append((z[a]))\n", " price5min_sell.append(gup.iloc[-1,2])\n", " else:\n", " pass\n", " print(\"Buy stock found for 5 minute are :=\" ,buy5minute)\n", " print(\"Sell stocks found for 5 minute are:=\" ,sell5minute)\n", " a=a+1\n", " if a==len(tokenall):\n", " file=str(buy5minute)\n", " filee=str(sell5minute)\n", " with open(\"tokens.txt\",\"w\") as f:\n", " f.write(file)\n", " f.write(filee)\n", " break\n", " buyframe={\"SYMBOLS_BUY\":buy5minute,\"TOKENS_BUY\":buy5minutesym,\"Price\":price5min_buy}\n", " fivemin=pd.DataFrame(buyframe)\n", " display(fivemin)\n", " buyframee={\"SYMBOLS_SELL\":sell5minutesym,\"TOKENS_SELL\":sell5minute,\"Price\":price5min_sell}\n", " fivemine=pd.DataFrame(buyframee)\n", " display(fivemine)\n", " ashi()\n", " print(\"5 minute data complete! Now getting Data of 15 minutes \")\n", " time_frame =\"15minute\"\n", " a=0\n", " def ashi15():\n", " global a\n", " global BUY_listindicator\n", " global SELL_listindicator\n", " while(True):\n", " print(\"\\n\" )\n", " print(\"Current Token Number which is processing is\",a)\n", " #km=datetime.now().minute\n", " #ks=datetime.now().second\n", " #if km%1==0 and ks==1:\n", " clear_output(wait=True) \n", " now_utc = datetime.now(timezone('UTC'))\n", " now_asia = now_utc.astimezone(timezone('Asia/Kolkata'))\n", " #now_asia = now_asia.strftime(\"%S \")\n", " now_asia = now_asia.strftime(\"%Y-%m-%d _ %H:%M:%S \")\n", " edu2=now_asia\n", " eduu2.append(edu2)\n", " dff=kite.historical_data(tokenall[a],sdate,todate,time_frame,0)\n", " dfw=pd.DataFrame(dff)[:-1]\n", " df=pd.DataFrame(dfw[['date','open','high','low','close']])\n", " slow_ema = [3,5,7,9,11,13,15,17,19,21,23]\n", " fast_ema = [25,28,31,34,37,40,43,46,49,52,55,58,61,64,67,70,200]\n", " def EMA(df, base, target, period, alpha=False):\n", " con = pd.concat([df[:period][base].rolling(window=period).mean(), df[period:][base]])\n", " if (alpha == True):\n", " # (1 - alpha) * previous_val + alpha * current_val where alpha = 1 / period\n", " df[target] = con.ewm(alpha=1 / period, adjust=False).mean()\n", " else:\n", " # ((current_val - previous_val) * coeff) + previous_val where coeff = 2 / (period + 1)\n", " df[target] = con.ewm(span=period, adjust=False).mean()\n", " df.fillna(0,inplace = True)\n", " # return df\n", " for j in slow_ema:\n", " val = \"ema\"+\"_\"+str(j)\n", " EMA(df,\"close\",val,j)\n", " for k in fast_ema:\n", " val = \"ema\"+\"_\"+str(k)\n", " EMA(df,\"close\",val,k)\n", " def super_guppy(interval,df,anchor=0):\n", " anchor = 0\n", " ShowBreak = True\n", " ShowSwing = True\n", " ShowCon = False\n", " uOCCswing = False\n", " Lookback = 6\n", " emaFilter = False\n", " mult = 0\n", " buybreak = 0\n", " sellbreak = 0\n", " buy_barssince_var = 0\n", " sell_barssince_var = 0\n", " buybreak_barssince_var = 0\n", " sellbreak_barssince_var = 0\n", " barssince_lst = list()\n", " barssince_var = 0\n", " bar_count_var = 0\n", " buy1 = list()\n", " sell1 = list()\n", " buy2 = list()\n", " sell2 = list()\n", " buybreak1 = list()\n", " sellbreak1 = list()\n", " def barssince(b,barssince_var):\n", " barssince_lst = []\n", " barssince_var = 0 \n", " new_var = len(b)\n", " for i in b[::-1]:\n", " if i == 1:\n", " break\n", " barssince_lst.append(i)\n", " barssince_var = len(barssince_lst)\n", " return barssince_var\n", " barssince_lst.clear()\n", " #isIntraday\n", " if interval < 1441 :\n", " if (anchor==0 or interval <= 0 or interval >= anchor or anchor > 1441 ):\n", " mult = 1\n", " else:\n", " if round(anchor/interval) > 1:\n", " mult = round(anchor/interval)\n", " else:\n", " mult = 1\n", " else:\n", " mult = 1\n", " #isIntraday Not\n", " if interval > 1441:\n", " if (anchor==0 or interval <= 0 or interval >= anchor or anchor < 52 ):\n", " mult = mult\n", " else:\n", " if round(anchor/interval) > 1:\n", " mult = round(anchor/interval)\n", " else:\n", " mult = 1\n", " else:\n", " mult = mult\n", " mult = 1\n", " for i in range(len(df)):\n", " emaF1 = df.loc[i,'ema_3']\n", " emaF2 = df.loc[i,'ema_5']\n", " emaF3 = df.loc[i,'ema_7']\n", " emaF4 = df.loc[i,'ema_9']\n", " emaF5 = df.loc[i,'ema_11']\n", " emaF6 = df.loc[i,'ema_13']\n", " emaF7 = df.loc[i,'ema_15']\n", " emaF8 = df.loc[i,'ema_17']\n", " emaF9 = df.loc[i,'ema_19']\n", " emaF10 = df.loc[i,'ema_21']\n", " emaF11 = df.loc[i,'ema_23']\n", " emaS1 = df.loc[i,'ema_25']\n", " emaS2 = df.loc[i,'ema_28']\n", " emaS3 = df.loc[i,'ema_31']\n", " emaS4 = df.loc[i,'ema_34']\n", " emaS5 = df.loc[i,'ema_37']\n", " emaS6 = df.loc[i,'ema_40']\n", " emaS7 = df.loc[i,'ema_43']\n", " emaS8 = df.loc[i,'ema_46']\n", " emaS9 = df.loc[i,'ema_49']\n", " emaS10 = df.loc[i,'ema_52']\n", " emaS11 = df.loc[i,'ema_55']\n", " emaS12 = df.loc[i,'ema_58']\n", " emaS13 = df.loc[i,'ema_61']\n", " emaS14 = df.loc[i,'ema_64']\n", " emaS15 = df.loc[i,'ema_67']\n", " emaS16 = df.loc[i,'ema_70']\n", " ema200 = df.loc[i,'ema_200'] \n", " emafast = (emaF1 + emaF2 + emaF3 + emaF4 + emaF5 + emaF6 + emaF7 + emaF8 + emaF9 + emaF10 + emaF11)/11\n", " emaslow = (emaS1 + emaS2 + emaS3 + emaS4 + emaS5 + emaS6 + emaS7 + emaS8 + emaS9 + emaS10 + emaS11 + emaS12 + emaS13 + emaS14 + emaS15 + emaS16)/16\n", " #Fast EMA Color Rules\n", " colfastL = (emaF1>emaF2 and emaF2>emaF3 and emaF3>emaF4 and emaF4>emaF5 and emaF5>emaF6 and emaF6>emaF7 and emaF7>emaF8 and emaF8>emaF9 and emaF9>emaF10 and emaF10>emaF11)\n", " colfastS = (emaF1emaS2 and emaS2>emaS3 and emaS3>emaS4 and emaS4>emaS5 and emaS5>emaS6 and emaS6>emaS7 and emaS7>emaS8) and (emaS8>emaS9 and emaS9>emaS10 and emaS10>emaS11 and emaS11>emaS12 and emaS12>emaS13 and emaS13>emaS14 and emaS14>emaS15 and emaS15>emaS16)\n", " colslowS = (emaS1 emaslow and not colslowS and colfastL and (not ShowCon or colslowL) and (not emaFilter or emafast>ema200):\n", " if int(buy1[-1]) > 0:\n", " buy = buy1[-1] + 1\n", " else:\n", " buy = 1\n", " else:\n", " buy = 0\n", " buy1.append(buy)\n", " if emafast < emaslow and not colslowL and colfastS and (not ShowCon or colslowS) and (not emaFilter or emafast 0:\n", " sell = sell1[-1] + 1\n", " else:\n", " sell = 1\n", " else:\n", " sell = 0\n", " sell1.append(sell)\n", " #buy\n", " if buy>1 and colfastL and (uOCCswing and ((df.loc[i-1,'close']df.loc[i,'open']))):\n", " buy3 = 1\n", " else:\n", " buy3 = buy\n", " buy2.append(buy3)\n", " #sell \n", " if sell>1 and colfastS and (uOCCswing and ((df.loc[i-1,'close']df.loc[i,'open']))):\n", " sell3 = 1\n", " else:\n", " sell3 = sell\n", " sell2.append(sell3)\n", " #buybreak\n", " if emafast > emaslow and not colslowS and (not emaFilter or emafast>ema200):\n", " if buybreak1[-1] > 0:\n", " buybreak = buybreak1[-1] + 1\n", " else:\n", " buybreak = 1\n", " else:\n", " buybreak = 0\n", " buybreak1.append(buybreak)\n", " if emafast < emaslow and not colslowL and (not emaFilter or emafast 0:\n", " sellbreak = sellbreak1[-1]+1\n", " else:\n", " sellbreak = 1\n", " else:\n", " sellbreak = 0\n", " sellbreak1.append(sellbreak)\n", " #arrow plotting\n", " #buy_arrow\n", " buy_barssince_var = barssince(buy2[:-1],barssince_var)\n", " if (ShowSwing and buy3==1)and buy_barssince_var > 6:\n", " buy_arrow = 1\n", " else:\n", " buy_arrow = 0\n", " #sell arrow\n", " sell_barssince_var = barssince(sell2[:-1],barssince_var)\n", " if ShowSwing and (sell3==1 and sell_barssince_var > 6):\n", " sell_arrow = 1\n", " else:\n", " sell_arrow = 0\n", " #buybreak_arrow\n", " buybreak_barssince_var = barssince(buybreak1[:-1],barssince_var)\n", " sellbreak_barssince_var = barssince(sellbreak1[:-1],barssince_var)\n", "\n", " if ShowBreak and buybreak==1 and (sellbreak_barssince_var>Lookback) and (buybreak_barssince_var>Lookback):\n", " buybreak_arrow = 1\n", " else:\n", " buybreak_arrow = 0\n", " #sellbreak_arrow\n", " if ShowBreak and sellbreak==1 and (buybreak_barssince_var>Lookback) and (sellbreak_barssince_var>Lookback):\n", " sellbreak_arrow = 1\n", " else:\n", " sellbreak_arrow = 0\n", " if buy_arrow==1 and sell_arrow==0 and buybreak_arrow==0 and sellbreak_arrow==0:\n", " arrow_color = 'green'\n", " elif buy_arrow==0 and sell_arrow==1 and buybreak_arrow==0 and sellbreak_arrow==0:\n", " arrow_color = 'red'\n", " elif sell_arrow==0 and (buy_arrow==0 or buy_arrow==1) and buybreak_arrow==1 and sellbreak_arrow==0:\n", " arrow_color = 'aqua'\n", " elif buy_arrow==0 and (sell_arrow==1 or sell_arrow==0) and buybreak_arrow==0 and sellbreak_arrow==1:\n", " arrow_color = 'blue'\n", " else:\n", " arrow_color = 'none'\n", " df.loc[i,'arrow_color'] = arrow_color\n", " df = df[['date','open','high','low','close','arrow_color']]\n", " return df\n", " df=super_guppy(15,df)\n", " gup=df\n", " print(\" \\n \")\n", " print(\" \\t \\t \\t \\t Zerodha GUPPY SCREENER on 15 minute data \")\n", " print(\" \\t \\t \\t \\t 15 minute Program Start time is \", eduu2[0])\n", " print(\"\\t \\t \\t \\n Current Token checking \" , tokenall[a])\n", " print(\"\\n\" )\n", " print(\" \\t \\t \\t \\n Current Colour on this token is \" , gup.iloc[-1,5])\n", " if \"green\" in gup.iloc[-1,5]:\n", " print(\"Buy stock found \")\n", " buy10minute.append((tokenall[a]))\n", " buy10minutesym.append((z[a]))\n", " price15min_buy.append(gup.iloc[-1,2])\n", " if \"red\" in gup.iloc[-1,5]:\n", " print(\" Sell Stock found \")\n", " sell10minute.append((tokenall[a]))\n", " sell10minutesym.append((z[a]))\n", " priceedit.append(gup.iloc[-1,2])\n", " else:\n", " pass\n", " print(\"Buy stock found for 15 minute are :=\" ,buy10minute)\n", " print(\"Sell stocks found for 15 minute are:=\" ,sell10minute)\n", " a=a+1\n", " if a==len(tokenall):\n", " file=str(buy5minute)\n", " filee=str(sell5minute)\n", " file2=str(buy10minute)\n", " filee2=str(sell10minute)\n", " with open(\"tokens.txt\",\"w\") as f:\n", " f.write(file)\n", " f.write(filee)\n", " f.write(file2)\n", " f.write(filee2)\n", " break\n", " \n", " buyframe15={\"SYMBOLS_BUY\":buy10minutesym,\"TOKENS_BUY\":buy10minute,\"Price\":price15min_buy}\n", " fifteenemin=pd.DataFrame(buyframe15)\n", " display(fifteenemin)\n", " buyframe156={\"SYMBOLS_SELL\":sell10minutesym,\"TOKENS_SELL\":sell10minute,\"Price\":priceedit}\n", " fifteenemin6=pd.DataFrame(buyframe156)\n", " display(fifteenemin6)\n", "\n", " ashi15()\n", " print(\"5 and 15 minute data complete now getting Data of 30 minutes of minute frame\")\n", " time_frame =\"30minute\"\n", " a=0\n", " def ashi30():\n", " global a\n", " global BUY_listindicator\n", " global SELL_listindicator\n", " while(True):\n", " print(\"\\n\" )\n", " print(\"Current Token Number which is processing is\",a)\n", " #km=datetime.now().minute\n", " #ks=datetime.now().second\n", " #if km%1==0 and ks==1:\n", " clear_output(wait=True) \n", " now_utc = datetime.now(timezone('UTC'))\n", " now_asia = now_utc.astimezone(timezone('Asia/Kolkata'))\n", " #now_asia = now_asia.strftime(\"%S \")\n", " now_asia = now_asia.strftime(\"%Y-%m-%d _ %H:%M:%S \")\n", " edu3=now_asia\n", " eduu3.append(edu3)\n", " dff=kite.historical_data(tokenall[a],sdate,todate,time_frame,0)\n", " dfw=pd.DataFrame(dff)[:-1]\n", " df=pd.DataFrame(dfw[['date','open','high','low','close']])\n", " slow_ema = [3,5,7,9,11,13,15,17,19,21,23]\n", " fast_ema = [25,28,31,34,37,40,43,46,49,52,55,58,61,64,67,70,200]\n", " def EMA(df, base, target, period, alpha=False):\n", " con = pd.concat([df[:period][base].rolling(window=period).mean(), df[period:][base]])\n", " if (alpha == True):\n", " # (1 - alpha) * previous_val + alpha * current_val where alpha = 1 / period\n", " df[target] = con.ewm(alpha=1 / period, adjust=False).mean()\n", " else:\n", " # ((current_val - previous_val) * coeff) + previous_val where coeff = 2 / (period + 1)\n", " df[target] = con.ewm(span=period, adjust=False).mean()\n", " df.fillna(0,inplace = True)\n", " # return df\n", " for j in slow_ema:\n", " val = \"ema\"+\"_\"+str(j)\n", " EMA(df,\"close\",val,j)\n", " for k in fast_ema:\n", " val = \"ema\"+\"_\"+str(k)\n", " EMA(df,\"close\",val,k)\n", " def super_guppy(interval,df,anchor=0):\n", " anchor = 0\n", " ShowBreak = True\n", " ShowSwing = True\n", " ShowCon = False\n", " uOCCswing = False\n", " Lookback = 6\n", " emaFilter = False\n", " mult = 0\n", " buybreak = 0\n", " sellbreak = 0\n", " buy_barssince_var = 0\n", " sell_barssince_var = 0\n", " buybreak_barssince_var = 0\n", " sellbreak_barssince_var = 0\n", " barssince_lst = list()\n", " barssince_var = 0\n", " bar_count_var = 0\n", " buy1 = list()\n", " sell1 = list()\n", " buy2 = list()\n", " sell2 = list()\n", " buybreak1 = list()\n", " sellbreak1 = list()\n", " def barssince(b,barssince_var):\n", " barssince_lst = []\n", " barssince_var = 0 \n", " new_var = len(b)\n", " for i in b[::-1]:\n", " if i == 1:\n", " break\n", " barssince_lst.append(i)\n", " barssince_var = len(barssince_lst)\n", " return barssince_var\n", " barssince_lst.clear()\n", " #isIntraday\n", " if interval < 1441 :\n", " if (anchor==0 or interval <= 0 or interval >= anchor or anchor > 1441 ):\n", " mult = 1\n", " else:\n", " if round(anchor/interval) > 1:\n", " mult = round(anchor/interval)\n", " else:\n", " mult = 1\n", " else:\n", " mult = 1\n", " #isIntraday Not\n", " if interval > 1441:\n", " if (anchor==0 or interval <= 0 or interval >= anchor or anchor < 52 ):\n", " mult = mult\n", " else:\n", " if round(anchor/interval) > 1:\n", " mult = round(anchor/interval)\n", " else:\n", " mult = 1\n", " else:\n", " mult = mult\n", " mult = 1\n", " for i in range(len(df)):\n", " emaF1 = df.loc[i,'ema_3']\n", " emaF2 = df.loc[i,'ema_5']\n", " emaF3 = df.loc[i,'ema_7']\n", " emaF4 = df.loc[i,'ema_9']\n", " emaF5 = df.loc[i,'ema_11']\n", " emaF6 = df.loc[i,'ema_13']\n", " emaF7 = df.loc[i,'ema_15']\n", " emaF8 = df.loc[i,'ema_17']\n", " emaF9 = df.loc[i,'ema_19']\n", " emaF10 = df.loc[i,'ema_21']\n", " emaF11 = df.loc[i,'ema_23']\n", " emaS1 = df.loc[i,'ema_25']\n", " emaS2 = df.loc[i,'ema_28']\n", " emaS3 = df.loc[i,'ema_31']\n", " emaS4 = df.loc[i,'ema_34']\n", " emaS5 = df.loc[i,'ema_37']\n", " emaS6 = df.loc[i,'ema_40']\n", " emaS7 = df.loc[i,'ema_43']\n", " emaS8 = df.loc[i,'ema_46']\n", " emaS9 = df.loc[i,'ema_49']\n", " emaS10 = df.loc[i,'ema_52']\n", " emaS11 = df.loc[i,'ema_55']\n", " emaS12 = df.loc[i,'ema_58']\n", " emaS13 = df.loc[i,'ema_61']\n", " emaS14 = df.loc[i,'ema_64']\n", " emaS15 = df.loc[i,'ema_67']\n", " emaS16 = df.loc[i,'ema_70']\n", " ema200 = df.loc[i,'ema_200'] \n", " emafast = (emaF1 + emaF2 + emaF3 + emaF4 + emaF5 + emaF6 + emaF7 + emaF8 + emaF9 + emaF10 + emaF11)/11\n", " emaslow = (emaS1 + emaS2 + emaS3 + emaS4 + emaS5 + emaS6 + emaS7 + emaS8 + emaS9 + emaS10 + emaS11 + emaS12 + emaS13 + emaS14 + emaS15 + emaS16)/16\n", " #Fast EMA Color Rules\n", " colfastL = (emaF1>emaF2 and emaF2>emaF3 and emaF3>emaF4 and emaF4>emaF5 and emaF5>emaF6 and emaF6>emaF7 and emaF7>emaF8 and emaF8>emaF9 and emaF9>emaF10 and emaF10>emaF11)\n", " colfastS = (emaF1emaS2 and emaS2>emaS3 and emaS3>emaS4 and emaS4>emaS5 and emaS5>emaS6 and emaS6>emaS7 and emaS7>emaS8) and (emaS8>emaS9 and emaS9>emaS10 and emaS10>emaS11 and emaS11>emaS12 and emaS12>emaS13 and emaS13>emaS14 and emaS14>emaS15 and emaS15>emaS16)\n", " colslowS = (emaS1 emaslow and not colslowS and colfastL and (not ShowCon or colslowL) and (not emaFilter or emafast>ema200):\n", " if int(buy1[-1]) > 0:\n", " buy = buy1[-1] + 1\n", " else:\n", " buy = 1\n", " else:\n", " buy = 0\n", " buy1.append(buy)\n", " if emafast < emaslow and not colslowL and colfastS and (not ShowCon or colslowS) and (not emaFilter or emafast 0:\n", " sell = sell1[-1] + 1\n", " else:\n", " sell = 1\n", " else:\n", " sell = 0\n", " sell1.append(sell)\n", " #buy\n", " if buy>1 and colfastL and (uOCCswing and ((df.loc[i-1,'close']df.loc[i,'open']))):\n", " buy3 = 1\n", " else:\n", " buy3 = buy\n", " buy2.append(buy3)\n", " #sell \n", " if sell>1 and colfastS and (uOCCswing and ((df.loc[i-1,'close']df.loc[i,'open']))):\n", " sell3 = 1\n", " else:\n", " sell3 = sell\n", " sell2.append(sell3)\n", " #buybreak\n", " if emafast > emaslow and not colslowS and (not emaFilter or emafast>ema200):\n", " if buybreak1[-1] > 0:\n", " buybreak = buybreak1[-1] + 1\n", " else:\n", " buybreak = 1\n", " else:\n", " buybreak = 0\n", " buybreak1.append(buybreak)\n", " if emafast < emaslow and not colslowL and (not emaFilter or emafast 0:\n", " sellbreak = sellbreak1[-1]+1\n", " else:\n", " sellbreak = 1\n", " else:\n", " sellbreak = 0\n", " sellbreak1.append(sellbreak)\n", " #arrow plotting\n", " #buy_arrow\n", " buy_barssince_var = barssince(buy2[:-1],barssince_var)\n", " if (ShowSwing and buy3==1)and buy_barssince_var > 6:\n", " buy_arrow = 1\n", " else:\n", " buy_arrow = 0\n", " #sell arrow\n", " sell_barssince_var = barssince(sell2[:-1],barssince_var)\n", " if ShowSwing and (sell3==1 and sell_barssince_var > 6):\n", " sell_arrow = 1\n", " else:\n", " sell_arrow = 0\n", " #buybreak_arrow\n", " buybreak_barssince_var = barssince(buybreak1[:-1],barssince_var)\n", " sellbreak_barssince_var = barssince(sellbreak1[:-1],barssince_var)\n", "\n", " if ShowBreak and buybreak==1 and (sellbreak_barssince_var>Lookback) and (buybreak_barssince_var>Lookback):\n", " buybreak_arrow = 1\n", " else:\n", " buybreak_arrow = 0\n", " #sellbreak_arrow\n", " if ShowBreak and sellbreak==1 and (buybreak_barssince_var>Lookback) and (sellbreak_barssince_var>Lookback):\n", " sellbreak_arrow = 1\n", " else:\n", " sellbreak_arrow = 0\n", " if buy_arrow==1 and sell_arrow==0 and buybreak_arrow==0 and sellbreak_arrow==0:\n", " arrow_color = 'green'\n", " elif buy_arrow==0 and sell_arrow==1 and buybreak_arrow==0 and sellbreak_arrow==0:\n", " arrow_color = 'red'\n", " elif sell_arrow==0 and (buy_arrow==0 or buy_arrow==1) and buybreak_arrow==1 and sellbreak_arrow==0:\n", " arrow_color = 'aqua'\n", " elif buy_arrow==0 and (sell_arrow==1 or sell_arrow==0) and buybreak_arrow==0 and sellbreak_arrow==1:\n", " arrow_color = 'blue'\n", " else:\n", " arrow_color = 'none'\n", " df.loc[i,'arrow_color'] = arrow_color\n", " df = df[['date','open','high','low','close','arrow_color']]\n", " return df\n", " df=super_guppy(15,df)\n", " gup=df\n", " print(\" \\n \")\n", " print(\" \\t \\t \\t \\t Zerodha GUPPY SCREENER for 30 minute Data\")\n", " print(\" \\t \\t \\t \\t 30 minute Program Start time is \", eduu3[0])\n", " print(\"\\n\" )\n", " print(\"\\t \\t \\t \\n Current Token checking \" , tokenall[a])\n", " print(\"\\n\" )\n", " print(\" \\t \\t \\t \\n Current Colour on this token is \" , gup.iloc[-1,5])\n", " if \"green\" in gup.iloc[-1,5]:\n", " print(\"BUY stock found \")\n", " buy15minute.append((tokenall[a]))\n", " buy15minutesym.append((z[a]))\n", " price30min_buy.append(gup.iloc[-1,2])\n", " if \"red\" in gup.iloc[-1,5]:\n", " print(\" SELL Stock found \")\n", " sell15minute.append((tokenall[a]))\n", " sell15minutesym.append((z[a]))\n", " price30min_sell.append(gup.iloc[-1,2])\n", " else:\n", " pass\n", " print(\"Buy stock found for 30 minute are :=\" ,buy15minute)\n", " print(\"Sell stocks found for 30 minute are:=\" ,sell15minute)\n", " a=a+1\n", " if a==len(tokenall):\n", " file=str(buy5minute)\n", " filee=str(sell5minute)\n", " file2=str(buy10minute)\n", " filee2=str(sell10minute)\n", " file3=str(buy15minute)\n", " filee3=str(sell15minute)\n", " with open(\"tokens\",\"w\") as f:\n", " f.write(file)\n", " f.write(filee)\n", " f.write(file2)\n", " f.write(filee2)\n", " f.write(file3)\n", " f.write(filee3)\n", " print(\"SCANNING COMPLETE\")\n", " break\n", " buyframe30={\"SYMBOLS_BUY\":buy15minutesym,\"TOKENS_BUY\":buy15minute,\"Price\":price30min_buy}\n", " thirtymin=pd.DataFrame(buyframe30)\n", " display(thirtymin)\n", " buyframe303={\"SYMBOLS_SELL\":sell15minutesym,\"TOKENS_SELL\":sell15minute,\"Price\":price30min_sell}\n", " thirtymin3=pd.DataFrame(buyframe303)\n", " display(thirtymin3)\n", " ashi30()\n", " print(\" \\n \")\n", " print(\"5 ,15 and 30 are completed ! Results are \")\n", " print(\"\\n BUY/SELL 5 minute frame\" )\n", " print(\" \\t \\t \\t \\t 5 minute Program Start time is \", eduu[0])\n", " print(\" \\n \")\n", " print(\"\\n BUY/SELL 5 minute frame\" )\n", " buyframe={\"SYMBOLS_BUY\":buy5minute,\"TOKENS_BUY\":buy5minutesym,\"Price\":price5min_buy}\n", " fivemin=pd.DataFrame(buyframe)\n", " display(fivemin)\n", " buyframee={\"SYMBOLS_SELL\":sell5minutesym,\"TOKENS_SELL\":sell5minute,\"Price\":price5min_sell}\n", " fivemine=pd.DataFrame(buyframee)\n", " display(fivemine)\n", " print(\"\\n BUY/SELL 15 minute frame\" )\n", " print(\" \\t \\t \\t \\t 15 minute Program Start time is \", eduu2[0])\n", " buyframe15={\"SYMBOLS_BUY\":buy10minutesym,\"TOKENS_BUY\":buy10minute,\"Price\":price15min_buy}\n", " fifteenemin=pd.DataFrame(buyframe15)\n", " display(fifteenemin)\n", " buyframe156={\"SYMBOLS_SELL\":sell10minutesym,\"TOKENS_SELL\":sell10minute,\"Price\":priceedit}\n", " fifteenemin6=pd.DataFrame(buyframe156)\n", " display(fifteenemin6)\n", " print(\"\\n\" )\n", " print(\"\\n BUY/SELL 30 minute frame\" )\n", " print(\" \\t \\t \\t \\t 30 minute Program Start time is \", eduu3[0])\n", " buyframe30={\"SYMBOLS_BUY\":buy15minutesym,\"TOKENS_BUY\":buy15minute,\"Price\":price30min_buy}\n", " thirtymin=pd.DataFrame(buyframe30)\n", " display(thirtymin)\n", " buyframe303={\"SYMBOLS_SELL\":sell15minutesym,\"TOKENS_SELL\":sell15minute,\"Price\":price30min_sell}\n", " thirtymin3=pd.DataFrame(buyframe303)\n", " display(thirtymin3)\n", " print(\"\\n\")\n", " # buy\n", " k=set(buy5minute)\n", " l=set(buy10minute)\n", " m=set(buy15minute)\n", " # sell\n", " n=set(sell5minute)\n", " s=set(sell10minute)\n", " p=set(sell15minute)\n", " buya=n|s|p\n", " sellb=k|l|m\n", " print(\" \\t \\t \\t \\t \\t ALL ' BUY | SELL ' - Neglecting Common\")\n", " print(\"\\n\")\n", " print(\"BUY from ALL \",sellb)\n", " print(\"SELL From ALL \",buya)\n", " print(\"\\n\")\n", " print(\" \\t \\t \\t \\t \\t COMMON ' BUY & SELL ' \")\n", " print(\"\\n\")\n", " buycommmon=n&s&p\n", " sellcommon=k&l&m\n", " print(\"BUY from ALL \",buycommmon)\n", " print(\"SELL From ALL \",sellcommon)\n", " print(\"\\n\")\n", " # finding coomon name \n", " comm_buy=[]\n", " comm_buy_sym=[]\n", " comm_sell=[]\n", " comm_sell_sym=[]\n", " ee=0\n", " buy_commmon=list(buycommmon)\n", " sell_common=list(sellcommon)\n", " if buy_commmon:\n", " print(\"BUY COMMON FOUND\")\n", " while (True):\n", " df=pd.DataFrame(kite.instruments(\"NSE\"))[[\"instrument_token\",\"tradingsymbol\",\"name\"]]\n", " zall=df[df[\"instrument_token\"]==buy_commmon[ee]]\n", " comm_buy.append(zall.iloc[-1,0])\n", " comm_buy_sym.append(zall.iloc[-1,1])\n", " ee=ee+1\n", " if ee==len(buy_commmon):\n", " break\n", " if sell_common:\n", " print(\"BUY COMMON FOUND\")\n", " while (True):\n", " df=pd.DataFrame(kite.instruments(\"NSE\"))[[\"instrument_token\",\"tradingsymbol\",\"name\"]]\n", " zall=df[df[\"instrument_token\"]==sell_common[ee]]\n", " comm_sell.append(zall.iloc[-1,0])\n", " comm_sell_sym.append(zall.iloc[-1,1])\n", " ee=ee+1\n", " if ee==len(sell_common):\n", " break\n", " print(\"BUY sell COMMON STOCK\")\n", " dic_comm_buy={\"BUY_common_symbol\":comm_buy_sym, \"BUY_common_Token\":comm_buy}\n", " dic_comm_buy_disp=pd.DataFrame(dic_comm_buy)\n", " dic_comm_sell={\"SELL_common_symbol\":comm_sell_sym, \"SELL_common_Token\":comm_sell}\n", " dic_comm_sell_disp=pd.DataFrame(dic_comm_sell)\n", " display(dic_comm_buy_disp)\n", " display(dic_comm_sell_disp)\n", " print(\"\\t \\t \\t \\t \\t !! ALL COMPLETED !!\")\n", " print(\" \\n \")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 2 } # END