Strategy vault / DCA & fixed investment
Dollar Cost Averaging Strategy with Take Profit
Pine Script strategy by Zer3192.
Pine ScriptDCA & fixed investment
The original spec has no written description. Read the source below.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 100 | Investment Amount |
| v_input_2 | 0 | Investment Period: W | M |
| v_input_3 | 0.2 | Stop loss percentage |
| v_input_4 | 0.1 | Take profit percentage |
Source Pine Script
/*backtest
start: 2022-10-18 00:00:00
end: 2023-10-24 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("Weekly Dollar Cost Averaging", overlay=true,pyramiding = 5)
// Define investment amount and investment period
investmentAmount = input(100, title="Investment Amount")
investmentPeriod = input("W", title="Investment Period", options=["W", "M"])
// Stop loss percentage
stopLossPercentage = input(0.2, title="Stop loss percentage")
// Take profit percentage
takeProfitPercentage = input(0.1, title="Take profit percentage")
// Calculate stop loss and take profit levels
stopLossLevel = strategy.position_avg_price * (1 - stopLossPercentage/100)
takeProfitLevel = strategy.position_avg_price * (1 + takeProfitPercentage/100)
// Define buy conditions
buyCondition = investmentPeriod == "W" ? change(strategy.position_size) >= 0 : change(strategy.position_size) <= 0
// Calculate buy quantity
buyQuantity = buyCondition ? investmentAmount / close : 0
// Execute buy operation
strategy.entry("Buy", strategy.long, qty=buyQuantity)
//Profit Taking Conditions
if (close>= takeProfitLevel) and (strategy.position_size > 0)
strategy.close_all()
else
if(close<=stopLossLevel) and (strategy.position_size<0)
strategy.close_all()
// Print buy information
plotshape(buyCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="Buy")
// Print holding information
plot(strategy.position_size > 0 ? strategy.position_size : na, title="Position Size", color=color.blue, style=plot.style_line, linewidth=2)
Published by Zer3192 on the FMZ strategy square · last modified 2023-10-25. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Dollar-Cost-Averaging-Strategy-with-Take-Profit.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- Dollar Cost Averaging Investment StrategyPine Script · DCA & fixed investment · 1d
- Dynamic DCA based Cryptocurrency Quantitative Trading StrategyPine Script · DCA & fixed investment · 1h
- Dynamic Position Building StrategyPine Script · DCA & fixed investment · 1h
- Fibonacci Zone DCA StrategyPine Script · DCA & fixed investment · 1d
- Multi Indicator Confirmation EMA Breakout with DCA and Dynamic Take Profit StrategyPine Script · DCA & fixed investment · 1d
- Bollinger Band and RSI Mixing with DCA StrategyPine Script · DCA & fixed investment · 1d