[bot] Signal Trigger with Multiple Positions

5 3544 Views 6 Comments 250 Tipped Credits 3 years ago
    • #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
    • #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

    • #3169
      Up
      1
      Down
      ::

      Another great script! Thanks!

      250 HaasScript Credits
    • #3302
      Mihail
      Basic
      Up
      0
      Down
      ::

      When using the script Signal Trigger with Multiple Positions, an error occurs on Binance:
      WARNING: Order has failed to execute. Reason: Parameter ‘reduceOnly’ sent when not required. (Exchange error code: -1106)

      Tell me please, I just need to remove the only parameter in the code or replace it with another one, because is it really not possible to place orders with reduce only on binance in the web version?
      Here is the piece of code:

      if allowshort then
      if And(ShortOID == ”, shortsignal == SignalShort, checkdelta(false, Max(LastShortPrice(), GetPositionEnterPrice(ShortPosId)), spreadk)) then
      params.positionId = ShortPosId; params.note = ‘Go Short – ‘..ShortPosId; params.reduceOnly = false
      CC_getOID(false, k, PlaceGoShortOrder(getprice(false, false, k), TradeAmount(), params))
      elseif And(allowshortx, ShortOID == ”, shortsignal == SignalExitShort, checkdelta(true, Min(LastExitShortPrice(), GetPositionEnterPrice(ShortPosId)), spreadk)) then
      params.positionId = ShortPosId; params.note = ‘Exit Short – ‘..ShortPosId; params.reduceOnly = true
      CC_getOID(false, k, PlaceExitShortOrder(getprice(false, true, k), TradeAmount()/xdivs, params))
      end
      end
      if allowlong then
      if And(LongOID == ”, longsignal == SignalLong, checkdelta(true, Min(LastLongPrice(), GetPositionEnterPrice(LongPosId)), spreadk)) then
      params.positionId = LongPosId; params.note = ‘Go Long – ‘..LongPosId; params.reduceOnly = false
      CC_getOID(true, k, PlaceGoLongOrder(getprice(true, false, k), TradeAmount(), params))
      elseif And(allowlongx, LongOID == ”, longsignal == SignalExitLong, checkdelta(false, Max(LastExitLongPrice(), GetPositionEnterPrice(LongPosId)), spreadk)) then
      params.positionId = LongPosId; params.note = ‘Exit Long – ‘..LongPosId; params.reduceOnly = true
      CC_getOID(true, k, PlaceExitLongOrder(getprice(true, true, k), TradeAmount()/xdivl, params))
      end

    • #3435
      AlesVrto
      Basic
      Up
      0
      Down
      ::

      Script error.What should i change here?Where to copy and paste CC_getPID and CC_getOID scripts?

      ERROR: – CC_getPID
      ERROR: – CC_getOID
      ERROR: Unknown references:

      Finally I figure out. You need to create custom scripts to work properly.

    • #3558
      AlesVrto
      Basic
      Up
      0
      Down
      ::

      Can you write settings for this bot?

Login or Register to Comment

Unlock your crypto trading potential

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

Join for Free