{"id":1308,"date":"2016-01-16T00:06:01","date_gmt":"2016-01-15T23:06:01","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/?p=1308"},"modified":"2016-01-29T00:12:27","modified_gmt":"2016-01-28T23:12:27","slug":"automatic-support-and-resistance-lines-based-on-last-hhv-and-llv-value","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2016\/01\/16\/automatic-support-and-resistance-lines-based-on-last-hhv-and-llv-value\/","title":{"rendered":"Automatic support and resistance lines based on last HHV and LLV value"},"content":{"rendered":"
In this example we will present a method to plot automatic support and resistance lines based on recently hit highs\/lows. In order to draw horizontal lines showing levels of recent HHV\/LLV values and start drawing at the point of the chart, which defines given price level – we first need to identify the bar, where the line should start. This can be done with use of HHVBars<\/a> \/ LLVBars<\/a> functions.<\/p> These functions allow to find out the number of bars that have passed since our support or resistance level was established, so we could prevent from drawing the lines before these points.<\/p> This example shows how to draw support and resistance lines based on HHV\/LLV levels:<\/p> The chart below shows the output produced by the formula:<\/p> <\/p>","protected":false},"excerpt":{"rendered":" In this example we will present a method to plot automatic support and resistance lines based on recently hit highs\/lows. In order to draw horizontal lines showing levels of recent HHV\/LLV values and start drawing at the point of the chart, which defines given price level – we first need to identify the bar, where […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[55,92,91],"_links":{"self":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1308"}],"collection":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/comments?post=1308"}],"version-history":[{"count":1,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1308\/revisions"}],"predecessor-version":[{"id":1310,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1308\/revisions\/1310"}],"wp:attachment":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/media?parent=1308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/categories?post=1308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/tags?post=1308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<\/span>\/\/ define reusable function
<\/span>function <\/span>SupResLevels<\/span>( <\/span>bars<\/span>, <\/span>colorUp<\/span>, <\/span>ColorDn <\/span>)
{
<\/span>bi <\/span>= <\/span>BarIndex<\/span>();
<\/span>lvbi <\/span>= <\/span>LastValue<\/span>( <\/span>bi <\/span>);
<\/span>\/\/ return HHV value only for bars starting from the bar where HHV level was established
<\/span>hv <\/span>= <\/span>IIf<\/span>( <\/span>bi <\/span>>= <\/span>lvbi <\/span>- <\/span>LastValue<\/span>( <\/span>HHVBars<\/span>( <\/span>High<\/span>, <\/span>bars <\/span>) ), <\/span>LastValue<\/span>( <\/span>HHV<\/span>( <\/span>High<\/span>, <\/span>bars <\/span>) ), <\/span>Null <\/span>);
<\/span>\/\/ the same approach for LLV
<\/span>lv <\/span>= <\/span>IIf<\/span>( <\/span>bi <\/span>>= <\/span>lvbi <\/span>- <\/span>LastValue<\/span>( <\/span>LLVBars<\/span>( <\/span>Low<\/span>, <\/span>bars <\/span>) ), <\/span>LastValue<\/span>( <\/span>LLV<\/span>( <\/span>Low<\/span>, <\/span>bars <\/span>) ), <\/span>Null <\/span>);
<\/span>\/\/ plot levels
<\/span>Plot<\/span>( <\/span>hv<\/span>, <\/span>"hv"<\/span>, <\/span>colorUp<\/span>, <\/span>styleDashed <\/span>);
<\/span>Plot<\/span>( <\/span>lv<\/span>, <\/span>"lv"<\/span>, <\/span>ColorDn<\/span>, <\/span>styleDashed <\/span>);
}
<\/span>\/\/ price plot
<\/span>Plot<\/span>( <\/span>Close<\/span>, <\/span>"Close"<\/span>, <\/span>colorDefault<\/span>, <\/span>styleBar <\/span>);
<\/span>\/\/ call function with various parameters
<\/span>SupResLevels<\/span>( <\/span>10<\/span>, <\/span>colorGreen<\/span>, <\/span>colorRed <\/span>);
<\/span>SupResLevels<\/span>( <\/span>50<\/span>, <\/span>colorGreen<\/span>, <\/span>colorRed <\/span>)<\/code>