Simple VWAP Window Strategy
betaDescription
A simple example strategy utilizing the CC_VWAPWindow command.
This strategy while works well enough alone should be built ontop of to ensure correct money management.
Screenshot is of default settings on
Kucoin Futures - ADA/USDT
1 Hour Candles
HaasScript
-- [r4stl1n] Simple VWAP Window Strat
--
-- This is an example of using the VWAPWindow command to
-- create a strategy
--
--------------------------------
-- You are on your own with this script
--------------------------------
-- ~Bored and programming~
HideOrderSettings()
-- Wrap our entire strategy in the OptimizedForInteral
-- To ensure our strat only runs on new complete candles
OptimizedForInterval(0, function()
vwapWindowSize = Input("VWAP Window Size",20,"VWAP Window Size","")
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
local market = PriceMarket()
local currentPosition = GetPositionDirection()
local currentPrice = CurrentPrice()
-- Rolling window of 20 candles
local vwap = CC_VWAPWindow(vwapWindowSize)
if vwap[3] != nil
then
local goLong = (vwap[1] - vwap[3]) > 0
local goShort = (vwap[1] - vwap[3]) < 0
if goLong and currentPosition != PositionLong
then
if currentPosition == PositionShort
then
-- Uncomment to enable shorts
--short_exit_cmd(currentPrice.close, TradeAmount(), {type=MarketOrderType, note='Long'})
end
long_entry_cmd(currentPrice.close, TradeAmount(), {type=MarketOrderType, note='Long'})
end
if goShort and currentPosition != PositionShort
then
if currentPosition == PositionLong
then
long_exit_cmd(currentPrice.close, TradeAmount(), {type=MarketOrderType, note='Long'})
end
-- Uncomment to enable shorts
--short_entry_cmd(currentPrice.close, TradeAmount(), {type=MarketOrderType, note='Short'})
end
Plot(0, "VWAP Window", vwap, {c=Cyan})
end
end)
0 Comments
Sign in to leave a comment.
No comments yet. Be the first!