0bps

Strategy vault / DCA & fixed investment

Fixed Investment and Take Profit Script

Pine Script strategy by Zer3192.

Author
Zer3192
Complexity
Starter · 25 lines
Parameters
2

The original spec has no written description. Read the source below.

Parameters

NameDefaultWhat it controls
v_input_15Maximum loss percentage
v_input_23Take profit value

Source Pine Script

//@version=4

strategy("Regular Investment Profit Taking", overlay=true)

//Define the maximum loss percentage
maxLossPercent = input(title="Maximum loss percentage", type=float,defval=5)

//Define take-profit number
stopProfitVal = input(title="Take profit value", type=float, defval=3) 

//The main contract holds a long position
longCondition = crossover(open, close) //The main contract goes long by breaking through the closing price horizontally at the opening price

if (longCondition)
    strategy.entry("Long", strategy.long, comment="Open Long") 

//Stop-loss condition
//if (strategy.position_size > 0)  
    //strategy.exit("Exit long", stop=strategy.position_avg_price * (1 - maxLossPercent/100)) 

//Profit Taking Conditions
profitExit = strategy.position_avg_price + stopProfitVal
if (strategy.position_size > 0)
     strategy.exit("Exit long", limit = profitExit)

Published by Zer3192 on the FMZ strategy square · last modified 2023-01-29. 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.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Fixed-Investment-and-Take-Profit-Script.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. 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

esc

Try , , or .

↑↓ move↵ open