[pshaiTemplate] MA + BB Scalper Template

stable
By pshai in Trading Bots Published November 2019 👁 1,900 views 💬 0 comments

Description

Scalper template utilizing fully configurable BB and MA.
HaasScript
-- MA + BB Scalper template
-- by pshai 2019

--------------------------------------------------------------
-- Helpers
local srcOptions = {
  close = 'close',
  hl = 'hl',
  hlc = 'hlc',
  ohlc = 'ohlc'
}

function getSource(srcType)
  if srcType == srcOptions.ohlc then
    return ClosePrices
  elseif srcType == srcOptions.hlc then
    return HLPrices
  elseif srcType == srcOptions.hl then
    return HLCPrices
  end

  return ClosePrices
end


--------------------------------------------------------------
-- Inputs
local maSrcType = InputOptions('Source', srcOptions.close, srcOptions, '', 'Moving Average')
local maSrc = getSource(maSrcType)
local maPeriod = Input('Period Length', 9, '', 'Moving Average')
local maType = InputMaTypes('Type', SmaType, '', 'Moving Average')

local bbSrcType = InputOptions('Source', srcOptions.close, srcOptions, '', 'BBands')
local bbSrc = getSource(maSrcType)
local bbPeriod = Input('Period Length', 20, '', 'BBands')
local bbDev = Input('Deviation', 2, '', 'BBands')
local bbType = InputMaTypes('Type', SmaType, '', 'BBands')

--------------------------------------------------------------
-- Data
local ma = MA(maSrc(), maPeriod, maType)
local bb = BBANDS(bbSrc(), bbPeriod, bbDev, bbDev, maType)

--------------------------------------------------------------
-- Charts
local l_bbUpper = Plot(0, 'BB Upper', bb.upper, {c=SkyBlue, w=2}) -- BB Upper
local l_bbLower = Plot(0, 'BB Lower', bb.lower, {c=SkyBlue, w=2}) -- BB Lower
Plot(0, 'BB Middle', bb.middle, SkyBlue) -- BB Middle
PlotBands(l_bbLower, l_bbUpper, SkyBlue(10)) -- Band
Plot(0, 'MA', ma, {c=Orange, w=2}) -- MA line

--------------------------------------------------------------
-- Trading logic
if ma > bb.middle then
  -- look for long entries
elseif ma < bb.middle then
  -- look for short entries
end

-- You might want to separate order handling,
-- TP and SL systems from the upper part.

--------------------------------------------------------------
-- Notes:
-- You have multiple options for BB upper and lower bands:
-- * Stop-loss for entries (lower for longs, upper for shorts)
-- * Breakout type of entry with market order
-- * Determine the range of your entry, TP and SL levels

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!