[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Help to create trailing stop bands



PureBytes Links

Trading Reference Links

How this works?

To define an uptrend, the last low is compared to the lows of the
previous 9 days. If it is higher than all of those days, a reading of
the ATR is taken and then multiplied by the user defined multiple.
This value is then subtracted from the last low, creating the stop
loss point for the following days. If the price closes below the stop
loss, the Trailer then switches to looking at the highs instead of the
lows. If the high of the day is lower than the high of last 9 days, a
reading of the ATR is taken and then added to the most recent
high, giving a buy stop.

Could you help me to translate this code to AFL:
Static buystop As Single 
		Static x As Single 
		Static z As Integer 
		Static zerolow,zerolow2 As Single 

		If isfirstbar = True Then 
			x = 0 
			buystop = price.low
			zerolow = price.low 
			zerolow2 = price.low 
		End If 




		If  price.Last > buystop And (x - (mult * atr.value)) < (price.low -
(mult * atr.value)) And price.low > price.low(1) And price.low >
price.low(2) And price.low > price.low(3) _
			And price.low > price.low(4) And price.low > price.low(5) And
price.low > price.low(6) _
			And price.low > price.low(7) And price.low > price.low(8) And
price.low > price.low(9)  Then
			x = price.low
			buystop = x - (mult * atr.value) 
 
		End If

		If price.Last < buystop And (x + (mult * atr.value)) > (price.high +
(mult * atr.value)) And price.high < price.high(1) And price.high <
price.high(2) And price.high < price.high(3) _
			And price.high < price.high(4) And price.high < price.high(5) And
price.high < price.high(6) _ 
			And price.high < price.high(7) And price.high < price.high(8) And
price.high < price.high(9) Then
	
			x = price.high
			buystop = x + (mult * atr.value)

		End If

		plot = buystop

Thanks!




------------------------------------

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/