{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import vectorbtpro as vbt\n",
    "from lightweight_charts import chart, Panel\n",
    "\n",
    "# Pulling ETH-USD data\n",
    "data = vbt.YFData.pull(\"ETH-USD\")\n",
    "close = data.close\n",
    "high = data.high\n",
    "low = data.low\n",
    "\n",
    "# Define a simple moving average crossover strategy using EWM\n",
    "short_ma = vbt.MA.run(close, window=6, wtype=\"exp\").ma\n",
    "long_ma = vbt.MA.run(close, window=73, wtype=\"exp\").ma\n",
    "\n",
    "# Generate signals\n",
    "long_entries = short_ma > long_ma\n",
    "long_exits = short_ma < long_ma\n",
    "short_entries = short_ma < long_ma\n",
    "short_exits = short_ma > long_ma\n",
    "\n",
    "clean_long_entries, clean_long_exits = long_entries.vbt.signals.clean(long_exits)\n",
    "clean_short_entries, clean_short_exits = short_entries.vbt.signals.clean(short_exits)\n",
    "\n",
    "# ohlcv_df = data.ohlcv.get()\n",
    "\n",
    "#assume i want to display simple entries or exits on series or ohlcv \n",
    "#based on tuple positions it determines entries or exits (and set colors and shape accordingly)\n",
    "pane1 = Panel(\n",
    "    ohlcv=(data.ohlcv.get(), clean_long_entries, clean_short_entries)\n",
    ")\n",
    "ch = chart([pane1], title=\"Chart with Entry/Exit Markers\", session=None, size=\"s\")\n",
    "\n",
    "#if you want to display more entries or exits, use tuples with their colors\n",
    "pane1 = Panel(\n",
    "    ohlcv=(data.ohlcv.get(),\n",
    "           [(clean_long_entries, \"yellow\"), (clean_short_entries, \"pink\")], #list of entries tuples with color\n",
    "           [(clean_long_exits, \"yellow\"), (clean_short_exits, \"pink\")] #list of exits tuples with color\n",
    "           ), \n",
    ")\n",
    "\n",
    "# # Create the chart with the panel\n",
    "ch = chart([pane1], title=\"Chart with EntryShort/ExitShort (yellow) and EntryLong/ExitLong markers (pink)\", sync=True, session=None, size=\"s\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "\n",
    "\n",
    "# # Add the markers to the chart using markers_set method\n",
    "# entry_signals = pd.DataFrame({\n",
    "#     'time': clean_long_entries.index.astype(str),\n",
    "#     'value': clean_long_entries.values\n",
    "# }).dropna()\n",
    "# entry_signals['value'] = entry_signals['value'].astype(bool)\n",
    "\n",
    "# ch.markers_set(entry_signals, type='entries')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "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.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
