Gunbot's AutoConfig supports percentage-based comparisons between two ledger keys using the differenceBigger and differenceSmaller filters. These filters help measure relative change, such as price vs. average buy price or a gap between two indicators stored in the ledger.
Nearly every option that follows can be set without editing files by hand.
Click the ⋮ (three-dots) menu ➜ AutoConfig, step through the wizard, and press Save; it will write a correct autoconfig.json for you.
Calculating Relative Change with Difference Filters
The differenceBigger and differenceSmaller filters measure how much one ledger value has changed relative to another, expressed as a percentage. The calculation is typically:
Percentage Difference = ((Value of Ledger Key 2 - Value of Ledger Key 1) / abs(Value of Ledger Key 1)) * 100
(Note: Implementations can vary slightly, especially around the use of abs() or division-by-zero handling. Treat this as a percentage change from Key1 to Key2.)
These filters are used in AutoConfig jobs that process existing pairs (for example, manageOverrides).
Filter Types and Configuration
filterType: "differenceBigger"- Purpose: Passes if the calculated percentage difference (LedgerKey2 relative to LedgerKey1) is greater than a specified delta percentage.
- Logic:
((LKV2 - LKV1) / abs(LKV1)) * 100 > deltaPercent - Example: Check if the current Bid price (
Bid) is more than 2% above the average buy price (ABP).This passes if"profitMarginCheck": {
"filterType": "differenceBigger",
// The first field name's value is Ledger Key 1 (base for comparison)
"averageBuy": "ABP",
// The second field name's value is Ledger Key 2 (value being compared)
"currentBidPrice": "Bid",
// The third field name's value is the delta percentage
"minProfitPct": 2
}((this.pair.Bid - this.pair.ABP) / abs(this.pair.ABP)) * 100 > 2.0. The keysaverageBuy,currentBidPrice, andminProfitPctare descriptive; their values ("ABP","Bid",2) are what AutoConfig uses.
filterType: "differenceSmaller"- Purpose: Passes if the calculated percentage difference is less than a specified delta percentage.
- Logic:
((LKV2 - LKV1) / abs(LKV1)) * 100 < deltaPercent - Example: Check if the current Bid price (
Bid) has dropped by less than 1.5% from theABP(i.e., it hasn't dropped much, or has even gone up).This filter passes if"smallDropOrProfit": {
"filterType": "differenceSmaller",
"buyReference": "ABP", // Ledger Key 1
"priceToCheck": "BID", // Ledger Key 2
"maxAcceptableDropPct": -1.5 // Delta: Note the negative for a drop
// This actually checks if Bid is NOT more than 1.5% BELOW ABP
// So, if Bid is (ABP * 0.984), diff is -1.6%, fails.
// If Bid is (ABP * 0.99), diff is -1.0%, passes.
}((this.pair.Bid - this.pair.ABP) / abs(this.pair.ABP)) * 100 < -1.5. A more intuitive way to check if price is "not too far below" a reference isdifferenceBiggerwith a negative delta, such asdeltaPercent: -1.5.
General Configuration Structure: An AutoConfig job using these filters would look like:
{
"relativeChangeTrader": {
"enabled": true,
"type": "manageOverrides",
"schedule": "*/3 * * * *",
"pairs": { /* ... */ },
"filters": {
"significantProfitRealized": {
"filterType": "differenceBigger",
"ledgerKey1_avgCost": "ABP", // Base value for comparison
"ledgerKey2_currentPrice": "Bid", // Value to check
"delta_TargetPercent": 3.0 // Required percentage difference
}
},
"overrides": { /* Apply overrides if Bid is >3% above ABP */ }
}
}
The keys for the ledger fields and the delta (for example, ledgerKey1_avgCost, delta_TargetPercent) are for readability. AutoConfig interprets the two ledger keys and the delta based on the values you supply.
Common Ledger Keys for Difference Calculation
These filters work best with numerical ledger keys, such as:
Bid,Ask,ABP
Use Cases
Profit/Loss Thresholds:
differenceBiggerwithABP(key1) andBid(key2) to check if current price is X% above average cost.differenceSmallerwithABP(key1) andBid(key2) and a negative delta to check if price has dropped more than X% below average cost (potential stop-loss condition).
Indicator Spread/Convergence:
- If your strategy stores moving average values like
ema1andema2in the ledger:- Use
differenceBiggerwithema2(key1) andema1(key2) and a small positive delta (e.g., 0.1%) to confirm a bullish MA cross where the fast MA is clearly above the slow MA. - Use
differenceSmallerwithema1(key1) andema2(key2) and a small positive delta (e.g., 0.05%) to find MAs that are very close (converging).
- Use
- If your strategy stores moving average values like
Distance from price levels:
- Check if
BidisdifferenceBiggerby X% fromlowBB(if available in ledger) to see if price has bounced significantly off a lower band.
- Check if
Important Notes
- Numerical values: Both ledger keys must resolve to numbers for the calculation to be meaningful.
- Order of keys matters:
((LKV2 - LKV1) / abs(LKV1)) * 100measures change relative to LKV1. Swapping them flips the sign and meaning. - Division by zero: If Ledger Key 1 (
LKV1) is zero, the calculation can fail. Keep this in mind for values likeABPthat may be zero. - Descriptive parameter keys: Readable keys (like
baseValueForCalc,comparedValue,percentageThreshold) make AutoConfig JSON easier to maintain.
The differenceBigger and differenceSmaller filters let you apply percentage-based logic to ledger values without writing custom JavaScript for common comparisons.