pshaiKo_MadHatter testing123
stableDescription
"pshaiKo_b" MadHatter -
Some mods.. a working work in progress..
added essentials:
ProfitTrailerQuiet:
https://www.haasscripts.com/t/haasbot-essentials-ptq-profittrailer-quiet-inputs-trailstart-2-traildistance-0-6/
[Kobalt updated sorted] Mad Hatter Indicators: v2.1
MHB BBands v2
https://www.haasscripts.com/t/kob-advanced-mad-hatter-indicatorsbbands/
MHB RSI v2
https://www.haasscripts.com/t/kob-advanced-mad-hatter-indicators/
MHB MACD v2
https://www.haasscripts.com/t/kob-advanced-mad-hatter-indicators-macd/
HaasScript
EnableHighSpeedUpdates(true)
HideOrderSettings()
-- market compatibility
local isSpot = MarketType() == SpotTrading
local buy_cmd = isSpot and PlaceBuyOrder or PlaceGoLongOrder
local sell_cmd = isSpot and PlaceSellOrder or PlaceGoShortOrder
InputGroupHeader('Entering')
maxEntries = Input(' Max. Entries', 10, 'The maximum amount of entries allowed per position')
entryTimeLimit = Input(' Entry Cooldown', 10, 'Entry cooldown in minutes. Use this to ensure bot doesn\'t consume all entries on consecutive signals (unless that is wanted behavior). Set this to zero to ignore')
entryOrderType = InputOrderType(' Order Type', MakerOrCancelOrderType)
entryOrderOffset = Input( 'Order depth offset %', 0.07 , 'Offset from best bid - ask')
entryTimeout = Input('Order Timeout', 777, 'Entry order timeout in minutes')
InputGroupHeader('Exiting')
exitOrderType = InputOrderType('Exit Order Type', MakerOrCancelOrderType)
exitTimeout = Input('Exit Order Timeout', 10, 'Exit order timeout in minutes')
stopLoss = Input('Stop Loss (%)', 0)
--takeProfit = Input('3. Take Profit (%)', 1)
safeties = SafetyContainer(StopLoss(stopLoss), CC_ProfitTrailerQ(2, 0.5))
-- Indicatora
InputGroupHeader('MHB Indicator Settings')
consensus = Input(' Indicator Consensus', true)
--InputGroupHeader('MadHatterBBands')
bbandResult = CC_MadHatterBBandsv2(0, '')
--InputGroupHeader('MadHatter MACD')
macdResult = CC_MadHatterMACDv2(1, '')
--InputGroupHeader('MadHatter RSI')
rsiResult = CC_MadHatterRSIV2(2, '')
indicatorContainer = IndicatorContainer(
bbandResult,
macdResult,
rsiResult
)
indicatorSignal = indicatorContainer[1]
if consensus then
indicatorSignal = indicatorContainer[2]
end
-- Insurances
insurances = InsuranceContainer(OvercomeFeeCosts())
-- useful data
local cp = CurrentPrice()
local botPos = GetPositionDirection()
local botRoi = GetPositionROI()
local entryCount = Load('ec', 0)
-- entry logic function
local updateEntryLogic = function(isLong)
local orderId = Load('en_oid', '')
local remaining = 0
local cmd = isLong and buy_cmd or sell_cmd
if orderId != '' then
local order = OrderContainer(orderId)
if order.isOpen then
return -- nothing to do
else
remaining = order.executedAmount - order.filledAmount
if order.isFilled and remaining == 0 then
-- increment entryCount
entryCount = entryCount + 1
end
orderId = ''
end
end
if entryCount < maxEntries then
local price = isLong and SubPerc(cp.bid, entryOrderOffset) or AddPerc(cp.ask, entryOrderOffset)
local amount = remaining == 0 and TradeAmount() or remaining
local note = (isLong and 'L' or 'S') .. (entryCount + 1)
if IsTradeAmountEnough(PriceMarket(), price, amount, true) then
-- place order
orderId = cmd(price, amount, {type = entryOrderType, note = note, timeout = entryTimeout})
end
end
Save('en_oid', orderId)
end
-- exit logic function
local updateExitLogic = function(isProfit)
local orderId = Load('ex_oid', '')
local remaining = 0
if orderId != '' then
local order = OrderContainer(orderId)
if order.isOpen then
return -- nothing to do
else
remaining = order.executedAmount - order.filledAmount
if order.isFilled and remaining == 0 then
-- reset entryCount since we exited successfully
entryCount = 0
end
orderId = ''
end
end
local note = isProfit and 'Take-Profit Trailer' or 'Stop-Loss'
-- place order
orderId = PlaceExitPositionOrder({type = exitOrderType, note = note, timeout = exitTimeout})
Save('ex_oid', orderId)
end
-- the new logic
if insurances and (entryTimeLimit == 0 or TradeOncePerBar(entryTimeLimit)) then
-- having botRoi in the rules will make sure we don't
-- increase position size in the profitable direction.
-- we only want to add to the position when we are on
-- the losing side, to ensure our DCA/AvgEP moves only
-- outwards - not inwards!
if indicatorSignal == SignalBuy
and botPos != PositionShort
and botRoi <= 0 then
updateEntryLogic(true)
elseif indicatorSignal == SignalSell
and botPos != PositionLong
and botRoi <= 0 then
updateEntryLogic(false)
end
end
-- safeties
if safeties and botPos != NoPosition then
updateExitLogic(botRoi > 0)
end
-- Save memory
Save('ec', entryCount)
-- Reports
Finalize(function()
CustomReport('BBands Signal', bbandResult)
CustomReport('MACD Signal', macdResult)
CustomReport('RSI Signal', rsiResult)
CustomReport('Entry Count', entryCount)
end)
0 Comments
Sign in to leave a comment.
No comments yet. Be the first!