//@Name:Fractal Change //@Description:Triggers when there is a flag/bar colour change based on the Fractals study. The alternative mode counts through 4 bars instead of the standard 5 //@Returns:Number //@Width:95 //@Env:Production //@Update:Periodic //@DefaultRangeMax:1 //@DefaultRangeMin:-1 //A fractal pattern on a bar chart consists of a minimum of 5 consecutive bars. The middle bar must have a higher high (or lower low) than the two preceding bars and the two //following bars. //If a bar’s high (or low) is equal to the high (low) of the middle bar, it does not count as one of the five bars because it isn’t lower (higher) than that bar. //An arrow above or below the bar indicates the fractal. (See example chart) // 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. //Draws the indicators on a chart when you select the chart for a new share. var useAlt = false //Uses the alternetive 4 bar fractal. 5 searches for low,low,HIGH,low,low, while 4 searches for low,low,HIGH,low. function init() { buttonHandle = createButton("x", button); } function onNewChart() { clearDisplay(); draw(); } //Updates the graph if the data is updated, so when a new bar is added. function onNewBarUpdate() { clearDisplay(); draw(); } function button() { if (useAlt) useAlt=false; else useAlt=true; draw(); } function draw() { setTitle("Fractals ("+(useAlt?"4":"5")+" bar check)"); clearDisplay(); setButtonText(buttonHandle, useAlt == 0 ? "Standard Mode" : "Alternative Mode"); var bkCol = getBackColour(); //set the neutral colour to the inverse of the background colour var neutralCol = Colour.RGB(255-bkCol%256,255-Math.floor(bkCol%65536/256),255-Math.floor(bkCol/65536)); for (var i=2;i bars[i].low) { bars[i].colour = Colour.Blue; setBrushColour(Colour.LightBlue); drawSymbol(i,bars[i].low*0.99,Symbol.FlagUp,"L"); } } }