KEMBAR78
Level BOC Script | PDF | Data Analysis
0% found this document useful (0 votes)
4 views16 pages

Level BOC Script

The document outlines a Python script that processes EUR/USD candlestick data to detect trends and pivot points using exponential moving averages (EMA) and custom functions. It imports necessary libraries, loads the data, calculates the EMA, and identifies pivot points for visualization. The script also generates a candlestick chart with markers indicating detected pivot points.

Uploaded by

henex31312
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views16 pages

Level BOC Script

The document outlines a Python script that processes EUR/USD candlestick data to detect trends and pivot points using exponential moving averages (EMA) and custom functions. It imports necessary libraries, loads the data, calculates the EMA, and identifies pivot points for visualization. The script also generates a candlestick chart with markers indicating detected pivot points.

Uploaded by

henex31312
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Level Break Out

Load the data


import pandas as pd
import pandas_ta as ta
import pandas as pd
import numpy as np
import plotly.graph_objects as go
from scipy import stats

df = pd.read_csv("EURUSD_Candlestick_1_D_BID_05.05.2003-28.10.2023.csv")

df.rename(columns={
'Open': 'open',
'High': 'high',
'Low': 'low',
'Close': 'close',
'Volume': 'volume'
}, inplace=True)

df=df[df['volume']!=0]
df.reset_index(drop=True, inplace=True)

df['EMA'] = ta.ema(df.close, length=50)


df.tail()

df=df[0:]
df.reset_index(drop=True, inplace=True)

Trend detection
EMAsignal = [0]*len(df)
backcandles = 10

for row in range(backcandles, len(df)):


upt = 1
dnt = 1
for i in range(row-backcandles, row+1):
if max(df.open[i], df.close[i])>=df.EMA[i]:
dnt=0
if min(df.open[i], df.close[i])<=df.EMA[i]:
upt=0
if upt==1 and dnt==1:
EMAsignal[row]=3
elif upt==1:
EMAsignal[row]=2
elif dnt==1:
EMAsignal[row]=1

df['EMASignal'] = EMAsignal

df

Gmt time open high low close \


0 05.05.2003 00:00:00.000 1.12161 1.13009 1.12014 1.12924
1 06.05.2003 00:00:00.000 1.12921 1.14506 1.12723 1.14234
2 07.05.2003 00:00:00.000 1.14218 1.14323 1.13265 1.13494
3 08.05.2003 00:00:00.000 1.13507 1.15077 1.13006 1.14820
4 09.05.2003 00:00:00.000 1.14831 1.15366 1.14346 1.14867
... ... ... ... ... ...
6405 24.10.2023 00:00:00.000 1.06699 1.06942 1.05830 1.05949
6406 25.10.2023 00:00:00.000 1.05952 1.06067 1.05601 1.05661
6407 26.10.2023 00:00:00.000 1.05661 1.05691 1.05221 1.05638
6408 27.10.2023 00:00:00.000 1.05637 1.05970 1.05354 1.05605
6409 29.10.2023 00:00:00.000 1.05644 1.05749 1.05588 1.05618

volume EMA EMASignal


0 1.276006e+06 NaN 0
1 1.281467e+06 NaN 0
2 1.272597e+06 NaN 0
3 1.266581e+06 NaN 0
4 1.273339e+06 NaN 0
... ... ... ...
6405 2.703091e+05 1.064827 0
6406 2.475389e+05 1.064505 0
6407 2.871348e+05 1.064186 0
6408 2.156052e+05 1.063867 0
6409 7.605180e+03 1.063566 0

[6410 rows x 8 columns]

def isPivot(candle, window):


"""
function that detects if a candle is a pivot/fractal point
args: candle index, window before and after candle to test if pivot
returns: 1 if pivot high, 2 if pivot low, 3 if both and 0 default
"""
if candle-window < 0 or candle+window >= len(df):
return 0

pivotHigh = 1
pivotLow = 2
for i in range(candle-window, candle+window+1):
if df.iloc[candle].low > df.iloc[i].low:
pivotLow=0
if df.iloc[candle].high < df.iloc[i].high:
pivotHigh=0
if (pivotHigh and pivotLow):
return 3
elif pivotHigh:
return pivotHigh
elif pivotLow:
return pivotLow
else:
return 0

window=6
df['isPivot'] = df.apply(lambda x: isPivot(x.name,window), axis=1)

def pointpos(x):
if x['isPivot']==2:
return x['low']-1e-3
elif x['isPivot']==1:
return x['high']+1e-3
else:
return np.nan
df['pointpos'] = df.apply(lambda row: pointpos(row), axis=1)

dfpl = df[4300:4600]
fig = go.Figure(data=[go.Candlestick(x=dfpl.index,
open=dfpl['open'],
high=dfpl['high'],
low=dfpl['low'],
close=dfpl['close'])])

fig.add_scatter(x=dfpl.index, y=dfpl['pointpos'], mode="markers",


marker=dict(size=5, color="MediumPurple"),
name="pivot")
fig.update_layout(xaxis_rangeslider_visible=False)
fig.show()

{"config":{"plotlyServerURL":"https://plot.ly"},"data":[{"close":[1.07075,1.0
8008,1.07653,1.07617,1.07818,1.07824,1.0743,1.06788,1.06913,1.06572,1.06397,1
.06187,1.05987,1.05782,1.0603,1.06712,1.06114,1.06251,1.06088,1.0541,1.05505,
1.05839,1.05595,1.0552,1.05838,1.05692,1.05359,1.0507,1.06203,1.06207,1.05789
,1.05692,1.05447,1.05794,1.06728,1.06894,1.06507,1.06119,1.07375,1.07718,1.07
382,1.0742,1.07368,1.08125,1.07891,1.0783,1.07969,1.08451,1.08608,1.08162,1.0
7583,1.06877,1.06528,1.06692,1.06695,1.06779,1.06717,1.06437,1.05889,1.05805,
1.05971,1.06102,1.06698,1.06148,1.06105,1.06097,1.06432,1.07274,1.07145,1.071
41,1.07237,1.08733,1.08649,1.09275,1.09083,1.0865,1.08961,1.09057,1.09084,1.0
9346,1.0888,1.09804,1.0995,1.09647,1.09265,1.08861,1.08671,1.08642,1.0931,1.0
9277,1.09799,1.10933,1.11541,1.11101,1.12065,1.12032,1.12373,1.11788,1.12304,
1.121,1.11799,1.1176,1.1129,1.11728,1.1239,1.12128,1.12825,1.12772,1.12573,1.
12702,1.12554,1.11883,1.11941,1.12016,1.11973,1.12091,1.12129,1.11486,1.11968
,1.12039,1.11445,1.11363,1.11667,1.11497,1.11918,1.11997,1.11828,1.13369,1.13
782,1.14394,1.14251,1.14232,1.13723,1.13595,1.13464,1.14212,1.13996,1.14034,1
.13963,1.14738,1.14533,1.14045,1.14685,1.1474,1.14732,1.15478,1.15287,1.16283
,1.16622,1.16814,1.16384,1.16444,1.17316,1.16898,1.17478,1.17468,1.18208,1.18
109,1.18514,1.18822,1.1773,1.17769,1.17995,1.1754,1.17631,1.177,1.18199,1.182
52,1.17755,1.17403,1.17737,1.17156,1.17591,1.17562,1.18112,1.17615,1.18155,1.
17977,1.19219,1.19511,1.19638,1.19697,1.18906,1.19092,1.18597,1.18818,1.18928
,1.19236,1.19264,1.20278,1.20347,1.20169,1.19577,1.19711,1.18879,1.1921,1.194
47,1.19378,1.196,1.19925,1.18743,1.19447,1.19466,1.19267,1.18555,1.17838,1.17
497,1.17812,1.18137,1.18079,1.17315,1.17477,1.17566,1.17138,1.17299,1.17424,1
.1741,1.18134,1.18641,1.18309,1.18191,1.18145,1.17945,1.17711,1.17942,1.18484
,1.17817,1.17546,1.17548,1.176,1.18195,1.16377,1.16083,1.16056,1.16512,1.1651
8,1.16282,1.16586,1.1606,1.16147,1.16113,1.16008,1.1595,1.16462,1.16638,1.166
09,1.16646,1.17906,1.17826,1.17781,1.17879,1.17344,1.17371,1.17416,1.18146,1.
18503,1.19286,1.19274,1.19041,1.18491,1.1852,1.18979,1.18942,1.18565,1.18676,
1.18304,1.18039,1.17725,1.1772,1.17675,1.17762,1.17422,1.18361,1.17745,1.1749
2,1.17432,1.17837,1.18369,1.18776,1.18521,1.18607,1.18505,1.1871,1.18571,1.19
002,1.19394,1.19985,1.20106,1.20614,1.20107,1.20664,1.20304,1.2037,1.19698,1.
19284,1.19558,1.20427,1.21993,1.21919,1.22665],"high":[1.07402,1.08122,1.0807
3,1.08288,1.07975,1.07915,1.07887,1.07444,1.07139,1.07095,1.06677,1.0637,1.06
585,1.06333,1.06092,1.06794,1.06767,1.06329,1.06299,1.06127,1.0574,1.05952,1.
06179,1.05645,1.06306,1.06301,1.05894,1.05456,1.06239,1.06215,1.06399,1.06025
,1.05741,1.06151,1.0699,1.06925,1.07142,1.06624,1.07399,1.07742,1.07823,1.074
51,1.07772,1.08191,1.08245,1.08048,1.08179,1.08492,1.09058,1.08725,1.08264,1.
07679,1.07018,1.06737,1.06809,1.06851,1.06889,1.0684,1.06659,1.05885,1.06064,
1.06299,1.06751,1.06775,1.06294,1.06155,1.06703,1.07359,1.07367,1.07775,1.073
79,1.09164,1.08774,1.09499,1.09507,1.09327,1.09474,1.0911,1.09239,1.09359,1.0
9367,1.0987,1.09995,1.10216,1.09968,1.09333,1.0898,1.08929,1.09342,1.0935,1.0
9893,1.10971,1.11704,1.11719,1.12117,1.121,1.12634,1.12682,1.12332,1.12503,1.
12346,1.11849,1.11898,1.12054,1.12521,1.12566,1.1285,1.12837,1.12785,1.12842,
1.12823,1.1269,1.12157,1.12096,1.12321,1.12249,1.12958,1.12285,1.12016,1.1207
9,1.12128,1.11648,1.1169,1.11779,1.12089,1.11999,1.12198,1.13494,1.13906,1.14
455,1.14443,1.14266,1.14248,1.13769,1.13685,1.14254,1.14398,1.14038,1.1418,1.
14797,1.14588,1.14558,1.14719,1.1475,1.1487,1.15831,1.15533,1.1658,1.16828,1.
16816,1.16842,1.17121,1.17473,1.17767,1.17639,1.17618,1.18454,1.18389,1.191,1
.1893,1.18891,1.17929,1.1814,1.18238,1.17699,1.17851,1.18472,1.18275,1.18382,
1.17928,1.17793,1.17899,1.17743,1.17609,1.1828,1.18241,1.18232,1.18169,1.1941
4,1.19595,1.19857,1.20701,1.19843,1.19229,1.19798,1.18859,1.19218,1.19406,1.1
9499,1.20592,1.20923,1.20254,1.20295,1.1978,1.19947,1.19228,1.19873,1.19503,1
.19692,1.20064,1.20342,1.19535,1.20044,1.19268,1.19365,1.18615,1.1795,1.1804,
1.18325,1.18151,1.18079,1.17732,1.17877,1.17787,1.17387,1.17435,1.17561,1.182
54,1.1869,1.18797,1.18748,1.18178,1.18196,1.17949,1.18053,1.18579,1.18579,1.1
7743,1.17774,1.17927,1.18203,1.18367,1.16437,1.16153,1.16579,1.16613,1.1657,1
.16873,1.16904,1.16179,1.1624,1.16154,1.16111,1.16548,1.16778,1.16646,1.16751
,1.1805,1.18604,1.18008,1.18217,1.1797,1.18085,1.17577,1.18269,1.18559,1.1944
3,1.1936,1.19611,1.19198,1.18827,1.19315,1.19403,1.18751,1.18785,1.18766,1.18
48,1.18146,1.17744,1.17718,1.18117,1.17926,1.18404,1.18625,1.18123,1.17509,1.
18342,1.18487,1.19017,1.18895,1.1864,1.18515,1.18766,1.18787,1.19102,1.19589,
1.20254,1.20166,1.20811,1.20638,1.20889,1.20829,1.20389,1.20521,1.19755,1.201
79,1.20589,1.22184,1.22117,1.22964],"low":[1.06203,1.06846,1.0731,1.0756,1.07
115,1.0778,1.07059,1.06561,1.06407,1.06509,1.06077,1.06174,1.0592,1.05608,1.0
5214,1.05998,1.06054,1.06075,1.06031,1.05258,1.04938,1.05376,1.05565,1.05517,
1.05515,1.05666,1.05142,1.04948,1.05022,1.06002,1.05747,1.05581,1.05347,1.052
49,1.0578,1.06747,1.06448,1.06003,1.06073,1.07057,1.07274,1.07317,1.0719,1.07
353,1.07758,1.0768,1.07602,1.08264,1.08377,1.07988,1.07398,1.06718,1.06508,1.
06585,1.06423,1.06355,1.06349,1.06289,1.05806,1.05734,1.05698,1.05785,1.0589,
1.06094,1.0606,1.06028,1.06085,1.06372,1.06998,1.07069,1.06822,1.08648,1.0820
7,1.08512,1.08557,1.08517,1.08571,1.08905,1.0884,1.08881,1.08813,1.08749,1.09
494,1.09633,1.09164,1.08633,1.08532,1.0839,1.08556,1.09226,1.09225,1.0979,1.1
0816,1.10757,1.10995,1.11916,1.11614,1.1175,1.11685,1.11937,1.11605,1.11672,1
.11277,1.11094,1.11645,1.12021,1.12049,1.12701,1.12342,1.12404,1.12039,1.118,
1.11663,1.11971,1.11918,1.11852,1.1193,1.11321,1.11384,1.11956,1.11409,1.1118
8,1.11272,1.11392,1.11452,1.11902,1.11717,1.118,1.12917,1.13768,1.13921,1.141
63,1.1355,1.13359,1.13123,1.13299,1.13796,1.13924,1.13817,1.13828,1.14515,1.1
3705,1.13914,1.1465,1.14348,1.14714,1.15099,1.14792,1.1619,1.16615,1.16259,1.
16308,1.16125,1.16501,1.16711,1.17443,1.17231,1.17852,1.17937,1.18305,1.17281
,1.17706,1.17766,1.17151,1.16891,1.17041,1.17485,1.1818,1.17682,1.16872,1.168
16,1.16622,1.17102,1.175,1.17311,1.17451,1.17403,1.17841,1.17733,1.19403,1.19
168,1.19465,1.18804,1.18231,1.18499,1.18738,1.18776,1.18682,1.19028,1.1914,1.
20146,1.20112,1.19476,1.19262,1.1873,1.1838,1.19011,1.19174,1.1915,1.19536,1.
18613,1.18656,1.19369,1.18947,1.18319,1.17574,1.17171,1.17212,1.17726,1.17886
,1.17301,1.16961,1.17464,1.1699,1.16692,1.17267,1.17195,1.17405,1.17952,1.182
52,1.18053,1.18056,1.17805,1.17361,1.17302,1.17679,1.17624,1.17513,1.1725,1.1
7428,1.1753,1.16314,1.15741,1.15937,1.15976,1.16248,1.16064,1.16261,1.15991,1
.16038,1.15802,1.15539,1.15792,1.15856,1.16227,1.16558,1.16373,1.16625,1.1768
3,1.17569,1.17738,1.17223,1.17249,1.17128,1.17346,1.18132,1.18367,1.19239,1.1
8903,1.18271,1.18167,1.1809,1.18508,1.18562,1.18291,1.18007,1.17806,1.17713,1
.17301,1.17636,1.17639,1.17174,1.17294,1.17645,1.17488,1.17377,1.1742,1.17764
,1.18289,1.18493,1.18169,1.1844,1.18429,1.18465,1.1855,1.1897,1.19369,1.20007
,1.20078,1.20011,1.20044,1.20205,1.20259,1.1956,1.19156,1.19231,1.19291,1.204
01,1.21908,1.21876],"open":[1.07169,1.07075,1.08008,1.07654,1.07618,1.07896,1
.07824,1.0743,1.06788,1.0691,1.06571,1.06285,1.06186,1.05986,1.05783,1.0603,1
.06709,1.06075,1.0625,1.06088,1.05411,1.05505,1.0584,1.05637,1.0552,1.05838,1
.05691,1.05358,1.0507,1.06097,1.06207,1.05789,1.05692,1.05447,1.05794,1.06747
,1.06894,1.06508,1.0612,1.07376,1.07717,1.07318,1.07421,1.07368,1.08124,1.078
91,1.07831,1.0835,1.08453,1.08609,1.08162,1.07582,1.06875,1.06594,1.06692,1.0
6695,1.06779,1.06715,1.06437,1.05866,1.05806,1.05972,1.06101,1.06698,1.06148,
1.06129,1.06096,1.06432,1.07274,1.07145,1.0714,1.09164,1.08733,1.08648,1.0927
7,1.09083,1.08651,1.09099,1.09057,1.09086,1.09346,1.0888,1.09806,1.10188,1.09
647,1.09265,1.08861,1.08671,1.08642,1.09288,1.09278,1.09798,1.10932,1.11543,1
.111,1.11917,1.12032,1.12371,1.11791,1.12306,1.12099,1.11701,1.11758,1.11291,
1.11728,1.12389,1.12127,1.12703,1.12775,1.12572,1.12701,1.12554,1.11884,1.120
61,1.12015,1.11972,1.12091,1.1213,1.11487,1.12053,1.12037,1.11443,1.11365,1.1
1666,1.11496,1.11963,1.11997,1.11827,1.13369,1.1378,1.14393,1.14175,1.14234,1
.13723,1.13596,1.13465,1.14212,1.13966,1.14032,1.13963,1.14568,1.14186,1.1404
3,1.147,1.14739,1.14733,1.15477,1.15286,1.16283,1.16635,1.16811,1.16384,1.164
44,1.17315,1.16898,1.17456,1.17469,1.18207,1.18113,1.18514,1.18822,1.17734,1.
17769,1.17995,1.1754,1.17631,1.177,1.182,1.18251,1.17757,1.17403,1.17737,1.17
156,1.17578,1.17561,1.18112,1.17617,1.18154,1.17976,1.19431,1.19511,1.1964,1.
19697,1.18906,1.1909,1.18815,1.18818,1.18928,1.19235,1.19263,1.20277,1.20138,
1.20169,1.19577,1.1971,1.18879,1.19211,1.19196,1.19378,1.19598,1.19924,1.1874
2,1.19446,1.18947,1.19266,1.18556,1.17838,1.17498,1.17813,1.17886,1.18079,1.1
7319,1.17476,1.17565,1.1714,1.17271,1.17422,1.1741,1.18134,1.1864,1.18309,1.1
8107,1.18147,1.17945,1.1771,1.17943,1.18485,1.17641,1.17552,1.17548,1.17599,1
.18195,1.16377,1.16067,1.16057,1.16513,1.16518,1.16282,1.16588,1.16155,1.1614
7,1.16113,1.16008,1.1595,1.16464,1.16572,1.16609,1.16646,1.17907,1.17826,1.17
783,1.17857,1.17344,1.17372,1.17416,1.18147,1.18504,1.19255,1.19273,1.1904,1.
18491,1.18519,1.1898,1.18607,1.18565,1.18677,1.18305,1.1804,1.17726,1.17651,1
.17675,1.17762,1.17423,1.18361,1.17745,1.17441,1.17432,1.17837,1.18368,1.1877
6,1.18521,1.1844,1.18505,1.18712,1.1857,1.19001,1.19395,1.20102,1.20105,1.206
14,1.20108,1.20663,1.20265,1.20371,1.19698,1.19282,1.19557,1.20427,1.21933,1.
2192],"type":"candlestick","x":[4300,4301,4302,4303,4304,4305,4306,4307,4308,
4309,4310,4311,4312,4313,4314,4315,4316,4317,4318,4319,4320,4321,4322,4323,43
24,4325,4326,4327,4328,4329,4330,4331,4332,4333,4334,4335,4336,4337,4338,4339
,4340,4341,4342,4343,4344,4345,4346,4347,4348,4349,4350,4351,4352,4353,4354,4
355,4356,4357,4358,4359,4360,4361,4362,4363,4364,4365,4366,4367,4368,4369,437
0,4371,4372,4373,4374,4375,4376,4377,4378,4379,4380,4381,4382,4383,4384,4385,
4386,4387,4388,4389,4390,4391,4392,4393,4394,4395,4396,4397,4398,4399,4400,44
01,4402,4403,4404,4405,4406,4407,4408,4409,4410,4411,4412,4413,4414,4415,4416
,4417,4418,4419,4420,4421,4422,4423,4424,4425,4426,4427,4428,4429,4430,4431,4
432,4433,4434,4435,4436,4437,4438,4439,4440,4441,4442,4443,4444,4445,4446,444
7,4448,4449,4450,4451,4452,4453,4454,4455,4456,4457,4458,4459,4460,4461,4462,
4463,4464,4465,4466,4467,4468,4469,4470,4471,4472,4473,4474,4475,4476,4477,44
78,4479,4480,4481,4482,4483,4484,4485,4486,4487,4488,4489,4490,4491,4492,4493
,4494,4495,4496,4497,4498,4499,4500,4501,4502,4503,4504,4505,4506,4507,4508,4
509,4510,4511,4512,4513,4514,4515,4516,4517,4518,4519,4520,4521,4522,4523,452
4,4525,4526,4527,4528,4529,4530,4531,4532,4533,4534,4535,4536,4537,4538,4539,
4540,4541,4542,4543,4544,4545,4546,4547,4548,4549,4550,4551,4552,4553,4554,45
55,4556,4557,4558,4559,4560,4561,4562,4563,4564,4565,4566,4567,4568,4569,4570
,4571,4572,4573,4574,4575,4576,4577,4578,4579,4580,4581,4582,4583,4584,4585,4
586,4587,4588,4589,4590,4591,4592,4593,4594,4595,4596,4597,4598,4599]},{"mark
er":{"color":"MediumPurple","size":5},"mode":"markers","name":"pivot","type":
"scatter","x":[4300,4301,4302,4303,4304,4305,4306,4307,4308,4309,4310,4311,43
12,4313,4314,4315,4316,4317,4318,4319,4320,4321,4322,4323,4324,4325,4326,4327
,4328,4329,4330,4331,4332,4333,4334,4335,4336,4337,4338,4339,4340,4341,4342,4
343,4344,4345,4346,4347,4348,4349,4350,4351,4352,4353,4354,4355,4356,4357,435
8,4359,4360,4361,4362,4363,4364,4365,4366,4367,4368,4369,4370,4371,4372,4373,
4374,4375,4376,4377,4378,4379,4380,4381,4382,4383,4384,4385,4386,4387,4388,43
89,4390,4391,4392,4393,4394,4395,4396,4397,4398,4399,4400,4401,4402,4403,4404
,4405,4406,4407,4408,4409,4410,4411,4412,4413,4414,4415,4416,4417,4418,4419,4
420,4421,4422,4423,4424,4425,4426,4427,4428,4429,4430,4431,4432,4433,4434,443
5,4436,4437,4438,4439,4440,4441,4442,4443,4444,4445,4446,4447,4448,4449,4450,
4451,4452,4453,4454,4455,4456,4457,4458,4459,4460,4461,4462,4463,4464,4465,44
66,4467,4468,4469,4470,4471,4472,4473,4474,4475,4476,4477,4478,4479,4480,4481
,4482,4483,4484,4485,4486,4487,4488,4489,4490,4491,4492,4493,4494,4495,4496,4
497,4498,4499,4500,4501,4502,4503,4504,4505,4506,4507,4508,4509,4510,4511,451
2,4513,4514,4515,4516,4517,4518,4519,4520,4521,4522,4523,4524,4525,4526,4527,
4528,4529,4530,4531,4532,4533,4534,4535,4536,4537,4538,4539,4540,4541,4542,45
43,4544,4545,4546,4547,4548,4549,4550,4551,4552,4553,4554,4555,4556,4557,4558
,4559,4560,4561,4562,4563,4564,4565,4566,4567,4568,4569,4570,4571,4572,4573,4
574,4575,4576,4577,4578,4579,4580,4581,4582,4583,4584,4585,4586,4587,4588,458
9,4590,4591,4592,4593,4594,4595,4596,4597,4598,4599],"y":[1.0610300000000001,
null,null,1.08388,null,null,null,null,null,null,null,null,null,null,null,null
,null,null,null,null,1.04838,null,null,null,null,null,null,1.04848,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,nu
ll,null,null,1.09158,null,null,null,null,null,null,null,null,null,null,null,1
.0559800000000001,null,null,null,null,null,null,null,null,null,null,null,null
,null,1.0960699999999999,null,null,null,null,null,null,null,null,1.10316,null
,null,null,1.0829000000000002,null,null,null,null,null,null,null,null,null,1.
1278199999999998,null,null,null,null,null,1.1099400000000001,null,null,1.1295
,null,null,null,null,null,null,null,null,null,1.13058,null,null,null,null,1.1
1088,null,null,null,null,null,null,null,1.1455499999999998,null,null,null,nul
l,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,1.192,null,null,null,null,null,n
ull,null,null,null,null,null,null,1.1652200000000001,null,null,null,null,null
,null,null,null,null,1.2080099999999998,null,null,null,null,null,null,null,nu
ll,1.21023,null,null,null,null,1.1828,null,null,null,null,1.2044199999999998,
null,null,null,null,null,null,null,null,null,null,null,null,null,1.16592,null
,null,null,null,1.1889699999999999,null,null,null,null,null,null,null,null,nu
ll,null,null,null,1.1564100000000002,null,null,null,null,null,1.17004,null,nu
ll,1.15439,null,null,null,null,null,null,1.1870399999999999,null,null,null,nu
ll,null,null,null,null,null,1.19711,null,null,null,null,null,null,null,null,n
ull,null,null,null,1.1707400000000001,null,null,null,null,null,null,null,null
,null,null,null,null,null,null,null,null,null,null,1.20989,null,null,null,1.1
9056,null,null,null,null,null]}],"layout":{"template":{"data":{"bar":[{"error
_x":{"color":"#2a3f5f"},"error_y":{"color":"#2a3f5f"},"marker":{"line":{"colo
r":"#E5ECF6","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity
":0.2}},"type":"bar"}],"barpolar":[{"marker":{"line":{"color":"#E5ECF6","widt
h":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"ba
rpolar"}],"carpet":[{"aaxis":{"endlinecolor":"#2a3f5f","gridcolor":"white","l
inecolor":"white","minorgridcolor":"white","startlinecolor":"#2a3f5f"},"baxis
":{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","minorgri
dcolor":"white","startlinecolor":"#2a3f5f"},"type":"carpet"}],"choropleth":[{
"colorbar":{"outlinewidth":0,"ticks":""},"type":"choropleth"}],"contour":[{"c
olorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0,"#0d0887"],[0.1111111
111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c1
79e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.666666
6666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fd
ca26"],[1,"#f0f921"]],"type":"contour"}],"contourcarpet":[{"colorbar":{"outli
newidth":0,"ticks":""},"type":"contourcarpet"}],"heatmap":[{"colorbar":{"outl
inewidth":0,"ticks":""},"colorscale":[[0,"#0d0887"],[0.1111111111111111,"#460
39f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.444444
4444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed
7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1,"#f0f
921"]],"type":"heatmap"}],"heatmapgl":[{"colorbar":{"outlinewidth":0,"ticks":
""},"colorscale":[[0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.22222222222
22222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"
],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777
777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1,"#f0f921"]],"type":"heatm
apgl"}],"histogram":[{"marker":{"pattern":{"fillmode":"overlay","size":10,"so
lidity":0.2}},"type":"histogram"}],"histogram2d":[{"colorbar":{"outlinewidth"
:0,"ticks":""},"colorscale":[[0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.
2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.444444444444444
4,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0
.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1,"#f0f921"]],"t
ype":"histogram2d"}],"histogram2dcontour":[{"colorbar":{"outlinewidth":0,"tic
ks":""},"colorscale":[[0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222
222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3
786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.777777
7777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1,"#f0f921"]],"type":"h
istogram2dcontour"}],"mesh3d":[{"colorbar":{"outlinewidth":0,"ticks":""},"typ
e":"mesh3d"}],"parcoords":[{"line":{"colorbar":{"outlinewidth":0,"ticks":""}}
,"type":"parcoords"}],"pie":[{"automargin":true,"type":"pie"}],"scatter":[{"f
illpattern":{"fillmode":"overlay","size":10,"solidity":0.2},"type":"scatter"}
],"scatter3d":[{"line":{"colorbar":{"outlinewidth":0,"ticks":""}},"marker":{"
colorbar":{"outlinewidth":0,"ticks":""}},"type":"scatter3d"}],"scattercarpet"
:[{"marker":{"colorbar":{"outlinewidth":0,"ticks":""}},"type":"scattercarpet"
}],"scattergeo":[{"marker":{"colorbar":{"outlinewidth":0,"ticks":""}},"type":
"scattergeo"}],"scattergl":[{"marker":{"colorbar":{"outlinewidth":0,"ticks":"
"}},"type":"scattergl"}],"scattermapbox":[{"marker":{"colorbar":{"outlinewidt
h":0,"ticks":""}},"type":"scattermapbox"}],"scatterpolar":[{"marker":{"colorb
ar":{"outlinewidth":0,"ticks":""}},"type":"scatterpolar"}],"scatterpolargl":[
{"marker":{"colorbar":{"outlinewidth":0,"ticks":""}},"type":"scatterpolargl"}
],"scatterternary":[{"marker":{"colorbar":{"outlinewidth":0,"ticks":""}},"typ
e":"scatterternary"}],"surface":[{"colorbar":{"outlinewidth":0,"ticks":""},"c
olorscale":[[0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,
"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5
555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778
,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1,"#f0f921"]],"type":"surface"}],
"table":[{"cells":{"fill":{"color":"#EBF0F8"},"line":{"color":"white"}},"head
er":{"fill":{"color":"#C8D4E3"},"line":{"color":"white"}},"type":"table"}]},"
layout":{"annotationdefaults":{"arrowcolor":"#2a3f5f","arrowhead":0,"arrowwid
th":1},"autotypenumbers":"strict","coloraxis":{"colorbar":{"outlinewidth":0,"
ticks":""}},"colorscale":{"diverging":[[0,"#8e0152"],[0.1,"#c51b7d"],[0.2,"#d
e77ae"],[0.3,"#f1b6da"],[0.4,"#fde0ef"],[0.5,"#f7f7f7"],[0.6,"#e6f5d0"],[0.7,
"#b8e186"],[0.8,"#7fbc41"],[0.9,"#4d9221"],[1,"#276419"]],"sequential":[[0,"#
0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.333
3333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"
#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.88
88888888888888,"#fdca26"],[1,"#f0f921"]],"sequentialminus":[[0,"#0d0887"],[0.
1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.333333333333333
3,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0
.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.88888888888888
88,"#fdca26"],[1,"#f0f921"]]},"colorway":["#636efa","#EF553B","#00cc96","#ab6
3fa","#FFA15A","#19d3f3","#FF6692","#B6E880","#FF97FF","#FECB52"],"font":{"co
lor":"#2a3f5f"},"geo":{"bgcolor":"white","lakecolor":"white","landcolor":"#E5
ECF6","showlakes":true,"showland":true,"subunitcolor":"white"},"hoverlabel":{
"align":"left"},"hovermode":"closest","mapbox":{"style":"light"},"paper_bgcol
or":"white","plot_bgcolor":"#E5ECF6","polar":{"angularaxis":{"gridcolor":"whi
te","linecolor":"white","ticks":""},"bgcolor":"#E5ECF6","radialaxis":{"gridco
lor":"white","linecolor":"white","ticks":""}},"scene":{"xaxis":{"backgroundco
lor":"#E5ECF6","gridcolor":"white","gridwidth":2,"linecolor":"white","showbac
kground":true,"ticks":"","zerolinecolor":"white"},"yaxis":{"backgroundcolor":
"#E5ECF6","gridcolor":"white","gridwidth":2,"linecolor":"white","showbackgrou
nd":true,"ticks":"","zerolinecolor":"white"},"zaxis":{"backgroundcolor":"#E5E
CF6","gridcolor":"white","gridwidth":2,"linecolor":"white","showbackground":t
rue,"ticks":"","zerolinecolor":"white"}},"shapedefaults":{"line":{"color":"#2
a3f5f"}},"ternary":{"aaxis":{"gridcolor":"white","linecolor":"white","ticks":
""},"baxis":{"gridcolor":"white","linecolor":"white","ticks":""},"bgcolor":"#
E5ECF6","caxis":{"gridcolor":"white","linecolor":"white","ticks":""}},"title"
:{"x":5.0e-
2},"xaxis":{"automargin":true,"gridcolor":"white","linecolor":"white","ticks"
:"","title":{"standoff":15},"zerolinecolor":"white","zerolinewidth":2},"yaxis
":{"automargin":true,"gridcolor":"white","linecolor":"white","ticks":"","titl
e":{"standoff":15},"zerolinecolor":"white","zerolinewidth":2}}},"xaxis":{"ran
geslider":{"visible":false}}}}

def detect_structure(candle, backcandles, window):


if (candle <= (backcandles+window)) or (candle+window+1 >= len(df)):
return 0

localdf = df.iloc[candle-backcandles-window:candle-window] #window must


be greater than pivot window to avoid look ahead bias
highs = localdf[localdf['isPivot'] == 1].high.tail(3).values
lows = localdf[localdf['isPivot'] == 2].low.tail(3).values
levelbreak = 0
zone_width = 0.01
if len(lows)==3:
support_condition = True
mean_low = lows.mean()
for low in lows:
if abs(low-mean_low)>zone_width:
support_condition = False
break
if support_condition and (mean_low -
df.loc[candle].close)>zone_width*2:
levelbreak = 1

if len(highs)==3:
resistance_condition = True
mean_high = highs.mean()
for high in highs:
if abs(high-mean_high)>zone_width:
resistance_condition = False
break
if resistance_condition and (df.loc[candle].close-
mean_high)>zone_width*2:
levelbreak = 2
return levelbreak

#df['pattern_detected'] = df.index.map(lambda x: detect_structure(x,


backcandles=40, window=15))
df['pattern_detected'] = df.apply(lambda row: detect_structure(row.name,
backcandles=40, window=6), axis=1)
df[df['pattern_detected']!=0].head(20)

Gmt time open high low close \


1507 27.02.2008 00:00:00.000 1.49948 1.51435 1.49774 1.51150
2418 25.01.2011 00:00:00.000 1.36425 1.37038 1.35742 1.36846
2419 26.01.2011 00:00:00.000 1.36845 1.37212 1.36449 1.37097
3049 30.01.2013 00:00:00.000 1.34874 1.35870 1.34817 1.35682
3050 31.01.2013 00:00:00.000 1.35680 1.36165 1.35408 1.36115
3051 01.02.2013 00:00:00.000 1.36115 1.37108 1.35860 1.36391
3052 03.02.2013 00:00:00.000 1.36521 1.36571 1.36449 1.36449
3054 05.02.2013 00:00:00.000 1.35103 1.35972 1.34577 1.35825
3649 31.12.2014 00:00:00.000 1.21613 1.21697 1.20968 1.20976
3757 06.05.2015 00:00:00.000 1.11794 1.13700 1.11750 1.13391
3758 07.05.2015 00:00:00.000 1.13391 1.13916 1.12282 1.12444
3851 24.08.2015 00:00:00.000 1.13761 1.17139 1.13692 1.15804
3852 25.08.2015 00:00:00.000 1.15806 1.15845 1.13968 1.15530
4394 19.05.2017 00:00:00.000 1.11100 1.12117 1.10995 1.12065
5501 02.12.2020 00:00:00.000 1.20707 1.21183 1.20399 1.21138
6108 11.11.2022 00:00:00.000 1.01915 1.03640 1.01630 1.03538
6109 13.11.2022 00:00:00.000 1.03354 1.03411 1.03141 1.03266
6110 14.11.2022 00:00:00.000 1.03266 1.03584 1.02713 1.03196
6111 15.11.2022 00:00:00.000 1.03196 1.04808 1.02799 1.03572
6112 16.11.2022 00:00:00.000 1.03574 1.04384 1.03307 1.03932

volume EMA EMASignal isPivot pointpos pattern_detected


1507 858801.3125 1.470108 2 0 NaN 2
2418 214800.8750 1.333875 0 0 NaN 2
2419 182469.0625 1.335330 2 0 NaN 2
3049 175367.4844 1.322583 2 0 NaN 2
3050 166226.0625 1.324095 2 0 NaN 2
3051 204622.9844 1.325656 2 1 1.37208 2
3052 4513.7002 1.327179 2 0 NaN 2
3054 197343.0469 1.329297 2 0 NaN 2
3649 73325.1016 1.238216 1 0 NaN 1
3757 240872.4063 1.096869 0 0 NaN 2
3758 253915.2500 1.097950 0 0 NaN 2
3851 291241.8125 1.109272 0 1 1.17239 2
3852 244246.8594 1.111077 0 0 NaN 2
4394 202951.0156 1.085657 2 0 NaN 2
5501 356276.7500 1.184375 2 0 NaN 2
6108 649651.6875 0.993790 0 0 NaN 2
6109 27155.2695 0.995314 0 0 NaN 2
6110 630287.8750 0.996752 0 0 NaN 2
6111 858243.3125 0.998280 0 1 1.04908 2
6112 830625.7500 0.999889 0 0 NaN 2

data = df[:5000].copy()
def SIGNAL():
return data.pattern_detected
data.rename(columns={
'open': 'Open',
'high': 'High',
'low': 'Low',
'close': 'Close',
'volume': 'Volume'
}, inplace=True)
data

Gmt time Open High Low Close \


0 05.05.2003 00:00:00.000 1.12161 1.13009 1.12014 1.12924
1 06.05.2003 00:00:00.000 1.12921 1.14506 1.12723 1.14234
2 07.05.2003 00:00:00.000 1.14218 1.14323 1.13265 1.13494
3 08.05.2003 00:00:00.000 1.13507 1.15077 1.13006 1.14820
4 09.05.2003 00:00:00.000 1.14831 1.15366 1.14346 1.14867
... ... ... ... ... ...
4995 22.04.2019 00:00:00.000 1.12440 1.12620 1.12357 1.12584
4996 23.04.2019 00:00:00.000 1.12585 1.12612 1.11921 1.12237
4997 24.04.2019 00:00:00.000 1.12239 1.12241 1.11406 1.11533
4998 25.04.2019 00:00:00.000 1.11534 1.11623 1.11178 1.11353
4999 26.04.2019 00:00:00.000 1.11353 1.11739 1.11111 1.11429

Volume EMA EMASignal isPivot pointpos pattern_detected


0 1.276006e+06 NaN 0 0 NaN 0
1 1.281467e+06 NaN 0 0 NaN 0
2 1.272597e+06 NaN 0 0 NaN 0
3 1.266581e+06 NaN 0 0 NaN 0
4 1.273339e+06 NaN 0 0 NaN 0
... ... ... ... ... ... ...
4995 1.848423e+05 1.128744 0 0 NaN 0
4996 3.667941e+05 1.128494 0 0 NaN 0
4997 3.960929e+05 1.127978 0 0 NaN 0
4998 3.468432e+05 1.127412 0 0 NaN 0
4999 3.413141e+05 1.126897 0 2 1.11011 0

[5000 rows x 11 columns]

data['RSI'] = ta.rsi(data['Close'])
data.set_index("Gmt time", inplace=True)
data.index = pd.to_datetime(data.index, format='%d.%m.%Y
%H:%M:%S.%f').floor('S')
data

Open High Low Close Volume EMA \


Gmt time
2003-05-05 1.12161 1.13009 1.12014 1.12924 1.276006e+06 NaN
2003-05-06 1.12921 1.14506 1.12723 1.14234 1.281467e+06 NaN
2003-05-07 1.14218 1.14323 1.13265 1.13494 1.272597e+06 NaN
2003-05-08 1.13507 1.15077 1.13006 1.14820 1.266581e+06 NaN
2003-05-09 1.14831 1.15366 1.14346 1.14867 1.273339e+06 NaN
... ... ... ... ... ... ...
2019-04-22 1.12440 1.12620 1.12357 1.12584 1.848423e+05 1.128744
2019-04-23 1.12585 1.12612 1.11921 1.12237 3.667941e+05 1.128494
2019-04-24 1.12239 1.12241 1.11406 1.11533 3.960929e+05 1.127978
2019-04-25 1.11534 1.11623 1.11178 1.11353 3.468432e+05 1.127412
2019-04-26 1.11353 1.11739 1.11111 1.11429 3.413141e+05 1.126897

EMASignal isPivot pointpos pattern_detected RSI


Gmt time
2003-05-05 0 0 NaN 0 NaN
2003-05-06 0 0 NaN 0 NaN
2003-05-07 0 0 NaN 0 NaN
2003-05-08 0 0 NaN 0 NaN
2003-05-09 0 0 NaN 0 NaN
... ... ... ... ... ...
2019-04-22 0 0 NaN 0 47.863943
2019-04-23 0 0 NaN 0 42.087795
2019-04-24 0 0 NaN 0 33.306049
2019-04-25 0 0 NaN 0 31.496496
2019-04-26 0 2 1.11011 0 33.148033

[5000 rows x 11 columns]

from backtesting import Strategy


from backtesting import Backtest

class MyStrat(Strategy):
mysize = 10000
def init(self):
super().init()
self.signal = self.I(SIGNAL)

def next(self):
super().next()
TPSLRatio = 2
perc = 0.03

#Close trades if RSI is above 70 for long positions and below 30 for
short positions
for trade in self.trades:
if trade.is_long and self.data.RSI[-1] > 80:
trade.close()
elif trade.is_short and self.data.RSI[-1] < 20:
trade.close()

if self.signal!=0 and len(self.trades)==0 and


self.data.pattern_detected==2:
sl = self.data.Close[-1]-self.data.Close[-1]*perc
sldiff = abs(sl-self.data.Close[-1])
tp = self.data.Close[-1]+sldiff*TPSLRatio
self.buy(sl=sl, tp=tp, size=self.mysize)

elif self.signal!=0 and len(self.trades)==0 and


self.data.pattern_detected==1:
sl = self.data.Close[-1]+self.data.Close[-1]*perc
sldiff = abs(sl-self.data.Close[-1])
tp = self.data.Close[-1]-sldiff*TPSLRatio
self.sell(sl=sl, tp=tp, size=self.mysize)

bt = Backtest(data, MyStrat, cash=10000, margin=1/5)


stat = bt.run()
stat

Start 2003-05-05 00:00:00


End 2019-04-26 00:00:00
Duration 5835 days 00:00:00
Exposure Time [%] 3.64
Equity Final [$] 10951.735
Equity Peak [$] 11165.976
Return [%] 9.51735
Buy & Hold Return [%] -1.323899
Return (Ann.) [%] 0.459252
Volatility (Ann.) [%] 1.875674
Sharpe Ratio 0.244846
Sortino Ratio 0.358288
Calmar Ratio 0.053188
Max. Drawdown [%] -8.634543
Avg. Drawdown [%] -1.604492
Max. Drawdown Duration 2273 days 00:00:00
Avg. Drawdown Duration 196 days 00:00:00
# Trades 7
Win Rate [%] 57.142857
Best Trade [%] 6.140175
Worst Trade [%] -3.001675
Avg. Trade [%] 0.949154
Max. Trade Duration 76 days 00:00:00
Avg. Trade Duration 30 days 00:00:00
Profit Factor 1.793851
Expectancy [%] 1.020694
SQN 0.704579
_strategy MyStrat
_equity_curve E...
_trades Size EntryB...
dtype: object

from backtesting import Strategy


from backtesting import Backtest

class MyStrat(Strategy):
mysize = 5000 #5000
def init(self):
super().init()
self.signal = self.I(SIGNAL)

def next(self):
super().next()
TPSLRatio = 2
perc = 0.03

if len(self.trades)==1:
for trade in self.trades:
trade.sl = trade.entry_price
#self.trades[-1].sl = self.trades[-1].entry_price

# Close trades if RSI is above 70 for long positions and below 30 for
short positions
# for trade in self.trades:
# if trade.is_long and self.data.RSI[-1] > 80:
# trade.close()
# elif trade.is_short and self.data.RSI[-1] < 20:
# trade.close()

if self.signal!=0 and len(self.trades)==0 and


self.data.pattern_detected==2:
sl1 = self.data.Close[-1]-self.data.Close[-1]*perc
sldiff = abs(sl1-self.data.Close[-1])
tp1 = self.data.Close[-1]+sldiff*TPSLRatio
tp2 = self.data.Close[-1]+sldiff
self.buy(sl=sl1, tp=tp1, size=self.mysize)
self.buy(sl=sl1, tp=tp2, size=self.mysize)

elif self.signal!=0 and len(self.trades)==0 and


self.data.pattern_detected==1:
sl1 = self.data.Close[-1]+self.data.Close[-1]*perc
sldiff = abs(sl1-self.data.Close[-1])
tp1 = self.data.Close[-1]-sldiff*TPSLRatio
tp2 = self.data.Close[-1]-sldiff
self.sell(sl=sl1, tp=tp1, size=self.mysize)
self.sell(sl=sl1, tp=tp1, size=self.mysize)

bt = Backtest(data, MyStrat, cash=10000, margin=1/5)


stat = bt.run()
stat

Start 2003-05-05 00:00:00


End 2019-04-26 00:00:00
Duration 5835 days 00:00:00
Exposure Time [%] 3.2
Equity Final [$] 10977.233
Equity Peak [$] 11195.828
Return [%] 9.77233
Buy & Hold Return [%] -1.323899
Return (Ann.) [%] 0.471027
Volatility (Ann.) [%] 1.606914
Sharpe Ratio 0.293125
Sortino Ratio 0.426861
Calmar Ratio 0.083404
Max. Drawdown [%] -5.64755
Avg. Drawdown [%] -1.563433
Max. Drawdown Duration 1442 days 00:00:00
Avg. Drawdown Duration 202 days 00:00:00
# Trades 14
Win Rate [%] 57.142857
Best Trade [%] 4.13753
Worst Trade [%] -2.001692
Avg. Trade [%] 0.991537
Max. Trade Duration 60 days 00:00:00
Avg. Trade Duration 23 days 00:00:00
Profit Factor 2.199643
Expectancy [%] 1.028308
SQN 1.456806
_strategy MyStrat
_equity_curve E...
_trades Size EntryB...
dtype: object

bt.plot()

BokehDeprecationWarning: Passing lists of formats for DatetimeTickFormatter


scales was deprecated in Bokeh 3.0. Configure a single string format for each
scale
f:\Python\Lib\site-packages\backtesting\_plotting.py:250: UserWarning:

DatetimeFormatter scales now only accept a single format. Using the first
provided: '%d %b'

BokehDeprecationWarning: Passing lists of formats for DatetimeTickFormatter


scales was deprecated in Bokeh 3.0. Configure a single string format for each
scale
f:\Python\Lib\site-packages\backtesting\_plotting.py:250: UserWarning:

DatetimeFormatter scales now only accept a single format. Using the first
provided: '%m/%Y'

f:\Python\Lib\site-packages\backtesting\_plotting.py:659: UserWarning:

found multiple competing values for 'toolbar.active_drag' property; using the


latest value
f:\Python\Lib\site-packages\backtesting\_plotting.py:659: UserWarning:

found multiple competing values for 'toolbar.active_scroll' property; using


the latest value

GridPlot(id='p1693', ...)

You might also like