Hello,
I got this code from Internet:
/*
Bill William's Alligator System II Awesome Oscillator, modified from williamAlligator2.
Reference Website:
==================
http://www.alpari-idc.com/en/market-analysis-guide/chaos-theory/alligator-and-gator.html
Original by by Steve Wiser - slwiserr@erols.com
Modified by TohMz on June 9th, 2008
*/
SetChartOptions( 0, chartShowArrows|chartShowDates );
_SECTION_BEGIN("BW Alligator");
/*** The trend indicators ***/
P= ParamList("Price", "Close|(H+L)/2|(H+C+L)/3",1);
if (P=="Close")
A = C;
else
if (P=="(H+C+L)/3")
A = (H+C+L)/3;
else
A = (H+L)/2;
AlligatorJaw = Ref(Wilders(A,13),-8);
AlligatorTeeth = Ref(Wilders(A,8), -5);
AlligatorLips = Ref(Wilders(A,5), -3);
AO=MA(A,5)-MA(A,34);
AOcolor=IIf(AO>Ref(AO,-1),colorGreen,colorRed);
AC=AO-MA(AO,5);
ACcolor=IIf(AC>Ref(AC,-1),colorGreen,colorRed);
Plot(AO,"AO",AOcolor,styleHistogram|styleThick);
_SECTION_END();
_SECTION_BEGIN("BW Fractal");
UpFractal= ValueWhen(
(Ref(H,-2) > Ref(H, -4)) AND
(Ref(H,-2) > Ref(H, -3)) AND
(Ref(H,-2) > Ref(H, -1)) AND
(Ref(H,-2) > H), Ref(H,-2));
DownFractal= ValueWhen(
(Ref(L,-2) <= Ref(L, -4)) AND
(Ref(L,-2) <= Ref(L, -3)) AND
(Ref(L,-2) <= Ref(L, -1)) AND
(Ref(L,-2) <= L), Ref(L,-2));
_SECTION_END();
_SECTION_BEGIN("Exploration");
/*
Buy: Scan stocks only breakout..maxbreakout (1~30%, default) and Trend is bullish
Sell: Scan stocks only breakout..maxbreakout (1~30%, default) and Trend is bearish
*/
//== Price Increment Value - depend on different country
Inc = 1;
//== Set the Price Range for stock to scan
PriceFrom = Param("Price From:", 50, 1, 200000, Inc);
PriceTo = Param("Price To:", 200000, 1, 200000, Inc);
MaxBreakOut = Param("Max Breakout (%)", 5, 1, 30);
MaxBreakOut = MaxBreakOut/100;
Buy = C>UpFractal AND C<=(1+MaxBreakOut)*UpFractal AND AlligatorTeeth>AlligatorJaw; /* AND AlligatorLips>AlligatorTeeth; */
Sell = C<DownFractal AND C>=(1-MaxBreakOut)*DownFractal AND AlligatorTeeth<AlligatorJaw; /* AND AlligatorLips<AlligatorTeeth; */
Filter = (Buy OR Sell) AND (MA(V,3)/EMA(V,17))>1;
AddTextColumn(FullName(), "Security", 1.0, colorDefault, colorDefault, 200);
AddTextColumn( WriteIf(Buy,"Buy", WriteIf(Sell, "Sell", "")), "Trade", 1.0);
AddColumn( UpFractal, "Up Fratal");
AddColumn( DownFractal, "Down Fratal");
AddColumn( MA(V,3)/EMA(V,17), "MAV(3/17)");
AddColumn( C, "Today's Close");
SetSortColumns(-2);
_SECTION_END();
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", Status("pxheight")/6 );
GfxSetTextAlign( 6 );// center alignment
GfxSetTextColor( ParamColor( "Warna", colorLightGrey ) );
GfxSetBkMode(0); // transparent
GfxTextOut( "Awesome", Status("pxwidth")/2, Status("pxheight")/2 );
It plots histograms on the chart and generates buy and sell signals based on combination of certain conditions. I am more interested in the exploration part of it.
After setting the time range as 27th March, it generates a few results - one of the stock is Apollo Tyre, the hourly chart of which is as below:
If the histograms start forming above 0, it's a bullish trend and vice versa. But the code also considers other conditions before generating buy signal. But I want is simple - the moment histogram crosses above 0, it should give me buy signal.
For example - if the last histogram was at -4 and the next one starts forming above 0, that's when I want a buy signal to be generated. I have added some annotations onto the same chart as above to better illustrate what I'm looking for:
As you can see in the above screenshot, I am only looking for crossovers, i.e, when histogram which was formed below 0 starts forming new one above 0 will create buy signal and vice versa for sell.
Thanks!