PINE LIBRARY
tradeEngine

Library "tradeEngine"
calculateLiquidationPrice(entryPrice, isLong, leverage, buffer)
Parameters:
entryPrice (float)
isLong (bool)
leverage (int)
buffer (float)
calculateTPLevels(entryPrice, atr, isLong, risk)
Parameters:
entryPrice (float)
atr (float)
isLong (bool)
risk (RiskConfig)
calculateSL(entryLow, entryHigh, isLong, risk)
Parameters:
entryLow (float)
entryHigh (float)
isLong (bool)
risk (RiskConfig)
simulateTrade(highs, lows, closes, entryIdx, entryPrice, entryLow, entryHigh, entryATR, isLong, risk, maxBars)
Parameters:
highs (array<float>)
lows (array<float>)
closes (array<float>)
entryIdx (int)
entryPrice (float)
entryLow (float)
entryHigh (float)
entryATR (float)
isLong (bool)
risk (RiskConfig)
maxBars (int)
createRiskConfig(leverage, liqBuffer, useTP1, tp1ATR, useTP2, tp2ATR, useSL, slBuffer, maker, taker, slip)
Parameters:
leverage (int)
liqBuffer (float)
useTP1 (bool)
tp1ATR (float)
useTP2 (bool)
tp2ATR (float)
useSL (bool)
slBuffer (float)
maker (float)
taker (float)
slip (float)
TradeResult
Fields:
exitType (series string)
exitBarIdx (series int)
exitPrice (series float)
finalPnL (series float)
maxPnL (series float)
tp1Hit (series bool)
tp2Hit (series bool)
slHit (series bool)
liquidated (series bool)
barsInTrade (series int)
tp1Level (series float)
tp2Level (series float)
slLevel (series float)
liqLevel (series float)
RiskConfig
Fields:
leverage (series int)
liquidationBuffer (series float)
useTP1 (series bool)
tp1ATR (series float)
useTP2 (series bool)
tp2ATR (series float)
useFixedSL (series bool)
slBuffer (series float)
makerFee (series float)
takerFee (series float)
slippage (series float)
calculateLiquidationPrice(entryPrice, isLong, leverage, buffer)
Parameters:
entryPrice (float)
isLong (bool)
leverage (int)
buffer (float)
calculateTPLevels(entryPrice, atr, isLong, risk)
Parameters:
entryPrice (float)
atr (float)
isLong (bool)
risk (RiskConfig)
calculateSL(entryLow, entryHigh, isLong, risk)
Parameters:
entryLow (float)
entryHigh (float)
isLong (bool)
risk (RiskConfig)
simulateTrade(highs, lows, closes, entryIdx, entryPrice, entryLow, entryHigh, entryATR, isLong, risk, maxBars)
Parameters:
highs (array<float>)
lows (array<float>)
closes (array<float>)
entryIdx (int)
entryPrice (float)
entryLow (float)
entryHigh (float)
entryATR (float)
isLong (bool)
risk (RiskConfig)
maxBars (int)
createRiskConfig(leverage, liqBuffer, useTP1, tp1ATR, useTP2, tp2ATR, useSL, slBuffer, maker, taker, slip)
Parameters:
leverage (int)
liqBuffer (float)
useTP1 (bool)
tp1ATR (float)
useTP2 (bool)
tp2ATR (float)
useSL (bool)
slBuffer (float)
maker (float)
taker (float)
slip (float)
TradeResult
Fields:
exitType (series string)
exitBarIdx (series int)
exitPrice (series float)
finalPnL (series float)
maxPnL (series float)
tp1Hit (series bool)
tp2Hit (series bool)
slHit (series bool)
liquidated (series bool)
barsInTrade (series int)
tp1Level (series float)
tp2Level (series float)
slLevel (series float)
liqLevel (series float)
RiskConfig
Fields:
leverage (series int)
liquidationBuffer (series float)
useTP1 (series bool)
tp1ATR (series float)
useTP2 (series bool)
tp2ATR (series float)
useFixedSL (series bool)
slBuffer (series float)
makerFee (series float)
takerFee (series float)
slippage (series float)
Pine library
In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in publications is governed by House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Pine library
In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in publications is governed by House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.