Hi I'm looking for a study to be written on pine script with a few variables, long alert, short alert, and adjustable take profit percentage
$10-30 USD
Paid on delivery
I have already got my basic strategy I just wanted a variable take profit alert
So if its a buy signal the TP will be.. close[1]- open[1]/100*to inputval
But if it a short signal TP will be for short signal only
I have some of the code written my self I just a bit stuck with my take profit alert
//@version=4
study("PixMix", overlay=true)
//////////////////////////////////////
// Example buy and sell strategy
//////////////////////////////////////
source = input(close)
slowLength = input(20, "fast", minval=2,step=1)
fastLength = input(50, "slow", minval=2,step=1)
// Calculate moving averages
fastSMA = sma(source, slowLength)
slowSMA = sma(source, fastLength)
// Calculate trading conditions
buy = close<open
sell = close>open
plotshape(buy, "buy", [login to view URL], [login to view URL], [login to view URL], text="buy", textcolor=[login to view URL], editable=false)
plotshape(sell, "sell", [login to view URL], [login to view URL], [login to view URL], text="sell", textcolor=[login to view URL], editable=false)
//////////////////////////////////////
// Take profit
//////////////////////////////////////
use_tp = input(true, "Take Profit?")
tp_trigger = input(25, "Take profit %", minval=0, step=0.1, type=[login to view URL]) * 0.01
ttp_trigger = input(2, "Trailing Take Profit %", minval=0, step=0.1, type=[login to view URL]) * 0.01
// trend states
since_buy = barssince(buy)
since_sell = barssince(sell)
buy_trend = since_sell > since_buy
sell_trend = since_sell < since_buy
change_trend = (buy_trend and sell_trend[1]) or (sell_trend and buy_trend[1])
// get the entry price
entry_price = valuewhen(buy or sell, source, 0)
// is take profit triggered?
var tp_price_trigger = -0.0
var is_tp_trigger_hit = false
var tp_trail = 0.0
tp_close_long = false
tp_close_short = false
if use_tp
// If the trend changed, then reset the trigger
if change_trend
// calculate take profit trigger value
tp_price_trigger := close[1]-open[1]/100*tp_trigger
is_tp_trigger_hit := false
// tp_close_long := false
// tp_close_short := false
if buy[1]
// Is the take profit long price trigger hit?
is_tp_trigger_hit := (high >= tp_price_trigger) or (not change_trend and is_tp_trigger_hit[1])
// calculate take profit long trail
tp_trail := max(high, change_trend ? tp_price_trigger : tp_trail[1])
tp_close_long := (is_tp_trigger_hit and (high <= tp_trail * (1.0 - ttp_trigger))) or (not change_trend and tp_close_long[1])
else if sell[1]
// Is the take profit short price trigger hit?
is_tp_trigger_hit := (low >= tp_price_trigger) or (not change_trend and is_tp_trigger_hit[1])
// calculate take profit short trail
tp_trail := min(low, change_trend ? tp_price_trigger : tp_trail[1])
tp_close_short := (is_tp_trigger_hit and (low >= tp_trail * (1.0 + ttp_trigger))) or (not change_trend and tp_close_short[1])
/ display take profit trigger
plot(use_tp and tp_price_trigger != -1.0 ? tp_price_trigger : na,
title='Take Profit Price Trigger', color=[login to view URL],
style=plot.style_cross, linewidth=3)
plotshape(tp_close_long and not tp_close_long[1], "L/EX", [login to view URL],
[login to view URL], [login to view URL], text="L/EX", textcolor=[login to view URL], editable=true)
plotshape(tp_close_short and not tp_close_short[1], "S/EX", [login to view URL],
[login to view URL], [login to view URL], text="S/EX", textcolor=[login to view URL], editable=true)
alertcondition(condition = close<open, title = 'buy', message = ' - long')
alertcondition(condition = close>open, title = 'sell', message = ' - sell')
//take profit allert
alertcondition(condition = close[1]-open[1]/100*tp_trigger, title = 'Take profit buy', message = ' - take profitbuy')
Project ID: #31759713
About the project
2 freelancers are bidding on average $83 for this job
If you are looking to develop website with a captivating design to strengthen your business or to enlarge your market through web server then you are on the right place. I give webpage design and development administr More