-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1h-ethbusd.pine
86 lines (65 loc) · 3.49 KB
/
1h-ethbusd.pine
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//@version=2
strategy("1H_ETHBUSD_CDC_ATR", overlay=true, precision=4, calc_on_every_tick=true, max_bars_back=2000, initial_capital=100)
/////////notes////////////////////////////////////////
// This is based on the ATR trailing stop indicator //
// width addition of two levels of stops and //
// different interpretation. //
// This is a fast-reacting system and is better //
// suited for higher volatility markets //
//////////////////////////////////////////////////////
SC = input(close,"data array",source) // data array
// Fast Trail //
AP1 = input(4,"fast ATR period",integer) // ATR Period
AF1 = input(0.5,"fast ATR multiplier",float) // ATR Factor
SL1 = AF1*atr(AP1) // Stop Loss
Trail1 = iff(SC>nz(Trail1[1],0) and SC[1]>nz(Trail1[1],0),max(nz(Trail1[1],0),SC-SL1),iff(SC<nz(Trail1[1],0) and SC[1]<nz(Trail1[1],0),min(nz(Trail1[1],0),SC+SL1),iff(SC>nz(Trail1[1],0),SC-SL1,SC+SL1)))
// Slow Trail //
AP2 = input(20,"slow ATR perod",integer) // ATR Period
AF2 = input(4.5,"slow ATR multiplier",float) // ATR Factor
SL2 = AF2*atr(AP2) // Stop Loss
Trail2 = iff(SC>nz(Trail2[1],0) and SC[1]>nz(Trail2[1],0),max(nz(Trail2[1],0),SC-SL2),iff(SC<nz(Trail2[1],0) and SC[1]<nz(Trail2[1],0),min(nz(Trail2[1],0),SC+SL2),iff(SC>nz(Trail2[1],0),SC-SL2,SC+SL2)))
// ATRCD Histogram //
// to plot these, uncomment the code in the plot section below and change indicator overlay to false, also comment out the other plots //
Hst = Trail1-Trail2
Sig = ema(Hst,9)
// Bar color for trade signal //
Blue = Hst<0 and Hst>Sig
Green = Hst>0 and Hst>Sig
Gray = Hst>0 and Hst<Sig
Red = Hst<0 and Hst<Sig
// Signals //
Bull = barssince(Green)<barssince(Red)
Bear = barssince(Red)<barssince(Green)
Buy = Green and Bear[1]
Sell = Red and Bull[1]
if Buy
strategy.entry("OPEN LONG",strategy.long,0.8, when=strategy.position_size <= 0)
strategy.exit("TPSL LONG ",from_entry="OPEN LONG", profit=10*1000, loss=10*300.0)
if Sell
strategy.entry("OPEN SHORT",strategy.short,0.8,when=strategy.position_size >= 0)
strategy.exit("TPSL SHORT",from_entry="OPEN SHORT", profit=10*1000.0, loss=10*300.0)
// if (SUMMARY_SIGNALS == 1) and strategy.position_size <= 0
// strategy.entry(id="LONG",long=true,qty=TEST_CONTRACT_SIZE, comment = "OPEN LONG")
// if (SUMMARY_SIGNALS == 2) and strategy.position_size >= 0 and inDateRange
// if (LONG_ONLY)
// strategy.close_all(comment = "TPSL LONG")
// else
// strategy.entry(id="SHORT",long=false,qty=TEST_CONTRACT_SIZE, comment = "OPEN SHORT")
// longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
// if (longCondition)
// strategy.entry("My Long Entry Id", strategy.long)
// shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
// if (shortCondition)
// strategy.entry("My Short Entry Id", strategy.short)
// Alert //
alertcondition(Buy,"Buy Signal","Buy ATR Trailing Stop")
alertcondition(Sell,"Sell Signal","Sell ATR Trailing Stop")
TS1 = plot(Trail1,"fast trail", style = circles)
TS2 = plot(Trail2,"slow trail", style = line, color=SC>Trail2? green : red, linewidth=2)
fill(TS1,TS2,Bull ? green : red,transp = 90)
plotcolor = input(0,"Paint color on chart")
plotbuysell = input(0,"Plot Buy/Sell arrows")
bcl = iff(plotcolor == 1,Blue ? blue : Green ? lime : Gray ? gray : Red ? red : white,na)
barcolor(bcl)
plotshape(Buy[1] and plotbuysell==1,"Buy",shape.arrowup,location.belowbar,green,text="buy")
plotshape(Sell[1] and plotbuysell==1,"Sell",shape.arrowdown,location.abovebar,red,text="sell")