Replies: 1 comment 1 reply
-
backtesting.py/backtesting/backtesting.py Lines 711 to 715 in 94d20da Limit price (or current market price for |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
below are my strategy code
it use MACD, EMA simple
I have some problem with code that when i run and got this kind of message
backtesting.py", line 713, in new_order raise ValueError(ValueError: Long orders require: SL (38498.388) < LIMIT (38293.637299999995) < TP (38846.265)
i know whats meaning about error but dont know how to fix it
just guess it have problem with setting SL/TP
can you guys solve this error?
thanks
this is error message
File "c:\Users\ssungjae\Dropbox\PC\Desktop\Python_auto\MACD_backtesting.py", line 82, in
stats = bt.run()
File "C:\Users\ssungjae\Anaconda3\lib\site-packages\backtesting\backtesting.py", line 1170, in run
strategy.next()
File "c:\Users\ssungjae\Dropbox\PC\Desktop\Python_auto\MACD_backtesting.py", line 59, in next
self.buy(sl = long_sl, tp = long_tp, limit = None)
File "C:\Users\ssungjae\Anaconda3\lib\site-packages\backtesting\backtesting.py", line 210, in buy
return self._broker.new_order(size, limit, stop, sl, tp)
File "C:\Users\ssungjae\Anaconda3\lib\site-packages\backtesting\backtesting.py", line 713, in new_order
raise ValueError(
ValueError: Long orders require: SL (38377.374) < LIMIT (37722.729699999996) < TP (38724.157499999994)
import ccxt
import time
import pandas as pd
import pprint
import numpy
import talib
from backtesting import Strategy
access = ""
secret = ""
binanceX = ccxt.binance(config={
'apiKey': access,
'secret': secret,
'enableRateLimit': True,
'options': {
'defaultType': 'future'
}
})
load candle data
def GetOhlcv(binance, Ticker, period):
btc_ohlcv = binance.fetch_ohlcv(Ticker, period)
df = pd.DataFrame(btc_ohlcv, columns=['datetime', 'Open', 'High', 'Low', 'Close', 'Volume'])
df['datetime'] = pd.to_datetime(df['datetime'], unit='ms')
df.set_index('datetime', inplace=True)
return df
df_5min = GetOhlcv(binanceX, 'BTC/USDT', '5m')
class MACD_EMA(Strategy):
### EMA 간격
n50 = 50
n200 = 200
df_5min = GetOhlcv(binanceX, 'BTC/USDT', '5m')
from backtesting import Backtest
bt = Backtest(df_5min, MACD_EMA, margin=0.1, cash=1000, commission=0.003, exclusive_orders=False,)
stats = bt.run()
bt.plot()
Beta Was this translation helpful? Give feedback.
All reactions