-
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— Author – Strooth – Find me on discord – strooth#4739
— Feel free to donate to support my work or if my script helped you in any way <3
— BTC Adress: 33MsEAbA8tg7SpohgnCpSrmPTBih2UkhxQ
—Related Scripts From This Author
-
-
November 10, 2021 at 11:05 AM #2680HedgehogBasic::
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
-
November 10, 2021 at 11:28 AM #2685HedgehogBasic
-
November 10, 2021 at 6:39 PM #2690
-
-
July 19, 2022 at 5:40 PM #3169Team HaasScriptsAdmin
-
November 1, 2022 at 2:09 PM #3302MihailBasic::
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 -
April 15, 2023 at 1:55 PM #3435
-
November 9, 2023 at 9:29 PM #3558
-