//@Name:Alligator //@Description:Draws the Alligator which was designed by Bill Williams // 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: Phil Tolhurst, ShareScope Support //Alligator's Jaw (the blue line)- 13-period moving average at the mid price (High+Low)/2, which is offset 8 bars into the future; //Alligator's Teeth (the red line)- 8-period moving average at the mid price (High+Low)/2, which is offset 5 bars into the future; //Alligator's Lips (the green line) - 5-period moving average at the mid price (High+Low)/2, which is offset 2 bars into the future. var colour1 = Colour.RGB(0,0,255); var pen1 = 0; var width1 = 1; var colour2 = Colour.RGB(255,0,0); var pen2 = 0; var width2 = 1; var colour3 = Colour.RGB(0,255,0); var pen3 = 0; var width3 = 1; var alligator = [13,8,8,5,5,2] function init(status) { if(status==Loading) { storage.setAt(0,colour1); storage.setAt(1,pen1); storage.setAt(2,width1); storage.setAt(3,colour2); storage.setAt(4,pen2); storage.setAt(5,width2); storage.setAt(6,colour3); storage.setAt(7,pen3); storage.setAt(8,width3); } buttonHandle = createButton("Set", onButton0); } //What happens if the set button is clicked: function onButton0() { colour1 = storage.getAt(0); pen1 = storage.getAt(1); width1 = storage.getAt(2); colour2 = storage.getAt(3); pen2 = storage.getAt(4); width2 = storage.getAt(5); colour3 = storage.getAt(6); pen3 = storage.getAt(7); width3 = storage.getAt(8); { var dlg = new Dialog("Settings...",200,60); dlg.addOkButton(); dlg.addCancelButton(); dlg.addColLinePicker("VAL1",70,5,-1,-1,"Alligator's Jaw","",colour1,pen1,width1); dlg.addColLinePicker("VAL2",70,22,-1,-1,"Alligator's Teeth","",colour2,pen2,width2); dlg.addColLinePicker("VAL3",70,39,-1,-1,"Alligator's Lips","",colour3,pen3,width3); if (dlg.show()==Dialog.Cancel) return false; colour1 = dlg.getValue("VAL1").colour; pen1 = dlg.getValue("VAL1").pen; width1 = dlg.getValue("VAL1").width; colour2 = dlg.getValue("VAL2").colour; pen2 = dlg.getValue("VAL2").pen; width2 = dlg.getValue("VAL2").width; colour3 = dlg.getValue("VAL3").colour; pen3 = dlg.getValue("VAL3").pen; width3 = dlg.getValue("VAL3").width; colour1 = storage.getAt(0); pen1 = storage.getAt(1); width1 = storage.getAt(2); colour2 = storage.getAt(3); pen2 = storage.getAt(4); width2 = storage.getAt(5); colour3 = storage.getAt(6); pen3 = storage.getAt(7); width3 = storage.getAt(8); } draw(); } //This defines what happens when he study is added to a chart or we select a new share. function onNewChart() { draw(); } //Updates the graph if the data is updated. function onBarClose(preExisting) { if (!preExisting) { draw(); } } function onNewBarUpdate(preExisting) { if (!preExisting) { draw(); } } //Draws a new line depending which button has been clicked on function draw() { clearDisplay(); var settings = [pen1,width1,colour1,pen2,width2,colour2,pen3,width3,colour3]; for(var j=0;j<3;j++) { var period = alligator[0+(2*j)]; var offset = alligator[1+(2*j)]; setPenStyle(settings[0+(3*j)],settings[1+(3*j)],settings[2+(3*j)]) var maRes = []; maRes = smma_calc(period,0); for(i=0;i0) { moveTo(i+offset,maRes[i]); continue; } else lineTo(i+offset,maRes[i]); } } } function smma_calc(period,mcOption) { var sum = 0; var SMMA = []; var source = []; for(var i=0;i