0bps

Strategy vault / Other

BTC bot

Pine Script strategy by Zer3192.

Pine ScriptOtherRSIEMA
Author
Zer3192
Complexity
Intermediate · 70 lines
Parameters
12
Backtest bar
4h · intraday

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

Parameters

NameDefaultWhat it controls
v_input_10Strategy Direction: long | short | all
v_input_2WhigherTF
v_input_32factor
v_input_421length
v_input_515stop loss
v_input_625qty_percent1
v_input_725qty_percent2
v_input_825qty_percent3
v_input_93Take profit1
v_input_105Take profit2
v_input_117Take profit3
v_input_1210Take profit4

Source Pine Script

/*backtest
start: 2022-05-28 00:00:00
end: 2022-08-28 00:00:00
period: 4h
basePeriod: 15m
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RafaelZioni


// © theCrypster 2020

//@version=4
strategy(title = "BTC bot", overlay = true, pyramiding=1,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.075)
strat_dir_input = input(title="Strategy Direction", defval="long", options=["long", "short", "all"])
strat_dir_value = strat_dir_input == "long" ? strategy.direction.long : strat_dir_input == "short" ? strategy.direction.short : strategy.direction.all
strategy.risk.allow_entry_in(strat_dir_value)
//INPUTS
higherTF = input("W", type=input.resolution)
pc = security(syminfo.tickerid, higherTF, close[1], lookahead=true)
ph = security(syminfo.tickerid, higherTF, high[1], lookahead=true)
pl = security(syminfo.tickerid, higherTF, low[1], lookahead=true)

PP = 0.0,R1 = 0.0, R2 = 0.0, R3 = 0.0,S1 = 0.0, S2 = 0.0, S3 = 0.0

PP := (ph + pl + pc) / 3
R1 := PP     + (PP   - pl)
S1 := PP     - (ph - PP)
R2 := PP     + (ph - pl)
S2 := PP     - (ph - pl)
factor=input(2)
R3 := ph  + factor * (PP   - pl) 
S3 := pl   - 2 * (ph - PP) 

// 
length=input(21)
//
p = close
vrsi = rsi(p, length)
pp=ema(vrsi,length)
d=(vrsi-pp)*5
cc=(vrsi+d+pp)/2
//
low1=crossover(cc,0)

sell=crossover(close[1],R3) 
//
l = low1
s=sell
if l 
    strategy.entry("buy", strategy.long)
if s 
    strategy.entry("sell", strategy.short)
per(pcnt) =>
    strategy.position_size != 0 ? round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)
stoploss=input(title=" stop loss", defval=15, minval=0.01)
los = per(stoploss)
q1=input(title=" qty_percent1", defval=25, minval=1)
q2=input(title=" qty_percent2", defval=25, minval=1)
q3=input(title=" qty_percent3", defval=25, minval=1)
tp1=input(title=" Take profit1", defval=3, minval=0.01)
tp2=input(title=" Take profit2", defval=5, minval=0.01)
tp3=input(title=" Take profit3", defval=7, minval=0.01)
tp4=input(title=" Take profit4", defval=10, minval=0.01)
strategy.exit("x1", qty_percent = q1, profit = per(tp1), loss = los)
strategy.exit("x2", qty_percent = q2, profit = per(tp2), loss = los)
strategy.exit("x3", qty_percent = q3, profit = per(tp3), loss = los)
strategy.exit("x4", profit = per(tp4), loss = los)

Published by Zer3192 on the FMZ strategy square · last modified 2022-08-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/BTC-bot.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