Spot Market Trading Bot Template with Bot Inheritance

0 226 Views No Comments 1 month ago
HTS CLOUDSTABLE
  • Hi, once again me, HaHa.

    I like you to inspire your thinking what is possible with HaasScript.

    I like modularizing code as much as much as I can, as a Software Developer and so I do it with HaasScripts.

    I developed a Spot Market Trading Bot Template that can ease your development very much.

    You call it in your code like this: (easy peasy)


    local bot = CC_SpotBot('Alfonso #002')
    --- here you can add optional parts parts
    bot:run()

    Here, you can see an example:


    -- Author: romdisc
    -- test bot

    local bot = CC_SpotBot('My Spot Bot #001')

    bot.inputs = function(bot_name)
    local dict = {}

    InputGroupHeader(bot_name .. ' - Settings')

    dict.period = Input('Period', 14)
    dict.buyLevel = Input('Buy level', 30)
    dict.sellLevel = Input('Sell level', 70)

    return dict

    end

    bot.indicators = function(inputs)
    local dict = {}

    dict.rsi = RSI(ClosePrices(), inputs.period)

    return dict
    end

    bot.signal = function(signal, indicators, inputs)

    signal = IfNull(signal, SignalNone)

    if indicators.rsi < inputs.buyLevel then signal = SignalBuy
    elseif indicators.rsi > inputs.sellLevel then signal = SignalSell
    else signal = SignalNone end

    return signal
    end

    bot.plot = function(indicators, inputs)
    Plot(1, 'RSI', indicators.rsi, SkyBlue)
    PlotHorizontalLine(1, 'Buy', Cyan, inputs.sellLevel, Dotted)
    PlotHorizontalLine(1, 'Buy', Cyan, inputs.buyLevel, Dotted)
    end

    bot:run()

    This bot template is very flexible. You can inherit your own version out of the super class SpotBot maybe for Future Trading or some other customazations.


    DefineCommand('MyCustomBot', 'My Custom Bot inheritins SpotBot')

    local bot_name = DefineParameter(StringType, 'Bot', 'Bot Name', true, 'Bot')

    local Bot = CC_SpotBot(bot_name)

    -- override default behavour of your parent strategy and/or any other function
    Bot.strategy = function(signal, indicators, inputs)
    -- your different strategy algorithm (possibly your future strategy)
    end

    DefineOutput(ListDynamicType, Bot(bot_name), 'Bot Template')

    Happy Coding !!! – Cheers!!!

    HaasScript Code
    Sign in or Register to download for free
  • Phemex x HaasOnline Promotion Type: contest Expires: May 31, 2024 Exclusive
    Receive up to 1,200 USDT! The more you trade, the more you earn.
Login or Register to Comment

Unlock your crypto trading potential

Create a free account and enjoy everything we have to offer.

Join for Free