need help whit an indicator
#5
If you want to try my transformation into that indicator's strategy. Unfortunately, the openings of the operations take place at the closing of the previous candles (obviously) and this is the difference between automatic strategies and indicators. Of course, I do not know if my code is correct, I'm just an amateur, maybe the experts of this forum will be able to improve my work ...

However, for me, the outcome is not bad on high timeframe (Daily / 4 hours), even if I did not have time to find optimized parameters ...


Code:
//@version=3
Code:
//
// @author LazyBear  -> (mod)
//
// If you use this code in its original/modified form, do drop me a note.
//
strategy("WaveTrend with Crosses [LazyBear] mod",pyramiding = 0, shorttitle="WT_CROSS_LB mod",
    initial_capital = 10000,
        currency = "EUR",
            default_qty_type = strategy.percent_of_equity,
                default_qty_value = 100,
                    commission_type = strategy.commission.percent,
                        commission_value = 0.1,
                            overlay=true)

FromYear  = input(title = "From Year", type = integer, defval = 2018, minval = 2011, maxval = 2050)
FromMonth = input(title = "From Month", type = integer, defval = 2, minval = 1, maxval = 12)
FromDay   = input(title = "From Day", type = integer, defval = 6, minval = 1, maxval = 31)
ToYear    = input(title = "To Year", type = integer, defval = 2050, minval = 2011, maxval = 2050)
ToMonth   = input(title = "To Month", type = integer, defval = 12, minval = 1, maxval = 12)
ToDay     = input(title = "To Day", type = integer, defval = 31, minval = 1, maxval = 31)

start = timestamp(FromYear, FromMonth, FromDay, 00, 00)
finish = timestamp(ToYear, ToMonth, ToDay, 23, 59)
itsTime = time >= start and time < finish ? true : false

n1 = input(10, "Channel Length")
n2 = input(21, "Average Length")
LongEntryLevel = input(-50, "Long Entry Level")
LongExitLevel = input(30, "Long Exit Level")
ShortEnabled = input (title="Short Enabled?", defval = false)
ShortEntryLevel = input(50, "Short Entry Level")
ShortExitLevel = input(-30, "Short Exit Level")

Stoploss = input(0, "StopLoss % (0=disabled)", type=float)/100
Takeprofit = input(0, "TakeProfit % (0=disabled)", type=float)/100


ap = hlc3
esa = ema(ap, n1)
d = ema(abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * d)
tci = ema(ci, n2)

wt1 = tci
wt2 = sma(wt1,4)

plot(0, color=gray, title="zeroline")
plot(LongEntryLevel, color=green, title="LongEntryLevel")
plot(LongExitLevel, color=red, title="LongExitLevel")
plot(ShortEntryLevel, color=green, title="ShortEntryLevel")
plot(ShortExitLevel, color=red, title="ShortExitLevel")

plot(wt1, color=green, title="wt1")           // media verde
plot(wt2, color=red, title="wt2")             // media rossa
diff = wt1-wt2                                // differenza fra le due medie
plot(diff, color=blue, style=area, transp=80, title="wt1-wt2")
plot(cross(wt1, wt2) ? wt2 : na, color = black , style = circles, linewidth = 3)
plot(cross(wt1, wt2) ? wt2 : na, color = (diff < 0 ? red : lime) , style = circles, linewidth = 2)
barcolor(cross(wt1, wt2) ? (diff < 0 ? aqua : yellow) : na)

// Operatività
LongCondition = crossover(wt1,wt2) and wt2 < LongEntryLevel
ExitLongCondition = wt2 > LongExitLevel
ShortCondition = crossunder(wt1,wt2) and wt2 > ShortEntryLevel
ExitShortCondition = wt2 < ShortExitLevel

stoploss_level_long = Stoploss > 0 ? strategy.position_avg_price * (1 - Stoploss) : na
stoploss_level_short = Stoploss > 0 ? strategy.position_avg_price * (1 + Stoploss) : na
takeprofit_level_long = Takeprofit > 0 ? strategy.position_avg_price * (1 + Takeprofit) : na
takeprofit_level_short = Takeprofit > 0 ? strategy.position_avg_price * (1 - Takeprofit) : na

if (itsTime)
   strategy.entry(id="Long",long=true,when=LongCondition)
   strategy.close(id="Long",when=ExitLongCondition)
   strategy.exit(id="Long SL/TP", from_entry = "Long", limit = takeprofit_level_long, stop = stoploss_level_long)
   if (ShortEnabled)
       strategy.entry(id="Short",long=false,when=ShortCondition)
       strategy.close(id="Short",when=ExitShortCondition)
       strategy.exit(id="Short SL/TP", from_entry = "Short", limit = takeprofit_level_short, stop = stoploss_level_short)


ps. : thx Askmike for whitelist ;-)
  Reply


Messages In This Thread
need help whit an indicator - by fraser - 10-11-2018, 11:14 PM
RE: need help whit an indicator - by mark.sch - 10-12-2018, 09:48 AM
RE: need help whit an indicator - by fraser - 10-12-2018, 03:17 PM
RE: need help whit an indicator - by mark.sch - 10-12-2018, 03:49 PM
RE: need help whit an indicator - by Nigry - 10-16-2018, 06:43 AM

Forum Jump:


Users browsing this thread: