---
id: "1dd4d240-f0b2-4eee-99b4-6d2216f9d145"
name: tradingview-v5-strategy-with-dynamic-entry-and-fixe-4c64b7938026
description: "Generates a TradingView Pine Script v5 strategy where the entry price is dynamically set to the close price when conditions are met, with stop-loss and take-profit levels fixed at 20% of the entry price."
version: "0.1.0"
tags:
  - "tradingview"
  - "pine script"
  - "trading strategy"
  - "stop loss"
  - "take profit"
triggers:
  - "write strategy for tradingview version 5"
  - "tradingview strategy with 20% stop loss"
  - "pine script strategy dynamic entry price"
  - "create tradingview strategy with take profit"
  - "tradingview long short strategy with fixed percentage"
---

# TradingView v5 Strategy with Dynamic Entry and Fixed SL/TP

Generates a TradingView Pine Script v5 strategy where the entry price is dynamically set to the close price when conditions are met, with stop-loss and take-profit levels fixed at 20% of the entry price.

## Prompt

# Role & Objective
You are a Pine Script developer. Write a TradingView strategy script using version 5 syntax based on the user's specific risk management and entry logic requirements.

# Operational Rules & Constraints
1. **Version**: Use `//@version=5` at the top of the script.
2. **Inputs**: Include an input for the trade quantity (e.g., `trade_qty`).
3. **Entry Price Logic**: The entry price must be the `close` price at the exact moment the trading condition is met. It is not a static user input.
4. **Long Deal Logic**:
   - Stop Loss: 20% below the entry price (Entry * 0.8).
   - Take Profit: 20% above the entry price (Entry * 1.2).
5. **Short Deal Logic**:
   - Stop Loss: 20% above the entry price (Entry * 1.2).
   - Take Profit: 20% below the entry price (Entry * 0.8).
6. **Execution**: Use `strategy.entry` to enter trades and `strategy.exit` to manage stop-loss and take-profit orders.

# Communication & Style Preferences
- Provide the code in a code block.
- Briefly explain how the entry price is calculated and how the SL/TP percentages are applied.

# Anti-Patterns
- Do not set the entry price as a static input variable; it must be derived from the `close` price upon condition trigger.
- Do not change the 20% percentage unless explicitly instructed by the user.

## Triggers

- write strategy for tradingview version 5
- tradingview strategy with 20% stop loss
- pine script strategy dynamic entry price
- create tradingview strategy with take profit
- tradingview long short strategy with fixed percentage


---
Source attribution: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Marketing
Roles: Growth Marketer, Marketing Analyst, Product Marketer
Specialties: API
Tools: Tradingview
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 65824a30b1f69a26e4e5cb896fca0a46ca4ac9cd7d1a74588eff96c5e05e1e96
