[bot] Signal Trigger with Multiple Positions

2 142 Views 3 Comments 2 weeks ago
  • Basic bot/template for managing multiple positions and single order per position with stoploss and take profit

    Get a signal from where ever you like either from another script or remote signal and it will manage multiple positions both long and short.

    Requires my other custom commands to work –

    [cmd] GetPID (getPositionId)
    [cmd] getOID
    [cmd] CheckOpenOrder
    [cmd]CheckPositionId

    • This topic was modified 2 weeks, 2 days ago by strooth.
    • This topic was modified 2 weeks, 2 days ago by strooth.
    • This topic was modified 2 weeks, 2 days ago by strooth. Reason: add screenshots
    • This topic was modified 2 weeks, 2 days ago by strooth.
    • This topic was modified 2 weeks, 2 days ago by strooth.
    • This topic was modified 2 weeks, 2 days ago by strooth.
    • This topic was modified 2 weeks, 2 days ago by strooth.
    • This topic was modified 2 weeks, 2 days ago by strooth.
    HaasScript Code
    Sign in or Register to download for free
    • #2680
      Hedgehog
      Basic
      Up
      0
      Down
      ::

      Thank you for sharing this, I’ve been tinkering with something similar to no avail. I keep breaching my maxPosi. I set it equal to the net of my two open positions (buys/sells). Was wondering how to tru-up to the exchange periodically to ensure that there is no position drift, would you have anything that can help with that => I found sync_positions but haven’t been able to get it working (that was about a month ago so am more proficient with the code.

      I am using one of firetron’s dca models and trying to stop when I reach a certain “maxPosi”. I’ve inserted the following in Exit() and Go() as described below. for some reason doesn’t seem that efficient.

      Bot Description:

      --    Firetron's Hedged DCA Dipper
      --
      --    Runs a long and a short each doing dollar cost averaging strategy.
      --    Expands positions on an interval and exits whenever there is a profit.
      --    Only expands a position when its profit is less than a trigger.

      Add’s

      
       netPos = (LongAmount() - ShortAmount())
        if netPos < 0 and Abs(netPos) > maxPosi then
          ExitCheckShort(debugInfo)
        elseif netPos > 0 and netPos > maxPosi then
          ExitCheckLong(debugInfo)
        else 
        end
      

      Code Blocks Updated

      --  ------------------------------------
      --    Exiting
      --  ------------------------------------
       
      function Exit ()
       
        local debugInfo = GetDebugInfo()
        netPos = (LongAmount() - ShortAmount())
        if netPos < 0 and Abs(netPos) > maxPosi then
          ExitCheckShort(debugInfo)
        elseif netPos > 0 and netPos > maxPosi then
          ExitCheckLong(debugInfo)
        else 
        end
      
        ExitCheckShort(debugInfo)
        ExitCheckShort(debugInfo)
       
      end
      

      Second Spot

       
      function Go ()
       
        local debugInfo = GetDebugInfo()
       
        if debugInfo.isVerbose then
          SafeLog(logHRule)
        end
        
         netPos = (LongAmount() - ShortAmount())
        if netPos < 0 and Abs(netPos) > maxPosi then
          ExitCheckShort(debugInfo)
        elseif netPos > 0 and netPos > maxPosi then
          ExitCheckLong(debugInfo)
        else 
        end
      
        GoCheckLong(debugInfo)
        GoCheckShort(debugInfo)
       
      end
      • This reply was modified 2 weeks, 2 days ago by Hedgehog.
      • This reply was modified 2 weeks, 2 days ago by Hedgehog.
      • This reply was modified 2 weeks, 2 days ago by Hedgehog.
      • This reply was modified 2 weeks, 2 days ago by Hedgehog.
    • #2685
      Hedgehog
      Basic
      Up
      0
      Down
      ::

      Thank you again for this- enlightening. What is the ‘index’ referencing in your HS?

      • #2690
        strooth
        Basic
        Up
        0
        Down
        ::

        find me on the Haas Discord channel and pm me for help
        strooth#4739

Login or Register to Comment

Unlock your crypto trading potential

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

Join for Free