Simple RSING VWAP Strategy

beta
By r4stl1n in Trading Bots Published April 2022 👁 1,525 views 💬 2 comments

Description

This is a simple strategy that combines the RSING and VWAP Window into a single strategy. Working Defaults: ETH/USD - Perpetuals Interval = 15 Minutes RSING Length = 14 VWAP Window = 100 Stop Loss Percentage = 2 Stop Loss Shrinkage = 1
HaasScript
HideOrderSettings()

local risingLength = Input("Rising Length",14,"Rising Length","")
local vwapWindow = Input("VWAP Window",100,"VWAP Window","")

local stopLossPercentage = Input("Stop Loss Percentage",2, "Stop Loss Percentage","StopLoss")
local stopLossShrinkage = Input("Stop Loss Shrinkage",1, "Stop Loss Shrinkage","StopLoss")

OptimizedForInterval(0, function()

    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 cc = CC_RSING(risingLength)

    local vwap = CC_VWAPWindow(vwapWindow)
     
    if vwap[2] != nil 
    then

        local goLong = cc > 0 and (vwap[1]-vwap[2]) > 0
        local goShort = cc < 0 and (vwap[1]-vwap[2]) < 0

        if currentPosition != NoPosition
        then
            if ShrinkingTrailingStopLoss(stopLossPercentage,stopLossShrinkage)
            then
                if currentPosition == PositionLong
                then
                    long_exit_cmd(currentPrice.close, TradeAmount(), {type=MarketOrderType, note='SL'})
                else
                    short_exit_cmd(currentPrice.close, TradeAmount(), {type=MarketOrderType, note='SL'})
                end
            end
        end

        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(1, "RSING", cc, {c=Cyan})
        Plot(2, "VWAP", vwap, {c=White})

    end

end)

2 Comments

Sign in to leave a comment.

V
vlfVJn about 4 years ago

Hello! I'm trying to run (backtest in Script Editor) the script but I'm getting an error 'Something went wrong running the script'. Commands 'RSING Momentum Indicator' and
'Simple RSING VWAP Strategy' saved. Haasonline Trade Server v3.3.44.0 RELEASE.
Please tell me what am I doing wrong?

T
Trentacles about 4 years ago

I think you have given this script as a dependency when I believe the VWAP window https://www.haasscripts.com/t/vwap-window/#post-2964 is meant to be included... But the the VWAP window script has an error ... I'm using HTS not the cloud...does this matter?
5. 08 Apr 2022 03:10:59 ---------------------DEBUG LOG------------------------------
4. 08 Apr 2022 03:10:59 ------------------------------------------------------------
3. 08 Apr 2022 03:10:59 WARNING: Skipping update because of scripting error.
2. 08 Apr 2022 03:10:59 ERROR: Unknown references: tostring
1. 08 Apr 2022 03:10:59 ERROR: Unknown references: tostring