0

So i currently cannot figure out how to add variable savepoints via the input fields. For example i want to enter a trade on a signal i declare (this is working). After this point i have lets say 5 variable save points in percentage values: 1%, 2%, 2,5%... If the value goes above the entry price + the % profit activate savepoint 1 and lets say autosell if the value falls below the savepoint -0,1%

Just an dummy example with a running trade | ETH/USDT:

Investement: 100$
Initial Crypto Price: 1000
Selling Crypto Price: 1020
Investment Fee: 0%
Exit Fee: 0,1%

Savepoint1: 0,7%
Savepoint2: 1,3%
Savepoint3: 2,2$
Savepoint4: 3,1%
Savepoint5: 4%

Profit would be currently 1,9% so the last Savepoint where it would automatically sell would be Savepoint 2 at 1,2% profit (SP1 - 0,1%)

This is the code snipped i have so far..

// Savepoints
SP1 = input.float(title="Savepoint 1", defval=0.6, minval=0, maxval=100)
SP2 = input.float(title="Savepoint 2", defval=1.2, minval=0, maxval=100)

var entryPrice = close

if tradeSignal
    strategy.entry("Enter Long", strategy.long)
    entryPrice := close
if close >= entryPrice + (entryPrice * SP1)
    if close <= entryPrice + (entryPrice * (SP2 - 0.1))
        strategy.exit(id="SP2", from_entry = "Enter Long", limit = entryPrice*(1+(SP2-0.1)/100))
    if close <= entryPrice + (entryPrice * (SP1 - 0.1))
        strategy.exit(id="SP1", from_entry = "Enter Long", limit = entryPrice*(1+(SP1-0.1)/100))
slake
  • 1
  • 1

1 Answers1

0

Your entryPrice is not good, you record the strategy.position_avg_price before entering the trade.
Your SP1 is a percentage and you compare it to a price... Can't work
You should use :

SP1 = 0.7
entryPrice = close
strategy.entry("Enter Long", strategy.long, limit=close)
if close >= SP1 and close <SP2
    Strategy.exit(id="SP1", from_entry = "Enter Long", limit = entryPrice*(1+(SP1-0.1)/100)
G.Lebret
  • 2,826
  • 2
  • 16
  • 27
  • Sorry, i adjusted the code in the OP – slake Nov 30 '22 at 14:24
  • @slake In your code, you use tradeSignal to open your position. Are you sure, once a strategy.enter is done = once a position is open, that tradeSignal won't go to true again ? – G.Lebret Dec 01 '22 at 01:12