[pshaiBot] YATS Bot
stableDescription
Yet Another Trend Scalper Bot! Or is it...?
This bot comes along with many different options to run it... Providing a lot of options for settings but this time also made it exchange-agnostic!
Make it a scalper?
Make it a swing trader?
It's all there for you to decide (or HaasLabs)!!!
Hope this simple, yet powerful little beast does you well!
REQUIRED CUSTOM COMMAND: https://www.haasscripts.com/t/pshaicmd-stoch-rsi/
HaasScript
-- [pshaiBot] YATS Bot
-- Yet Another Trend Scalper Bot, created by pshai (c) 2020
-- If you like what I'm doing, you can support me:
-- BTC: 3EsfrqARW7iPVKjZz6WgkMTrtw6SgJUUdV
-- ETH: 0x6b5120bdaf7cdfa523ecc0209b0c67cd67dd2140
--------------------------------
-- If you have any feedback or need help (with my scripts)...
-- ...you know where to find me.
--------------------------------
-- ~May the profits be with you~
-- script settings
EnableHighSpeedUpdates(true)
HideOrderSettings()
-- trading commands
local isSpot = MarketType() == SpotTrading
local long_entry_cmd = isSpot and PlaceBuyOrder or PlaceGoLongOrder
local long_exit_cmd = isSpot and PlaceSellOrder or PlaceExitLongOrder
local short_entry_cmd = isSpot and PlaceSellOrder or PlaceGoShortOrder
local short_exit_cmd = isSpot and PlaceBuyOrder or PlaceExitShortOrder
-- inputs
local tf1 = InputInterval('1. Timeframe (Entry)', 5, 'Timeframe for StochRSI()', 'Intervals')
local tf2 = InputInterval('2. Timeframe (Momentum)', 15, 'Timeframe for MOM()', 'Intervals')
local tf3 = InputInterval('3. Timeframe (Trend)', 45, 'Timeframe for ADX(), ATR() and MA()s', 'Intervals')
local period_adx = Input('1. ADX Length', 14, '', 'Period Lengths')
local period_atr = Input('2. ATR Length', 14, '', 'Period Lengths')
local period_ma1 = Input('3. MA1 Length', 10, '', 'Period Lengths')
local period_ma2 = Input('4. MA2 Length', 36, '', 'Period Lengths')
local period_mom = Input('5. MOM Length', 100, '', 'Period Lengths')
local period_moms = Input('6. MOM Smooth', 9, '', 'Period Lengths')
local period_rsi = Input('7. RSI Length', 9, '', 'Period Lengths')
local period_stoch = Input('8. STOCH Length', 7, '', 'Period Lengths')
local period_smk = Input('9. Smooth %K Length', 5, '', 'Period Lengths')
local period_smd = Input('10. Smooth %D Length', 2, '', 'Period Lengths')
local stoch_ob = Input('1. Short Overbought', 80, '', 'Levels')
local stoch_os = Input('2. Long Oversold', 20, '', 'Levels')
local adx_limit = Input('3. ADX Limit', 0, 'If ADX is below this level, the bot will not trade!', 'Levels')
local ma_type1 = InputMaTypes('1. MA1 Type', EmaType, '', 'MA Types')
local ma_type2 = InputMaTypes('2. MA2 Type', EmaType, '', 'MA Types')
local sl_prc = Input('StopLoss %', 0.5)
-- data
local h = {
tf1 = HighPrices(tf1),
tf2 = HighPrices(tf2),
tf3 = HighPrices(tf3)
}
local l = {
tf1 = LowPrices(tf1),
tf2 = LowPrices(tf2),
tf3 = LowPrices(tf3)
}
local c = {
tf1 = ClosePrices(tf1),
tf2 = ClosePrices(tf2),
tf3 = ClosePrices(tf3)
}
local cp = CurrentPrice()
local adx = ADX(h.tf3, l.tf3, c.tf3, period_adx)
local atr = ATR(h.tf3, l.tf3, c.tf3, period_atr)
local ma1 = MA(c.tf3, period_ma1, ma_type1)
local ma2 = MA(c.tf3, period_ma2, ma_type2)
local mom = EMA(MOM(c.tf2, period_mom), period_moms)
local rsi = CC_StochRSI(period_rsi, period_stoch, period_smk, period_smd, c.tf1)
-- plots
Plot(0, 'MA1', ma1)
Plot(0, 'MA2', ma2, Purple)
Plot(1, 'ADX', adx)
PlotHorizontalZone(1, '', Red(10), 0, adx_limit)
Plot(2, 'MOM', mom)
Plot(3, '%K', rsi.slowK, Yellow)
Plot(3, '%D', rsi.slowD, Red)
PlotHorizontalLine(3, '', Gray, stoch_os, Dashed)
PlotHorizontalLine(3, '', Gray, stoch_ob, Dashed)
-- helpers
function canTrade()
local time = Load('time', Time())
return Time() >= time
end
function setTimer(minutes)
Save('time', Time() + minutes * 60)
end
-- da logic
local rules = {
adx = adx > adx_limit,
ma_up = ma1 > ma2,
ma_dn = ma1 < ma2,
mom_up = mom > 0,
mom_dn = mom < 0,
entry_up = rsi.slowK < rsi.slowD and rsi.slowK < stoch_os,
entry_dn = rsi.slowK > rsi.slowD and rsi.slowK > stoch_ob
}
local xid = Load('xid', '') -- order id for the ideal exit
local go_long = rules.adx and rules.ma_up and rules.mom_up and rules.entry_up
local go_short = rules.adx and rules.ma_dn and rules.mom_dn and rules.entry_dn
local bot_pos = GetPositionDirection()
if bot_pos == NoPosition and canTrade() then
if go_long then
long_entry_cmd(cp.close, TradeAmount(), {type=MarketOrderType, note='LE'})
xid = long_exit_cmd(cp.close + atr, TradeAmount(), {type=NoTimeOutOrderType, note='LX'})
elseif go_short then
short_entry_cmd(cp.close, TradeAmount(), {type=MarketOrderType, note='SE'})
xid = short_exit_cmd(cp.close - atr, TradeAmount(), {type=NoTimeOutOrderType, note='SX'})
end
else
if StopLoss(sl_prc) then
if xid != '' and IsOrderOpen(xid) then
CancelOrder(xid)
end
SetFee(0.075) -- for backtesting and sim runs
if bot_pos == PositionLong then
long_exit_cmd(cp.close, TradeAmount(), {type=MarketOrderType, note='LX-SL'})
elseif bot_pos == PositionShort then
short_exit_cmd(cp.close, TradeAmount(), {type=MarketOrderType, note='SX-SL'})
end
setTimer(30) -- cooldown if stoploss
end
end
-- save
Save('xid', xid)
0 Comments
Sign in to leave a comment.
No comments yet. Be the first!