I'm new to Pine Scripts and I'm trying to write a Strategy to test a new Indicator, the below is my code
if Up and (downbefore == true)
strategy.entry("buy",strategy.long,1000000)
strategy.exit("Exit buy", from_entry="buy", profit = 150000, loss = 10000, trail_points = 5000, trail_offset = 100)
upbefore := true
downbefore := false
if Down and (upbefore == true)
strategy.entry("Sell",strategy.short,1000000)
strategy.exit("Exit sell", from_entry="Sell", profit = 150000, loss = 10000, trail_points = 5000, trail_offset = 100)
upbefore := false
downbefore := true
- I want to ask the behavior of profit and loss each and everytime the price hit 100, and hit 5000 unit of profit.
- Will the loss value change from 100000 to 50000 and then 0 if the price hit the 50000 100000 150000 unit?
- and if so, what will the trail_offset do on this fomular? and how will it affect the profit and loss when the price hit 50000 100000 150000 unit?
I did read the document at https://www.tradingview.com/pine-script-reference/v5/ but it is difficult for me to visualize how it work in the real situation.
- If possible, please give me an example of how it works. Thank alot.
- NOTE: it is hard for me since there is the theory of trail_price also, it is almost the same as trail_point to the point I can not say the different, since we just need to add the executed_price with point and we will get the price on trail_price, so why bother using trail_price? why we must have 2 of them, both trail_price and trail_point?
You nailed it "trail_price" is for specifying a which exact price the trailing should start "trail_point" does the same and requires a number of ticks/pips/usd away from the entry to start We have to use either one, not both at the same time - the one to use depends on your strategy code logic
2/
The way I understand it When your long reaches 5000 pips in profit, then the trailing stop activates and at every 100 pips increment from there, the trailing will move 100 pips higher too. There will be a 100 pips difference between the highest point reached by your trade and the trailed stop loss.
3/The best way to understand what's going on is to plot your stop loss. There are plenty of trailing stop loss + trailing stop loss trigger price activation examples in the open-source library. You could use one of those