//@Name:Noise Trading //@Description:Displays up and down swings, used for noise trading. As described on Stocks & Commodities, October 2010. // Care has been taken in preparing this code but it is provided without guarantee. // You are welcome to modify and extend it. Please add your name as a modifier if you distribute it. //Coded by: Richard Chiesa, ShareScript Support var noiseCol = Colour.White; var buyCol = Colour.RGB(0,220,0); var sellCol = Colour.RGB(220,0,0); function onNewChart() { onZoom(); } function onZoom() { clearDisplay(); useAltRange(false); var bkCol = getBackColour(); //the noiseCol is equal to noiseCol = Colour.RGB(255-bkCol%256,255-Math.floor(bkCol%65536/256),255-Math.floor(bkCol/65536)); //setup the first swing if (bars[1].high bars[i-1].low) { peak = bars[i].low; bars[i].colour = buyCol; lineTo(i,peak); } else if (upSwing && bars[i].high < peak) { lineTo(i,peak); upSwing = false; peak = bars[i].high; bars[i].colour = sellCol; setPenStyle(Pen.Solid,1,sellCol); moveTo(i,peak); } else if (!upSwing && bars[i].high < bars[i-1].high) { peak = bars[i].high; bars[i].colour = sellCol; lineTo(i,peak); } else if (!upSwing && bars[i].low > peak) { lineTo(i,peak); upSwing = true; peak = bars[i].low; bars[i].colour = buyCol; setPenStyle(Pen.Solid,1,buyCol); moveTo(i,peak); } else { lineTo(i,peak); } } var f = getMinVisibleBarIndex(); var l = getMaxVisibleBarIndex(); var noiseCount = 0; for (var i=f;i<=l;i++) if (bars[i].colour == noiseCol) noiseCount++; setPenStyle(Pen.Solid,0,noiseCol); setBrushColour(Colour.RGB(150,150,255)); setFillMode(FillMode.Solid); setAltRange(0,1000); useAltRange(true); var x1 = (l-f)/1000; //0.1% of the X-axis drawText(f+x1*3,30,(noiseCount/(l-f+1)*100).toFixed(1)+"% Noise",BoxAlign.Right | BoxAlign.Bottom,TextAlign.Centre,1,1); }