JSFiddle - React, Tailwind, and code Playground
JavaScript
// simulator for stepgridhedge exponential buydown
// strategy info: https://wiki.gunthy.org/trading-strategy-options/futures/stepgridhedge/
// enter your values and hit 'run' to get the results in the console window
// settings to simulate position
const type = 'LONG' // or 'SHORT'
const bid = 60 // set current price
const ABP = 50 // set avg entry price for long position
const ABP_s = 50 // set avg entry price for short position
const howManyTL = 10 // set 'buy count' for long position
const howManyTL_s = 10 // set 'buy count' for short position
const step = 2 // set absolute step size
// set buydown exponent (default: 0.5)
const buydownExponent = 0.5
// prevent dca too close around entry, no dca zone increases when position size grows
const entry = type === 'LONG' ? ABP : ABP_s
const howMany = type === 'LONG' ? howManyTL : howManyTL_s
const noDcaZone = step * Math.pow(howMany, buydownExponent)
const enoughDifference = type === 'LONG' ? bid < entry - noDcaZone : bid > entry + noDcaZone
console.log('noDcaZone from avg entry: ', noDcaZone)
console.log('dca allowed at current price', enoughDifference)