// Downloaded From https://www.WiseStockTrader.com _SECTION_BEGIN("BAB 18 for analysis"); SetChartOptions(0,chartShowArrows|chartShowDates); _N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) )); Plot( C, "Close", ParamColor("Color", colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); MinBars = 200; MinBarsOK = IIf(BarCount >= MinBars, True, False); if (MinBarsOK) { ; /* ********************************** Code to automatically identify pivots ********************************** */ // -- what will be our lookback range for the hh and ll? farback=Param("How Far back to go",200,1,50,1); nBars = Param("Number of bars", 100, 0, 50, 1); // -- Create 0-initialized arrays the size of barcount aHPivs = H - H; aLPivs = L - L; // -- More for future use, not necessary for basic plotting aHPivHighs = H - H; aLPivLows = L - L; aHPivIdxs = H - H; aLPivIdxs = L - L; nHPivs = 0; nLPivs = 0; lastHPIdx = 0; lastLPIdx = 0; lastHPH = 0; lastLPL = 0; curPivBarIdx = 0; // -- looking back from the current bar, how many bars // back were the hhv and llv values of the previous // n bars, etc.? aHHVBars = HHVBars(H, nBars); aLLVBars = LLVBars(L, nBars); aHHV = HHV(H, nBars); aLLV = LLV(L, nBars); // -- Would like to set this up so pivots are calculated back from // last visible bar to make it easy to "go back" and see the pivots // this code would find. However, the first instance of // _Trace output will show a value of 0 aVisBars = Status("barvisible"); nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0))); _TRACE("Last visible bar: " + nLastVisBar); // -- Initialize value of curTrend curBar = (BarCount-1); curTrend = ""; if (aLLVBars[curBar] < aHHVBars[curBar]) { curTrend = "D"; } else { curTrend = "U"; } // -- Loop through bars. Search for // entirely array-based approach // in future version for (i=0; i lastHPIdx) { // -- Bar and price info for candidate pivot candIdx = curBar - aHHVBars[curBar]; candPrc = aHHV[curBar]; if ( lastHPH < candPrc AND candIdx > lastLPIdx AND candIdx < curBar) { // -- OK, we'll add this as a pivot... aHPivs[candIdx] = 1; // ...and then rearrange elements in the // pivot information arrays for (j=0; j candPrc AND candIdx > lastHPIdx AND candIdx < curBar) { // -- OK, we'll add this as a pivot... aLPivs[candIdx] = 1; // ...and then rearrange elements in the // pivot information arrays for (j=0; j Ref( DayOfWeek(),1),WeeklyPrice); Monthly=ValueWhen(Day() > Ref( Day(), 1 ),MonthlyPrice); MonthlyAvg=EMA(Monthly,MonthlyPds); WeeklyAvg=EMA(Weekly,WeeklyPds); DailyAvg=EMA(DailyPrice,DailyPds); x = DailyAvg; y = WeeklyAvg; Buy=Cross(x,y); PlotShapes(shapeUpArrow*Buy,colorCustom11, 0, L, -5 ); Sell=Cross(y,x); PlotShapes(shapeDownArrow*Sell,colorCustom12, 0, H, -5 ); AlertIf( Buy, "SOUND C:\\Windows\\Media\\notify.wav", "Audio alert", 2 ); AlertIf( Sell, "SOUND C:\\Windows\\Media\\chord.wav", "Audio alert", 2 ); Graph0=C; Graph0Style=64; Graph0Color=Color; Graph1=WeeklyAvg; Graph1Style=1+4;//Thick line Graph1Color=WklyAvgColor; Graph2=DailyAvg; Graph2Style=1; Graph2Color=DlyAvgColor; Graph3=MonthlyAvg; Graph3Style=1; Graph3Color=MthAvgColor; Title=Name()+" "+"("+WriteVal(WeeklyPds,1)+")"+" Week Moving Average= "+"("+WriteVal(WeeklyAvg,1.2)+")"+" :: "+"("+WriteVal(DailyPds,1)+")"+" Period Moving Average= "+"("+WriteVal(DailyAvg,1.2)+")"+" :: "+"("+WriteVal(MonthlyPds,1)+")"+" Month Moving Average= "+"("+WriteVal(MonthlyAvg,1.2)+")"; _SECTION_END();