indicators-all.src.js 322 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814
  1. /**
  2. * @license Highstock JS v8.0.0 (2019-12-10)
  3. *
  4. * All technical indicators for Highstock
  5. *
  6. * (c) 2010-2019 Pawel Fus
  7. *
  8. * License: www.highcharts.com/license
  9. */
  10. 'use strict';
  11. (function (factory) {
  12. if (typeof module === 'object' && module.exports) {
  13. factory['default'] = factory;
  14. module.exports = factory;
  15. } else if (typeof define === 'function' && define.amd) {
  16. define('highcharts/indicators/indicators-all', ['highcharts', 'highcharts/modules/stock'], function (Highcharts) {
  17. factory(Highcharts);
  18. factory.Highcharts = Highcharts;
  19. return factory;
  20. });
  21. } else {
  22. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  23. }
  24. }(function (Highcharts) {
  25. var _modules = Highcharts ? Highcharts._modules : {};
  26. function _registerModule(obj, path, args, fn) {
  27. if (!obj.hasOwnProperty(path)) {
  28. obj[path] = fn.apply(null, args);
  29. }
  30. }
  31. _registerModule(_modules, 'mixins/indicator-required.js', [_modules['parts/Globals.js']], function (H) {
  32. /**
  33. *
  34. * (c) 2010-2019 Daniel Studencki
  35. *
  36. * License: www.highcharts.com/license
  37. *
  38. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  39. *
  40. * */
  41. var error = H.error;
  42. /* eslint-disable no-invalid-this, valid-jsdoc */
  43. var requiredIndicatorMixin = {
  44. /**
  45. * Check whether given indicator is loaded, else throw error.
  46. * @private
  47. * @param {Highcharts.Indicator} indicator
  48. * Indicator constructor function.
  49. * @param {string} requiredIndicator
  50. * Required indicator type.
  51. * @param {string} type
  52. * Type of indicator where function was called (parent).
  53. * @param {Highcharts.IndicatorCallbackFunction} callback
  54. * Callback which is triggered if the given indicator is loaded.
  55. * Takes indicator as an argument.
  56. * @param {string} errMessage
  57. * Error message that will be logged in console.
  58. * @return {boolean}
  59. * Returns false when there is no required indicator loaded.
  60. */
  61. isParentLoaded: function (indicator, requiredIndicator, type, callback, errMessage) {
  62. if (indicator) {
  63. return callback ? callback(indicator) : true;
  64. }
  65. error(errMessage || this.generateMessage(type, requiredIndicator));
  66. return false;
  67. },
  68. /**
  69. * @private
  70. * @param {string} indicatorType
  71. * Indicator type
  72. * @param {string} required
  73. * Required indicator
  74. * @return {string}
  75. * Error message
  76. */
  77. generateMessage: function (indicatorType, required) {
  78. return 'Error: "' + indicatorType +
  79. '" indicator type requires "' + required +
  80. '" indicator loaded before. Please read docs: ' +
  81. 'https://api.highcharts.com/highstock/plotOptions.' +
  82. indicatorType;
  83. }
  84. };
  85. return requiredIndicatorMixin;
  86. });
  87. _registerModule(_modules, 'indicators/indicators.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['mixins/indicator-required.js']], function (H, U, requiredIndicatorMixin) {
  88. /* *
  89. *
  90. * License: www.highcharts.com/license
  91. *
  92. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  93. *
  94. * */
  95. var extend = U.extend, isArray = U.isArray, pick = U.pick, splat = U.splat;
  96. var error = H.error, Series = H.Series, addEvent = H.addEvent, seriesType = H.seriesType, seriesTypes = H.seriesTypes, ohlcProto = H.seriesTypes.ohlc.prototype, generateMessage = requiredIndicatorMixin.generateMessage;
  97. /**
  98. * The parameter allows setting line series type and use OHLC indicators. Data
  99. * in OHLC format is required.
  100. *
  101. * @sample {highstock} stock/indicators/use-ohlc-data
  102. * Plot line on Y axis
  103. *
  104. * @type {boolean}
  105. * @product highstock
  106. * @apioption plotOptions.line.useOhlcData
  107. */
  108. /* eslint-disable no-invalid-this */
  109. addEvent(H.Series, 'init', function (eventOptions) {
  110. var series = this, options = eventOptions.options;
  111. if (options.useOhlcData &&
  112. options.id !== 'highcharts-navigator-series') {
  113. extend(series, {
  114. pointValKey: ohlcProto.pointValKey,
  115. keys: ohlcProto.keys,
  116. pointArrayMap: ohlcProto.pointArrayMap,
  117. toYData: ohlcProto.toYData
  118. });
  119. }
  120. });
  121. addEvent(Series, 'afterSetOptions', function (e) {
  122. var options = e.options, dataGrouping = options.dataGrouping;
  123. if (dataGrouping &&
  124. options.useOhlcData &&
  125. options.id !== 'highcharts-navigator-series') {
  126. dataGrouping.approximation = 'ohlc';
  127. }
  128. });
  129. /* eslint-enable no-invalid-this */
  130. /**
  131. * The SMA series type.
  132. *
  133. * @private
  134. * @class
  135. * @name Highcharts.seriesTypes.sma
  136. *
  137. * @augments Highcharts.Series
  138. */
  139. seriesType('sma', 'line',
  140. /**
  141. * Simple moving average indicator (SMA). This series requires `linkedTo`
  142. * option to be set.
  143. *
  144. * @sample stock/indicators/sma
  145. * Simple moving average indicator
  146. *
  147. * @extends plotOptions.line
  148. * @since 6.0.0
  149. * @excluding allAreas, colorAxis, dragDrop, joinBy, keys,
  150. * navigatorOptions, pointInterval, pointIntervalUnit,
  151. * pointPlacement, pointRange, pointStart, showInNavigator,
  152. * stacking, useOhlcData
  153. * @product highstock
  154. * @requires stock/indicators/indicators
  155. * @optionparent plotOptions.sma
  156. */
  157. {
  158. /**
  159. * The name of the series as shown in the legend, tooltip etc. If not
  160. * set, it will be based on a technical indicator type and default
  161. * params.
  162. *
  163. * @type {string}
  164. */
  165. name: void 0,
  166. tooltip: {
  167. /**
  168. * Number of decimals in indicator series.
  169. */
  170. valueDecimals: 4
  171. },
  172. /**
  173. * The main series ID that indicator will be based on. Required for this
  174. * indicator.
  175. *
  176. * @type {string}
  177. */
  178. linkedTo: void 0,
  179. /**
  180. * Whether to compare indicator to the main series values
  181. * or indicator values.
  182. *
  183. * @sample {highstock} stock/plotoptions/series-comparetomain/
  184. * Difference between comparing SMA values to the main series
  185. * and its own values.
  186. *
  187. * @type {boolean}
  188. */
  189. compareToMain: false,
  190. /**
  191. * Paramters used in calculation of regression series' points.
  192. */
  193. params: {
  194. /**
  195. * The point index which indicator calculations will base. For
  196. * example using OHLC data, index=2 means the indicator will be
  197. * calculated using Low values.
  198. */
  199. index: 0,
  200. /**
  201. * The base period for indicator calculations. This is the number of
  202. * data points which are taken into account for the indicator
  203. * calculations.
  204. */
  205. period: 14
  206. }
  207. },
  208. /**
  209. * @lends Highcharts.Series.prototype
  210. */
  211. {
  212. processData: function () {
  213. var series = this, compareToMain = series.options.compareToMain, linkedParent = series.linkedParent;
  214. Series.prototype.processData.apply(series, arguments);
  215. if (linkedParent && linkedParent.compareValue && compareToMain) {
  216. series.compareValue = linkedParent.compareValue;
  217. }
  218. return;
  219. },
  220. bindTo: {
  221. series: true,
  222. eventName: 'updatedData'
  223. },
  224. hasDerivedData: true,
  225. useCommonDataGrouping: true,
  226. nameComponents: ['period'],
  227. nameSuffixes: [],
  228. calculateOn: 'init',
  229. // Defines on which other indicators is this indicator based on.
  230. requiredIndicators: [],
  231. requireIndicators: function () {
  232. var obj = {
  233. allLoaded: true
  234. };
  235. // Check whether all required indicators are loaded, else return
  236. // the object with missing indicator's name.
  237. this.requiredIndicators.forEach(function (indicator) {
  238. if (seriesTypes[indicator]) {
  239. seriesTypes[indicator].prototype.requireIndicators();
  240. }
  241. else {
  242. obj.allLoaded = false;
  243. obj.needed = indicator;
  244. }
  245. });
  246. return obj;
  247. },
  248. init: function (chart, options) {
  249. var indicator = this, requiredIndicators = indicator.requireIndicators();
  250. // Check whether all required indicators are loaded.
  251. if (!requiredIndicators.allLoaded) {
  252. return error(generateMessage(indicator.type, requiredIndicators.needed));
  253. }
  254. Series.prototype.init.call(indicator, chart, options);
  255. // Make sure we find series which is a base for an indicator
  256. chart.linkSeries();
  257. indicator.dataEventsToUnbind = [];
  258. /**
  259. * @private
  260. * @return {void}
  261. */
  262. function recalculateValues() {
  263. var oldData = indicator.points || [], oldDataLength = (indicator.xData || []).length, processedData = indicator.getValues(indicator.linkedParent, indicator.options.params) || {
  264. values: [],
  265. xData: [],
  266. yData: []
  267. }, croppedDataValues = [], overwriteData = true, oldFirstPointIndex, oldLastPointIndex, croppedData, min, max, i;
  268. // We need to update points to reflect changes in all,
  269. // x and y's, values. However, do it only for non-grouped
  270. // data - grouping does it for us (#8572)
  271. if (oldDataLength &&
  272. !indicator.hasGroupedData &&
  273. indicator.visible &&
  274. indicator.points) {
  275. // When data is cropped update only avaliable points (#9493)
  276. if (indicator.cropped) {
  277. if (indicator.xAxis) {
  278. min = indicator.xAxis.min;
  279. max = indicator.xAxis.max;
  280. }
  281. croppedData = indicator.cropData(processedData.xData, processedData.yData, min, max);
  282. for (i = 0; i < croppedData.xData.length; i++) {
  283. // (#10774)
  284. croppedDataValues.push([
  285. croppedData.xData[i]
  286. ].concat(splat(croppedData.yData[i])));
  287. }
  288. oldFirstPointIndex = processedData.xData.indexOf(indicator.xData[0]);
  289. oldLastPointIndex = processedData.xData.indexOf(indicator.xData[indicator.xData.length - 1]);
  290. // Check if indicator points should be shifted (#8572)
  291. if (oldFirstPointIndex === -1 &&
  292. oldLastPointIndex === processedData.xData.length - 2) {
  293. if (croppedDataValues[0][0] === oldData[0].x) {
  294. croppedDataValues.shift();
  295. }
  296. }
  297. indicator.updateData(croppedDataValues);
  298. // Omit addPoint() and removePoint() cases
  299. }
  300. else if (processedData.xData.length !== oldDataLength - 1 &&
  301. processedData.xData.length !== oldDataLength + 1) {
  302. overwriteData = false;
  303. indicator.updateData(processedData.values);
  304. }
  305. }
  306. if (overwriteData) {
  307. indicator.xData = processedData.xData;
  308. indicator.yData = processedData.yData;
  309. indicator.options.data = processedData.values;
  310. }
  311. // Removal of processedXData property is required because on
  312. // first translate processedXData array is empty
  313. if (indicator.bindTo.series === false) {
  314. delete indicator.processedXData;
  315. indicator.isDirty = true;
  316. indicator.redraw();
  317. }
  318. indicator.isDirtyData = false;
  319. }
  320. if (!indicator.linkedParent) {
  321. return error('Series ' +
  322. indicator.options.linkedTo +
  323. ' not found! Check `linkedTo`.', false, chart);
  324. }
  325. indicator.dataEventsToUnbind.push(addEvent(indicator.bindTo.series ?
  326. indicator.linkedParent : indicator.linkedParent.xAxis, indicator.bindTo.eventName, recalculateValues));
  327. if (indicator.calculateOn === 'init') {
  328. recalculateValues();
  329. }
  330. else {
  331. var unbinder = addEvent(indicator.chart, indicator.calculateOn, function () {
  332. recalculateValues();
  333. // Call this just once, on init
  334. unbinder();
  335. });
  336. }
  337. return indicator;
  338. },
  339. getName: function () {
  340. var name = this.name, params = [];
  341. if (!name) {
  342. (this.nameComponents || []).forEach(function (component, index) {
  343. params.push(this.options.params[component] +
  344. pick(this.nameSuffixes[index], ''));
  345. }, this);
  346. name = (this.nameBase || this.type.toUpperCase()) +
  347. (this.nameComponents ? ' (' + params.join(', ') + ')' : '');
  348. }
  349. return name;
  350. },
  351. getValues: function (series, params) {
  352. var period = params.period, xVal = series.xData, yVal = series.yData, yValLen = yVal.length, range = 0, sum = 0, SMA = [], xData = [], yData = [], index = -1, i, SMAPoint;
  353. if (xVal.length < period) {
  354. return;
  355. }
  356. // Switch index for OHLC / Candlestick / Arearange
  357. if (isArray(yVal[0])) {
  358. index = params.index ? params.index : 0;
  359. }
  360. // Accumulate first N-points
  361. while (range < period - 1) {
  362. sum += index < 0 ? yVal[range] : yVal[range][index];
  363. range++;
  364. }
  365. // Calculate value one-by-one for each period in visible data
  366. for (i = range; i < yValLen; i++) {
  367. sum += index < 0 ? yVal[i] : yVal[i][index];
  368. SMAPoint = [xVal[i], sum / period];
  369. SMA.push(SMAPoint);
  370. xData.push(SMAPoint[0]);
  371. yData.push(SMAPoint[1]);
  372. sum -= (index < 0 ?
  373. yVal[i - range] :
  374. yVal[i - range][index]);
  375. }
  376. return {
  377. values: SMA,
  378. xData: xData,
  379. yData: yData
  380. };
  381. },
  382. destroy: function () {
  383. this.dataEventsToUnbind.forEach(function (unbinder) {
  384. unbinder();
  385. });
  386. Series.prototype.destroy.apply(this, arguments);
  387. }
  388. });
  389. /**
  390. * A `SMA` series. If the [type](#series.sma.type) option is not specified, it
  391. * is inherited from [chart.type](#chart.type).
  392. *
  393. * @extends series,plotOptions.sma
  394. * @since 6.0.0
  395. * @product highstock
  396. * @excluding dataParser, dataURL, useOhlcData
  397. * @requires stock/indicators/indicators
  398. * @apioption series.sma
  399. */
  400. ''; // adds doclet above to the transpiled file
  401. });
  402. _registerModule(_modules, 'indicators/accumulation-distribution.src.js', [_modules['parts/Globals.js']], function (H) {
  403. /* *
  404. *
  405. * License: www.highcharts.com/license
  406. *
  407. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  408. * */
  409. var seriesType = H.seriesType;
  410. /* eslint-disable valid-jsdoc */
  411. // Utils:
  412. /**
  413. * @private
  414. */
  415. function populateAverage(xVal, yVal, yValVolume, i) {
  416. var high = yVal[i][1], low = yVal[i][2], close = yVal[i][3], volume = yValVolume[i], adY = close === high && close === low || high === low ?
  417. 0 :
  418. ((2 * close - low - high) / (high - low)) * volume, adX = xVal[i];
  419. return [adX, adY];
  420. }
  421. /* eslint-enable valid-jsdoc */
  422. /**
  423. * The AD series type.
  424. *
  425. * @private
  426. * @class
  427. * @name Highcharts.seriesTypes.ad
  428. *
  429. * @augments Highcharts.Series
  430. */
  431. seriesType('ad', 'sma',
  432. /**
  433. * Accumulation Distribution (AD). This series requires `linkedTo` option to
  434. * be set.
  435. *
  436. * @sample stock/indicators/accumulation-distribution
  437. * Accumulation/Distribution indicator
  438. *
  439. * @extends plotOptions.sma
  440. * @since 6.0.0
  441. * @product highstock
  442. * @requires stock/indicators/indicators
  443. * @requires stock/indicators/accumulation-distribution
  444. * @optionparent plotOptions.ad
  445. */
  446. {
  447. params: {
  448. /**
  449. * The id of volume series which is mandatory.
  450. * For example using OHLC data, volumeSeriesID='volume' means
  451. * the indicator will be calculated using OHLC and volume values.
  452. *
  453. * @since 6.0.0
  454. */
  455. volumeSeriesID: 'volume'
  456. }
  457. },
  458. /**
  459. * @lends Highcharts.Series#
  460. */
  461. {
  462. nameComponents: false,
  463. nameBase: 'Accumulation/Distribution',
  464. getValues: function (series, params) {
  465. var period = params.period, xVal = series.xData, yVal = series.yData, volumeSeriesID = params.volumeSeriesID, volumeSeries = series.chart.get(volumeSeriesID), yValVolume = volumeSeries && volumeSeries.yData, yValLen = yVal ? yVal.length : 0, AD = [], xData = [], yData = [], len, i, ADPoint;
  466. if (xVal.length <= period &&
  467. yValLen &&
  468. yVal[0].length !== 4) {
  469. return;
  470. }
  471. if (!volumeSeries) {
  472. H.error('Series ' +
  473. volumeSeriesID +
  474. ' not found! Check `volumeSeriesID`.', true, series.chart);
  475. return;
  476. }
  477. // i = period <-- skip first N-points
  478. // Calculate value one-by-one for each period in visible data
  479. for (i = period; i < yValLen; i++) {
  480. len = AD.length;
  481. ADPoint = populateAverage(xVal, yVal, yValVolume, i, period);
  482. if (len > 0) {
  483. ADPoint[1] += AD[len - 1][1];
  484. }
  485. AD.push(ADPoint);
  486. xData.push(ADPoint[0]);
  487. yData.push(ADPoint[1]);
  488. }
  489. return {
  490. values: AD,
  491. xData: xData,
  492. yData: yData
  493. };
  494. }
  495. });
  496. /**
  497. * A `AD` series. If the [type](#series.ad.type) option is not
  498. * specified, it is inherited from [chart.type](#chart.type).
  499. *
  500. * @extends series,plotOptions.ad
  501. * @since 6.0.0
  502. * @excluding dataParser, dataURL
  503. * @product highstock
  504. * @requires stock/indicators/indicators
  505. * @requires stock/indicators/accumulation-distribution
  506. * @apioption series.ad
  507. */
  508. ''; // add doclet above to transpiled file
  509. });
  510. _registerModule(_modules, 'indicators/ao.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  511. /* *
  512. *
  513. * License: www.highcharts.com/license
  514. *
  515. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  516. *
  517. * */
  518. var correctFloat = U.correctFloat, isArray = U.isArray;
  519. var noop = H.noop;
  520. /**
  521. * The AO series type
  522. *
  523. * @private
  524. * @class
  525. * @name Highcharts.seriesTypes.ao
  526. *
  527. * @augments Highcharts.Series
  528. */
  529. H.seriesType('ao', 'sma',
  530. /**
  531. * Awesome Oscillator. This series requires the `linkedTo` option to
  532. * be set and should be loaded after the `stock/indicators/indicators.js`
  533. *
  534. * @sample {highstock} stock/indicators/ao
  535. * Awesome
  536. *
  537. * @extends plotOptions.sma
  538. * @since 7.0.0
  539. * @product highstock
  540. * @excluding allAreas, colorAxis, joinBy, keys, navigatorOptions,
  541. * params, pointInterval, pointIntervalUnit, pointPlacement,
  542. * pointRange, pointStart, showInNavigator, stacking
  543. * @requires stock/indicators/indicators
  544. * @requires stock/indicators/ao
  545. * @optionparent plotOptions.ao
  546. */
  547. {
  548. /**
  549. * Color of the Awesome oscillator series bar that is greater than the
  550. * previous one. Note that if a `color` is defined, the `color`
  551. * takes precedence and the `greaterBarColor` is ignored.
  552. *
  553. * @sample {highstock} stock/indicators/ao/
  554. * greaterBarColor
  555. *
  556. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  557. * @since 7.0.0
  558. */
  559. greaterBarColor: '#06B535',
  560. /**
  561. * Color of the Awesome oscillator series bar that is lower than the
  562. * previous one. Note that if a `color` is defined, the `color`
  563. * takes precedence and the `lowerBarColor` is ignored.
  564. *
  565. * @sample {highstock} stock/indicators/ao/
  566. * lowerBarColor
  567. *
  568. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  569. * @since 7.0.0
  570. */
  571. lowerBarColor: '#F21313',
  572. threshold: 0,
  573. groupPadding: 0.2,
  574. pointPadding: 0.2,
  575. states: {
  576. hover: {
  577. halo: {
  578. size: 0
  579. }
  580. }
  581. }
  582. },
  583. /**
  584. * @lends Highcharts.Series#
  585. */
  586. {
  587. nameBase: 'AO',
  588. nameComponents: false,
  589. // Columns support:
  590. markerAttribs: noop,
  591. getColumnMetrics: H.seriesTypes.column.prototype.getColumnMetrics,
  592. crispCol: H.seriesTypes.column.prototype.crispCol,
  593. translate: H.seriesTypes.column.prototype.translate,
  594. drawPoints: H.seriesTypes.column.prototype.drawPoints,
  595. drawGraph: function () {
  596. var indicator = this, options = indicator.options, points = indicator.points, userColor = indicator.userOptions.color, positiveColor = options.greaterBarColor, negativeColor = options.lowerBarColor, firstPoint = points[0], i;
  597. if (!userColor && firstPoint) {
  598. firstPoint.color = positiveColor;
  599. for (i = 1; i < points.length; i++) {
  600. if (points[i].y > points[i - 1].y) {
  601. points[i].color = positiveColor;
  602. }
  603. else if (points[i].y < points[i - 1].y) {
  604. points[i].color = negativeColor;
  605. }
  606. else {
  607. points[i].color = points[i - 1].color;
  608. }
  609. }
  610. }
  611. },
  612. getValues: function (series) {
  613. var shortPeriod = 5, longPeriod = 34, xVal = series.xData || [], yVal = series.yData || [], yValLen = yVal.length, AO = [], // 0- date, 1- Awesome Oscillator
  614. xData = [], yData = [], high = 1, low = 2, shortSum = 0, longSum = 0, shortSMA, // Shorter Period SMA
  615. longSMA, // Longer Period SMA
  616. awesome, shortLastIndex, longLastIndex, price, i, j;
  617. if (xVal.length <= longPeriod ||
  618. !isArray(yVal[0]) ||
  619. yVal[0].length !== 4) {
  620. return;
  621. }
  622. for (i = 0; i < longPeriod - 1; i++) {
  623. price = (yVal[i][high] + yVal[i][low]) / 2;
  624. if (i >= longPeriod - shortPeriod) {
  625. shortSum = correctFloat(shortSum + price);
  626. }
  627. longSum = correctFloat(longSum + price);
  628. }
  629. for (j = longPeriod - 1; j < yValLen; j++) {
  630. price = (yVal[j][high] + yVal[j][low]) / 2;
  631. shortSum = correctFloat(shortSum + price);
  632. longSum = correctFloat(longSum + price);
  633. shortSMA = shortSum / shortPeriod;
  634. longSMA = longSum / longPeriod;
  635. awesome = correctFloat(shortSMA - longSMA);
  636. AO.push([xVal[j], awesome]);
  637. xData.push(xVal[j]);
  638. yData.push(awesome);
  639. shortLastIndex = j + 1 - shortPeriod;
  640. longLastIndex = j + 1 - longPeriod;
  641. shortSum = correctFloat(shortSum -
  642. (yVal[shortLastIndex][high] +
  643. yVal[shortLastIndex][low]) / 2);
  644. longSum = correctFloat(longSum -
  645. (yVal[longLastIndex][high] +
  646. yVal[longLastIndex][low]) / 2);
  647. }
  648. return {
  649. values: AO,
  650. xData: xData,
  651. yData: yData
  652. };
  653. }
  654. });
  655. /**
  656. * An `AO` series. If the [type](#series.ao.type)
  657. * option is not specified, it is inherited from [chart.type](#chart.type).
  658. *
  659. * @extends series,plotOptions.ao
  660. * @since 7.0.0
  661. * @product highstock
  662. * @excluding allAreas, colorAxis, dataParser, dataURL, joinBy, keys,
  663. * navigatorOptions, pointInterval, pointIntervalUnit,
  664. * pointPlacement, pointRange, pointStart, showInNavigator, stacking
  665. * @requires stock/indicators/indicators
  666. * @requires stock/indicators/ao
  667. * @apioption series.ao
  668. */
  669. ''; // for including the above in the doclets
  670. });
  671. _registerModule(_modules, 'mixins/multipe-lines.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  672. /**
  673. *
  674. * (c) 2010-2019 Wojciech Chmiel
  675. *
  676. * License: www.highcharts.com/license
  677. *
  678. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  679. *
  680. * */
  681. var defined = U.defined;
  682. var each = H.each, merge = H.merge, error = H.error, SMA = H.seriesTypes.sma;
  683. /**
  684. * Mixin useful for all indicators that have more than one line.
  685. * Merge it with your implementation where you will provide
  686. * getValues method appropriate to your indicator and pointArrayMap,
  687. * pointValKey, linesApiNames properites. Notice that pointArrayMap
  688. * should be consistent with amount of lines calculated in getValues method.
  689. *
  690. * @private
  691. * @mixin multipleLinesMixin
  692. */
  693. var multipleLinesMixin = {
  694. /* eslint-disable valid-jsdoc */
  695. /**
  696. * Lines ids. Required to plot appropriate amount of lines.
  697. * Notice that pointArrayMap should have more elements than
  698. * linesApiNames, because it contains main line and additional lines ids.
  699. * Also it should be consistent with amount of lines calculated in
  700. * getValues method from your implementation.
  701. *
  702. * @private
  703. * @name multipleLinesMixin.pointArrayMap
  704. * @type {Array<string>}
  705. */
  706. pointArrayMap: ['top', 'bottom'],
  707. /**
  708. * Main line id.
  709. *
  710. * @private
  711. * @name multipleLinesMixin.pointValKey
  712. * @type {string}
  713. */
  714. pointValKey: 'top',
  715. /**
  716. * Additional lines DOCS names. Elements of linesApiNames array should
  717. * be consistent with DOCS line names defined in your implementation.
  718. * Notice that linesApiNames should have decreased amount of elements
  719. * relative to pointArrayMap (without pointValKey).
  720. *
  721. * @private
  722. * @name multipleLinesMixin.linesApiNames
  723. * @type {Array<string>}
  724. */
  725. linesApiNames: ['bottomLine'],
  726. /**
  727. * Create translatedLines Collection based on pointArrayMap.
  728. *
  729. * @private
  730. * @function multipleLinesMixin.getTranslatedLinesNames
  731. * @param {string} [excludedValue]
  732. * Main line id
  733. * @return {Array<string>}
  734. * Returns translated lines names without excluded value.
  735. */
  736. getTranslatedLinesNames: function (excludedValue) {
  737. var translatedLines = [];
  738. each(this.pointArrayMap, function (propertyName) {
  739. if (propertyName !== excludedValue) {
  740. translatedLines.push('plot' +
  741. propertyName.charAt(0).toUpperCase() +
  742. propertyName.slice(1));
  743. }
  744. });
  745. return translatedLines;
  746. },
  747. /**
  748. * @private
  749. * @function multipleLinesMixin.toYData
  750. * @param {Highcharts.Point} point
  751. * Indicator point
  752. * @return {Array<number>}
  753. * Returns point Y value for all lines
  754. */
  755. toYData: function (point) {
  756. var pointColl = [];
  757. each(this.pointArrayMap, function (propertyName) {
  758. pointColl.push(point[propertyName]);
  759. });
  760. return pointColl;
  761. },
  762. /**
  763. * Add lines plot pixel values.
  764. *
  765. * @private
  766. * @function multipleLinesMixin.translate
  767. * @return {void}
  768. */
  769. translate: function () {
  770. var indicator = this, pointArrayMap = indicator.pointArrayMap, LinesNames = [], value;
  771. LinesNames = indicator.getTranslatedLinesNames();
  772. SMA.prototype.translate.apply(indicator, arguments);
  773. each(indicator.points, function (point) {
  774. each(pointArrayMap, function (propertyName, i) {
  775. value = point[propertyName];
  776. if (value !== null) {
  777. point[LinesNames[i]] = indicator.yAxis.toPixels(value, true);
  778. }
  779. });
  780. });
  781. },
  782. /**
  783. * Draw main and additional lines.
  784. *
  785. * @private
  786. * @function multipleLinesMixin.drawGraph
  787. * @return {void}
  788. */
  789. drawGraph: function () {
  790. var indicator = this, pointValKey = indicator.pointValKey, linesApiNames = indicator.linesApiNames, mainLinePoints = indicator.points, pointsLength = mainLinePoints.length, mainLineOptions = indicator.options, mainLinePath = indicator.graph, gappedExtend = {
  791. options: {
  792. gapSize: mainLineOptions.gapSize
  793. }
  794. },
  795. // additional lines point place holders:
  796. secondaryLines = [], secondaryLinesNames = indicator.getTranslatedLinesNames(pointValKey), point;
  797. // Generate points for additional lines:
  798. each(secondaryLinesNames, function (plotLine, index) {
  799. // create additional lines point place holders
  800. secondaryLines[index] = [];
  801. while (pointsLength--) {
  802. point = mainLinePoints[pointsLength];
  803. secondaryLines[index].push({
  804. x: point.x,
  805. plotX: point.plotX,
  806. plotY: point[plotLine],
  807. isNull: !defined(point[plotLine])
  808. });
  809. }
  810. pointsLength = mainLinePoints.length;
  811. });
  812. // Modify options and generate additional lines:
  813. each(linesApiNames, function (lineName, i) {
  814. if (secondaryLines[i]) {
  815. indicator.points = secondaryLines[i];
  816. if (mainLineOptions[lineName]) {
  817. indicator.options = merge(mainLineOptions[lineName].styles, gappedExtend);
  818. }
  819. else {
  820. error('Error: "There is no ' + lineName +
  821. ' in DOCS options declared. Check if linesApiNames' +
  822. ' are consistent with your DOCS line names."' +
  823. ' at mixin/multiple-line.js:34');
  824. }
  825. indicator.graph = indicator['graph' + lineName];
  826. SMA.prototype.drawGraph.call(indicator);
  827. // Now save lines:
  828. indicator['graph' + lineName] = indicator.graph;
  829. }
  830. else {
  831. error('Error: "' + lineName + ' doesn\'t have equivalent ' +
  832. 'in pointArrayMap. To many elements in linesApiNames ' +
  833. 'relative to pointArrayMap."');
  834. }
  835. });
  836. // Restore options and draw a main line:
  837. indicator.points = mainLinePoints;
  838. indicator.options = mainLineOptions;
  839. indicator.graph = mainLinePath;
  840. SMA.prototype.drawGraph.call(indicator);
  841. }
  842. };
  843. return multipleLinesMixin;
  844. });
  845. _registerModule(_modules, 'indicators/aroon.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['mixins/multipe-lines.js']], function (H, U, multipleLinesMixin) {
  846. /* *
  847. *
  848. * License: www.highcharts.com/license
  849. *
  850. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  851. *
  852. * */
  853. var pick = U.pick;
  854. /* eslint-disable valid-jsdoc */
  855. // Utils
  856. // Index of element with extreme value from array (min or max)
  857. /**
  858. * @private
  859. */
  860. function getExtremeIndexInArray(arr, extreme) {
  861. var extremeValue = arr[0], valueIndex = 0, i;
  862. for (i = 1; i < arr.length; i++) {
  863. if (extreme === 'max' && arr[i] >= extremeValue ||
  864. extreme === 'min' && arr[i] <= extremeValue) {
  865. extremeValue = arr[i];
  866. valueIndex = i;
  867. }
  868. }
  869. return valueIndex;
  870. }
  871. /* eslint-enable valid-jsdoc */
  872. /**
  873. * The Aroon series type.
  874. *
  875. * @private
  876. * @class
  877. * @name Highcharts.seriesTypes.aroon
  878. *
  879. * @augments Highcharts.Series
  880. */
  881. H.seriesType('aroon', 'sma',
  882. /**
  883. * Aroon. This series requires the `linkedTo` option to be
  884. * set and should be loaded after the `stock/indicators/indicators.js`.
  885. *
  886. * @sample {highstock} stock/indicators/aroon
  887. * Aroon
  888. *
  889. * @extends plotOptions.sma
  890. * @since 7.0.0
  891. * @product highstock
  892. * @excluding allAreas, colorAxis, compare, compareBase, joinBy, keys,
  893. * navigatorOptions, pointInterval, pointIntervalUnit,
  894. * pointPlacement, pointRange, pointStart, showInNavigator,
  895. * stacking
  896. * @requires stock/indicators/indicators
  897. * @requires stock/indicators/aroon
  898. * @optionparent plotOptions.aroon
  899. */
  900. {
  901. /**
  902. * Paramters used in calculation of aroon series points.
  903. *
  904. * @excluding periods, index
  905. */
  906. params: {
  907. /**
  908. * Period for Aroon indicator
  909. */
  910. period: 25
  911. },
  912. marker: {
  913. enabled: false
  914. },
  915. tooltip: {
  916. pointFormat: '<span style="color:{point.color}">\u25CF</span><b> {series.name}</b><br/>Aroon Up: {point.y}<br/>Aroon Down: {point.aroonDown}<br/>'
  917. },
  918. /**
  919. * aroonDown line options.
  920. */
  921. aroonDown: {
  922. /**
  923. * Styles for an aroonDown line.
  924. */
  925. styles: {
  926. /**
  927. * Pixel width of the line.
  928. */
  929. lineWidth: 1,
  930. /**
  931. * Color of the line. If not set, it's inherited from
  932. * [plotOptions.aroon.color](#plotOptions.aroon.color).
  933. *
  934. * @type {Highcharts.ColorString}
  935. */
  936. lineColor: void 0
  937. }
  938. },
  939. dataGrouping: {
  940. approximation: 'averages'
  941. }
  942. },
  943. /**
  944. * @lends Highcharts.Series#
  945. */
  946. H.merge(multipleLinesMixin, {
  947. nameBase: 'Aroon',
  948. pointArrayMap: ['y', 'aroonDown'],
  949. pointValKey: 'y',
  950. linesApiNames: ['aroonDown'],
  951. getValues: function (series, params) {
  952. var period = params.period, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0,
  953. // 0- date, 1- Aroon Up, 2- Aroon Down
  954. AR = [], xData = [], yData = [], slicedY, low = 2, high = 1, aroonUp, aroonDown, xLow, xHigh, i;
  955. // For a N-period, we start from N-1 point, to calculate Nth point
  956. // That is why we later need to comprehend slice() elements list
  957. // with (+1)
  958. for (i = period - 1; i < yValLen; i++) {
  959. slicedY = yVal.slice(i - period + 1, i + 2);
  960. xLow = getExtremeIndexInArray(slicedY.map(function (elem) {
  961. return pick(elem[low], elem);
  962. }), 'min');
  963. xHigh = getExtremeIndexInArray(slicedY.map(function (elem) {
  964. return pick(elem[high], elem);
  965. }), 'max');
  966. aroonUp = (xHigh / period) * 100;
  967. aroonDown = (xLow / period) * 100;
  968. if (xVal[i + 1]) {
  969. AR.push([xVal[i + 1], aroonUp, aroonDown]);
  970. xData.push(xVal[i + 1]);
  971. yData.push([aroonUp, aroonDown]);
  972. }
  973. }
  974. return {
  975. values: AR,
  976. xData: xData,
  977. yData: yData
  978. };
  979. }
  980. }));
  981. /**
  982. * A Aroon indicator. If the [type](#series.aroon.type) option is not
  983. * specified, it is inherited from [chart.type](#chart.type).
  984. *
  985. * @extends series,plotOptions.aroon
  986. * @since 7.0.0
  987. * @product highstock
  988. * @excluding allAreas, colorAxis, compare, compareBase, dataParser, dataURL,
  989. * joinBy, keys, navigatorOptions, pointInterval, pointIntervalUnit,
  990. * pointPlacement, pointRange, pointStart, showInNavigator, stacking
  991. * @requires stock/indicators/indicators
  992. * @requires stock/indicators/aroon
  993. * @apioption series.aroon
  994. */
  995. ''; // to avoid removal of the above jsdoc
  996. });
  997. _registerModule(_modules, 'indicators/aroon-oscillator.src.js', [_modules['parts/Globals.js'], _modules['mixins/multipe-lines.js'], _modules['mixins/indicator-required.js']], function (H, multipleLinesMixin, requiredIndicatorMixin) {
  998. /* *
  999. *
  1000. * License: www.highcharts.com/license
  1001. *
  1002. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1003. *
  1004. * */
  1005. var AROON = H.seriesTypes.aroon, requiredIndicator = requiredIndicatorMixin;
  1006. /**
  1007. * The Aroon Oscillator series type.
  1008. *
  1009. * @private
  1010. * @class
  1011. * @name Highcharts.seriesTypes.aroonoscillator
  1012. *
  1013. * @augments Highcharts.Series
  1014. */
  1015. H.seriesType('aroonoscillator', 'aroon',
  1016. /**
  1017. * Aroon Oscillator. This series requires the `linkedTo` option to be set
  1018. * and should be loaded after the `stock/indicators/indicators.js` and
  1019. * `stock/indicators/aroon.js`.
  1020. *
  1021. * @sample {highstock} stock/indicators/aroon-oscillator
  1022. * Aroon Oscillator
  1023. *
  1024. * @extends plotOptions.aroon
  1025. * @since 7.0.0
  1026. * @product highstock
  1027. * @excluding allAreas, aroonDown, colorAxis, compare, compareBase,
  1028. * joinBy, keys, navigatorOptions, pointInterval,
  1029. * pointIntervalUnit, pointPlacement, pointRange, pointStart,
  1030. * showInNavigator, stacking
  1031. * @requires stock/indicators/indicators
  1032. * @requires stock/indicators/aroon
  1033. * @requires stock/indicators/aroon-oscillator
  1034. * @optionparent plotOptions.aroonoscillator
  1035. */
  1036. {
  1037. /**
  1038. * Paramters used in calculation of aroon oscillator series points.
  1039. *
  1040. * @excluding periods, index
  1041. */
  1042. params: {
  1043. /**
  1044. * Period for Aroon Oscillator
  1045. *
  1046. * @since 7.0.0
  1047. * @product highstock
  1048. */
  1049. period: 25
  1050. },
  1051. tooltip: {
  1052. pointFormat: '<span style="color:{point.color}">\u25CF</span><b> {series.name}</b>: {point.y}'
  1053. }
  1054. },
  1055. /**
  1056. * @lends Highcharts.Series#
  1057. */
  1058. H.merge(multipleLinesMixin, {
  1059. nameBase: 'Aroon Oscillator',
  1060. pointArrayMap: ['y'],
  1061. pointValKey: 'y',
  1062. linesApiNames: [],
  1063. init: function () {
  1064. var args = arguments, ctx = this;
  1065. requiredIndicator.isParentLoaded(AROON, 'aroon', ctx.type, function (indicator) {
  1066. indicator.prototype.init.apply(ctx, args);
  1067. return;
  1068. });
  1069. },
  1070. getValues: function (series, params) {
  1071. // 0- date, 1- Aroon Oscillator
  1072. var ARO = [], xData = [], yData = [], aroon, aroonUp, aroonDown, oscillator, i;
  1073. aroon = AROON.prototype.getValues.call(this, series, params);
  1074. for (i = 0; i < aroon.yData.length; i++) {
  1075. aroonUp = aroon.yData[i][0];
  1076. aroonDown = aroon.yData[i][1];
  1077. oscillator = aroonUp - aroonDown;
  1078. ARO.push([aroon.xData[i], oscillator]);
  1079. xData.push(aroon.xData[i]);
  1080. yData.push(oscillator);
  1081. }
  1082. return {
  1083. values: ARO,
  1084. xData: xData,
  1085. yData: yData
  1086. };
  1087. }
  1088. }));
  1089. /**
  1090. * An `Aroon Oscillator` series. If the [type](#series.aroonoscillator.type)
  1091. * option is not specified, it is inherited from [chart.type](#chart.type).
  1092. *
  1093. * @extends series,plotOptions.aroonoscillator
  1094. * @since 7.0.0
  1095. * @product highstock
  1096. * @excluding allAreas, aroonDown, colorAxis, compare, compareBase, dataParser,
  1097. * dataURL, joinBy, keys, navigatorOptions, pointInterval,
  1098. * pointIntervalUnit, pointPlacement, pointRange, pointStart,
  1099. * showInNavigator, stacking
  1100. * @requires stock/indicators/indicators
  1101. * @requires stock/indicators/aroon
  1102. * @requires stock/indicators/aroon-oscillator
  1103. * @apioption series.aroonoscillator
  1104. */
  1105. ''; // adds doclet above to the transpiled file
  1106. });
  1107. _registerModule(_modules, 'indicators/atr.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  1108. /* *
  1109. *
  1110. * License: www.highcharts.com/license
  1111. *
  1112. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1113. *
  1114. * */
  1115. var isArray = U.isArray;
  1116. var seriesType = H.seriesType, UNDEFINED;
  1117. /* eslint-disable valid-jsdoc */
  1118. // Utils:
  1119. /**
  1120. * @private
  1121. */
  1122. function accumulateAverage(points, xVal, yVal, i) {
  1123. var xValue = xVal[i], yValue = yVal[i];
  1124. points.push([xValue, yValue]);
  1125. }
  1126. /**
  1127. * @private
  1128. */
  1129. function getTR(currentPoint, prevPoint) {
  1130. var pointY = currentPoint, prevY = prevPoint, HL = pointY[1] - pointY[2], HCp = prevY === UNDEFINED ? 0 : Math.abs(pointY[1] - prevY[3]), LCp = prevY === UNDEFINED ? 0 : Math.abs(pointY[2] - prevY[3]), TR = Math.max(HL, HCp, LCp);
  1131. return TR;
  1132. }
  1133. /**
  1134. * @private
  1135. */
  1136. function populateAverage(points, xVal, yVal, i, period, prevATR) {
  1137. var x = xVal[i - 1], TR = getTR(yVal[i - 1], yVal[i - 2]), y;
  1138. y = (((prevATR * (period - 1)) + TR) / period);
  1139. return [x, y];
  1140. }
  1141. /* eslint-enable valid-jsdoc */
  1142. /**
  1143. * The ATR series type.
  1144. *
  1145. * @private
  1146. * @class
  1147. * @name Highcharts.seriesTypes.atr
  1148. *
  1149. * @augments Highcharts.Series
  1150. */
  1151. seriesType('atr', 'sma',
  1152. /**
  1153. * Average true range indicator (ATR). This series requires `linkedTo`
  1154. * option to be set.
  1155. *
  1156. * @sample stock/indicators/atr
  1157. * ATR indicator
  1158. *
  1159. * @extends plotOptions.sma
  1160. * @since 6.0.0
  1161. * @product highstock
  1162. * @requires stock/indicators/indicators
  1163. * @requires stock/indicators/atr
  1164. * @optionparent plotOptions.atr
  1165. */
  1166. {
  1167. params: {
  1168. period: 14
  1169. }
  1170. },
  1171. /**
  1172. * @lends Highcharts.Series#
  1173. */
  1174. {
  1175. getValues: function (series, params) {
  1176. var period = params.period, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0, xValue = xVal[0], yValue = yVal[0], range = 1, prevATR = 0, TR = 0, ATR = [], xData = [], yData = [], point, i, points;
  1177. points = [[xValue, yValue]];
  1178. if ((xVal.length <= period) ||
  1179. !isArray(yVal[0]) ||
  1180. yVal[0].length !== 4) {
  1181. return;
  1182. }
  1183. for (i = 1; i <= yValLen; i++) {
  1184. accumulateAverage(points, xVal, yVal, i);
  1185. if (period < range) {
  1186. point = populateAverage(points, xVal, yVal, i, period, prevATR);
  1187. prevATR = point[1];
  1188. ATR.push(point);
  1189. xData.push(point[0]);
  1190. yData.push(point[1]);
  1191. }
  1192. else if (period === range) {
  1193. prevATR = TR / (i - 1);
  1194. ATR.push([xVal[i - 1], prevATR]);
  1195. xData.push(xVal[i - 1]);
  1196. yData.push(prevATR);
  1197. range++;
  1198. }
  1199. else {
  1200. TR += getTR(yVal[i - 1], yVal[i - 2]);
  1201. range++;
  1202. }
  1203. }
  1204. return {
  1205. values: ATR,
  1206. xData: xData,
  1207. yData: yData
  1208. };
  1209. }
  1210. });
  1211. /**
  1212. * A `ATR` series. If the [type](#series.atr.type) option is not specified, it
  1213. * is inherited from [chart.type](#chart.type).
  1214. *
  1215. * @extends series,plotOptions.atr
  1216. * @since 6.0.0
  1217. * @product highstock
  1218. * @excluding dataParser, dataURL
  1219. * @requires stock/indicators/indicators
  1220. * @requires stock/indicators/atr
  1221. * @apioption series.atr
  1222. */
  1223. ''; // to include the above in the js output
  1224. });
  1225. _registerModule(_modules, 'indicators/bollinger-bands.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['mixins/multipe-lines.js']], function (H, U, multipleLinesMixin) {
  1226. /**
  1227. *
  1228. * License: www.highcharts.com/license
  1229. *
  1230. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1231. *
  1232. * */
  1233. var isArray = U.isArray;
  1234. var merge = H.merge, SMA = H.seriesTypes.sma;
  1235. /* eslint-disable valid-jsdoc */
  1236. // Utils:
  1237. /**
  1238. * @private
  1239. */
  1240. function getStandardDeviation(arr, index, isOHLC, mean) {
  1241. var variance = 0, arrLen = arr.length, std = 0, i = 0, value;
  1242. for (; i < arrLen; i++) {
  1243. value = (isOHLC ? arr[i][index] : arr[i]) - mean;
  1244. variance += value * value;
  1245. }
  1246. variance = variance / (arrLen - 1);
  1247. std = Math.sqrt(variance);
  1248. return std;
  1249. }
  1250. /* eslint-enable valid-jsdoc */
  1251. /**
  1252. * Bollinger Bands series type.
  1253. *
  1254. * @private
  1255. * @class
  1256. * @name Highcharts.seriesTypes.bb
  1257. *
  1258. * @augments Highcharts.Series
  1259. */
  1260. H.seriesType('bb', 'sma',
  1261. /**
  1262. * Bollinger bands (BB). This series requires the `linkedTo` option to be
  1263. * set and should be loaded after the `stock/indicators/indicators.js` file.
  1264. *
  1265. * @sample stock/indicators/bollinger-bands
  1266. * Bollinger bands
  1267. *
  1268. * @extends plotOptions.sma
  1269. * @since 6.0.0
  1270. * @product highstock
  1271. * @requires stock/indicators/indicators
  1272. * @requires stock/indicators/bollinger-bands
  1273. * @optionparent plotOptions.bb
  1274. */
  1275. {
  1276. params: {
  1277. period: 20,
  1278. /**
  1279. * Standard deviation for top and bottom bands.
  1280. */
  1281. standardDeviation: 2,
  1282. index: 3
  1283. },
  1284. /**
  1285. * Bottom line options.
  1286. */
  1287. bottomLine: {
  1288. /**
  1289. * Styles for a bottom line.
  1290. */
  1291. styles: {
  1292. /**
  1293. * Pixel width of the line.
  1294. */
  1295. lineWidth: 1,
  1296. /**
  1297. * Color of the line. If not set, it's inherited from
  1298. * [plotOptions.bb.color](#plotOptions.bb.color).
  1299. *
  1300. * @type {Highcharts.ColorString}
  1301. */
  1302. lineColor: void 0
  1303. }
  1304. },
  1305. /**
  1306. * Top line options.
  1307. *
  1308. * @extends plotOptions.bb.bottomLine
  1309. */
  1310. topLine: {
  1311. styles: {
  1312. lineWidth: 1,
  1313. /**
  1314. * @type {Highcharts.ColorString}
  1315. */
  1316. lineColor: void 0
  1317. }
  1318. },
  1319. tooltip: {
  1320. pointFormat: '<span style="color:{point.color}">\u25CF</span><b> {series.name}</b><br/>Top: {point.top}<br/>Middle: {point.middle}<br/>Bottom: {point.bottom}<br/>'
  1321. },
  1322. marker: {
  1323. enabled: false
  1324. },
  1325. dataGrouping: {
  1326. approximation: 'averages'
  1327. }
  1328. },
  1329. /**
  1330. * @lends Highcharts.Series#
  1331. */
  1332. H.merge(multipleLinesMixin, {
  1333. pointArrayMap: ['top', 'middle', 'bottom'],
  1334. pointValKey: 'middle',
  1335. nameComponents: ['period', 'standardDeviation'],
  1336. linesApiNames: ['topLine', 'bottomLine'],
  1337. init: function () {
  1338. SMA.prototype.init.apply(this, arguments);
  1339. // Set default color for lines:
  1340. this.options = merge({
  1341. topLine: {
  1342. styles: {
  1343. lineColor: this.color
  1344. }
  1345. },
  1346. bottomLine: {
  1347. styles: {
  1348. lineColor: this.color
  1349. }
  1350. }
  1351. }, this.options);
  1352. },
  1353. getValues: function (series, params) {
  1354. var period = params.period, standardDeviation = params.standardDeviation, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0,
  1355. // 0- date, 1-middle line, 2-top line, 3-bottom line
  1356. BB = [],
  1357. // middle line, top line and bottom line
  1358. ML, TL, BL, date, xData = [], yData = [], slicedX, slicedY, stdDev, isOHLC, point, i;
  1359. if (xVal.length < period) {
  1360. return;
  1361. }
  1362. isOHLC = isArray(yVal[0]);
  1363. for (i = period; i <= yValLen; i++) {
  1364. slicedX = xVal.slice(i - period, i);
  1365. slicedY = yVal.slice(i - period, i);
  1366. point = SMA.prototype.getValues.call(this, {
  1367. xData: slicedX,
  1368. yData: slicedY
  1369. }, params);
  1370. date = point.xData[0];
  1371. ML = point.yData[0];
  1372. stdDev = getStandardDeviation(slicedY, params.index, isOHLC, ML);
  1373. TL = ML + standardDeviation * stdDev;
  1374. BL = ML - standardDeviation * stdDev;
  1375. BB.push([date, TL, ML, BL]);
  1376. xData.push(date);
  1377. yData.push([TL, ML, BL]);
  1378. }
  1379. return {
  1380. values: BB,
  1381. xData: xData,
  1382. yData: yData
  1383. };
  1384. }
  1385. }));
  1386. /**
  1387. * A bollinger bands indicator. If the [type](#series.bb.type) option is not
  1388. * specified, it is inherited from [chart.type](#chart.type).
  1389. *
  1390. * @extends series,plotOptions.bb
  1391. * @since 6.0.0
  1392. * @excluding dataParser, dataURL
  1393. * @product highstock
  1394. * @requires stock/indicators/indicators
  1395. * @requires stock/indicators/bollinger-bands
  1396. * @apioption series.bb
  1397. */
  1398. ''; // to include the above in the js output
  1399. });
  1400. _registerModule(_modules, 'indicators/cci.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  1401. /* *
  1402. *
  1403. * License: www.highcharts.com/license
  1404. *
  1405. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1406. * */
  1407. var isArray = U.isArray;
  1408. var seriesType = H.seriesType;
  1409. /* eslint-disable valid-jsdoc */
  1410. // Utils:
  1411. /**
  1412. * @private
  1413. */
  1414. function sumArray(array) {
  1415. return array.reduce(function (prev, cur) {
  1416. return prev + cur;
  1417. }, 0);
  1418. }
  1419. /**
  1420. * @private
  1421. */
  1422. function meanDeviation(arr, sma) {
  1423. var len = arr.length, sum = 0, i;
  1424. for (i = 0; i < len; i++) {
  1425. sum += Math.abs(sma - (arr[i]));
  1426. }
  1427. return sum;
  1428. }
  1429. /* eslint-enable valid-jsdoc */
  1430. /**
  1431. * The CCI series type.
  1432. *
  1433. * @private
  1434. * @class
  1435. * @name Highcharts.seriesTypes.cci
  1436. *
  1437. * @augments Highcharts.Series
  1438. */
  1439. seriesType('cci', 'sma',
  1440. /**
  1441. * Commodity Channel Index (CCI). This series requires `linkedTo` option to
  1442. * be set.
  1443. *
  1444. * @sample stock/indicators/cci
  1445. * CCI indicator
  1446. *
  1447. * @extends plotOptions.sma
  1448. * @since 6.0.0
  1449. * @product highstock
  1450. * @requires stock/indicators/indicators
  1451. * @requires stock/indicators/cci
  1452. * @optionparent plotOptions.cci
  1453. */
  1454. {
  1455. params: {
  1456. period: 14
  1457. }
  1458. },
  1459. /**
  1460. * @lends Highcharts.Series#
  1461. */
  1462. {
  1463. getValues: function (series, params) {
  1464. var period = params.period, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0, TP = [], periodTP = [], range = 1, CCI = [], xData = [], yData = [], CCIPoint, p, len, smaTP, TPtemp, meanDev, i;
  1465. // CCI requires close value
  1466. if (xVal.length <= period ||
  1467. !isArray(yVal[0]) ||
  1468. yVal[0].length !== 4) {
  1469. return;
  1470. }
  1471. // accumulate first N-points
  1472. while (range < period) {
  1473. p = yVal[range - 1];
  1474. TP.push((p[1] + p[2] + p[3]) / 3);
  1475. range++;
  1476. }
  1477. for (i = period; i <= yValLen; i++) {
  1478. p = yVal[i - 1];
  1479. TPtemp = (p[1] + p[2] + p[3]) / 3;
  1480. len = TP.push(TPtemp);
  1481. periodTP = TP.slice(len - period);
  1482. smaTP = sumArray(periodTP) / period;
  1483. meanDev = meanDeviation(periodTP, smaTP) / period;
  1484. CCIPoint = ((TPtemp - smaTP) / (0.015 * meanDev));
  1485. CCI.push([xVal[i - 1], CCIPoint]);
  1486. xData.push(xVal[i - 1]);
  1487. yData.push(CCIPoint);
  1488. }
  1489. return {
  1490. values: CCI,
  1491. xData: xData,
  1492. yData: yData
  1493. };
  1494. }
  1495. });
  1496. /**
  1497. * A `CCI` series. If the [type](#series.cci.type) option is not
  1498. * specified, it is inherited from [chart.type](#chart.type).
  1499. *
  1500. * @extends series,plotOptions.cci
  1501. * @since 6.0.0
  1502. * @excluding dataParser, dataURL
  1503. * @product highstock
  1504. * @requires stock/indicators/indicators
  1505. * @requires stock/indicators/cci
  1506. * @apioption series.cci
  1507. */
  1508. ''; // to include the above in the js output
  1509. });
  1510. _registerModule(_modules, 'indicators/cmf.src.js', [_modules['parts/Globals.js']], function (H) {
  1511. /* *
  1512. *
  1513. * (c) 2010-2019 Highsoft AS
  1514. *
  1515. * Author: Sebastian Domas
  1516. *
  1517. * Chaikin Money Flow indicator for Highstock
  1518. *
  1519. * License: www.highcharts.com/license
  1520. *
  1521. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1522. *
  1523. * */
  1524. /**
  1525. * The CMF series type.
  1526. *
  1527. * @private
  1528. * @class
  1529. * @name Highcharts.seriesTypes.cmf
  1530. *
  1531. * @augments Highcharts.Series
  1532. */
  1533. H.seriesType('cmf', 'sma',
  1534. /**
  1535. * Chaikin Money Flow indicator (cmf).
  1536. *
  1537. * @sample stock/indicators/cmf/
  1538. * Chaikin Money Flow indicator
  1539. *
  1540. * @extends plotOptions.sma
  1541. * @since 6.0.0
  1542. * @excluding animationLimit
  1543. * @product highstock
  1544. * @requires stock/indicators/indicators
  1545. * @requires stock/indicators/cmf
  1546. * @optionparent plotOptions.cmf
  1547. */
  1548. {
  1549. params: {
  1550. period: 14,
  1551. /**
  1552. * The id of another series to use its data as volume data for the
  1553. * indiator calculation.
  1554. */
  1555. volumeSeriesID: 'volume'
  1556. }
  1557. },
  1558. /**
  1559. * @lends Highcharts.Series#
  1560. */
  1561. {
  1562. nameBase: 'Chaikin Money Flow',
  1563. /**
  1564. * Checks if the series and volumeSeries are accessible, number of
  1565. * points.x is longer than period, is series has OHLC data
  1566. * @private
  1567. * @param {Highcharts.CMFIndicator} this indicator to use.
  1568. * @return {boolean} True if series is valid and can be computed,
  1569. * otherwise false.
  1570. */
  1571. isValid: function () {
  1572. var chart = this.chart, options = this.options, series = this.linkedParent, volumeSeries = (this.volumeSeries ||
  1573. (this.volumeSeries =
  1574. chart.get(options.params.volumeSeriesID))), isSeriesOHLC = (series &&
  1575. series.yData &&
  1576. series.yData[0].length === 4);
  1577. /**
  1578. * @private
  1579. * @param {Highcharts.Series} serie to check length validity on.
  1580. * @return {boolean|undefined} true if length is valid.
  1581. */
  1582. function isLengthValid(serie) {
  1583. return serie.xData &&
  1584. serie.xData.length >= options.params.period;
  1585. }
  1586. return !!(series &&
  1587. volumeSeries &&
  1588. isLengthValid(series) &&
  1589. isLengthValid(volumeSeries) && isSeriesOHLC);
  1590. },
  1591. /**
  1592. * Returns indicator's data.
  1593. * @private
  1594. * @param {Highcharts.CMFIndicator} this indicator to use.
  1595. * @param {Highcharts.Series} series to calculate values from
  1596. * @param {Highcharts.CMFIndicatorParamsOptions} params to pass
  1597. * @return {boolean|Highcharts.IndicatorNullableValuesObject} Returns false if the
  1598. * indicator is not valid, otherwise returns Values object.
  1599. */
  1600. getValues: function (series, params) {
  1601. if (!this.isValid()) {
  1602. return;
  1603. }
  1604. return this.getMoneyFlow(series.xData, series.yData, this.volumeSeries.yData, params.period);
  1605. },
  1606. /**
  1607. * @private
  1608. * @param {Array<number>} xData - x timestamp values
  1609. * @param {Array<number>} seriesYData - yData of basic series
  1610. * @param {Array<number>} volumeSeriesYData - yData of volume series
  1611. * @param {number} period - indicator's param
  1612. * @return {Highcharts.IndicatorNullableValuesObject} object containing computed money
  1613. * flow data
  1614. */
  1615. getMoneyFlow: function (xData, seriesYData, volumeSeriesYData, period) {
  1616. var len = seriesYData.length, moneyFlowVolume = [], sumVolume = 0, sumMoneyFlowVolume = 0, moneyFlowXData = [], moneyFlowYData = [], values = [], i, point, nullIndex = -1;
  1617. /**
  1618. * Calculates money flow volume, changes i, nullIndex vars from
  1619. * upper scope!
  1620. * @private
  1621. * @param {Array<number>} ohlc - OHLC point
  1622. * @param {number} volume - Volume point's y value
  1623. * @return {number|null} - volume * moneyFlowMultiplier
  1624. **/
  1625. function getMoneyFlowVolume(ohlc, volume) {
  1626. var high = ohlc[1], low = ohlc[2], close = ohlc[3], isValid = volume !== null &&
  1627. high !== null &&
  1628. low !== null &&
  1629. close !== null &&
  1630. high !== low;
  1631. /**
  1632. * @private
  1633. * @param {number} h - High value
  1634. * @param {number} l - Low value
  1635. * @param {number} c - Close value
  1636. * @return {number} calculated multiplier for the point
  1637. **/
  1638. function getMoneyFlowMultiplier(h, l, c) {
  1639. return ((c - l) - (h - c)) / (h - l);
  1640. }
  1641. return isValid ?
  1642. getMoneyFlowMultiplier(high, low, close) * volume :
  1643. ((nullIndex = i), null);
  1644. }
  1645. if (period > 0 && period <= len) {
  1646. for (i = 0; i < period; i++) {
  1647. moneyFlowVolume[i] = getMoneyFlowVolume(seriesYData[i], volumeSeriesYData[i]);
  1648. sumVolume += volumeSeriesYData[i];
  1649. sumMoneyFlowVolume += moneyFlowVolume[i];
  1650. }
  1651. moneyFlowXData.push(xData[i - 1]);
  1652. moneyFlowYData.push(i - nullIndex >= period && sumVolume !== 0 ?
  1653. sumMoneyFlowVolume / sumVolume :
  1654. null);
  1655. values.push([moneyFlowXData[0], moneyFlowYData[0]]);
  1656. for (; i < len; i++) {
  1657. moneyFlowVolume[i] = getMoneyFlowVolume(seriesYData[i], volumeSeriesYData[i]);
  1658. sumVolume -= volumeSeriesYData[i - period];
  1659. sumVolume += volumeSeriesYData[i];
  1660. sumMoneyFlowVolume -= moneyFlowVolume[i - period];
  1661. sumMoneyFlowVolume += moneyFlowVolume[i];
  1662. point = [
  1663. xData[i],
  1664. i - nullIndex >= period ?
  1665. sumMoneyFlowVolume / sumVolume :
  1666. null
  1667. ];
  1668. moneyFlowXData.push(point[0]);
  1669. moneyFlowYData.push(point[1]);
  1670. values.push([point[0], point[1]]);
  1671. }
  1672. }
  1673. return {
  1674. values: values,
  1675. xData: moneyFlowXData,
  1676. yData: moneyFlowYData
  1677. };
  1678. }
  1679. });
  1680. /**
  1681. * A `CMF` series. If the [type](#series.cmf.type) option is not
  1682. * specified, it is inherited from [chart.type](#chart.type).
  1683. *
  1684. * @extends series,plotOptions.cmf
  1685. * @since 6.0.0
  1686. * @product highstock
  1687. * @excluding dataParser, dataURL
  1688. * @requires stock/indicators/indicators
  1689. * @requires stock/indicators/cmf
  1690. * @apioption series.cmf
  1691. */
  1692. ''; // adds doclet above to the transpiled file
  1693. });
  1694. _registerModule(_modules, 'indicators/dpo.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  1695. /* *
  1696. *
  1697. * License: www.highcharts.com/license
  1698. *
  1699. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1700. *
  1701. * */
  1702. var correctFloat = U.correctFloat, pick = U.pick;
  1703. /* eslint-disable valid-jsdoc */
  1704. // Utils
  1705. /**
  1706. * @private
  1707. */
  1708. function accumulatePoints(sum, yVal, i, index, subtract) {
  1709. var price = pick(yVal[i][index], yVal[i]);
  1710. if (subtract) {
  1711. return correctFloat(sum - price);
  1712. }
  1713. return correctFloat(sum + price);
  1714. }
  1715. /* eslint-enable valid-jsdoc */
  1716. /**
  1717. * The DPO series type.
  1718. *
  1719. * @private
  1720. * @class
  1721. * @name Highcharts.seriesTypes.dpo
  1722. *
  1723. * @augments Highcharts.Series
  1724. */
  1725. H.seriesType('dpo', 'sma',
  1726. /**
  1727. * Detrended Price Oscillator. This series requires the `linkedTo` option to
  1728. * be set and should be loaded after the `stock/indicators/indicators.js`.
  1729. *
  1730. * @sample {highstock} stock/indicators/dpo
  1731. * Detrended Price Oscillator
  1732. *
  1733. * @extends plotOptions.sma
  1734. * @since 7.0.0
  1735. * @product highstock
  1736. * @excluding allAreas, colorAxis, compare, compareBase, joinBy, keys,
  1737. * navigatorOptions, pointInterval, pointIntervalUnit,
  1738. * pointPlacement, pointRange, pointStart, showInNavigator,
  1739. * stacking
  1740. * @requires stock/indicators/indicators
  1741. * @requires stock/indicators/dpo
  1742. * @optionparent plotOptions.dpo
  1743. */
  1744. {
  1745. /**
  1746. * Parameters used in calculation of Detrended Price Oscillator series
  1747. * points.
  1748. */
  1749. params: {
  1750. /**
  1751. * Period for Detrended Price Oscillator
  1752. */
  1753. period: 21
  1754. }
  1755. },
  1756. /**
  1757. * @lends Highcharts.Series#
  1758. */
  1759. {
  1760. nameBase: 'DPO',
  1761. getValues: function (series, params) {
  1762. var period = params.period, index = params.index, offset = Math.floor(period / 2 + 1), range = period + offset, xVal = series.xData || [], yVal = series.yData || [], yValLen = yVal.length,
  1763. // 0- date, 1- Detrended Price Oscillator
  1764. DPO = [], xData = [], yData = [], sum = 0, oscillator, periodIndex, rangeIndex, price, i, j;
  1765. if (xVal.length <= range) {
  1766. return;
  1767. }
  1768. // Accumulate first N-points for SMA
  1769. for (i = 0; i < period - 1; i++) {
  1770. sum = accumulatePoints(sum, yVal, i, index);
  1771. }
  1772. // Detrended Price Oscillator formula:
  1773. // DPO = Price - Simple moving average [from (n / 2 + 1) days ago]
  1774. for (j = 0; j <= yValLen - range; j++) {
  1775. periodIndex = j + period - 1;
  1776. rangeIndex = j + range - 1;
  1777. // adding the last period point
  1778. sum = accumulatePoints(sum, yVal, periodIndex, index);
  1779. price = pick(yVal[rangeIndex][index], yVal[rangeIndex]);
  1780. oscillator = price - sum / period;
  1781. // substracting the first period point
  1782. sum = accumulatePoints(sum, yVal, j, index, true);
  1783. DPO.push([xVal[rangeIndex], oscillator]);
  1784. xData.push(xVal[rangeIndex]);
  1785. yData.push(oscillator);
  1786. }
  1787. return {
  1788. values: DPO,
  1789. xData: xData,
  1790. yData: yData
  1791. };
  1792. }
  1793. });
  1794. /**
  1795. * A Detrended Price Oscillator. If the [type](#series.dpo.type) option is not
  1796. * specified, it is inherited from [chart.type](#chart.type).
  1797. *
  1798. * @extends series,plotOptions.dpo
  1799. * @since 7.0.0
  1800. * @product highstock
  1801. * @excluding allAreas, colorAxis, compare, compareBase, dataParser, dataURL,
  1802. * joinBy, keys, navigatorOptions, pointInterval, pointIntervalUnit,
  1803. * pointPlacement, pointRange, pointStart, showInNavigator, stacking
  1804. * @requires stock/indicators/indicators
  1805. * @requires stock/indicators/dpo
  1806. * @apioption series.dpo
  1807. */
  1808. ''; // to include the above in the js output'
  1809. });
  1810. _registerModule(_modules, 'indicators/ema.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  1811. /* *
  1812. *
  1813. * License: www.highcharts.com/license
  1814. *
  1815. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1816. *
  1817. * */
  1818. var correctFloat = U.correctFloat, isArray = U.isArray;
  1819. var seriesType = H.seriesType;
  1820. /**
  1821. * The EMA series type.
  1822. *
  1823. * @private
  1824. * @class
  1825. * @name Highcharts.seriesTypes.ema
  1826. *
  1827. * @augments Highcharts.Series
  1828. */
  1829. seriesType('ema', 'sma',
  1830. /**
  1831. * Exponential moving average indicator (EMA). This series requires the
  1832. * `linkedTo` option to be set.
  1833. *
  1834. * @sample stock/indicators/ema
  1835. * Exponential moving average indicator
  1836. *
  1837. * @extends plotOptions.sma
  1838. * @since 6.0.0
  1839. * @product highstock
  1840. * @requires stock/indicators/indicators
  1841. * @requires stock/indicators/ema
  1842. * @optionparent plotOptions.ema
  1843. */
  1844. {
  1845. params: {
  1846. /**
  1847. * The point index which indicator calculations will base. For
  1848. * example using OHLC data, index=2 means the indicator will be
  1849. * calculated using Low values.
  1850. *
  1851. * By default index value used to be set to 0. Since Highstock 7
  1852. * by default index is set to 3 which means that the ema
  1853. * indicator will be calculated using Close values.
  1854. */
  1855. index: 3,
  1856. period: 9 // @merge 14 in v6.2
  1857. }
  1858. },
  1859. /**
  1860. * @lends Highcharts.Series#
  1861. */
  1862. {
  1863. accumulatePeriodPoints: function (period, index, yVal) {
  1864. var sum = 0, i = 0, y = 0;
  1865. while (i < period) {
  1866. y = index < 0 ? yVal[i] : yVal[i][index];
  1867. sum = sum + y;
  1868. i++;
  1869. }
  1870. return sum;
  1871. },
  1872. calculateEma: function (xVal, yVal, i, EMApercent, calEMA, index, SMA) {
  1873. var x = xVal[i - 1], yValue = index < 0 ?
  1874. yVal[i - 1] :
  1875. yVal[i - 1][index], y;
  1876. y = typeof calEMA === 'undefined' ?
  1877. SMA : correctFloat((yValue * EMApercent) +
  1878. (calEMA * (1 - EMApercent)));
  1879. return [x, y];
  1880. },
  1881. getValues: function (series, params) {
  1882. var period = params.period, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0, EMApercent = 2 / (period + 1), sum = 0, EMA = [], xData = [], yData = [], index = -1, SMA = 0, calEMA, EMAPoint, i;
  1883. // Check period, if bigger than points length, skip
  1884. if (yValLen < period) {
  1885. return;
  1886. }
  1887. // Switch index for OHLC / Candlestick / Arearange
  1888. if (isArray(yVal[0])) {
  1889. index = params.index ? params.index : 0;
  1890. }
  1891. // Accumulate first N-points
  1892. sum = this.accumulatePeriodPoints(period, index, yVal);
  1893. // first point
  1894. SMA = sum / period;
  1895. // Calculate value one-by-one for each period in visible data
  1896. for (i = period; i < yValLen + 1; i++) {
  1897. EMAPoint = this.calculateEma(xVal, yVal, i, EMApercent, calEMA, index, SMA);
  1898. EMA.push(EMAPoint);
  1899. xData.push(EMAPoint[0]);
  1900. yData.push(EMAPoint[1]);
  1901. calEMA = EMAPoint[1];
  1902. }
  1903. return {
  1904. values: EMA,
  1905. xData: xData,
  1906. yData: yData
  1907. };
  1908. }
  1909. });
  1910. /**
  1911. * A `EMA` series. If the [type](#series.ema.type) option is not
  1912. * specified, it is inherited from [chart.type](#chart.type).
  1913. *
  1914. * @extends series,plotOptions.ema
  1915. * @since 6.0.0
  1916. * @product highstock
  1917. * @excluding dataParser, dataURL
  1918. * @requires stock/indicators/indicators
  1919. * @requires stock/indicators/ema
  1920. * @apioption series.ema
  1921. */
  1922. ''; // adds doclet above to the transpiled file
  1923. });
  1924. _registerModule(_modules, 'indicators/chaikin.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['mixins/indicator-required.js']], function (H, U, requiredIndicatorMixin) {
  1925. /* *
  1926. *
  1927. * License: www.highcharts.com/license
  1928. *
  1929. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1930. *
  1931. * */
  1932. var correctFloat = U.correctFloat;
  1933. var EMA = H.seriesTypes.ema, AD = H.seriesTypes.ad, error = H.error, requiredIndicator = requiredIndicatorMixin;
  1934. /**
  1935. * The Chaikin series type.
  1936. *
  1937. * @private
  1938. * @class
  1939. * @name Highcharts.seriesTypes.chaikin
  1940. *
  1941. * @augments Highcharts.Series
  1942. */
  1943. H.seriesType('chaikin', 'ema',
  1944. /**
  1945. * Chaikin Oscillator. This series requires the `linkedTo` option to
  1946. * be set and should be loaded after the `stock/indicators/indicators.js`
  1947. * and `stock/indicators/ema.js`.
  1948. *
  1949. * @sample {highstock} stock/indicators/chaikin
  1950. * Chaikin Oscillator
  1951. *
  1952. * @extends plotOptions.ema
  1953. * @since 7.0.0
  1954. * @product highstock
  1955. * @excluding allAreas, colorAxis, joinBy, keys, navigatorOptions,
  1956. * pointInterval, pointIntervalUnit, pointPlacement,
  1957. * pointRange, pointStart, showInNavigator, stacking
  1958. * @requires stock/indicators/indicators
  1959. * @requires stock/indicators/ema
  1960. * @requires stock/indicators/chaikin
  1961. * @optionparent plotOptions.chaikin
  1962. */
  1963. {
  1964. /**
  1965. * Paramters used in calculation of Chaikin Oscillator
  1966. * series points.
  1967. *
  1968. * @excluding index, period
  1969. */
  1970. params: {
  1971. /**
  1972. * The id of volume series which is mandatory.
  1973. * For example using OHLC data, volumeSeriesID='volume' means
  1974. * the indicator will be calculated using OHLC and volume values.
  1975. */
  1976. volumeSeriesID: 'volume',
  1977. /**
  1978. * Periods for Chaikin Oscillator calculations.
  1979. *
  1980. * @type {Array<number>}
  1981. * @default [3, 10]
  1982. */
  1983. periods: [3, 10]
  1984. }
  1985. },
  1986. /**
  1987. * @lends Highcharts.Series#
  1988. */
  1989. {
  1990. nameBase: 'Chaikin Osc',
  1991. nameComponents: ['periods'],
  1992. init: function () {
  1993. var args = arguments, ctx = this;
  1994. requiredIndicator.isParentLoaded(EMA, 'ema', ctx.type, function (indicator) {
  1995. indicator.prototype.init.apply(ctx, args);
  1996. return;
  1997. });
  1998. },
  1999. getValues: function (series, params) {
  2000. var periods = params.periods, period = params.period,
  2001. // Accumulation Distribution Line data
  2002. ADL,
  2003. // 0- date, 1- Chaikin Oscillator
  2004. CHA = [], xData = [], yData = [], periodsOffset,
  2005. // Shorter Period EMA
  2006. SPE,
  2007. // Longer Period EMA
  2008. LPE, oscillator, i;
  2009. // Check if periods are correct
  2010. if (periods.length !== 2 || periods[1] <= periods[0]) {
  2011. error('Error: "Chaikin requires two periods. Notice, first ' +
  2012. 'period should be lower than the second one."');
  2013. return;
  2014. }
  2015. ADL = AD.prototype.getValues.call(this, series, {
  2016. volumeSeriesID: params.volumeSeriesID,
  2017. period: period
  2018. });
  2019. // Check if adl is calculated properly, if not skip
  2020. if (!ADL) {
  2021. return;
  2022. }
  2023. SPE = EMA.prototype.getValues.call(this, ADL, {
  2024. period: periods[0]
  2025. });
  2026. LPE = EMA.prototype.getValues.call(this, ADL, {
  2027. period: periods[1]
  2028. });
  2029. // Check if ema is calculated properly, if not skip
  2030. if (!SPE || !LPE) {
  2031. return;
  2032. }
  2033. periodsOffset = periods[1] - periods[0];
  2034. for (i = 0; i < LPE.yData.length; i++) {
  2035. oscillator = correctFloat(SPE.yData[i + periodsOffset] -
  2036. LPE.yData[i]);
  2037. CHA.push([LPE.xData[i], oscillator]);
  2038. xData.push(LPE.xData[i]);
  2039. yData.push(oscillator);
  2040. }
  2041. return {
  2042. values: CHA,
  2043. xData: xData,
  2044. yData: yData
  2045. };
  2046. }
  2047. });
  2048. /**
  2049. * A `Chaikin Oscillator` series. If the [type](#series.chaikin.type)
  2050. * option is not specified, it is inherited from [chart.type](#chart.type).
  2051. *
  2052. * @extends series,plotOptions.chaikin
  2053. * @since 7.0.0
  2054. * @product highstock
  2055. * @excluding allAreas, colorAxis, dataParser, dataURL, joinBy, keys,
  2056. * navigatorOptions, pointInterval, pointIntervalUnit,
  2057. * pointPlacement, pointRange, pointStart, stacking, showInNavigator
  2058. * @requires stock/indicators/indicators
  2059. * @requires stock/indicators/ema
  2060. * @requires stock/indicators/chaikin
  2061. * @apioption series.chaikin
  2062. */
  2063. ''; // to include the above in the js output
  2064. });
  2065. _registerModule(_modules, 'indicators/dema.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['mixins/indicator-required.js']], function (H, U, requiredIndicatorMixin) {
  2066. /* *
  2067. *
  2068. * License: www.highcharts.com/license
  2069. *
  2070. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2071. *
  2072. * */
  2073. var correctFloat = U.correctFloat, isArray = U.isArray;
  2074. var EMAindicator = H.seriesTypes.ema, requiredIndicator = requiredIndicatorMixin;
  2075. /**
  2076. * The DEMA series Type
  2077. *
  2078. * @private
  2079. * @class
  2080. * @name Highcharts.seriesTypes.dema
  2081. *
  2082. * @augments Highcharts.Series
  2083. */
  2084. H.seriesType('dema', 'ema',
  2085. /**
  2086. * Double exponential moving average (DEMA) indicator. This series requires
  2087. * `linkedTo` option to be set and should be loaded after the
  2088. * `stock/indicators/indicators.js` and `stock/indicators/ema.js`.
  2089. *
  2090. * @sample {highstock} stock/indicators/dema
  2091. * DEMA indicator
  2092. *
  2093. * @extends plotOptions.ema
  2094. * @since 7.0.0
  2095. * @product highstock
  2096. * @excluding allAreas, colorAxis, compare, compareBase, joinBy, keys,
  2097. * navigatorOptions, pointInterval, pointIntervalUnit,
  2098. * pointPlacement, pointRange, pointStart, showInNavigator,
  2099. * stacking
  2100. * @requires stock/indicators/indicators
  2101. * @requires stock/indicators/ema
  2102. * @requires stock/indicators/dema
  2103. * @optionparent plotOptions.dema
  2104. */
  2105. {},
  2106. /**
  2107. * @lends Highcharts.Series#
  2108. */
  2109. {
  2110. init: function () {
  2111. var args = arguments, ctx = this;
  2112. requiredIndicator.isParentLoaded(EMAindicator, 'ema', ctx.type, function (indicator) {
  2113. indicator.prototype.init.apply(ctx, args);
  2114. return;
  2115. });
  2116. },
  2117. getEMA: function (yVal, prevEMA, SMA, index, i, xVal) {
  2118. return EMAindicator.prototype.calculateEma(xVal || [], yVal, typeof i === 'undefined' ? 1 : i, this.chart.series[0].EMApercent, prevEMA, typeof index === 'undefined' ? -1 : index, SMA);
  2119. },
  2120. getValues: function (series, params) {
  2121. var period = params.period, doubledPeriod = 2 * period, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0, index = -1, accumulatePeriodPoints = 0, SMA = 0, DEMA = [], xDataDema = [], yDataDema = [], EMA = 0,
  2122. // EMA(EMA)
  2123. EMAlevel2,
  2124. // EMA of previous point
  2125. prevEMA, prevEMAlevel2,
  2126. // EMA values array
  2127. EMAvalues = [], i, DEMAPoint;
  2128. series.EMApercent = (2 / (period + 1));
  2129. // Check period, if bigger than EMA points length, skip
  2130. if (yValLen < 2 * period - 1) {
  2131. return;
  2132. }
  2133. // Switch index for OHLC / Candlestick / Arearange
  2134. if (isArray(yVal[0])) {
  2135. index = params.index ? params.index : 0;
  2136. }
  2137. // Accumulate first N-points
  2138. accumulatePeriodPoints =
  2139. EMAindicator.prototype.accumulatePeriodPoints(period, index, yVal);
  2140. // first point
  2141. SMA = accumulatePeriodPoints / period;
  2142. accumulatePeriodPoints = 0;
  2143. // Calculate value one-by-one for each period in visible data
  2144. for (i = period; i < yValLen + 2; i++) {
  2145. if (i < yValLen + 1) {
  2146. EMA = this.getEMA(yVal, prevEMA, SMA, index, i)[1];
  2147. EMAvalues.push(EMA);
  2148. }
  2149. prevEMA = EMA;
  2150. // Summing first period points for EMA(EMA)
  2151. if (i < doubledPeriod) {
  2152. accumulatePeriodPoints += EMA;
  2153. }
  2154. else {
  2155. // Calculate DEMA
  2156. // First DEMA point
  2157. if (i === doubledPeriod) {
  2158. SMA = accumulatePeriodPoints / period;
  2159. }
  2160. EMA = EMAvalues[i - period - 1];
  2161. EMAlevel2 = this.getEMA([EMA], prevEMAlevel2, SMA)[1];
  2162. DEMAPoint = [
  2163. xVal[i - 2],
  2164. correctFloat(2 * EMA - EMAlevel2)
  2165. ];
  2166. DEMA.push(DEMAPoint);
  2167. xDataDema.push(DEMAPoint[0]);
  2168. yDataDema.push(DEMAPoint[1]);
  2169. prevEMAlevel2 = EMAlevel2;
  2170. }
  2171. }
  2172. return {
  2173. values: DEMA,
  2174. xData: xDataDema,
  2175. yData: yDataDema
  2176. };
  2177. }
  2178. });
  2179. /**
  2180. * A `DEMA` series. If the [type](#series.ema.type) option is not
  2181. * specified, it is inherited from [chart.type](#chart.type).
  2182. *
  2183. * @extends series,plotOptions.ema
  2184. * @since 7.0.0
  2185. * @product highstock
  2186. * @excluding allAreas, colorAxis, compare, compareBase, dataParser, dataURL,
  2187. * joinBy, keys, navigatorOptions, pointInterval, pointIntervalUnit,
  2188. * pointPlacement, pointRange, pointStart, showInNavigator, stacking
  2189. * @requires stock/indicators/indicators
  2190. * @requires stock/indicators/ema
  2191. * @requires stock/indicators/dema
  2192. * @apioption series.dema
  2193. */
  2194. ''; // adds doclet above to the transpiled file
  2195. });
  2196. _registerModule(_modules, 'indicators/tema.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['mixins/indicator-required.js']], function (H, U, requiredIndicatorMixin) {
  2197. /* *
  2198. *
  2199. * License: www.highcharts.com/license
  2200. *
  2201. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2202. *
  2203. * */
  2204. var correctFloat = U.correctFloat, isArray = U.isArray;
  2205. var EMAindicator = H.seriesTypes.ema, requiredIndicator = requiredIndicatorMixin;
  2206. /**
  2207. * The TEMA series type.
  2208. *
  2209. * @private
  2210. * @class
  2211. * @name Highcharts.seriesTypes.tema
  2212. *
  2213. * @augments Highcharts.Series
  2214. */
  2215. H.seriesType('tema', 'ema',
  2216. /**
  2217. * Triple exponential moving average (TEMA) indicator. This series requires
  2218. * `linkedTo` option to be set and should be loaded after the
  2219. * `stock/indicators/indicators.js` and `stock/indicators/ema.js`.
  2220. *
  2221. * @sample {highstock} stock/indicators/tema
  2222. * TEMA indicator
  2223. *
  2224. * @extends plotOptions.ema
  2225. * @since 7.0.0
  2226. * @product highstock
  2227. * @excluding allAreas, colorAxis, compare, compareBase, joinBy, keys,
  2228. * navigatorOptions, pointInterval, pointIntervalUnit,
  2229. * pointPlacement, pointRange, pointStart, showInNavigator,
  2230. * stacking
  2231. * @requires stock/indicators/indicators
  2232. * @requires stock/indicators/ema
  2233. * @requires stock/indicators/tema
  2234. * @optionparent plotOptions.tema
  2235. */
  2236. {},
  2237. /**
  2238. * @lends Highcharts.Series#
  2239. */
  2240. {
  2241. init: function () {
  2242. var args = arguments, ctx = this;
  2243. requiredIndicator.isParentLoaded(EMAindicator, 'ema', ctx.type, function (indicator) {
  2244. indicator.prototype.init.apply(ctx, args);
  2245. return;
  2246. });
  2247. },
  2248. getEMA: function (yVal, prevEMA, SMA, index, i, xVal) {
  2249. return EMAindicator.prototype.calculateEma(xVal || [], yVal, typeof i === 'undefined' ? 1 : i, this.chart.series[0].EMApercent, prevEMA, typeof index === 'undefined' ? -1 : index, SMA);
  2250. },
  2251. getTemaPoint: function (xVal, tripledPeriod, EMAlevels, i) {
  2252. var TEMAPoint = [
  2253. xVal[i - 3],
  2254. correctFloat(3 * EMAlevels.level1 -
  2255. 3 * EMAlevels.level2 + EMAlevels.level3)
  2256. ];
  2257. return TEMAPoint;
  2258. },
  2259. getValues: function (series, params) {
  2260. var period = params.period, doubledPeriod = 2 * period, tripledPeriod = 3 * period, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0, index = -1, accumulatePeriodPoints = 0, SMA = 0, TEMA = [], xDataTema = [], yDataTema = [],
  2261. // EMA of previous point
  2262. prevEMA, prevEMAlevel2,
  2263. // EMA values array
  2264. EMAvalues = [], EMAlevel2values = [], i, TEMAPoint,
  2265. // This object contains all EMA EMAlevels calculated like below
  2266. // EMA = level1
  2267. // EMA(EMA) = level2,
  2268. // EMA(EMA(EMA)) = level3,
  2269. EMAlevels = {};
  2270. series.EMApercent = (2 / (period + 1));
  2271. // Check period, if bigger than EMA points length, skip
  2272. if (yValLen < 3 * period - 2) {
  2273. return;
  2274. }
  2275. // Switch index for OHLC / Candlestick / Arearange
  2276. if (isArray(yVal[0])) {
  2277. index = params.index ? params.index : 0;
  2278. }
  2279. // Accumulate first N-points
  2280. accumulatePeriodPoints =
  2281. EMAindicator.prototype.accumulatePeriodPoints(period, index, yVal);
  2282. // first point
  2283. SMA = accumulatePeriodPoints / period;
  2284. accumulatePeriodPoints = 0;
  2285. // Calculate value one-by-one for each period in visible data
  2286. for (i = period; i < yValLen + 3; i++) {
  2287. if (i < yValLen + 1) {
  2288. EMAlevels.level1 = this.getEMA(yVal, prevEMA, SMA, index, i)[1];
  2289. EMAvalues.push(EMAlevels.level1);
  2290. }
  2291. prevEMA = EMAlevels.level1;
  2292. // Summing first period points for ema(ema)
  2293. if (i < doubledPeriod) {
  2294. accumulatePeriodPoints += EMAlevels.level1;
  2295. }
  2296. else {
  2297. // Calculate dema
  2298. // First dema point
  2299. if (i === doubledPeriod) {
  2300. SMA = accumulatePeriodPoints / period;
  2301. accumulatePeriodPoints = 0;
  2302. }
  2303. EMAlevels.level1 = EMAvalues[i - period - 1];
  2304. EMAlevels.level2 = this.getEMA([EMAlevels.level1], prevEMAlevel2, SMA)[1];
  2305. EMAlevel2values.push(EMAlevels.level2);
  2306. prevEMAlevel2 = EMAlevels.level2;
  2307. // Summing first period points for ema(ema(ema))
  2308. if (i < tripledPeriod) {
  2309. accumulatePeriodPoints += EMAlevels.level2;
  2310. }
  2311. else {
  2312. // Calculate tema
  2313. // First tema point
  2314. if (i === tripledPeriod) {
  2315. SMA = accumulatePeriodPoints / period;
  2316. }
  2317. if (i === yValLen + 1) {
  2318. // Calculate the last ema and emaEMA points
  2319. EMAlevels.level1 = EMAvalues[i - period - 1];
  2320. EMAlevels.level2 = this.getEMA([EMAlevels.level1], prevEMAlevel2, SMA)[1];
  2321. EMAlevel2values.push(EMAlevels.level2);
  2322. }
  2323. EMAlevels.level1 = EMAvalues[i - period - 2];
  2324. EMAlevels.level2 = EMAlevel2values[i - 2 * period - 1];
  2325. EMAlevels.level3 = this.getEMA([EMAlevels.level2], EMAlevels.prevLevel3, SMA)[1];
  2326. TEMAPoint = this.getTemaPoint(xVal, tripledPeriod, EMAlevels, i);
  2327. // Make sure that point exists (for TRIX oscillator)
  2328. if (TEMAPoint) {
  2329. TEMA.push(TEMAPoint);
  2330. xDataTema.push(TEMAPoint[0]);
  2331. yDataTema.push(TEMAPoint[1]);
  2332. }
  2333. EMAlevels.prevLevel3 = EMAlevels.level3;
  2334. }
  2335. }
  2336. }
  2337. return {
  2338. values: TEMA,
  2339. xData: xDataTema,
  2340. yData: yDataTema
  2341. };
  2342. }
  2343. });
  2344. /**
  2345. * A `TEMA` series. If the [type](#series.ema.type) option is not
  2346. * specified, it is inherited from [chart.type](#chart.type).
  2347. *
  2348. * @extends series,plotOptions.ema
  2349. * @since 7.0.0
  2350. * @product highstock
  2351. * @excluding allAreas, colorAxis, compare, compareBase, dataParser, dataURL,
  2352. * joinBy, keys, navigatorOptions, pointInterval, pointIntervalUnit,
  2353. * pointPlacement, pointRange, pointStart, showInNavigator, stacking
  2354. * @requires stock/indicators/indicators
  2355. * @requires stock/indicators/ema
  2356. * @requires stock/indicators/tema
  2357. * @apioption series.tema
  2358. */
  2359. ''; // to include the above in the js output
  2360. });
  2361. _registerModule(_modules, 'indicators/trix.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['mixins/indicator-required.js']], function (H, U, requiredIndicator) {
  2362. /* *
  2363. *
  2364. * License: www.highcharts.com/license
  2365. *
  2366. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2367. *
  2368. * */
  2369. var correctFloat = U.correctFloat;
  2370. var TEMA = H.seriesTypes.tema;
  2371. /**
  2372. * The TRIX series type.
  2373. *
  2374. * @private
  2375. * @class
  2376. * @name Highcharts.seriesTypes.trix
  2377. *
  2378. * @augments Highcharts.Series
  2379. */
  2380. H.seriesType('trix', 'tema',
  2381. /**
  2382. * Triple exponential average (TRIX) oscillator. This series requires
  2383. * `linkedTo` option to be set.
  2384. *
  2385. * Requires https://code.highcharts.com/stock/indicators/ema.js
  2386. * and https://code.highcharts.com/stock/indicators/tema.js.
  2387. *
  2388. * @sample {highstock} stock/indicators/trix
  2389. * TRIX indicator
  2390. *
  2391. * @extends plotOptions.tema
  2392. * @since 7.0.0
  2393. * @product highstock
  2394. * @excluding allAreas, colorAxis, compare, compareBase, joinBy, keys,
  2395. * navigatorOptions, pointInterval, pointIntervalUnit,
  2396. * pointPlacement, pointRange, pointStart, showInNavigator,
  2397. * stacking
  2398. * @optionparent plotOptions.trix
  2399. */
  2400. {},
  2401. /**
  2402. * @lends Highcharts.Series#
  2403. */
  2404. {
  2405. init: function () {
  2406. var args = arguments, ctx = this;
  2407. requiredIndicator.isParentLoaded(TEMA, 'tema', ctx.type, function (indicator) {
  2408. indicator.prototype.init.apply(ctx, args);
  2409. return;
  2410. });
  2411. },
  2412. // TRIX is calculated using TEMA so we just extend getTemaPoint method.
  2413. getTemaPoint: function (xVal, tripledPeriod, EMAlevels, i) {
  2414. if (i > tripledPeriod) {
  2415. var TRIXPoint = [
  2416. xVal[i - 3],
  2417. EMAlevels.prevLevel3 !== 0 ?
  2418. correctFloat(EMAlevels.level3 - EMAlevels.prevLevel3) /
  2419. EMAlevels.prevLevel3 * 100 : null
  2420. ];
  2421. }
  2422. return TRIXPoint;
  2423. }
  2424. });
  2425. /**
  2426. * A `TRIX` series. If the [type](#series.tema.type) option is not specified, it
  2427. * is inherited from [chart.type](#chart.type).
  2428. *
  2429. * @extends series,plotOptions.tema
  2430. * @since 7.0.0
  2431. * @product highstock
  2432. * @excluding allAreas, colorAxis, compare, compareBase, dataParser, dataURL,
  2433. * joinBy, keys, navigatorOptions, pointInterval, pointIntervalUnit,
  2434. * pointPlacement, pointRange, pointStart, showInNavigator, stacking
  2435. * @apioption series.trix
  2436. */
  2437. ''; // to include the above in the js output
  2438. });
  2439. _registerModule(_modules, 'indicators/apo.src.js', [_modules['parts/Globals.js'], _modules['mixins/indicator-required.js']], function (H, requiredIndicatorMixin) {
  2440. /* *
  2441. *
  2442. * License: www.highcharts.com/license
  2443. *
  2444. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2445. *
  2446. * */
  2447. var EMA = H.seriesTypes.ema, error = H.error, requiredIndicator = requiredIndicatorMixin;
  2448. /**
  2449. * The APO series type.
  2450. *
  2451. * @private
  2452. * @class
  2453. * @name Highcharts.seriesTypes.apo
  2454. *
  2455. * @augments Highcharts.Series
  2456. */
  2457. H.seriesType('apo', 'ema',
  2458. /**
  2459. * Absolute Price Oscillator. This series requires the `linkedTo` option to
  2460. * be set and should be loaded after the `stock/indicators/indicators.js`
  2461. * and `stock/indicators/ema.js`.
  2462. *
  2463. * @sample {highstock} stock/indicators/apo
  2464. * Absolute Price Oscillator
  2465. *
  2466. * @extends plotOptions.ema
  2467. * @since 7.0.0
  2468. * @product highstock
  2469. * @excluding allAreas, colorAxis, joinBy, keys, navigatorOptions,
  2470. * pointInterval, pointIntervalUnit, pointPlacement,
  2471. * pointRange, pointStart, showInNavigator, stacking
  2472. * @requires stock/indicators/indicators
  2473. * @requires stock/indicators/ema
  2474. * @requires stock/indicators/apo
  2475. * @optionparent plotOptions.apo
  2476. */
  2477. {
  2478. /**
  2479. * Paramters used in calculation of Absolute Price Oscillator
  2480. * series points.
  2481. *
  2482. * @excluding period
  2483. */
  2484. params: {
  2485. /**
  2486. * Periods for Absolute Price Oscillator calculations.
  2487. *
  2488. * @type {Array<number>}
  2489. * @default [10, 20]
  2490. * @since 7.0.0
  2491. */
  2492. periods: [10, 20]
  2493. }
  2494. },
  2495. /**
  2496. * @lends Highcharts.Series.prototype
  2497. */
  2498. {
  2499. nameBase: 'APO',
  2500. nameComponents: ['periods'],
  2501. init: function () {
  2502. var args = arguments, ctx = this;
  2503. requiredIndicator.isParentLoaded(EMA, 'ema', ctx.type, function (indicator) {
  2504. indicator.prototype.init.apply(ctx, args);
  2505. return;
  2506. });
  2507. },
  2508. getValues: function (series, params) {
  2509. var periods = params.periods, index = params.index,
  2510. // 0- date, 1- Absolute price oscillator
  2511. APO = [], xData = [], yData = [], periodsOffset,
  2512. // Shorter Period EMA
  2513. SPE,
  2514. // Longer Period EMA
  2515. LPE, oscillator, i;
  2516. // Check if periods are correct
  2517. if (periods.length !== 2 || periods[1] <= periods[0]) {
  2518. error('Error: "APO requires two periods. Notice, first period ' +
  2519. 'should be lower than the second one."');
  2520. return;
  2521. }
  2522. SPE = EMA.prototype.getValues.call(this, series, {
  2523. index: index,
  2524. period: periods[0]
  2525. });
  2526. LPE = EMA.prototype.getValues.call(this, series, {
  2527. index: index,
  2528. period: periods[1]
  2529. });
  2530. // Check if ema is calculated properly, if not skip
  2531. if (!SPE || !LPE) {
  2532. return;
  2533. }
  2534. periodsOffset = periods[1] - periods[0];
  2535. for (i = 0; i < LPE.yData.length; i++) {
  2536. oscillator = (SPE.yData[i + periodsOffset] -
  2537. LPE.yData[i]);
  2538. APO.push([LPE.xData[i], oscillator]);
  2539. xData.push(LPE.xData[i]);
  2540. yData.push(oscillator);
  2541. }
  2542. return {
  2543. values: APO,
  2544. xData: xData,
  2545. yData: yData
  2546. };
  2547. }
  2548. });
  2549. /**
  2550. * An `Absolute Price Oscillator` series. If the [type](#series.apo.type) option
  2551. * is not specified, it is inherited from [chart.type](#chart.type).
  2552. *
  2553. * @extends series,plotOptions.apo
  2554. * @since 7.0.0
  2555. * @product highstock
  2556. * @excluding allAreas, colorAxis, dataParser, dataURL, joinBy, keys,
  2557. * navigatorOptions, pointInterval, pointIntervalUnit,
  2558. * pointPlacement, pointRange, pointStart, showInNavigator, stacking
  2559. * @requires stock/indicators/indicators
  2560. * @requires stock/indicators/ema
  2561. * @requires stock/indicators/apo
  2562. * @apioption series.apo
  2563. */
  2564. ''; // to include the above in the js output
  2565. });
  2566. _registerModule(_modules, 'indicators/ichimoku-kinko-hyo.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  2567. /* *
  2568. *
  2569. * License: www.highcharts.com/license
  2570. *
  2571. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2572. *
  2573. * */
  2574. /* eslint-enable @typescript-eslint/interface-name-prefix */
  2575. var defined = U.defined, isArray = U.isArray, objectEach = U.objectEach;
  2576. var UNDEFINED, seriesType = H.seriesType, merge = H.merge, color = H.color, SMA = H.seriesTypes.sma;
  2577. /* eslint-disable require-jsdoc */
  2578. // Utils:
  2579. function maxHigh(arr) {
  2580. return arr.reduce(function (max, res) {
  2581. return Math.max(max, res[1]);
  2582. }, -Infinity);
  2583. }
  2584. function minLow(arr) {
  2585. return arr.reduce(function (min, res) {
  2586. return Math.min(min, res[2]);
  2587. }, Infinity);
  2588. }
  2589. function highlowLevel(arr) {
  2590. return {
  2591. high: maxHigh(arr),
  2592. low: minLow(arr)
  2593. };
  2594. }
  2595. function getClosestPointRange(axis) {
  2596. var closestDataRange, loopLength, distance, xData, i;
  2597. axis.series.forEach(function (series) {
  2598. if (series.xData) {
  2599. xData = series.xData;
  2600. loopLength = series.xIncrement ? 1 : xData.length - 1;
  2601. for (i = loopLength; i > 0; i--) {
  2602. distance = xData[i] - xData[i - 1];
  2603. if (closestDataRange === UNDEFINED ||
  2604. distance < closestDataRange) {
  2605. closestDataRange = distance;
  2606. }
  2607. }
  2608. }
  2609. });
  2610. return closestDataRange;
  2611. }
  2612. // Check two lines intersection (line a1-a2 and b1-b2)
  2613. // Source: https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
  2614. function checkLineIntersection(a1, a2, b1, b2) {
  2615. if (a1 && a2 && b1 && b2) {
  2616. var saX = a2.plotX - a1.plotX, // Auxiliary section a2-a1 X
  2617. saY = a2.plotY - a1.plotY, // Auxiliary section a2-a1 Y
  2618. sbX = b2.plotX - b1.plotX, // Auxiliary section b2-b1 X
  2619. sbY = b2.plotY - b1.plotY, // Auxiliary section b2-b1 Y
  2620. sabX = a1.plotX - b1.plotX, // Auxiliary section a1-b1 X
  2621. sabY = a1.plotY - b1.plotY, // Auxiliary section a1-b1 Y
  2622. // First degree Bézier parameters
  2623. u, t;
  2624. u = (-saY * sabX + saX * sabY) / (-sbX * saY + saX * sbY);
  2625. t = (sbX * sabY - sbY * sabX) / (-sbX * saY + saX * sbY);
  2626. if (u >= 0 && u <= 1 && t >= 0 && t <= 1) {
  2627. return {
  2628. plotX: a1.plotX + (t * saX),
  2629. plotY: a1.plotY + (t * saY)
  2630. };
  2631. }
  2632. }
  2633. return false;
  2634. }
  2635. // Parameter opt (indicator options object) include indicator, points,
  2636. // nextPoints, color, options, gappedExtend and graph properties
  2637. function drawSenkouSpan(opt) {
  2638. var indicator = opt.indicator;
  2639. indicator.points = opt.points;
  2640. indicator.nextPoints = opt.nextPoints;
  2641. indicator.color = opt.color;
  2642. indicator.options = merge(opt.options.senkouSpan.styles, opt.gap);
  2643. indicator.graph = opt.graph;
  2644. indicator.fillGraph = true;
  2645. SMA.prototype.drawGraph.call(indicator);
  2646. }
  2647. // Data integrity in Ichimoku is different than default "averages":
  2648. // Point: [undefined, value, value, ...] is correct
  2649. // Point: [undefined, undefined, undefined, ...] is incorrect
  2650. H.approximations['ichimoku-averages'] = function () {
  2651. var ret = [], isEmptyRange;
  2652. [].forEach.call(arguments, function (arr, i) {
  2653. ret.push(H.approximations.average(arr));
  2654. isEmptyRange = !isEmptyRange && typeof ret[i] === 'undefined';
  2655. });
  2656. // Return undefined when first elem. is undefined and let
  2657. // sum method handle null (#7377)
  2658. return isEmptyRange ? void 0 : ret;
  2659. };
  2660. /* eslint-enable require-jsdoc */
  2661. /**
  2662. * The IKH series type.
  2663. *
  2664. * @private
  2665. * @class
  2666. * @name Highcharts.seriesTypes.ikh
  2667. *
  2668. * @augments Highcharts.Series
  2669. */
  2670. seriesType('ikh', 'sma',
  2671. /**
  2672. * Ichimoku Kinko Hyo (IKH). This series requires `linkedTo` option to be
  2673. * set.
  2674. *
  2675. * @sample stock/indicators/ichimoku-kinko-hyo
  2676. * Ichimoku Kinko Hyo indicator
  2677. *
  2678. * @extends plotOptions.sma
  2679. * @since 6.0.0
  2680. * @excluding allAreas, colorAxis, compare, compareBase, joinBy, keys,
  2681. * navigatorOptions, pointInterval, pointIntervalUnit,
  2682. * pointPlacement, pointRange, pointStart, showInNavigator,
  2683. * stacking
  2684. * @product highstock
  2685. * @requires stock/indicators/indicators
  2686. * @requires stock/indicators/ichimoku-kinko-hyo
  2687. * @optionparent plotOptions.ikh
  2688. */
  2689. {
  2690. params: {
  2691. period: 26,
  2692. /**
  2693. * The base period for Tenkan calculations.
  2694. */
  2695. periodTenkan: 9,
  2696. /**
  2697. * The base period for Senkou Span B calculations
  2698. */
  2699. periodSenkouSpanB: 52
  2700. },
  2701. marker: {
  2702. enabled: false
  2703. },
  2704. tooltip: {
  2705. pointFormat: '<span style="color:{point.color}">\u25CF</span> <b> {series.name}</b><br/>' +
  2706. 'TENKAN SEN: {point.tenkanSen:.3f}<br/>' +
  2707. 'KIJUN SEN: {point.kijunSen:.3f}<br/>' +
  2708. 'CHIKOU SPAN: {point.chikouSpan:.3f}<br/>' +
  2709. 'SENKOU SPAN A: {point.senkouSpanA:.3f}<br/>' +
  2710. 'SENKOU SPAN B: {point.senkouSpanB:.3f}<br/>'
  2711. },
  2712. /**
  2713. * The styles for Tenkan line
  2714. */
  2715. tenkanLine: {
  2716. styles: {
  2717. /**
  2718. * Pixel width of the line.
  2719. */
  2720. lineWidth: 1,
  2721. /**
  2722. * Color of the line.
  2723. *
  2724. * @type {Highcharts.ColorString}
  2725. */
  2726. lineColor: void 0
  2727. }
  2728. },
  2729. /**
  2730. * The styles for Kijun line
  2731. */
  2732. kijunLine: {
  2733. styles: {
  2734. /**
  2735. * Pixel width of the line.
  2736. */
  2737. lineWidth: 1,
  2738. /**
  2739. * Color of the line.
  2740. *
  2741. * @type {Highcharts.ColorString}
  2742. */
  2743. lineColor: void 0
  2744. }
  2745. },
  2746. /**
  2747. * The styles for Chikou line
  2748. */
  2749. chikouLine: {
  2750. styles: {
  2751. /**
  2752. * Pixel width of the line.
  2753. */
  2754. lineWidth: 1,
  2755. /**
  2756. * Color of the line.
  2757. *
  2758. * @type {Highcharts.ColorString}
  2759. */
  2760. lineColor: void 0
  2761. }
  2762. },
  2763. /**
  2764. * The styles for Senkou Span A line
  2765. */
  2766. senkouSpanA: {
  2767. styles: {
  2768. /**
  2769. * Pixel width of the line.
  2770. */
  2771. lineWidth: 1,
  2772. /**
  2773. * Color of the line.
  2774. *
  2775. * @type {Highcharts.ColorString}
  2776. */
  2777. lineColor: void 0
  2778. }
  2779. },
  2780. /**
  2781. * The styles for Senkou Span B line
  2782. */
  2783. senkouSpanB: {
  2784. styles: {
  2785. /**
  2786. * Pixel width of the line.
  2787. */
  2788. lineWidth: 1,
  2789. /**
  2790. * Color of the line.
  2791. *
  2792. * @type {Highcharts.ColorString}
  2793. */
  2794. lineColor: void 0
  2795. }
  2796. },
  2797. /**
  2798. * The styles for area between Senkou Span A and B.
  2799. */
  2800. senkouSpan: {
  2801. /**
  2802. * Color of the area between Senkou Span A and B,
  2803. * when Senkou Span A is above Senkou Span B. Note that if
  2804. * a `style.fill` is defined, the `color` takes precedence and
  2805. * the `style.fill` is ignored.
  2806. *
  2807. * @see [senkouSpan.styles.fill](#series.ikh.senkouSpan.styles.fill)
  2808. *
  2809. * @sample stock/indicators/ichimoku-kinko-hyo
  2810. * Ichimoku Kinko Hyo color
  2811. *
  2812. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  2813. * @since 7.0.0
  2814. * @apioption plotOptions.ikh.senkouSpan.color
  2815. */
  2816. /**
  2817. * Color of the area between Senkou Span A and B,
  2818. * when Senkou Span A is under Senkou Span B.
  2819. *
  2820. * @sample stock/indicators/ikh-negative-color
  2821. * Ichimoku Kinko Hyo negativeColor
  2822. *
  2823. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  2824. * @since 7.0.0
  2825. * @apioption plotOptions.ikh.senkouSpan.negativeColor
  2826. */
  2827. styles: {
  2828. /**
  2829. * Color of the area between Senkou Span A and B.
  2830. *
  2831. * @deprecated
  2832. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  2833. */
  2834. fill: 'rgba(255, 0, 0, 0.5)'
  2835. }
  2836. },
  2837. dataGrouping: {
  2838. approximation: 'ichimoku-averages'
  2839. }
  2840. },
  2841. /**
  2842. * @lends Highcharts.Series#
  2843. */
  2844. {
  2845. pointArrayMap: [
  2846. 'tenkanSen',
  2847. 'kijunSen',
  2848. 'chikouSpan',
  2849. 'senkouSpanA',
  2850. 'senkouSpanB'
  2851. ],
  2852. pointValKey: 'tenkanSen',
  2853. nameComponents: ['periodSenkouSpanB', 'period', 'periodTenkan'],
  2854. init: function () {
  2855. SMA.prototype.init.apply(this, arguments);
  2856. // Set default color for lines:
  2857. this.options = merge({
  2858. tenkanLine: {
  2859. styles: {
  2860. lineColor: this.color
  2861. }
  2862. },
  2863. kijunLine: {
  2864. styles: {
  2865. lineColor: this.color
  2866. }
  2867. },
  2868. chikouLine: {
  2869. styles: {
  2870. lineColor: this.color
  2871. }
  2872. },
  2873. senkouSpanA: {
  2874. styles: {
  2875. lineColor: this.color,
  2876. fill: color(this.color).setOpacity(0.5).get()
  2877. }
  2878. },
  2879. senkouSpanB: {
  2880. styles: {
  2881. lineColor: this.color,
  2882. fill: color(this.color).setOpacity(0.5).get()
  2883. }
  2884. },
  2885. senkouSpan: {
  2886. styles: {
  2887. fill: color(this.color).setOpacity(0.2).get()
  2888. }
  2889. }
  2890. }, this.options);
  2891. },
  2892. toYData: function (point) {
  2893. return [
  2894. point.tenkanSen,
  2895. point.kijunSen,
  2896. point.chikouSpan,
  2897. point.senkouSpanA,
  2898. point.senkouSpanB
  2899. ];
  2900. },
  2901. translate: function () {
  2902. var indicator = this;
  2903. SMA.prototype.translate.apply(indicator);
  2904. indicator.points.forEach(function (point) {
  2905. indicator.pointArrayMap.forEach(function (value) {
  2906. if (defined(point[value])) {
  2907. point['plot' + value] =
  2908. indicator.yAxis.toPixels(point[value], true);
  2909. // Add extra parameters for support tooltip in moved
  2910. // lines
  2911. point.plotY = point['plot' + value];
  2912. point.tooltipPos = [
  2913. point.plotX,
  2914. point['plot' + value]
  2915. ];
  2916. point.isNull = false;
  2917. }
  2918. });
  2919. });
  2920. },
  2921. // One does not simply
  2922. // Render five linesZ
  2923. // And an arearange
  2924. // In just one series..
  2925. drawGraph: function () {
  2926. var indicator = this, mainLinePoints = (indicator.points), pointsLength = mainLinePoints.length, mainLineOptions = (indicator.options), mainLinePath = (indicator.graph), mainColor = indicator.color, gappedExtend = {
  2927. options: {
  2928. gapSize: mainLineOptions.gapSize
  2929. }
  2930. }, pointArrayMapLength = indicator.pointArrayMap.length, allIchimokuPoints = [[], [], [], [], [], []], ikhMap = {
  2931. tenkanLine: allIchimokuPoints[0],
  2932. kijunLine: allIchimokuPoints[1],
  2933. chikouLine: allIchimokuPoints[2],
  2934. senkouSpanA: allIchimokuPoints[3],
  2935. senkouSpanB: allIchimokuPoints[4],
  2936. senkouSpan: allIchimokuPoints[5]
  2937. }, intersectIndexColl = [], senkouSpanOptions = indicator.options.senkouSpan, color = (senkouSpanOptions.color ||
  2938. senkouSpanOptions.styles.fill), negativeColor = (senkouSpanOptions.negativeColor),
  2939. // Points to create color and negativeColor senkouSpan
  2940. points = [
  2941. [],
  2942. [] // Points negative color
  2943. ],
  2944. // For span, we need an access to the next points, used in
  2945. // getGraphPath()
  2946. nextPoints = [
  2947. [],
  2948. [] // NextPoints negative color
  2949. ], lineIndex = 0, position, point, i, startIntersect, endIntersect, sectionPoints, sectionNextPoints, pointsPlotYSum, nextPointsPlotYSum, senkouSpanTempColor, concatArrIndex, j, k;
  2950. indicator.ikhMap = ikhMap;
  2951. // Generate points for all lines and spans lines:
  2952. while (pointsLength--) {
  2953. point = mainLinePoints[pointsLength];
  2954. for (i = 0; i < pointArrayMapLength; i++) {
  2955. position = indicator.pointArrayMap[i];
  2956. if (defined(point[position])) {
  2957. allIchimokuPoints[i].push({
  2958. plotX: point.plotX,
  2959. plotY: point['plot' + position],
  2960. isNull: false
  2961. });
  2962. }
  2963. }
  2964. if (negativeColor &&
  2965. pointsLength !== mainLinePoints.length - 1) {
  2966. // Check if lines intersect
  2967. var index = ikhMap.senkouSpanB.length - 1, intersect = checkLineIntersection(ikhMap.senkouSpanA[index - 1], ikhMap.senkouSpanA[index], ikhMap.senkouSpanB[index - 1], ikhMap.senkouSpanB[index]), intersectPointObj = {
  2968. plotX: intersect.plotX,
  2969. plotY: intersect.plotY,
  2970. isNull: false,
  2971. intersectPoint: true
  2972. };
  2973. if (intersect) {
  2974. // Add intersect point to ichimoku points collection
  2975. // Create senkouSpan sections
  2976. ikhMap.senkouSpanA.splice(index, 0, intersectPointObj);
  2977. ikhMap.senkouSpanB.splice(index, 0, intersectPointObj);
  2978. intersectIndexColl.push(index);
  2979. }
  2980. }
  2981. }
  2982. // Modify options and generate lines:
  2983. objectEach(ikhMap, function (values, lineName) {
  2984. if (mainLineOptions[lineName] &&
  2985. lineName !== 'senkouSpan') {
  2986. // First line is rendered by default option
  2987. indicator.points = allIchimokuPoints[lineIndex];
  2988. indicator.options = merge(mainLineOptions[lineName].styles, gappedExtend);
  2989. indicator.graph = indicator['graph' + lineName];
  2990. indicator.fillGraph = false;
  2991. indicator.color = mainColor;
  2992. SMA.prototype.drawGraph.call(indicator);
  2993. // Now save line
  2994. indicator['graph' + lineName] = indicator.graph;
  2995. }
  2996. lineIndex++;
  2997. });
  2998. // Generate senkouSpan area:
  2999. // If graphColection exist then remove svg
  3000. // element and indicator property
  3001. if (indicator.graphCollection) {
  3002. indicator.graphCollection.forEach(function (graphName) {
  3003. indicator[graphName].destroy();
  3004. delete indicator[graphName];
  3005. });
  3006. }
  3007. // Clean grapCollection or initialize it
  3008. indicator.graphCollection = [];
  3009. // When user set negativeColor property
  3010. if (negativeColor &&
  3011. ikhMap.senkouSpanA[0] &&
  3012. ikhMap.senkouSpanB[0]) {
  3013. // Add first and last point to senkouSpan area sections
  3014. intersectIndexColl.unshift(0);
  3015. intersectIndexColl.push(ikhMap.senkouSpanA.length - 1);
  3016. // Populate points and nextPoints arrays
  3017. for (j = 0; j < intersectIndexColl.length - 1; j++) {
  3018. startIntersect = intersectIndexColl[j];
  3019. endIntersect = intersectIndexColl[j + 1];
  3020. sectionPoints = ikhMap.senkouSpanB.slice(startIntersect, endIntersect + 1);
  3021. sectionNextPoints = ikhMap.senkouSpanA.slice(startIntersect, endIntersect + 1);
  3022. // Add points to color or negativeColor arrays
  3023. // Check the middle point (if exist)
  3024. if (Math.floor(sectionPoints.length / 2) >= 1) {
  3025. var x = Math.floor(sectionPoints.length / 2);
  3026. // When middle points has equal values
  3027. // Compare all ponints plotY value sum
  3028. if (sectionPoints[x].plotY ===
  3029. sectionNextPoints[x].plotY) {
  3030. pointsPlotYSum = 0;
  3031. nextPointsPlotYSum = 0;
  3032. for (k = 0; k < sectionPoints.length; k++) {
  3033. pointsPlotYSum +=
  3034. sectionPoints[k].plotY;
  3035. nextPointsPlotYSum +=
  3036. sectionNextPoints[k].plotY;
  3037. }
  3038. concatArrIndex = (pointsPlotYSum > nextPointsPlotYSum ? 0 : 1);
  3039. points[concatArrIndex] = (points[concatArrIndex].concat(sectionPoints));
  3040. nextPoints[concatArrIndex] = (nextPoints[concatArrIndex].concat(sectionNextPoints));
  3041. }
  3042. else {
  3043. // Compare middle point of the section
  3044. concatArrIndex = (sectionPoints[x].plotY >
  3045. sectionNextPoints[x].plotY ?
  3046. 0 : 1);
  3047. points[concatArrIndex] = (points[concatArrIndex].concat(sectionPoints));
  3048. nextPoints[concatArrIndex] = (nextPoints[concatArrIndex].concat(sectionNextPoints));
  3049. }
  3050. }
  3051. else {
  3052. // Compare first point of the section
  3053. concatArrIndex = (sectionPoints[0].plotY >
  3054. sectionNextPoints[0].plotY ?
  3055. 0 : 1);
  3056. points[concatArrIndex] = (points[concatArrIndex].concat(sectionPoints));
  3057. nextPoints[concatArrIndex] = (nextPoints[concatArrIndex].concat(sectionNextPoints));
  3058. }
  3059. }
  3060. // Render color and negativeColor paths
  3061. [
  3062. 'graphsenkouSpanColor', 'graphsenkouSpanNegativeColor'
  3063. ].forEach(function (areaName, i) {
  3064. if (points[i].length && nextPoints[i].length) {
  3065. senkouSpanTempColor = (i === 0) ?
  3066. color : negativeColor;
  3067. drawSenkouSpan({
  3068. indicator: indicator,
  3069. points: points[i],
  3070. nextPoints: nextPoints[i],
  3071. color: senkouSpanTempColor,
  3072. options: mainLineOptions,
  3073. gap: gappedExtend,
  3074. graph: indicator[areaName]
  3075. });
  3076. // Now save line
  3077. indicator[areaName] = indicator.graph;
  3078. indicator.graphCollection.push(areaName);
  3079. }
  3080. });
  3081. }
  3082. else {
  3083. // When user set only senkouSpan style.fill property
  3084. drawSenkouSpan({
  3085. indicator: indicator,
  3086. points: ikhMap.senkouSpanB,
  3087. nextPoints: ikhMap.senkouSpanA,
  3088. color: color,
  3089. options: mainLineOptions,
  3090. gap: gappedExtend,
  3091. graph: indicator.graphsenkouSpan
  3092. });
  3093. // Now save line
  3094. indicator.graphsenkouSpan = indicator.graph;
  3095. }
  3096. // Clean temporary properties:
  3097. delete indicator.nextPoints;
  3098. delete indicator.fillGraph;
  3099. // Restore options and draw the Tenkan line:
  3100. indicator.points = mainLinePoints;
  3101. indicator.options = mainLineOptions;
  3102. indicator.graph = mainLinePath;
  3103. },
  3104. getGraphPath: function (points) {
  3105. var indicator = this, path = [], spanA, fillArray = [], spanAarr = [];
  3106. points = points || this.points;
  3107. // Render Senkou Span
  3108. if (indicator.fillGraph && indicator.nextPoints) {
  3109. spanA = SMA.prototype.getGraphPath.call(indicator,
  3110. // Reverse points, so Senkou Span A will start from the end:
  3111. indicator.nextPoints);
  3112. spanA[0] = 'L';
  3113. path = SMA.prototype.getGraphPath.call(indicator, points);
  3114. spanAarr = spanA.slice(0, path.length);
  3115. for (var i = (spanAarr.length - 1); i > 0; i -= 3) {
  3116. fillArray.push(spanAarr[i - 2], spanAarr[i - 1], spanAarr[i]);
  3117. }
  3118. path = path.concat(fillArray);
  3119. }
  3120. else {
  3121. path = SMA.prototype.getGraphPath.apply(indicator, arguments);
  3122. }
  3123. return path;
  3124. },
  3125. getValues: function (series, params) {
  3126. var period = params.period, periodTenkan = params.periodTenkan, periodSenkouSpanB = params.periodSenkouSpanB, xVal = series.xData, yVal = series.yData, xAxis = series.xAxis, yValLen = (yVal && yVal.length) || 0, closestPointRange = getClosestPointRange(xAxis), IKH = [], xData = [], dateStart, date, slicedTSY, slicedKSY, slicedSSBY, pointTS, pointKS, pointSSB, i, TS, KS, CS, SSA, SSB;
  3127. // Ikh requires close value
  3128. if (xVal.length <= period ||
  3129. !isArray(yVal[0]) ||
  3130. yVal[0].length !== 4) {
  3131. return;
  3132. }
  3133. // Add timestamps at the beginning
  3134. dateStart = xVal[0] - (period * closestPointRange);
  3135. for (i = 0; i < period; i++) {
  3136. xData.push(dateStart + i * closestPointRange);
  3137. }
  3138. for (i = 0; i < yValLen; i++) {
  3139. // Tenkan Sen
  3140. if (i >= periodTenkan) {
  3141. slicedTSY = yVal.slice(i - periodTenkan, i);
  3142. pointTS = highlowLevel(slicedTSY);
  3143. TS = (pointTS.high + pointTS.low) / 2;
  3144. }
  3145. if (i >= period) {
  3146. slicedKSY = yVal.slice(i - period, i);
  3147. pointKS = highlowLevel(slicedKSY);
  3148. KS = (pointKS.high + pointKS.low) / 2;
  3149. SSA = (TS + KS) / 2;
  3150. }
  3151. if (i >= periodSenkouSpanB) {
  3152. slicedSSBY = yVal.slice(i - periodSenkouSpanB, i);
  3153. pointSSB = highlowLevel(slicedSSBY);
  3154. SSB = (pointSSB.high + pointSSB.low) / 2;
  3155. }
  3156. CS = yVal[i][3];
  3157. date = xVal[i];
  3158. if (IKH[i] === UNDEFINED) {
  3159. IKH[i] = [];
  3160. }
  3161. if (IKH[i + period] === UNDEFINED) {
  3162. IKH[i + period] = [];
  3163. }
  3164. IKH[i + period][0] = TS;
  3165. IKH[i + period][1] = KS;
  3166. IKH[i + period][2] = UNDEFINED;
  3167. IKH[i][2] = CS;
  3168. if (i <= period) {
  3169. IKH[i + period][3] = UNDEFINED;
  3170. IKH[i + period][4] = UNDEFINED;
  3171. }
  3172. if (IKH[i + 2 * period] === UNDEFINED) {
  3173. IKH[i + 2 * period] = [];
  3174. }
  3175. IKH[i + 2 * period][3] = SSA;
  3176. IKH[i + 2 * period][4] = SSB;
  3177. xData.push(date);
  3178. }
  3179. // Add timestamps for further points
  3180. for (i = 1; i <= period; i++) {
  3181. xData.push(date + i * closestPointRange);
  3182. }
  3183. return {
  3184. values: IKH,
  3185. xData: xData,
  3186. yData: IKH
  3187. };
  3188. }
  3189. });
  3190. /**
  3191. * A `IKH` series. If the [type](#series.ikh.type) option is not
  3192. * specified, it is inherited from [chart.type](#chart.type).
  3193. *
  3194. * @extends series,plotOptions.ikh
  3195. * @since 6.0.0
  3196. * @product highstock
  3197. * @excluding dataParser, dataURL
  3198. * @requires stock/indicators/indicators
  3199. * @requires stock/indicators/ichimoku-kinko-hyo
  3200. * @apioption series.ikh
  3201. */
  3202. ''; // add doclet above to transpiled file
  3203. });
  3204. _registerModule(_modules, 'indicators/keltner-channels.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['mixins/multipe-lines.js']], function (H, U, multipleLinesMixin) {
  3205. /* *
  3206. *
  3207. * License: www.highcharts.com/license
  3208. *
  3209. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3210. *
  3211. * */
  3212. var correctFloat = U.correctFloat;
  3213. var SMA = H.seriesTypes.sma, EMA = H.seriesTypes.ema, ATR = H.seriesTypes.atr, merge = H.merge;
  3214. /**
  3215. * The Keltner Channels series type.
  3216. *
  3217. * @private
  3218. * @class
  3219. * @name Highcharts.seriesTypes.keltnerchannels
  3220. *
  3221. * @augments Highcharts.Series
  3222. */
  3223. H.seriesType('keltnerchannels', 'sma',
  3224. /**
  3225. * Keltner Channels. This series requires the `linkedTo` option to be set
  3226. * and should be loaded after the `stock/indicators/indicators.js`,
  3227. * `stock/indicators/atr.js`, and `stock/ema/.js`.
  3228. *
  3229. * @sample {highstock} stock/indicators/keltner-channels
  3230. * Keltner Channels
  3231. *
  3232. * @extends plotOptions.sma
  3233. * @since 7.0.0
  3234. * @product highstock
  3235. * @excluding allAreas, colorAxis, compare, compareBase, joinBy, keys,
  3236. * navigatorOptions, pointInterval, pointIntervalUnit,
  3237. * pointPlacement, pointRange, pointStart,showInNavigator,
  3238. * stacking
  3239. * @requires stock/indicators/indicators
  3240. * @requires stock/indicators/keltner-channels
  3241. * @optionparent plotOptions.keltnerchannels
  3242. */
  3243. {
  3244. params: {
  3245. period: 20,
  3246. /**
  3247. * The ATR period.
  3248. */
  3249. periodATR: 10,
  3250. /**
  3251. * The ATR multiplier.
  3252. */
  3253. multiplierATR: 2
  3254. },
  3255. /**
  3256. * Bottom line options.
  3257. *
  3258. */
  3259. bottomLine: {
  3260. /**
  3261. * Styles for a bottom line.
  3262. *
  3263. */
  3264. styles: {
  3265. /**
  3266. * Pixel width of the line.
  3267. */
  3268. lineWidth: 1,
  3269. /**
  3270. * Color of the line. If not set, it's inherited from
  3271. * `plotOptions.keltnerchannels.color`
  3272. */
  3273. lineColor: void 0
  3274. }
  3275. },
  3276. /**
  3277. * Top line options.
  3278. *
  3279. * @extends plotOptions.keltnerchannels.bottomLine
  3280. */
  3281. topLine: {
  3282. styles: {
  3283. lineWidth: 1,
  3284. lineColor: void 0
  3285. }
  3286. },
  3287. tooltip: {
  3288. pointFormat: '<span style="color:{point.color}">\u25CF</span><b> {series.name}</b><br/>Upper Channel: {point.top}<br/>EMA({series.options.params.period}): {point.middle}<br/>Lower Channel: {point.bottom}<br/>'
  3289. },
  3290. marker: {
  3291. enabled: false
  3292. },
  3293. dataGrouping: {
  3294. approximation: 'averages'
  3295. },
  3296. lineWidth: 1
  3297. },
  3298. /**
  3299. * @lends Highcharts.Series#
  3300. */
  3301. merge(multipleLinesMixin, {
  3302. pointArrayMap: ['top', 'middle', 'bottom'],
  3303. pointValKey: 'middle',
  3304. nameBase: 'Keltner Channels',
  3305. nameComponents: ['period', 'periodATR', 'multiplierATR'],
  3306. linesApiNames: ['topLine', 'bottomLine'],
  3307. requiredIndicators: ['ema', 'atr'],
  3308. init: function () {
  3309. SMA.prototype.init.apply(this, arguments);
  3310. // Set default color for lines:
  3311. this.options = merge({
  3312. topLine: {
  3313. styles: {
  3314. lineColor: this.color
  3315. }
  3316. },
  3317. bottomLine: {
  3318. styles: {
  3319. lineColor: this.color
  3320. }
  3321. }
  3322. }, this.options);
  3323. },
  3324. getValues: function (series, params) {
  3325. var period = params.period, periodATR = params.periodATR, multiplierATR = params.multiplierATR, index = params.index, yVal = series.yData, yValLen = yVal ? yVal.length : 0,
  3326. // Keltner Channels array structure:
  3327. // 0-date, 1-top line, 2-middle line, 3-bottom line
  3328. KC = [],
  3329. // middle line, top line and bottom lineI
  3330. ML, TL, BL, date, seriesEMA = EMA.prototype.getValues(series, {
  3331. period: period,
  3332. index: index
  3333. }), seriesATR = ATR.prototype.getValues(series, {
  3334. period: periodATR
  3335. }), pointEMA, pointATR, xData = [], yData = [], i;
  3336. if (yValLen < period) {
  3337. return;
  3338. }
  3339. for (i = period; i <= yValLen; i++) {
  3340. pointEMA = seriesEMA.values[i - period];
  3341. pointATR = seriesATR.values[i - periodATR];
  3342. date = pointEMA[0];
  3343. TL = correctFloat(pointEMA[1] + (multiplierATR * pointATR[1]));
  3344. BL = correctFloat(pointEMA[1] - (multiplierATR * pointATR[1]));
  3345. ML = pointEMA[1];
  3346. KC.push([date, TL, ML, BL]);
  3347. xData.push(date);
  3348. yData.push([TL, ML, BL]);
  3349. }
  3350. return {
  3351. values: KC,
  3352. xData: xData,
  3353. yData: yData
  3354. };
  3355. }
  3356. }));
  3357. /**
  3358. * A Keltner Channels indicator. If the [type](#series.keltnerchannels.type)
  3359. * option is not specified, it is inherited from[chart.type](#chart.type).
  3360. *
  3361. * @extends series,plotOptions.keltnerchannels
  3362. * @since 7.0.0
  3363. * @product highstock
  3364. * @excluding allAreas, colorAxis, compare, compareBase, dataParser, dataURL,
  3365. * joinBy, keys, navigatorOptions, pointInterval,
  3366. * pointIntervalUnit, pointPlacement, pointRange, pointStart,
  3367. * stacking, showInNavigator
  3368. * @requires stock/indicators/indicators
  3369. * @requires stock/indicators/keltner-channels
  3370. * @apioption series.keltnerchannels
  3371. */
  3372. ''; // to include the above in the js output
  3373. });
  3374. _registerModule(_modules, 'indicators/macd.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  3375. /* *
  3376. *
  3377. * License: www.highcharts.com/license
  3378. *
  3379. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3380. *
  3381. * */
  3382. var correctFloat = U.correctFloat, defined = U.defined;
  3383. var seriesType = H.seriesType, noop = H.noop, merge = H.merge, SMA = H.seriesTypes.sma, EMA = H.seriesTypes.ema;
  3384. /**
  3385. * The MACD series type.
  3386. *
  3387. * @private
  3388. * @class
  3389. * @name Highcharts.seriesTypes.macd
  3390. *
  3391. * @augments Highcharts.Series
  3392. */
  3393. seriesType('macd', 'sma',
  3394. /**
  3395. * Moving Average Convergence Divergence (MACD). This series requires
  3396. * `linkedTo` option to be set and should be loaded after the
  3397. * `stock/indicators/indicators.js` and `stock/indicators/ema.js`.
  3398. *
  3399. * @sample stock/indicators/macd
  3400. * MACD indicator
  3401. *
  3402. * @extends plotOptions.sma
  3403. * @since 6.0.0
  3404. * @product highstock
  3405. * @requires stock/indicators/indicators
  3406. * @requires stock/indicators/macd
  3407. * @optionparent plotOptions.macd
  3408. */
  3409. {
  3410. params: {
  3411. /**
  3412. * The short period for indicator calculations.
  3413. */
  3414. shortPeriod: 12,
  3415. /**
  3416. * The long period for indicator calculations.
  3417. */
  3418. longPeriod: 26,
  3419. /**
  3420. * The base period for signal calculations.
  3421. */
  3422. signalPeriod: 9,
  3423. period: 26
  3424. },
  3425. /**
  3426. * The styles for signal line
  3427. */
  3428. signalLine: {
  3429. /**
  3430. * @sample stock/indicators/macd-zones
  3431. * Zones in MACD
  3432. *
  3433. * @extends plotOptions.macd.zones
  3434. */
  3435. zones: [],
  3436. styles: {
  3437. /**
  3438. * Pixel width of the line.
  3439. */
  3440. lineWidth: 1,
  3441. /**
  3442. * Color of the line.
  3443. *
  3444. * @type {Highcharts.ColorString}
  3445. */
  3446. lineColor: void 0
  3447. }
  3448. },
  3449. /**
  3450. * The styles for macd line
  3451. */
  3452. macdLine: {
  3453. /**
  3454. * @sample stock/indicators/macd-zones
  3455. * Zones in MACD
  3456. *
  3457. * @extends plotOptions.macd.zones
  3458. */
  3459. zones: [],
  3460. styles: {
  3461. /**
  3462. * Pixel width of the line.
  3463. */
  3464. lineWidth: 1,
  3465. /**
  3466. * Color of the line.
  3467. *
  3468. * @type {Highcharts.ColorString}
  3469. */
  3470. lineColor: void 0
  3471. }
  3472. },
  3473. threshold: 0,
  3474. groupPadding: 0.1,
  3475. pointPadding: 0.1,
  3476. states: {
  3477. hover: {
  3478. halo: {
  3479. size: 0
  3480. }
  3481. }
  3482. },
  3483. tooltip: {
  3484. pointFormat: '<span style="color:{point.color}">\u25CF</span> <b> {series.name}</b><br/>' +
  3485. 'Value: {point.MACD}<br/>' +
  3486. 'Signal: {point.signal}<br/>' +
  3487. 'Histogram: {point.y}<br/>'
  3488. },
  3489. dataGrouping: {
  3490. approximation: 'averages'
  3491. },
  3492. minPointLength: 0
  3493. },
  3494. /**
  3495. * @lends Highcharts.Series#
  3496. */
  3497. {
  3498. nameComponents: ['longPeriod', 'shortPeriod', 'signalPeriod'],
  3499. requiredIndicators: ['ema'],
  3500. // "y" value is treated as Histogram data
  3501. pointArrayMap: ['y', 'signal', 'MACD'],
  3502. parallelArrays: ['x', 'y', 'signal', 'MACD'],
  3503. pointValKey: 'y',
  3504. // Columns support:
  3505. markerAttribs: noop,
  3506. getColumnMetrics: H.seriesTypes.column.prototype.getColumnMetrics,
  3507. crispCol: H.seriesTypes.column.prototype.crispCol,
  3508. // Colors and lines:
  3509. init: function () {
  3510. SMA.prototype.init.apply(this, arguments);
  3511. // Check whether series is initialized. It may be not initialized,
  3512. // when any of required indicators is missing.
  3513. if (this.options) {
  3514. // Set default color for a signal line and the histogram:
  3515. this.options = merge({
  3516. signalLine: {
  3517. styles: {
  3518. lineColor: this.color
  3519. }
  3520. },
  3521. macdLine: {
  3522. styles: {
  3523. color: this.color
  3524. }
  3525. }
  3526. }, this.options);
  3527. // Zones have indexes automatically calculated, we need to
  3528. // translate them to support multiple lines within one indicator
  3529. this.macdZones = {
  3530. zones: this.options.macdLine.zones,
  3531. startIndex: 0
  3532. };
  3533. this.signalZones = {
  3534. zones: this.macdZones.zones.concat(this.options.signalLine.zones),
  3535. startIndex: this.macdZones.zones.length
  3536. };
  3537. this.resetZones = true;
  3538. }
  3539. },
  3540. toYData: function (point) {
  3541. return [point.y, point.signal, point.MACD];
  3542. },
  3543. translate: function () {
  3544. var indicator = this, plotNames = ['plotSignal', 'plotMACD'];
  3545. H.seriesTypes.column.prototype.translate.apply(indicator);
  3546. indicator.points.forEach(function (point) {
  3547. [point.signal, point.MACD].forEach(function (value, i) {
  3548. if (value !== null) {
  3549. point[plotNames[i]] =
  3550. indicator.yAxis.toPixels(value, true);
  3551. }
  3552. });
  3553. });
  3554. },
  3555. destroy: function () {
  3556. // this.graph is null due to removing two times the same SVG element
  3557. this.graph = null;
  3558. this.graphmacd = this.graphmacd && this.graphmacd.destroy();
  3559. this.graphsignal = this.graphsignal && this.graphsignal.destroy();
  3560. SMA.prototype.destroy.apply(this, arguments);
  3561. },
  3562. drawPoints: H.seriesTypes.column.prototype.drawPoints,
  3563. drawGraph: function () {
  3564. var indicator = this, mainLinePoints = indicator.points, pointsLength = mainLinePoints.length, mainLineOptions = indicator.options, histogramZones = indicator.zones, gappedExtend = {
  3565. options: {
  3566. gapSize: mainLineOptions.gapSize
  3567. }
  3568. }, otherSignals = [[], []], point;
  3569. // Generate points for top and bottom lines:
  3570. while (pointsLength--) {
  3571. point = mainLinePoints[pointsLength];
  3572. if (defined(point.plotMACD)) {
  3573. otherSignals[0].push({
  3574. plotX: point.plotX,
  3575. plotY: point.plotMACD,
  3576. isNull: !defined(point.plotMACD)
  3577. });
  3578. }
  3579. if (defined(point.plotSignal)) {
  3580. otherSignals[1].push({
  3581. plotX: point.plotX,
  3582. plotY: point.plotSignal,
  3583. isNull: !defined(point.plotMACD)
  3584. });
  3585. }
  3586. }
  3587. // Modify options and generate smoothing line:
  3588. ['macd', 'signal'].forEach(function (lineName, i) {
  3589. indicator.points = otherSignals[i];
  3590. indicator.options = merge(mainLineOptions[lineName + 'Line'].styles, gappedExtend);
  3591. indicator.graph = indicator['graph' + lineName];
  3592. // Zones extension:
  3593. indicator.currentLineZone = lineName + 'Zones';
  3594. indicator.zones =
  3595. indicator[indicator.currentLineZone].zones;
  3596. SMA.prototype.drawGraph.call(indicator);
  3597. indicator['graph' + lineName] = indicator.graph;
  3598. });
  3599. // Restore options:
  3600. indicator.points = mainLinePoints;
  3601. indicator.options = mainLineOptions;
  3602. indicator.zones = histogramZones;
  3603. indicator.currentLineZone = null;
  3604. // indicator.graph = null;
  3605. },
  3606. getZonesGraphs: function (props) {
  3607. var allZones = SMA.prototype.getZonesGraphs.call(this, props), currentZones = allZones;
  3608. if (this.currentLineZone) {
  3609. currentZones = allZones.splice(this[this.currentLineZone].startIndex + 1);
  3610. if (!currentZones.length) {
  3611. // Line has no zones, return basic graph "zone"
  3612. currentZones = [props[0]];
  3613. }
  3614. else {
  3615. // Add back basic prop:
  3616. currentZones.splice(0, 0, props[0]);
  3617. }
  3618. }
  3619. return currentZones;
  3620. },
  3621. applyZones: function () {
  3622. // Histogram zones are handled by drawPoints method
  3623. // Here we need to apply zones for all lines
  3624. var histogramZones = this.zones;
  3625. // signalZones.zones contains all zones:
  3626. this.zones = this.signalZones.zones;
  3627. SMA.prototype.applyZones.call(this);
  3628. // applyZones hides only main series.graph, hide macd line manually
  3629. if (this.graphmacd && this.options.macdLine.zones.length) {
  3630. this.graphmacd.hide();
  3631. }
  3632. this.zones = histogramZones;
  3633. },
  3634. getValues: function (series, params) {
  3635. var j = 0, MACD = [], xMACD = [], yMACD = [], signalLine = [], shortEMA, longEMA, i;
  3636. if (series.xData.length <
  3637. params.longPeriod + params.signalPeriod) {
  3638. return;
  3639. }
  3640. // Calculating the short and long EMA used when calculating the MACD
  3641. shortEMA = EMA.prototype.getValues(series, {
  3642. period: params.shortPeriod
  3643. });
  3644. longEMA = EMA.prototype.getValues(series, {
  3645. period: params.longPeriod
  3646. });
  3647. shortEMA = shortEMA.values;
  3648. longEMA = longEMA.values;
  3649. // Subtract each Y value from the EMA's and create the new dataset
  3650. // (MACD)
  3651. for (i = 1; i <= shortEMA.length; i++) {
  3652. if (defined(longEMA[i - 1]) &&
  3653. defined(longEMA[i - 1][1]) &&
  3654. defined(shortEMA[i + params.shortPeriod + 1]) &&
  3655. defined(shortEMA[i + params.shortPeriod + 1][0])) {
  3656. MACD.push([
  3657. shortEMA[i + params.shortPeriod + 1][0],
  3658. 0,
  3659. null,
  3660. shortEMA[i + params.shortPeriod + 1][1] -
  3661. longEMA[i - 1][1]
  3662. ]);
  3663. }
  3664. }
  3665. // Set the Y and X data of the MACD. This is used in calculating the
  3666. // signal line.
  3667. for (i = 0; i < MACD.length; i++) {
  3668. xMACD.push(MACD[i][0]);
  3669. yMACD.push([0, null, MACD[i][3]]);
  3670. }
  3671. // Setting the signalline (Signal Line: X-day EMA of MACD line).
  3672. signalLine = EMA.prototype.getValues({
  3673. xData: xMACD,
  3674. yData: yMACD
  3675. }, {
  3676. period: params.signalPeriod,
  3677. index: 2
  3678. });
  3679. signalLine = signalLine.values;
  3680. // Setting the MACD Histogram. In comparison to the loop with pure
  3681. // MACD this loop uses MACD x value not xData.
  3682. for (i = 0; i < MACD.length; i++) {
  3683. // detect the first point
  3684. if (MACD[i][0] >= signalLine[0][0]) {
  3685. MACD[i][2] = signalLine[j][1];
  3686. yMACD[i] = [0, signalLine[j][1], MACD[i][3]];
  3687. if (MACD[i][3] === null) {
  3688. MACD[i][1] = 0;
  3689. yMACD[i][0] = 0;
  3690. }
  3691. else {
  3692. MACD[i][1] = correctFloat(MACD[i][3] -
  3693. signalLine[j][1]);
  3694. yMACD[i][0] = correctFloat(MACD[i][3] -
  3695. signalLine[j][1]);
  3696. }
  3697. j++;
  3698. }
  3699. }
  3700. return {
  3701. values: MACD,
  3702. xData: xMACD,
  3703. yData: yMACD
  3704. };
  3705. }
  3706. });
  3707. /**
  3708. * A `MACD` series. If the [type](#series.macd.type) option is not
  3709. * specified, it is inherited from [chart.type](#chart.type).
  3710. *
  3711. * @extends series,plotOptions.macd
  3712. * @since 6.0.0
  3713. * @product highstock
  3714. * @excluding dataParser, dataURL
  3715. * @requires stock/indicators/indicators
  3716. * @requires stock/indicators/macd
  3717. * @apioption series.macd
  3718. */
  3719. ''; // to include the above in the js output
  3720. });
  3721. _registerModule(_modules, 'indicators/mfi.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  3722. /* *
  3723. *
  3724. * Money Flow Index indicator for Highstock
  3725. *
  3726. * (c) 2010-2019 Grzegorz Blachliński
  3727. *
  3728. * License: www.highcharts.com/license
  3729. *
  3730. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3731. *
  3732. * */
  3733. var isArray = U.isArray;
  3734. /* eslint-disable require-jsdoc */
  3735. // Utils:
  3736. function sumArray(array) {
  3737. return array.reduce(function (prev, cur) {
  3738. return prev + cur;
  3739. });
  3740. }
  3741. function toFixed(a, n) {
  3742. return parseFloat(a.toFixed(n));
  3743. }
  3744. function calculateTypicalPrice(point) {
  3745. return (point[1] + point[2] + point[3]) / 3;
  3746. }
  3747. function calculateRawMoneyFlow(typicalPrice, volume) {
  3748. return typicalPrice * volume;
  3749. }
  3750. /* eslint-enable require-jsdoc */
  3751. /**
  3752. * The MFI series type.
  3753. *
  3754. * @private
  3755. * @class
  3756. * @name Highcharts.seriesTypes.mfi
  3757. *
  3758. * @augments Highcharts.Series
  3759. */
  3760. H.seriesType('mfi', 'sma',
  3761. /**
  3762. * Money Flow Index. This series requires `linkedTo` option to be set and
  3763. * should be loaded after the `stock/indicators/indicators.js` file.
  3764. *
  3765. * @sample stock/indicators/mfi
  3766. * Money Flow Index Indicator
  3767. *
  3768. * @extends plotOptions.sma
  3769. * @since 6.0.0
  3770. * @product highstock
  3771. * @requires stock/indicators/indicators
  3772. * @requires stock/indicators/mfi
  3773. * @optionparent plotOptions.mfi
  3774. */
  3775. {
  3776. /**
  3777. * @excluding index
  3778. */
  3779. params: {
  3780. period: 14,
  3781. /**
  3782. * The id of volume series which is mandatory.
  3783. * For example using OHLC data, volumeSeriesID='volume' means
  3784. * the indicator will be calculated using OHLC and volume values.
  3785. */
  3786. volumeSeriesID: 'volume',
  3787. /**
  3788. * Number of maximum decimals that are used in MFI calculations.
  3789. */
  3790. decimals: 4
  3791. }
  3792. },
  3793. /**
  3794. * @lends Highcharts.Series#
  3795. */
  3796. {
  3797. nameBase: 'Money Flow Index',
  3798. getValues: function (series, params) {
  3799. var period = params.period, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0, decimals = params.decimals,
  3800. // MFI starts calculations from the second point
  3801. // Cause we need to calculate change between two points
  3802. range = 1, volumeSeries = series.chart.get(params.volumeSeriesID), yValVolume = (volumeSeries && volumeSeries.yData), MFI = [], isUp = false, xData = [], yData = [], positiveMoneyFlow = [], negativeMoneyFlow = [], newTypicalPrice, oldTypicalPrice, rawMoneyFlow, negativeMoneyFlowSum, positiveMoneyFlowSum, moneyFlowRatio, MFIPoint, i;
  3803. if (!volumeSeries) {
  3804. H.error('Series ' +
  3805. params.volumeSeriesID +
  3806. ' not found! Check `volumeSeriesID`.', true, series.chart);
  3807. return;
  3808. }
  3809. // MFI requires high low and close values
  3810. if ((xVal.length <= period) || !isArray(yVal[0]) ||
  3811. yVal[0].length !== 4 ||
  3812. !yValVolume) {
  3813. return;
  3814. }
  3815. // Calculate first typical price
  3816. newTypicalPrice = calculateTypicalPrice(yVal[range]);
  3817. // Accumulate first N-points
  3818. while (range < period + 1) {
  3819. // Calculate if up or down
  3820. oldTypicalPrice = newTypicalPrice;
  3821. newTypicalPrice = calculateTypicalPrice(yVal[range]);
  3822. isUp = newTypicalPrice >= oldTypicalPrice;
  3823. // Calculate raw money flow
  3824. rawMoneyFlow = calculateRawMoneyFlow(newTypicalPrice, yValVolume[range]);
  3825. // Add to array
  3826. positiveMoneyFlow.push(isUp ? rawMoneyFlow : 0);
  3827. negativeMoneyFlow.push(isUp ? 0 : rawMoneyFlow);
  3828. range++;
  3829. }
  3830. for (i = range - 1; i < yValLen; i++) {
  3831. if (i > range - 1) {
  3832. // Remove first point from array
  3833. positiveMoneyFlow.shift();
  3834. negativeMoneyFlow.shift();
  3835. // Calculate if up or down
  3836. oldTypicalPrice = newTypicalPrice;
  3837. newTypicalPrice = calculateTypicalPrice(yVal[i]);
  3838. isUp = newTypicalPrice > oldTypicalPrice;
  3839. // Calculate raw money flow
  3840. rawMoneyFlow = calculateRawMoneyFlow(newTypicalPrice, yValVolume[i]);
  3841. // Add to array
  3842. positiveMoneyFlow.push(isUp ? rawMoneyFlow : 0);
  3843. negativeMoneyFlow.push(isUp ? 0 : rawMoneyFlow);
  3844. }
  3845. // Calculate sum of negative and positive money flow:
  3846. negativeMoneyFlowSum = sumArray(negativeMoneyFlow);
  3847. positiveMoneyFlowSum = sumArray(positiveMoneyFlow);
  3848. moneyFlowRatio = positiveMoneyFlowSum / negativeMoneyFlowSum;
  3849. MFIPoint = toFixed(100 - (100 / (1 + moneyFlowRatio)), decimals);
  3850. MFI.push([xVal[i], MFIPoint]);
  3851. xData.push(xVal[i]);
  3852. yData.push(MFIPoint);
  3853. }
  3854. return {
  3855. values: MFI,
  3856. xData: xData,
  3857. yData: yData
  3858. };
  3859. }
  3860. });
  3861. /**
  3862. * A `MFI` series. If the [type](#series.mfi.type) option is not specified, it
  3863. * is inherited from [chart.type](#chart.type).
  3864. *
  3865. * @extends series,plotOptions.mfi
  3866. * @since 6.0.0
  3867. * @excluding dataParser, dataURL
  3868. * @product highstock
  3869. * @requires stock/indicators/indicators
  3870. * @requires stock/indicators/mfi
  3871. * @apioption series.mfi
  3872. */
  3873. ''; // to include the above in the js output
  3874. });
  3875. _registerModule(_modules, 'indicators/momentum.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  3876. /* *
  3877. *
  3878. * License: www.highcharts.com/license
  3879. *
  3880. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3881. *
  3882. * */
  3883. var isArray = U.isArray;
  3884. var seriesType = H.seriesType;
  3885. /* eslint-disable require-jsdoc */
  3886. function populateAverage(points, xVal, yVal, i, period) {
  3887. var mmY = yVal[i - 1][3] - yVal[i - period - 1][3], mmX = xVal[i - 1];
  3888. points.shift(); // remove point until range < period
  3889. return [mmX, mmY];
  3890. }
  3891. /* eslint-enable require-jsdoc */
  3892. /**
  3893. * The Momentum series type.
  3894. *
  3895. * @private
  3896. * @class
  3897. * @name Highcharts.seriesTypes.momentum
  3898. *
  3899. * @augments Highcharts.Series
  3900. */
  3901. seriesType('momentum', 'sma',
  3902. /**
  3903. * Momentum. This series requires `linkedTo` option to be set.
  3904. *
  3905. * @sample stock/indicators/momentum
  3906. * Momentum indicator
  3907. *
  3908. * @extends plotOptions.sma
  3909. * @since 6.0.0
  3910. * @product highstock
  3911. * @requires stock/indicators/indicators
  3912. * @requires stock/indicators/momentum
  3913. * @optionparent plotOptions.momentum
  3914. */
  3915. {
  3916. params: {
  3917. period: 14
  3918. }
  3919. },
  3920. /**
  3921. * @lends Highcharts.Series#
  3922. */
  3923. {
  3924. nameBase: 'Momentum',
  3925. getValues: function (series, params) {
  3926. var period = params.period, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0, xValue = xVal[0], yValue = yVal[0], MM = [], xData = [], yData = [], index, i, points, MMPoint;
  3927. if (xVal.length <= period) {
  3928. return;
  3929. }
  3930. // Switch index for OHLC / Candlestick / Arearange
  3931. if (isArray(yVal[0])) {
  3932. yValue = yVal[0][3];
  3933. }
  3934. else {
  3935. return;
  3936. }
  3937. // Starting point
  3938. points = [
  3939. [xValue, yValue]
  3940. ];
  3941. // Calculate value one-by-one for each period in visible data
  3942. for (i = (period + 1); i < yValLen; i++) {
  3943. MMPoint = populateAverage(points, xVal, yVal, i, period, index);
  3944. MM.push(MMPoint);
  3945. xData.push(MMPoint[0]);
  3946. yData.push(MMPoint[1]);
  3947. }
  3948. MMPoint = populateAverage(points, xVal, yVal, i, period, index);
  3949. MM.push(MMPoint);
  3950. xData.push(MMPoint[0]);
  3951. yData.push(MMPoint[1]);
  3952. return {
  3953. values: MM,
  3954. xData: xData,
  3955. yData: yData
  3956. };
  3957. }
  3958. });
  3959. /**
  3960. * A `Momentum` series. If the [type](#series.momentum.type) option is not
  3961. * specified, it is inherited from [chart.type](#chart.type).
  3962. *
  3963. * @extends series,plotOptions.momentum
  3964. * @since 6.0.0
  3965. * @excluding dataParser, dataURL
  3966. * @product highstock
  3967. * @requires stock/indicators/indicators
  3968. * @requires stock/indicators/momentum
  3969. * @apioption series.momentum
  3970. */
  3971. ''; // to include the above in the js output
  3972. });
  3973. _registerModule(_modules, 'indicators/natr.src.js', [_modules['parts/Globals.js']], function (H) {
  3974. /* *
  3975. *
  3976. * License: www.highcharts.com/license
  3977. *
  3978. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3979. *
  3980. * */
  3981. var ATR = H.seriesTypes.atr;
  3982. /**
  3983. * The NATR series type.
  3984. *
  3985. * @private
  3986. * @class
  3987. * @name Highcharts.seriesTypes.natr
  3988. *
  3989. * @augments Highcharts.Series
  3990. */
  3991. H.seriesType('natr', 'sma',
  3992. /**
  3993. * Normalized average true range indicator (NATR). This series requires
  3994. * `linkedTo` option to be set and should be loaded after the
  3995. * `stock/indicators/indicators.js` and `stock/indicators/atr.js`.
  3996. *
  3997. * @sample {highstock} stock/indicators/natr
  3998. * NATR indicator
  3999. *
  4000. * @extends plotOptions.atr
  4001. * @since 7.0.0
  4002. * @product highstock
  4003. * @requires stock/indicators/indicators
  4004. * @requires stock/indicators/natr
  4005. * @optionparent plotOptions.natr
  4006. */
  4007. {
  4008. tooltip: {
  4009. valueSuffix: '%'
  4010. }
  4011. },
  4012. /**
  4013. * @lends Highcharts.Series#
  4014. */
  4015. {
  4016. requiredIndicators: ['atr'],
  4017. getValues: function (series, params) {
  4018. var atrData = (ATR.prototype.getValues.apply(this, arguments)), atrLength = atrData.values.length, period = params.period - 1, yVal = series.yData, i = 0;
  4019. if (!atrData) {
  4020. return;
  4021. }
  4022. for (; i < atrLength; i++) {
  4023. atrData.yData[i] = (atrData.values[i][1] / yVal[period][3] * 100);
  4024. atrData.values[i][1] = atrData.yData[i];
  4025. period++;
  4026. }
  4027. return atrData;
  4028. }
  4029. });
  4030. /**
  4031. * A `NATR` series. If the [type](#series.natr.type) option is not specified, it
  4032. * is inherited from [chart.type](#chart.type).
  4033. *
  4034. * @extends series,plotOptions.natr
  4035. * @since 7.0.0
  4036. * @product highstock
  4037. * @excluding dataParser, dataURL
  4038. * @requires stock/indicators/indicators
  4039. * @requires stock/indicators/natr
  4040. * @apioption series.natr
  4041. */
  4042. ''; // to include the above in the js output'
  4043. });
  4044. _registerModule(_modules, 'indicators/pivot-points.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  4045. /* *
  4046. *
  4047. * License: www.highcharts.com/license
  4048. *
  4049. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4050. *
  4051. * */
  4052. var defined = U.defined, isArray = U.isArray;
  4053. var SMA = H.seriesTypes.sma;
  4054. /* eslint-disable valid-jsdoc */
  4055. /**
  4056. * @private
  4057. */
  4058. function destroyExtraLabels(point, functionName) {
  4059. var props = point.series.pointArrayMap, prop, i = props.length;
  4060. SMA.prototype.pointClass.prototype[functionName].call(point);
  4061. while (i--) {
  4062. prop = 'dataLabel' + props[i];
  4063. // S4 dataLabel could be removed by parent method:
  4064. if (point[prop] && point[prop].element) {
  4065. point[prop].destroy();
  4066. }
  4067. point[prop] = null;
  4068. }
  4069. }
  4070. /* eslint-enable valid-jsdoc */
  4071. /**
  4072. * The Pivot Points series type.
  4073. *
  4074. * @private
  4075. * @class
  4076. * @name Highcharts.seriesTypes.pivotpoints
  4077. *
  4078. * @augments Highcharts.Series
  4079. */
  4080. H.seriesType('pivotpoints', 'sma',
  4081. /**
  4082. * Pivot points indicator. This series requires the `linkedTo` option to be
  4083. * set and should be loaded after `stock/indicators/indicators.js` file.
  4084. *
  4085. * @sample stock/indicators/pivot-points
  4086. * Pivot points
  4087. *
  4088. * @extends plotOptions.sma
  4089. * @since 6.0.0
  4090. * @product highstock
  4091. * @requires stock/indicators/indicators
  4092. * @requires stock/indicators/pivotpoints
  4093. * @optionparent plotOptions.pivotpoints
  4094. */
  4095. {
  4096. /**
  4097. * @excluding index
  4098. */
  4099. params: {
  4100. period: 28,
  4101. /**
  4102. * Algorithm used to calculate ressistance and support lines based
  4103. * on pivot points. Implemented algorithms: `'standard'`,
  4104. * `'fibonacci'` and `'camarilla'`
  4105. */
  4106. algorithm: 'standard'
  4107. },
  4108. marker: {
  4109. enabled: false
  4110. },
  4111. enableMouseTracking: false,
  4112. dataLabels: {
  4113. enabled: true,
  4114. format: '{point.pivotLine}'
  4115. },
  4116. dataGrouping: {
  4117. approximation: 'averages'
  4118. }
  4119. },
  4120. /**
  4121. * @lends Highcharts.Series#
  4122. */
  4123. {
  4124. nameBase: 'Pivot Points',
  4125. pointArrayMap: ['R4', 'R3', 'R2', 'R1', 'P', 'S1', 'S2', 'S3', 'S4'],
  4126. pointValKey: 'P',
  4127. toYData: function (point) {
  4128. return [point.P]; // The rest should not affect extremes
  4129. },
  4130. translate: function () {
  4131. var indicator = this;
  4132. SMA.prototype.translate.apply(indicator);
  4133. indicator.points.forEach(function (point) {
  4134. indicator.pointArrayMap.forEach(function (value) {
  4135. if (defined(point[value])) {
  4136. point['plot' + value] = (indicator.yAxis.toPixels(point[value], true));
  4137. }
  4138. });
  4139. });
  4140. // Pivot points are rendered as horizontal lines
  4141. // And last point start not from the next one (as it's the last one)
  4142. // But from the approximated last position in a given range
  4143. indicator.plotEndPoint = indicator.xAxis.toPixels(indicator.endPoint, true);
  4144. },
  4145. getGraphPath: function (points) {
  4146. var indicator = this, pointsLength = points.length, allPivotPoints = ([[], [], [], [], [], [], [], [], []]), path = [], endPoint = indicator.plotEndPoint, pointArrayMapLength = indicator.pointArrayMap.length, position, point, i;
  4147. while (pointsLength--) {
  4148. point = points[pointsLength];
  4149. for (i = 0; i < pointArrayMapLength; i++) {
  4150. position = indicator.pointArrayMap[i];
  4151. if (defined(point[position])) {
  4152. allPivotPoints[i].push({
  4153. // Start left:
  4154. plotX: point.plotX,
  4155. plotY: point['plot' + position],
  4156. isNull: false
  4157. }, {
  4158. // Go to right:
  4159. plotX: endPoint,
  4160. plotY: point['plot' + position],
  4161. isNull: false
  4162. }, {
  4163. // And add null points in path to generate breaks:
  4164. plotX: endPoint,
  4165. plotY: null,
  4166. isNull: true
  4167. });
  4168. }
  4169. }
  4170. endPoint = point.plotX;
  4171. }
  4172. allPivotPoints.forEach(function (pivotPoints) {
  4173. path = path.concat(SMA.prototype.getGraphPath.call(indicator, pivotPoints));
  4174. });
  4175. return path;
  4176. },
  4177. // TODO: Rewrite this logic to use multiple datalabels
  4178. drawDataLabels: function () {
  4179. var indicator = this, pointMapping = indicator.pointArrayMap, currentLabel, pointsLength, point, i;
  4180. if (indicator.options.dataLabels.enabled) {
  4181. pointsLength = indicator.points.length;
  4182. // For every Ressitance/Support group we need to render labels.
  4183. // Add one more item, which will just store dataLabels from
  4184. // previous iteration
  4185. pointMapping.concat([false]).forEach(function (position, k) {
  4186. i = pointsLength;
  4187. while (i--) {
  4188. point = indicator.points[i];
  4189. if (!position) {
  4190. // Store S4 dataLabel too:
  4191. point['dataLabel' + pointMapping[k - 1]] =
  4192. point.dataLabel;
  4193. }
  4194. else {
  4195. point.y = point[position];
  4196. point.pivotLine = position;
  4197. point.plotY = point['plot' + position];
  4198. currentLabel = point['dataLabel' + position];
  4199. // Store previous label
  4200. if (k) {
  4201. point['dataLabel' + pointMapping[k - 1]] = point.dataLabel;
  4202. }
  4203. if (!point.dataLabels) {
  4204. point.dataLabels = [];
  4205. }
  4206. point.dataLabels[0] = point.dataLabel =
  4207. currentLabel =
  4208. currentLabel && currentLabel.element ?
  4209. currentLabel :
  4210. null;
  4211. }
  4212. }
  4213. SMA.prototype.drawDataLabels.apply(indicator, arguments);
  4214. });
  4215. }
  4216. },
  4217. getValues: function (series, params) {
  4218. var period = params.period, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0, placement = this[params.algorithm + 'Placement'],
  4219. // 0- from, 1- to, 2- R1, 3- R2, 4- pivot, 5- S1 etc.
  4220. PP = [], endTimestamp, xData = [], yData = [], slicedXLen, slicedX, slicedY, lastPP, pivot, avg, i;
  4221. // Pivot Points requires high, low and close values
  4222. if (xVal.length < period ||
  4223. !isArray(yVal[0]) ||
  4224. yVal[0].length !== 4) {
  4225. return;
  4226. }
  4227. for (i = period + 1; i <= yValLen + period; i += period) {
  4228. slicedX = xVal.slice(i - period - 1, i);
  4229. slicedY = yVal.slice(i - period - 1, i);
  4230. slicedXLen = slicedX.length;
  4231. endTimestamp = slicedX[slicedXLen - 1];
  4232. pivot = this.getPivotAndHLC(slicedY);
  4233. avg = placement(pivot);
  4234. lastPP = PP.push([endTimestamp]
  4235. .concat(avg));
  4236. xData.push(endTimestamp);
  4237. yData.push(PP[lastPP - 1].slice(1));
  4238. }
  4239. // We don't know exact position in ordinal axis
  4240. // So we use simple logic:
  4241. // Get first point in last range, calculate visible average range
  4242. // and multiply by period
  4243. this.endPoint = slicedX[0] + ((endTimestamp - slicedX[0]) /
  4244. slicedXLen) * period;
  4245. return {
  4246. values: PP,
  4247. xData: xData,
  4248. yData: yData
  4249. };
  4250. },
  4251. getPivotAndHLC: function (values) {
  4252. var high = -Infinity, low = Infinity, close = values[values.length - 1][3], pivot;
  4253. values.forEach(function (p) {
  4254. high = Math.max(high, p[1]);
  4255. low = Math.min(low, p[2]);
  4256. });
  4257. pivot = (high + low + close) / 3;
  4258. return [pivot, high, low, close];
  4259. },
  4260. standardPlacement: function (values) {
  4261. var diff = values[1] - values[2], avg = [
  4262. null,
  4263. null,
  4264. values[0] + diff,
  4265. values[0] * 2 - values[2],
  4266. values[0],
  4267. values[0] * 2 - values[1],
  4268. values[0] - diff,
  4269. null,
  4270. null
  4271. ];
  4272. return avg;
  4273. },
  4274. camarillaPlacement: function (values) {
  4275. var diff = values[1] - values[2], avg = [
  4276. values[3] + diff * 1.5,
  4277. values[3] + diff * 1.25,
  4278. values[3] + diff * 1.1666,
  4279. values[3] + diff * 1.0833,
  4280. values[0],
  4281. values[3] - diff * 1.0833,
  4282. values[3] - diff * 1.1666,
  4283. values[3] - diff * 1.25,
  4284. values[3] - diff * 1.5
  4285. ];
  4286. return avg;
  4287. },
  4288. fibonacciPlacement: function (values) {
  4289. var diff = values[1] - values[2], avg = [
  4290. null,
  4291. values[0] + diff,
  4292. values[0] + diff * 0.618,
  4293. values[0] + diff * 0.382,
  4294. values[0],
  4295. values[0] - diff * 0.382,
  4296. values[0] - diff * 0.618,
  4297. values[0] - diff,
  4298. null
  4299. ];
  4300. return avg;
  4301. }
  4302. },
  4303. /**
  4304. * @lends Highcharts.Point#
  4305. */
  4306. {
  4307. // Destroy labels:
  4308. // This method is called when cropping data:
  4309. destroyElements: function () {
  4310. destroyExtraLabels(this, 'destroyElements');
  4311. },
  4312. // This method is called when removing points, e.g. series.update()
  4313. destroy: function () {
  4314. destroyExtraLabels(this, 'destroyElements');
  4315. }
  4316. });
  4317. /**
  4318. * A pivot points indicator. If the [type](#series.pivotpoints.type) option is
  4319. * not specified, it is inherited from [chart.type](#chart.type).
  4320. *
  4321. * @extends series,plotOptions.pivotpoints
  4322. * @since 6.0.0
  4323. * @product highstock
  4324. * @excluding dataParser, dataURL
  4325. * @requires stock/indicators/indicators
  4326. * @requires stock/indicators/pivotpoints
  4327. * @apioption series.pivotpoints
  4328. */
  4329. ''; // to include the above in the js output'
  4330. });
  4331. _registerModule(_modules, 'indicators/ppo.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['mixins/indicator-required.js']], function (H, U, requiredIndicatorMixin) {
  4332. /* *
  4333. *
  4334. * License: www.highcharts.com/license
  4335. *
  4336. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4337. *
  4338. * */
  4339. var correctFloat = U.correctFloat;
  4340. var EMA = H.seriesTypes.ema, error = H.error, requiredIndicator = requiredIndicatorMixin;
  4341. /**
  4342. * The PPO series type.
  4343. *
  4344. * @private
  4345. * @class
  4346. * @name Highcharts.seriesTypes.ppo
  4347. *
  4348. * @augments Highcharts.Series
  4349. */
  4350. H.seriesType('ppo', 'ema',
  4351. /**
  4352. * Percentage Price Oscillator. This series requires the
  4353. * `linkedTo` option to be set and should be loaded after the
  4354. * `stock/indicators/indicators.js` and `stock/indicators/ema.js`.
  4355. *
  4356. * @sample {highstock} stock/indicators/ppo
  4357. * Percentage Price Oscillator
  4358. *
  4359. * @extends plotOptions.ema
  4360. * @since 7.0.0
  4361. * @product highstock
  4362. * @excluding allAreas, colorAxis, joinBy, keys, navigatorOptions,
  4363. * pointInterval, pointIntervalUnit, pointPlacement,
  4364. * pointRange, pointStart, showInNavigator, stacking
  4365. * @requires stock/indicators/indicators
  4366. * @requires stock/indicators/ema
  4367. * @requires stock/indicators/ppo
  4368. * @optionparent plotOptions.ppo
  4369. */
  4370. {
  4371. /**
  4372. * Paramters used in calculation of Percentage Price Oscillator series
  4373. * points.
  4374. *
  4375. * @excluding period
  4376. */
  4377. params: {
  4378. /**
  4379. * Periods for Percentage Price Oscillator calculations.
  4380. *
  4381. * @type {Array<number>}
  4382. * @default [12, 26]
  4383. */
  4384. periods: [12, 26]
  4385. }
  4386. },
  4387. /**
  4388. * @lends Highcharts.Series.prototype
  4389. */
  4390. {
  4391. nameBase: 'PPO',
  4392. nameComponents: ['periods'],
  4393. init: function () {
  4394. var args = arguments, ctx = this;
  4395. requiredIndicator.isParentLoaded(EMA, 'ema', ctx.type, function (indicator) {
  4396. indicator.prototype.init.apply(ctx, args);
  4397. return;
  4398. });
  4399. },
  4400. getValues: function (series, params) {
  4401. var periods = params.periods, index = params.index,
  4402. // 0- date, 1- Percentage Price Oscillator
  4403. PPO = [], xData = [], yData = [], periodsOffset,
  4404. // Shorter Period EMA
  4405. SPE,
  4406. // Longer Period EMA
  4407. LPE, oscillator, i;
  4408. // Check if periods are correct
  4409. if (periods.length !== 2 || periods[1] <= periods[0]) {
  4410. error('Error: "PPO requires two periods. Notice, first period ' +
  4411. 'should be lower than the second one."');
  4412. return;
  4413. }
  4414. SPE = EMA.prototype.getValues.call(this, series, {
  4415. index: index,
  4416. period: periods[0]
  4417. });
  4418. LPE = EMA.prototype.getValues.call(this, series, {
  4419. index: index,
  4420. period: periods[1]
  4421. });
  4422. // Check if ema is calculated properly, if not skip
  4423. if (!SPE || !LPE) {
  4424. return;
  4425. }
  4426. periodsOffset = periods[1] - periods[0];
  4427. for (i = 0; i < LPE.yData.length; i++) {
  4428. oscillator = correctFloat((SPE.yData[i + periodsOffset] -
  4429. LPE.yData[i]) /
  4430. LPE.yData[i] *
  4431. 100);
  4432. PPO.push([LPE.xData[i], oscillator]);
  4433. xData.push(LPE.xData[i]);
  4434. yData.push(oscillator);
  4435. }
  4436. return {
  4437. values: PPO,
  4438. xData: xData,
  4439. yData: yData
  4440. };
  4441. }
  4442. });
  4443. /**
  4444. * A `Percentage Price Oscillator` series. If the [type](#series.ppo.type)
  4445. * option is not specified, it is inherited from [chart.type](#chart.type).
  4446. *
  4447. * @extends series,plotOptions.ppo
  4448. * @since 7.0.0
  4449. * @product highstock
  4450. * @excluding allAreas, colorAxis, dataParser, dataURL, joinBy, keys,
  4451. * navigatorOptions, pointInterval, pointIntervalUnit,
  4452. * pointPlacement, pointRange, pointStart, showInNavigator, stacking
  4453. * @requires stock/indicators/indicators
  4454. * @requires stock/indicators/ema
  4455. * @requires stock/indicators/ppo
  4456. * @apioption series.ppo
  4457. */
  4458. ''; // to include the above in the js output
  4459. });
  4460. _registerModule(_modules, 'mixins/reduce-array.js', [_modules['parts/Globals.js']], function (H) {
  4461. /**
  4462. *
  4463. * (c) 2010-2019 Pawel Fus & Daniel Studencki
  4464. *
  4465. * License: www.highcharts.com/license
  4466. *
  4467. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4468. *
  4469. * */
  4470. var reduce = H.reduce;
  4471. var reduceArrayMixin = {
  4472. /**
  4473. * Get min value of array filled by OHLC data.
  4474. * @private
  4475. * @param {Array<*>} arr Array of OHLC points (arrays).
  4476. * @param {string} index Index of "low" value in point array.
  4477. * @return {number} Returns min value.
  4478. */
  4479. minInArray: function (arr, index) {
  4480. return reduce(arr, function (min, target) {
  4481. return Math.min(min, target[index]);
  4482. }, Number.MAX_VALUE);
  4483. },
  4484. /**
  4485. * Get max value of array filled by OHLC data.
  4486. * @private
  4487. * @param {Array<*>} arr Array of OHLC points (arrays).
  4488. * @param {string} index Index of "high" value in point array.
  4489. * @return {number} Returns max value.
  4490. */
  4491. maxInArray: function (arr, index) {
  4492. return reduce(arr, function (max, target) {
  4493. return Math.max(max, target[index]);
  4494. }, -Number.MAX_VALUE);
  4495. },
  4496. /**
  4497. * Get extremes of array filled by OHLC data.
  4498. * @private
  4499. * @param {Array<*>} arr Array of OHLC points (arrays).
  4500. * @param {string} minIndex Index of "low" value in point array.
  4501. * @param {string} maxIndex Index of "high" value in point array.
  4502. * @return {Array<number,number>} Returns array with min and max value.
  4503. */
  4504. getArrayExtremes: function (arr, minIndex, maxIndex) {
  4505. return reduce(arr, function (prev, target) {
  4506. return [
  4507. Math.min(prev[0], target[minIndex]),
  4508. Math.max(prev[1], target[maxIndex])
  4509. ];
  4510. }, [Number.MAX_VALUE, -Number.MAX_VALUE]);
  4511. }
  4512. };
  4513. return reduceArrayMixin;
  4514. });
  4515. _registerModule(_modules, 'indicators/price-channel.src.js', [_modules['parts/Globals.js'], _modules['mixins/reduce-array.js'], _modules['mixins/multipe-lines.js']], function (H, reduceArrayMixin, multipleLinesMixin) {
  4516. /* *
  4517. *
  4518. * License: www.highcharts.com/license
  4519. *
  4520. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4521. *
  4522. * */
  4523. var getArrayExtremes = reduceArrayMixin.getArrayExtremes, merge = H.merge;
  4524. /**
  4525. * The Price Channel series type.
  4526. *
  4527. * @private
  4528. * @class
  4529. * @name Highcharts.seriesTypes.pc
  4530. *
  4531. * @augments Highcharts.Series
  4532. */
  4533. H.seriesType('pc', 'sma',
  4534. /**
  4535. * Price channel (PC). This series requires the `linkedTo` option to be
  4536. * set and should be loaded after the `stock/indicators/indicators.js`.
  4537. *
  4538. * @sample {highstock} stock/indicators/price-channel
  4539. * Price Channel
  4540. *
  4541. * @extends plotOptions.sma
  4542. * @since 7.0.0
  4543. * @product highstock
  4544. * @excluding allAreas, colorAxis, compare, compareBase, joinBy, keys,
  4545. * navigatorOptions, pointInterval, pointIntervalUnit,
  4546. * pointPlacement, pointRange, pointStart, showInNavigator,
  4547. * stacking
  4548. * @requires stock/indicators/indicators
  4549. * @requires stock/indicators/price-channel
  4550. * @optionparent plotOptions.pc
  4551. */
  4552. {
  4553. /**
  4554. * @excluding index
  4555. */
  4556. params: {
  4557. period: 20
  4558. },
  4559. lineWidth: 1,
  4560. topLine: {
  4561. styles: {
  4562. /**
  4563. * Color of the top line. If not set, it's inherited from
  4564. * [plotOptions.pc.color](#plotOptions.pc.color).
  4565. *
  4566. * @type {Highcharts.ColorString}
  4567. */
  4568. lineColor: '#7cb5ec #434348 #90ed7d #f7a35c #8085e9 #f15c80 #e4d354 #2b908f #f45b5b #91e8e1'.split(' ')[2],
  4569. /**
  4570. * Pixel width of the line.
  4571. */
  4572. lineWidth: 1
  4573. }
  4574. },
  4575. bottomLine: {
  4576. styles: {
  4577. /**
  4578. * Color of the bottom line. If not set, it's inherited from
  4579. * [plotOptions.pc.color](#plotOptions.pc.color).
  4580. *
  4581. * @type {Highcharts.ColorString}
  4582. */
  4583. lineColor: '#7cb5ec #434348 #90ed7d #f7a35c #8085e9 #f15c80 #e4d354 #2b908f #f45b5b #91e8e1'.split(' ')[8],
  4584. /**
  4585. * Pixel width of the line.
  4586. */
  4587. lineWidth: 1
  4588. }
  4589. },
  4590. dataGrouping: {
  4591. approximation: 'averages'
  4592. }
  4593. },
  4594. /**
  4595. * @lends Highcharts.Series#
  4596. */
  4597. merge(multipleLinesMixin, {
  4598. pointArrayMap: ['top', 'middle', 'bottom'],
  4599. pointValKey: 'middle',
  4600. nameBase: 'Price Channel',
  4601. nameComponents: ['period'],
  4602. linesApiNames: ['topLine', 'bottomLine'],
  4603. getValues: function (series, params) {
  4604. var period = params.period, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0,
  4605. // 0- date, 1-top line, 2-middle line, 3-bottom line
  4606. PC = [],
  4607. // middle line, top line and bottom line
  4608. ML, TL, BL, date, low = 2, high = 1, xData = [], yData = [], slicedY, extremes, i;
  4609. if (yValLen < period) {
  4610. return;
  4611. }
  4612. for (i = period; i <= yValLen; i++) {
  4613. date = xVal[i - 1];
  4614. slicedY = yVal.slice(i - period, i);
  4615. extremes = getArrayExtremes(slicedY, low, high);
  4616. TL = extremes[1];
  4617. BL = extremes[0];
  4618. ML = (TL + BL) / 2;
  4619. PC.push([date, TL, ML, BL]);
  4620. xData.push(date);
  4621. yData.push([TL, ML, BL]);
  4622. }
  4623. return {
  4624. values: PC,
  4625. xData: xData,
  4626. yData: yData
  4627. };
  4628. }
  4629. }));
  4630. /**
  4631. * A Price channel indicator. If the [type](#series.pc.type) option is not
  4632. * specified, it is inherited from [chart.type](#chart.type).
  4633. *
  4634. * @extends series,plotOptions.pc
  4635. * @since 7.0.0
  4636. * @product highstock
  4637. * @excluding allAreas, colorAxis, compare, compareBase, dataParser, dataURL,
  4638. * joinBy, keys, navigatorOptions, pointInterval,
  4639. * pointIntervalUnit, pointPlacement, pointRange, pointStart,
  4640. * showInNavigator, stacking
  4641. * @requires stock/indicators/indicators
  4642. * @requires stock/indicators/price-channel
  4643. * @apioption series.pc
  4644. */
  4645. ''; // to include the above in the js output
  4646. });
  4647. _registerModule(_modules, 'indicators/price-envelopes.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  4648. /* *
  4649. *
  4650. * License: www.highcharts.com/license
  4651. *
  4652. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4653. *
  4654. * */
  4655. var isArray = U.isArray;
  4656. var merge = H.merge, SMA = H.seriesTypes.sma;
  4657. /**
  4658. * The Price Envelopes series type.
  4659. *
  4660. * @private
  4661. * @class
  4662. * @name Highcharts.seriesTypes.priceenvelopes
  4663. *
  4664. * @augments Highcharts.Series
  4665. */
  4666. H.seriesType('priceenvelopes', 'sma',
  4667. /**
  4668. * Price envelopes indicator based on [SMA](#plotOptions.sma) calculations.
  4669. * This series requires the `linkedTo` option to be set and should be loaded
  4670. * after the `stock/indicators/indicators.js` file.
  4671. *
  4672. * @sample stock/indicators/price-envelopes
  4673. * Price envelopes
  4674. *
  4675. * @extends plotOptions.sma
  4676. * @since 6.0.0
  4677. * @product highstock
  4678. * @requires stock/indicators/indicators
  4679. * @requires stock/indicators/price-envelopes
  4680. * @optionparent plotOptions.priceenvelopes
  4681. */
  4682. {
  4683. marker: {
  4684. enabled: false
  4685. },
  4686. tooltip: {
  4687. pointFormat: '<span style="color:{point.color}">\u25CF</span><b> {series.name}</b><br/>Top: {point.top}<br/>Middle: {point.middle}<br/>Bottom: {point.bottom}<br/>'
  4688. },
  4689. params: {
  4690. period: 20,
  4691. /**
  4692. * Percentage above the moving average that should be displayed.
  4693. * 0.1 means 110%. Relative to the calculated value.
  4694. */
  4695. topBand: 0.1,
  4696. /**
  4697. * Percentage below the moving average that should be displayed.
  4698. * 0.1 means 90%. Relative to the calculated value.
  4699. */
  4700. bottomBand: 0.1
  4701. },
  4702. /**
  4703. * Bottom line options.
  4704. */
  4705. bottomLine: {
  4706. styles: {
  4707. /**
  4708. * Pixel width of the line.
  4709. */
  4710. lineWidth: 1,
  4711. /**
  4712. * Color of the line. If not set, it's inherited from
  4713. * [plotOptions.priceenvelopes.color](
  4714. * #plotOptions.priceenvelopes.color).
  4715. *
  4716. * @type {Highcharts.ColorString}
  4717. */
  4718. lineColor: void 0
  4719. }
  4720. },
  4721. /**
  4722. * Top line options.
  4723. *
  4724. * @extends plotOptions.priceenvelopes.bottomLine
  4725. */
  4726. topLine: {
  4727. styles: {
  4728. lineWidth: 1
  4729. }
  4730. },
  4731. dataGrouping: {
  4732. approximation: 'averages'
  4733. }
  4734. },
  4735. /**
  4736. * @lends Highcharts.Series#
  4737. */
  4738. {
  4739. nameComponents: ['period', 'topBand', 'bottomBand'],
  4740. nameBase: 'Price envelopes',
  4741. pointArrayMap: ['top', 'middle', 'bottom'],
  4742. parallelArrays: ['x', 'y', 'top', 'bottom'],
  4743. pointValKey: 'middle',
  4744. init: function () {
  4745. SMA.prototype.init.apply(this, arguments);
  4746. // Set default color for lines:
  4747. this.options = merge({
  4748. topLine: {
  4749. styles: {
  4750. lineColor: this.color
  4751. }
  4752. },
  4753. bottomLine: {
  4754. styles: {
  4755. lineColor: this.color
  4756. }
  4757. }
  4758. }, this.options);
  4759. },
  4760. toYData: function (point) {
  4761. return [point.top, point.middle, point.bottom];
  4762. },
  4763. translate: function () {
  4764. var indicator = this, translatedEnvelopes = ['plotTop', 'plotMiddle', 'plotBottom'];
  4765. SMA.prototype.translate.apply(indicator);
  4766. indicator.points.forEach(function (point) {
  4767. [point.top, point.middle, point.bottom].forEach(function (value, i) {
  4768. if (value !== null) {
  4769. point[translatedEnvelopes[i]] =
  4770. indicator.yAxis.toPixels(value, true);
  4771. }
  4772. });
  4773. });
  4774. },
  4775. drawGraph: function () {
  4776. var indicator = this, middleLinePoints = indicator.points, pointsLength = middleLinePoints.length, middleLineOptions = (indicator.options), middleLinePath = indicator.graph, gappedExtend = {
  4777. options: {
  4778. gapSize: middleLineOptions.gapSize
  4779. }
  4780. }, deviations = [[], []], // top and bottom point place holders
  4781. point;
  4782. // Generate points for top and bottom lines:
  4783. while (pointsLength--) {
  4784. point = middleLinePoints[pointsLength];
  4785. deviations[0].push({
  4786. plotX: point.plotX,
  4787. plotY: point.plotTop,
  4788. isNull: point.isNull
  4789. });
  4790. deviations[1].push({
  4791. plotX: point.plotX,
  4792. plotY: point.plotBottom,
  4793. isNull: point.isNull
  4794. });
  4795. }
  4796. // Modify options and generate lines:
  4797. ['topLine', 'bottomLine'].forEach(function (lineName, i) {
  4798. indicator.points = deviations[i];
  4799. indicator.options = merge(middleLineOptions[lineName].styles, gappedExtend);
  4800. indicator.graph = indicator['graph' + lineName];
  4801. SMA.prototype.drawGraph.call(indicator);
  4802. // Now save lines:
  4803. indicator['graph' + lineName] = indicator.graph;
  4804. });
  4805. // Restore options and draw a middle line:
  4806. indicator.points = middleLinePoints;
  4807. indicator.options = middleLineOptions;
  4808. indicator.graph = middleLinePath;
  4809. SMA.prototype.drawGraph.call(indicator);
  4810. },
  4811. getValues: function (series, params) {
  4812. var period = params.period, topPercent = params.topBand, botPercent = params.bottomBand, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0,
  4813. // 0- date, 1-top line, 2-middle line, 3-bottom line
  4814. PE = [],
  4815. // middle line, top line and bottom line
  4816. ML, TL, BL, date, xData = [], yData = [], slicedX, slicedY, point, i;
  4817. // Price envelopes requires close value
  4818. if (xVal.length < period ||
  4819. !isArray(yVal[0]) ||
  4820. yVal[0].length !== 4) {
  4821. return;
  4822. }
  4823. for (i = period; i <= yValLen; i++) {
  4824. slicedX = xVal.slice(i - period, i);
  4825. slicedY = yVal.slice(i - period, i);
  4826. point = SMA.prototype.getValues.call(this, {
  4827. xData: slicedX,
  4828. yData: slicedY
  4829. }, params);
  4830. date = point.xData[0];
  4831. ML = point.yData[0];
  4832. TL = ML * (1 + topPercent);
  4833. BL = ML * (1 - botPercent);
  4834. PE.push([date, TL, ML, BL]);
  4835. xData.push(date);
  4836. yData.push([TL, ML, BL]);
  4837. }
  4838. return {
  4839. values: PE,
  4840. xData: xData,
  4841. yData: yData
  4842. };
  4843. }
  4844. });
  4845. /**
  4846. * A price envelopes indicator. If the [type](#series.priceenvelopes.type)
  4847. * option is not specified, it is inherited from [chart.type](#chart.type).
  4848. *
  4849. * @extends series,plotOptions.priceenvelopes
  4850. * @since 6.0.0
  4851. * @excluding dataParser, dataURL
  4852. * @product highstock
  4853. * @requires stock/indicators/indicators
  4854. * @requires stock/indicators/price-envelopes
  4855. * @apioption series.priceenvelopes
  4856. */
  4857. ''; // to include the above in the js output
  4858. });
  4859. _registerModule(_modules, 'indicators/psar.src.js', [_modules['parts/Globals.js']], function (H) {
  4860. /* *
  4861. *
  4862. * Parabolic SAR indicator for Highstock
  4863. *
  4864. * (c) 2010-2019 Grzegorz Blachliński
  4865. *
  4866. * License: www.highcharts.com/license
  4867. *
  4868. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4869. *
  4870. * */
  4871. /* eslint-disable require-jsdoc */
  4872. // Utils:
  4873. function toFixed(a, n) {
  4874. return parseFloat(a.toFixed(n));
  4875. }
  4876. function calculateDirection(previousDirection, low, high, PSAR) {
  4877. if ((previousDirection === 1 && low > PSAR) ||
  4878. (previousDirection === -1 && high > PSAR)) {
  4879. return 1;
  4880. }
  4881. return -1;
  4882. }
  4883. /* *
  4884. * Method for calculating acceleration factor
  4885. * dir - direction
  4886. * pDir - previous Direction
  4887. * eP - extreme point
  4888. * pEP - previous extreme point
  4889. * inc - increment for acceleration factor
  4890. * maxAcc - maximum acceleration factor
  4891. * initAcc - initial acceleration factor
  4892. */
  4893. function getAccelerationFactor(dir, pDir, eP, pEP, pAcc, inc, maxAcc, initAcc) {
  4894. if (dir === pDir) {
  4895. if (dir === 1 && (eP > pEP)) {
  4896. return (pAcc === maxAcc) ? maxAcc : toFixed(pAcc + inc, 2);
  4897. }
  4898. if (dir === -1 && (eP < pEP)) {
  4899. return (pAcc === maxAcc) ? maxAcc : toFixed(pAcc + inc, 2);
  4900. }
  4901. return pAcc;
  4902. }
  4903. return initAcc;
  4904. }
  4905. function getExtremePoint(high, low, previousDirection, previousExtremePoint) {
  4906. if (previousDirection === 1) {
  4907. return (high > previousExtremePoint) ? high : previousExtremePoint;
  4908. }
  4909. return (low < previousExtremePoint) ? low : previousExtremePoint;
  4910. }
  4911. function getEPMinusPSAR(EP, PSAR) {
  4912. return EP - PSAR;
  4913. }
  4914. function getAccelerationFactorMultiply(accelerationFactor, EPMinusSAR) {
  4915. return accelerationFactor * EPMinusSAR;
  4916. }
  4917. /* *
  4918. * Method for calculating PSAR
  4919. * pdir - previous direction
  4920. * sDir - second previous Direction
  4921. * PSAR - previous PSAR
  4922. * pACCMultiply - previous acceleration factor multiply
  4923. * sLow - second previous low
  4924. * pLow - previous low
  4925. * sHigh - second previous high
  4926. * pHigh - previous high
  4927. * pEP - previous extreme point
  4928. */
  4929. function getPSAR(pdir, sDir, PSAR, pACCMulti, sLow, pLow, pHigh, sHigh, pEP) {
  4930. if (pdir === sDir) {
  4931. if (pdir === 1) {
  4932. return (PSAR + pACCMulti < Math.min(sLow, pLow)) ?
  4933. PSAR + pACCMulti :
  4934. Math.min(sLow, pLow);
  4935. }
  4936. return (PSAR + pACCMulti > Math.max(sHigh, pHigh)) ?
  4937. PSAR + pACCMulti :
  4938. Math.max(sHigh, pHigh);
  4939. }
  4940. return pEP;
  4941. }
  4942. /* eslint-enable require-jsdoc */
  4943. /**
  4944. * The Parabolic SAR series type.
  4945. *
  4946. * @private
  4947. * @class
  4948. * @name Highcharts.seriesTypes.psar
  4949. *
  4950. * @augments Highcharts.Series
  4951. */
  4952. H.seriesType('psar', 'sma',
  4953. /**
  4954. * Parabolic SAR. This series requires `linkedTo`
  4955. * option to be set and should be loaded
  4956. * after `stock/indicators/indicators.js` file.
  4957. *
  4958. * @sample stock/indicators/psar
  4959. * Parabolic SAR Indicator
  4960. *
  4961. * @extends plotOptions.sma
  4962. * @since 6.0.0
  4963. * @product highstock
  4964. * @requires stock/indicators/indicators
  4965. * @requires stock/indicators/psar
  4966. * @optionparent plotOptions.psar
  4967. */
  4968. {
  4969. lineWidth: 0,
  4970. marker: {
  4971. enabled: true
  4972. },
  4973. states: {
  4974. hover: {
  4975. lineWidthPlus: 0
  4976. }
  4977. },
  4978. /**
  4979. * @excluding period
  4980. */
  4981. params: {
  4982. /**
  4983. * The initial value for acceleration factor.
  4984. * Acceleration factor is starting with this value
  4985. * and increases by specified increment each time
  4986. * the extreme point makes a new high.
  4987. * AF can reach a maximum of maxAccelerationFactor,
  4988. * no matter how long the uptrend extends.
  4989. */
  4990. initialAccelerationFactor: 0.02,
  4991. /**
  4992. * The Maximum value for acceleration factor.
  4993. * AF can reach a maximum of maxAccelerationFactor,
  4994. * no matter how long the uptrend extends.
  4995. */
  4996. maxAccelerationFactor: 0.2,
  4997. /**
  4998. * Acceleration factor increases by increment each time
  4999. * the extreme point makes a new high.
  5000. *
  5001. * @since 6.0.0
  5002. */
  5003. increment: 0.02,
  5004. /**
  5005. * Index from which PSAR is starting calculation
  5006. *
  5007. * @since 6.0.0
  5008. */
  5009. index: 2,
  5010. /**
  5011. * Number of maximum decimals that are used in PSAR calculations.
  5012. *
  5013. * @since 6.0.0
  5014. */
  5015. decimals: 4
  5016. }
  5017. }, {
  5018. nameComponents: false,
  5019. getValues: function (series, params) {
  5020. var xVal = series.xData, yVal = series.yData,
  5021. // Extreme point is the lowest low for falling and highest high
  5022. // for rising psar - and we are starting with falling
  5023. extremePoint = yVal[0][1], accelerationFactor = params.initialAccelerationFactor, maxAccelerationFactor = params.maxAccelerationFactor, increment = params.increment,
  5024. // Set initial acc factor (for every new trend!)
  5025. initialAccelerationFactor = params.initialAccelerationFactor, PSAR = yVal[0][2], decimals = params.decimals, index = params.index, PSARArr = [], xData = [], yData = [], previousDirection = 1, direction, EPMinusPSAR, accelerationFactorMultiply, newDirection, prevLow, prevPrevLow, prevHigh, prevPrevHigh, newExtremePoint, high, low, ind;
  5026. if (index >= yVal.length) {
  5027. return;
  5028. }
  5029. for (ind = 0; ind < index; ind++) {
  5030. extremePoint = Math.max(yVal[ind][1], extremePoint);
  5031. PSAR = Math.min(yVal[ind][2], toFixed(PSAR, decimals));
  5032. }
  5033. direction = (yVal[ind][1] > PSAR) ? 1 : -1;
  5034. EPMinusPSAR = getEPMinusPSAR(extremePoint, PSAR);
  5035. accelerationFactor = params.initialAccelerationFactor;
  5036. accelerationFactorMultiply = getAccelerationFactorMultiply(accelerationFactor, EPMinusPSAR);
  5037. PSARArr.push([xVal[index], PSAR]);
  5038. xData.push(xVal[index]);
  5039. yData.push(toFixed(PSAR, decimals));
  5040. for (ind = index + 1; ind < yVal.length; ind++) {
  5041. prevLow = yVal[ind - 1][2];
  5042. prevPrevLow = yVal[ind - 2][2];
  5043. prevHigh = yVal[ind - 1][1];
  5044. prevPrevHigh = yVal[ind - 2][1];
  5045. high = yVal[ind][1];
  5046. low = yVal[ind][2];
  5047. // Null points break PSAR
  5048. if (prevPrevLow !== null &&
  5049. prevPrevHigh !== null &&
  5050. prevLow !== null &&
  5051. prevHigh !== null &&
  5052. high !== null &&
  5053. low !== null) {
  5054. PSAR = getPSAR(direction, previousDirection, PSAR, accelerationFactorMultiply, prevPrevLow, prevLow, prevHigh, prevPrevHigh, extremePoint);
  5055. newExtremePoint = getExtremePoint(high, low, direction, extremePoint);
  5056. newDirection = calculateDirection(previousDirection, low, high, PSAR);
  5057. accelerationFactor = getAccelerationFactor(newDirection, direction, newExtremePoint, extremePoint, accelerationFactor, increment, maxAccelerationFactor, initialAccelerationFactor);
  5058. EPMinusPSAR = getEPMinusPSAR(newExtremePoint, PSAR);
  5059. accelerationFactorMultiply = getAccelerationFactorMultiply(accelerationFactor, EPMinusPSAR);
  5060. PSARArr.push([xVal[ind], toFixed(PSAR, decimals)]);
  5061. xData.push(xVal[ind]);
  5062. yData.push(toFixed(PSAR, decimals));
  5063. previousDirection = direction;
  5064. direction = newDirection;
  5065. extremePoint = newExtremePoint;
  5066. }
  5067. }
  5068. return {
  5069. values: PSARArr,
  5070. xData: xData,
  5071. yData: yData
  5072. };
  5073. }
  5074. });
  5075. /**
  5076. * A `PSAR` series. If the [type](#series.psar.type) option is not specified, it
  5077. * is inherited from [chart.type](#chart.type).
  5078. *
  5079. * @extends series,plotOptions.psar
  5080. * @since 6.0.0
  5081. * @product highstock
  5082. * @excluding dataParser, dataURL
  5083. * @requires stock/indicators/indicators
  5084. * @requires stock/indicators/psar
  5085. * @apioption series.psar
  5086. */
  5087. ''; // to include the above in the js output
  5088. });
  5089. _registerModule(_modules, 'indicators/roc.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  5090. /* *
  5091. *
  5092. * (c) 2010-2019 Kacper Madej
  5093. *
  5094. * License: www.highcharts.com/license
  5095. *
  5096. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  5097. *
  5098. * */
  5099. var isArray = U.isArray;
  5100. var seriesType = H.seriesType;
  5101. /* eslint-disable require-jsdoc */
  5102. // Utils:
  5103. function populateAverage(xVal, yVal, i, period, index) {
  5104. /* Calculated as:
  5105. (Closing Price [today] - Closing Price [n days ago]) /
  5106. Closing Price [n days ago] * 100
  5107. Return y as null when avoiding division by zero */
  5108. var nDaysAgoY, rocY;
  5109. if (index < 0) {
  5110. // y data given as an array of values
  5111. nDaysAgoY = yVal[i - period];
  5112. rocY = nDaysAgoY ?
  5113. (yVal[i] - nDaysAgoY) / nDaysAgoY * 100 :
  5114. null;
  5115. }
  5116. else {
  5117. // y data given as an array of arrays and the index should be used
  5118. nDaysAgoY = yVal[i - period][index];
  5119. rocY = nDaysAgoY ?
  5120. (yVal[i][index] - nDaysAgoY) / nDaysAgoY * 100 :
  5121. null;
  5122. }
  5123. return [xVal[i], rocY];
  5124. }
  5125. /* eslint-enable require-jsdoc */
  5126. /**
  5127. * The ROC series type.
  5128. *
  5129. * @private
  5130. * @class
  5131. * @name Highcharts.seriesTypes.roc
  5132. *
  5133. * @augments Highcharts.Series
  5134. */
  5135. seriesType('roc', 'sma',
  5136. /**
  5137. * Rate of change indicator (ROC). The indicator value for each point
  5138. * is defined as:
  5139. *
  5140. * `(C - Cn) / Cn * 100`
  5141. *
  5142. * where: `C` is the close value of the point of the same x in the
  5143. * linked series and `Cn` is the close value of the point `n` periods
  5144. * ago. `n` is set through [period](#plotOptions.roc.params.period).
  5145. *
  5146. * This series requires `linkedTo` option to be set.
  5147. *
  5148. * @sample stock/indicators/roc
  5149. * Rate of change indicator
  5150. *
  5151. * @extends plotOptions.sma
  5152. * @since 6.0.0
  5153. * @product highstock
  5154. * @requires stock/indicators/indicators
  5155. * @requires stock/indicators/roc
  5156. * @optionparent plotOptions.roc
  5157. */
  5158. {
  5159. params: {
  5160. index: 3,
  5161. period: 9
  5162. }
  5163. },
  5164. /**
  5165. * @lends Highcharts.Series#
  5166. */
  5167. {
  5168. nameBase: 'Rate of Change',
  5169. getValues: function (series, params) {
  5170. var period = params.period, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0, ROC = [], xData = [], yData = [], i, index = -1, ROCPoint;
  5171. // Period is used as a number of time periods ago, so we need more
  5172. // (at least 1 more) data than the period value
  5173. if (xVal.length <= period) {
  5174. return;
  5175. }
  5176. // Switch index for OHLC / Candlestick / Arearange
  5177. if (isArray(yVal[0])) {
  5178. index = params.index;
  5179. }
  5180. // i = period <-- skip first N-points
  5181. // Calculate value one-by-one for each period in visible data
  5182. for (i = period; i < yValLen; i++) {
  5183. ROCPoint = populateAverage(xVal, yVal, i, period, index);
  5184. ROC.push(ROCPoint);
  5185. xData.push(ROCPoint[0]);
  5186. yData.push(ROCPoint[1]);
  5187. }
  5188. return {
  5189. values: ROC,
  5190. xData: xData,
  5191. yData: yData
  5192. };
  5193. }
  5194. });
  5195. /**
  5196. * A `ROC` series. If the [type](#series.wma.type) option is not
  5197. * specified, it is inherited from [chart.type](#chart.type).
  5198. *
  5199. * Rate of change indicator (ROC). The indicator value for each point
  5200. * is defined as:
  5201. *
  5202. * `(C - Cn) / Cn * 100`
  5203. *
  5204. * where: `C` is the close value of the point of the same x in the
  5205. * linked series and `Cn` is the close value of the point `n` periods
  5206. * ago. `n` is set through [period](#series.roc.params.period).
  5207. *
  5208. * This series requires `linkedTo` option to be set.
  5209. *
  5210. * @extends series,plotOptions.roc
  5211. * @since 6.0.0
  5212. * @product highstock
  5213. * @excluding dataParser, dataURL
  5214. * @requires stock/indicators/indicators
  5215. * @requires stock/indicators/roc
  5216. * @apioption series.roc
  5217. */
  5218. ''; // to include the above in the js output
  5219. });
  5220. _registerModule(_modules, 'indicators/rsi.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  5221. /* *
  5222. *
  5223. * License: www.highcharts.com/license
  5224. *
  5225. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  5226. *
  5227. * */
  5228. var isArray = U.isArray;
  5229. /* eslint-disable require-jsdoc */
  5230. // Utils:
  5231. function toFixed(a, n) {
  5232. return parseFloat(a.toFixed(n));
  5233. }
  5234. /* eslint-enable require-jsdoc */
  5235. /**
  5236. * The RSI series type.
  5237. *
  5238. * @private
  5239. * @class
  5240. * @name Highcharts.seriesTypes.rsi
  5241. *
  5242. * @augments Highcharts.Series
  5243. */
  5244. H.seriesType('rsi', 'sma',
  5245. /**
  5246. * Relative strength index (RSI) technical indicator. This series
  5247. * requires the `linkedTo` option to be set and should be loaded after
  5248. * the `stock/indicators/indicators.js` file.
  5249. *
  5250. * @sample stock/indicators/rsi
  5251. * RSI indicator
  5252. *
  5253. * @extends plotOptions.sma
  5254. * @since 6.0.0
  5255. * @product highstock
  5256. * @requires stock/indicators/indicators
  5257. * @requires stock/indicators/rsi
  5258. * @optionparent plotOptions.rsi
  5259. */
  5260. {
  5261. /**
  5262. * @excluding index
  5263. */
  5264. params: {
  5265. period: 14,
  5266. /**
  5267. * Number of maximum decimals that are used in RSI calculations.
  5268. */
  5269. decimals: 4
  5270. }
  5271. },
  5272. /**
  5273. * @lends Highcharts.Series#
  5274. */
  5275. {
  5276. getValues: function (series, params) {
  5277. var period = params.period, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0, decimals = params.decimals,
  5278. // RSI starts calculations from the second point
  5279. // Cause we need to calculate change between two points
  5280. range = 1, RSI = [], xData = [], yData = [], index = 3, gain = 0, loss = 0, RSIPoint, change, avgGain, avgLoss, i;
  5281. // RSI requires close value
  5282. if ((xVal.length < period) || !isArray(yVal[0]) ||
  5283. yVal[0].length !== 4) {
  5284. return;
  5285. }
  5286. // Calculate changes for first N points
  5287. while (range < period) {
  5288. change = toFixed(yVal[range][index] - yVal[range - 1][index], decimals);
  5289. if (change > 0) {
  5290. gain += change;
  5291. }
  5292. else {
  5293. loss += Math.abs(change);
  5294. }
  5295. range++;
  5296. }
  5297. // Average for first n-1 points:
  5298. avgGain = toFixed(gain / (period - 1), decimals);
  5299. avgLoss = toFixed(loss / (period - 1), decimals);
  5300. for (i = range; i < yValLen; i++) {
  5301. change = toFixed(yVal[i][index] - yVal[i - 1][index], decimals);
  5302. if (change > 0) {
  5303. gain = change;
  5304. loss = 0;
  5305. }
  5306. else {
  5307. gain = 0;
  5308. loss = Math.abs(change);
  5309. }
  5310. // Calculate smoothed averages, RS, RSI values:
  5311. avgGain = toFixed((avgGain * (period - 1) + gain) / period, decimals);
  5312. avgLoss = toFixed((avgLoss * (period - 1) + loss) / period, decimals);
  5313. // If average-loss is equal zero, then by definition RSI is set
  5314. // to 100:
  5315. if (avgLoss === 0) {
  5316. RSIPoint = 100;
  5317. // If average-gain is equal zero, then by definition RSI is set
  5318. // to 0:
  5319. }
  5320. else if (avgGain === 0) {
  5321. RSIPoint = 0;
  5322. }
  5323. else {
  5324. RSIPoint = toFixed(100 - (100 / (1 + (avgGain / avgLoss))), decimals);
  5325. }
  5326. RSI.push([xVal[i], RSIPoint]);
  5327. xData.push(xVal[i]);
  5328. yData.push(RSIPoint);
  5329. }
  5330. return {
  5331. values: RSI,
  5332. xData: xData,
  5333. yData: yData
  5334. };
  5335. }
  5336. });
  5337. /**
  5338. * A `RSI` series. If the [type](#series.rsi.type) option is not
  5339. * specified, it is inherited from [chart.type](#chart.type).
  5340. *
  5341. * @extends series,plotOptions.rsi
  5342. * @since 6.0.0
  5343. * @product highstock
  5344. * @excluding dataParser, dataURL
  5345. * @requires stock/indicators/indicators
  5346. * @requires stock/indicators/rsi
  5347. * @apioption series.rsi
  5348. */
  5349. ''; // to include the above in the js output
  5350. });
  5351. _registerModule(_modules, 'indicators/stochastic.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['mixins/reduce-array.js'], _modules['mixins/multipe-lines.js']], function (H, U, reduceArrayMixin, multipleLinesMixin) {
  5352. /* *
  5353. *
  5354. * License: www.highcharts.com/license
  5355. *
  5356. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  5357. *
  5358. * */
  5359. var isArray = U.isArray;
  5360. var merge = H.merge, SMA = H.seriesTypes.sma, getArrayExtremes = reduceArrayMixin.getArrayExtremes;
  5361. /**
  5362. * The Stochastic series type.
  5363. *
  5364. * @private
  5365. * @class
  5366. * @name Highcharts.seriesTypes.stochastic
  5367. *
  5368. * @augments Highcharts.Series
  5369. */
  5370. H.seriesType('stochastic', 'sma',
  5371. /**
  5372. * Stochastic oscillator. This series requires the `linkedTo` option to be
  5373. * set and should be loaded after the `stock/indicators/indicators.js` file.
  5374. *
  5375. * @sample stock/indicators/stochastic
  5376. * Stochastic oscillator
  5377. *
  5378. * @extends plotOptions.sma
  5379. * @since 6.0.0
  5380. * @product highstock
  5381. * @excluding allAreas, colorAxis, joinBy, keys, navigatorOptions,
  5382. * pointInterval, pointIntervalUnit, pointPlacement,
  5383. * pointRange, pointStart, showInNavigator, stacking
  5384. * @requires stock/indicators/indicators
  5385. * @requires stock/indicators/stochastic
  5386. * @optionparent plotOptions.stochastic
  5387. */
  5388. {
  5389. /**
  5390. * @excluding index, period
  5391. */
  5392. params: {
  5393. /**
  5394. * Periods for Stochastic oscillator: [%K, %D].
  5395. *
  5396. * @type {Array<number,number>}
  5397. * @default [14, 3]
  5398. */
  5399. periods: [14, 3]
  5400. },
  5401. marker: {
  5402. enabled: false
  5403. },
  5404. tooltip: {
  5405. pointFormat: '<span style="color:{point.color}">\u25CF</span><b> {series.name}</b><br/>%K: {point.y}<br/>%D: {point.smoothed}<br/>'
  5406. },
  5407. /**
  5408. * Smoothed line options.
  5409. */
  5410. smoothedLine: {
  5411. /**
  5412. * Styles for a smoothed line.
  5413. */
  5414. styles: {
  5415. /**
  5416. * Pixel width of the line.
  5417. */
  5418. lineWidth: 1,
  5419. /**
  5420. * Color of the line. If not set, it's inherited from
  5421. * [plotOptions.stochastic.color
  5422. * ](#plotOptions.stochastic.color).
  5423. *
  5424. * @type {Highcharts.ColorString}
  5425. */
  5426. lineColor: void 0
  5427. }
  5428. },
  5429. dataGrouping: {
  5430. approximation: 'averages'
  5431. }
  5432. },
  5433. /**
  5434. * @lends Highcharts.Series#
  5435. */
  5436. H.merge(multipleLinesMixin, {
  5437. nameComponents: ['periods'],
  5438. nameBase: 'Stochastic',
  5439. pointArrayMap: ['y', 'smoothed'],
  5440. parallelArrays: ['x', 'y', 'smoothed'],
  5441. pointValKey: 'y',
  5442. linesApiNames: ['smoothedLine'],
  5443. init: function () {
  5444. SMA.prototype.init.apply(this, arguments);
  5445. // Set default color for lines:
  5446. this.options = merge({
  5447. smoothedLine: {
  5448. styles: {
  5449. lineColor: this.color
  5450. }
  5451. }
  5452. }, this.options);
  5453. },
  5454. getValues: function (series, params) {
  5455. var periodK = params.periods[0], periodD = params.periods[1], xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0,
  5456. // 0- date, 1-%K, 2-%D
  5457. SO = [], xData = [], yData = [], slicedY, close = 3, low = 2, high = 1, CL, HL, LL, K, D = null, points, extremes, i;
  5458. // Stochastic requires close value
  5459. if (yValLen < periodK ||
  5460. !isArray(yVal[0]) ||
  5461. yVal[0].length !== 4) {
  5462. return;
  5463. }
  5464. // For a N-period, we start from N-1 point, to calculate Nth point
  5465. // That is why we later need to comprehend slice() elements list
  5466. // with (+1)
  5467. for (i = periodK - 1; i < yValLen; i++) {
  5468. slicedY = yVal.slice(i - periodK + 1, i + 1);
  5469. // Calculate %K
  5470. extremes = getArrayExtremes(slicedY, low, high);
  5471. LL = extremes[0]; // Lowest low in %K periods
  5472. CL = yVal[i][close] - LL;
  5473. HL = extremes[1] - LL;
  5474. K = CL / HL * 100;
  5475. xData.push(xVal[i]);
  5476. yData.push([K, null]);
  5477. // Calculate smoothed %D, which is SMA of %K
  5478. if (i >= (periodK - 1) + (periodD - 1)) {
  5479. points = SMA.prototype.getValues.call(this, {
  5480. xData: xData.slice(-periodD),
  5481. yData: yData.slice(-periodD)
  5482. }, {
  5483. period: periodD
  5484. });
  5485. D = points.yData[0];
  5486. }
  5487. SO.push([xVal[i], K, D]);
  5488. yData[yData.length - 1][1] = D;
  5489. }
  5490. return {
  5491. values: SO,
  5492. xData: xData,
  5493. yData: yData
  5494. };
  5495. }
  5496. }));
  5497. /**
  5498. * A Stochastic indicator. If the [type](#series.stochastic.type) option is not
  5499. * specified, it is inherited from [chart.type](#chart.type).
  5500. *
  5501. * @extends series,plotOptions.stochastic
  5502. * @since 6.0.0
  5503. * @product highstock
  5504. * @excluding allAreas, colorAxis, dataParser, dataURL, joinBy, keys,
  5505. * navigatorOptions, pointInterval, pointIntervalUnit,
  5506. * pointPlacement, pointRange, pointStart, showInNavigator, stacking
  5507. * @requires stock/indicators/indicators
  5508. * @requires stock/indicators/stochastic
  5509. * @apioption series.stochastic
  5510. */
  5511. ''; // to include the above in the js output
  5512. });
  5513. _registerModule(_modules, 'indicators/slow-stochastic.src.js', [_modules['parts/Globals.js'], _modules['mixins/indicator-required.js']], function (H, requiredIndicator) {
  5514. /* *
  5515. *
  5516. * License: www.highcharts.com/license
  5517. *
  5518. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  5519. *
  5520. * */
  5521. var seriesTypes = H.seriesTypes;
  5522. /**
  5523. * The Slow Stochastic series type.
  5524. *
  5525. * @private
  5526. * @class
  5527. * @name Highcharts.seriesTypes.slowstochastic
  5528. *
  5529. * @augments Highcharts.Series
  5530. */
  5531. H.seriesType('slowstochastic', 'stochastic',
  5532. /**
  5533. * Slow Stochastic oscillator. This series requires the `linkedTo` option
  5534. * to be set and should be loaded after `stock/indicators/indicators.js`
  5535. * and `stock/indicators/stochastic.js` files.
  5536. *
  5537. * @sample stock/indicators/slow-stochastic
  5538. * Slow Stochastic oscillator
  5539. *
  5540. * @extends plotOptions.stochastic
  5541. * @since 8.0.0
  5542. * @product highstock
  5543. * @requires stock/indicators/indicators
  5544. * @requires stock/indicators/stochastic
  5545. * @requires stock/indicators/slowstochastic
  5546. * @optionparent plotOptions.slowstochastic
  5547. */
  5548. {
  5549. params: {
  5550. /**
  5551. * Periods for Slow Stochastic oscillator: [%K, %D, SMA(%D)].
  5552. *
  5553. * @type {Array<number,number,number>}
  5554. * @default [14, 3, 3]
  5555. */
  5556. periods: [14, 3, 3]
  5557. }
  5558. },
  5559. /**
  5560. * @lends Highcharts.Series#
  5561. */
  5562. {
  5563. nameBase: 'Slow Stochastic',
  5564. init: function () {
  5565. var args = arguments, ctx = this;
  5566. requiredIndicator.isParentLoaded(H.seriesTypes.stochastic, 'stochastic', ctx.type, function (indicator) {
  5567. indicator.prototype.init.apply(ctx, args);
  5568. return;
  5569. });
  5570. },
  5571. getValues: function (series, params) {
  5572. var periods = params.periods, fastValues = seriesTypes.stochastic.prototype.getValues.call(this, series, params), slowValues = {
  5573. values: [],
  5574. xData: [],
  5575. yData: []
  5576. };
  5577. var i = 0;
  5578. if (!fastValues) {
  5579. return;
  5580. }
  5581. slowValues.xData = fastValues.xData.slice(periods[1] - 1);
  5582. var fastYData = fastValues.yData.slice(periods[1] - 1);
  5583. // Get SMA(%D)
  5584. var smoothedValues = seriesTypes.sma.prototype.getValues.call(this, {
  5585. xData: slowValues.xData,
  5586. yData: fastYData
  5587. }, {
  5588. index: 1,
  5589. period: periods[2]
  5590. });
  5591. if (!smoothedValues) {
  5592. return;
  5593. }
  5594. var xDataLen = slowValues.xData.length;
  5595. // Format data
  5596. for (; i < xDataLen; i++) {
  5597. slowValues.yData[i] = [
  5598. fastYData[i][1],
  5599. smoothedValues.yData[i - periods[2] + 1] || null
  5600. ];
  5601. slowValues.values[i] = [
  5602. slowValues.xData[i],
  5603. fastYData[i][1],
  5604. smoothedValues.yData[i - periods[2] + 1] || null
  5605. ];
  5606. }
  5607. return slowValues;
  5608. }
  5609. });
  5610. /**
  5611. * A Slow Stochastic indicator. If the [type](#series.slowstochastic.type)
  5612. * option is not specified, it is inherited from [chart.type](#chart.type).
  5613. *
  5614. * @extends series,plotOptions.slowstochastic
  5615. * @since 8.0.0
  5616. * @product highstock
  5617. * @requires stock/indicators/indicators
  5618. * @requires stock/indicators/stochastic
  5619. * @requires stock/indicators/slowstochastic
  5620. * @apioption series.slowstochastic
  5621. */
  5622. ''; // to include the above in the js output
  5623. });
  5624. _registerModule(_modules, 'indicators/supertrend.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  5625. /* *
  5626. *
  5627. * License: www.highcharts.com/license
  5628. *
  5629. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  5630. *
  5631. * */
  5632. var correctFloat = U.correctFloat;
  5633. var isArray = U.isArray, objectEach = U.objectEach;
  5634. var ATR = H.seriesTypes.atr, SMA = H.seriesTypes.sma, merge = H.merge;
  5635. /* eslint-disable require-jsdoc */
  5636. // Utils:
  5637. function createPointObj(mainSeries, index, close) {
  5638. return {
  5639. index: index,
  5640. close: mainSeries.yData[index][close],
  5641. x: mainSeries.xData[index]
  5642. };
  5643. }
  5644. /* eslint-enable require-jsdoc */
  5645. /**
  5646. * The Supertrend series type.
  5647. *
  5648. * @private
  5649. * @class
  5650. * @name Highcharts.seriesTypes.supertrend
  5651. *
  5652. * @augments Highcharts.Series
  5653. */
  5654. H.seriesType('supertrend', 'sma',
  5655. /**
  5656. * Supertrend indicator. This series requires the `linkedTo` option to be
  5657. * set and should be loaded after the `stock/indicators/indicators.js` and
  5658. * `stock/indicators/sma.js`.
  5659. *
  5660. * @sample {highstock} stock/indicators/supertrend
  5661. * Supertrend indicator
  5662. *
  5663. * @extends plotOptions.sma
  5664. * @since 7.0.0
  5665. * @product highstock
  5666. * @excluding allAreas, cropThreshold, negativeColor, colorAxis, joinBy,
  5667. * keys, navigatorOptions, pointInterval, pointIntervalUnit,
  5668. * pointPlacement, pointRange, pointStart, showInNavigator,
  5669. * stacking, threshold
  5670. * @requires stock/indicators/indicators
  5671. * @requires stock/indicators/supertrend
  5672. * @optionparent plotOptions.supertrend
  5673. */
  5674. {
  5675. /**
  5676. * Paramters used in calculation of Supertrend indicator series points.
  5677. *
  5678. * @excluding index
  5679. */
  5680. params: {
  5681. /**
  5682. * Multiplier for Supertrend Indicator.
  5683. */
  5684. multiplier: 3,
  5685. /**
  5686. * The base period for indicator Supertrend Indicator calculations.
  5687. * This is the number of data points which are taken into account
  5688. * for the indicator calculations.
  5689. */
  5690. period: 10
  5691. },
  5692. /**
  5693. * Color of the Supertrend series line that is beneath the main series.
  5694. *
  5695. * @sample {highstock} stock/indicators/supertrend/
  5696. * Example with risingTrendColor
  5697. *
  5698. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  5699. */
  5700. risingTrendColor: '#06B535',
  5701. /**
  5702. * Color of the Supertrend series line that is above the main series.
  5703. *
  5704. * @sample {highstock} stock/indicators/supertrend/
  5705. * Example with fallingTrendColor
  5706. *
  5707. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  5708. */
  5709. fallingTrendColor: '#F21313',
  5710. /**
  5711. * The styles for the Supertrend line that intersect main series.
  5712. *
  5713. * @sample {highstock} stock/indicators/supertrend/
  5714. * Example with changeTrendLine
  5715. */
  5716. changeTrendLine: {
  5717. styles: {
  5718. /**
  5719. * Pixel width of the line.
  5720. */
  5721. lineWidth: 1,
  5722. /**
  5723. * Color of the line.
  5724. *
  5725. * @type {Highcharts.ColorString}
  5726. */
  5727. lineColor: '#333333',
  5728. /**
  5729. * The dash or dot style of the grid lines. For possible
  5730. * values, see
  5731. * [this demonstration](https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/plotoptions/series-dashstyle-all/).
  5732. *
  5733. * @sample {highcharts} highcharts/yaxis/gridlinedashstyle/
  5734. * Long dashes
  5735. * @sample {highstock} stock/xaxis/gridlinedashstyle/
  5736. * Long dashes
  5737. *
  5738. * @type {Highcharts.DashStyleValue}
  5739. * @since 7.0.0
  5740. */
  5741. dashStyle: 'LongDash'
  5742. }
  5743. }
  5744. },
  5745. /**
  5746. * @lends Highcharts.Series.prototype
  5747. */
  5748. {
  5749. nameBase: 'Supertrend',
  5750. nameComponents: ['multiplier', 'period'],
  5751. requiredIndicators: ['atr'],
  5752. init: function () {
  5753. var options, parentOptions;
  5754. SMA.prototype.init.apply(this, arguments);
  5755. options = this.options;
  5756. parentOptions = this.linkedParent.options;
  5757. // Indicator cropThreshold has to be equal linked series one
  5758. // reduced by period due to points comparison in drawGraph method
  5759. // (#9787)
  5760. options.cropThreshold = (parentOptions.cropThreshold -
  5761. (options.params.period - 1));
  5762. },
  5763. drawGraph: function () {
  5764. var indicator = this, indicOptions = indicator.options,
  5765. // Series that indicator is linked to
  5766. mainSeries = indicator.linkedParent, mainLinePoints = (mainSeries ? mainSeries.points : []), indicPoints = indicator.points, indicPath = indicator.graph, indicPointsLen = indicPoints.length,
  5767. // Points offset between lines
  5768. tempOffset = mainLinePoints.length - indicPointsLen, offset = tempOffset > 0 ? tempOffset : 0,
  5769. // @todo: fix when ichi-moku indicator is merged to master.
  5770. gappedExtend = {
  5771. options: {
  5772. gapSize: indicOptions.gapSize
  5773. }
  5774. },
  5775. // Sorted supertrend points array
  5776. groupedPoitns = {
  5777. top: [],
  5778. bottom: [],
  5779. intersect: [] // Change trend line points
  5780. },
  5781. // Options for trend lines
  5782. supertrendLineOptions = {
  5783. top: {
  5784. styles: {
  5785. lineWidth: indicOptions.lineWidth,
  5786. lineColor: (indicOptions.fallingTrendColor ||
  5787. indicOptions.color),
  5788. dashStyle: indicOptions.dashStyle
  5789. }
  5790. },
  5791. bottom: {
  5792. styles: {
  5793. lineWidth: indicOptions.lineWidth,
  5794. lineColor: (indicOptions.risingTrendColor ||
  5795. indicOptions.color),
  5796. dashStyle: indicOptions.dashStyle
  5797. }
  5798. },
  5799. intersect: indicOptions.changeTrendLine
  5800. }, close = 3,
  5801. // Supertrend line point
  5802. point,
  5803. // Supertrend line next point (has smaller x pos than point)
  5804. nextPoint,
  5805. // Main series points
  5806. mainPoint, nextMainPoint,
  5807. // Used when supertrend and main points are shifted
  5808. // relative to each other
  5809. prevMainPoint, prevPrevMainPoint,
  5810. // Used when particular point color is set
  5811. pointColor,
  5812. // Temporary points that fill groupedPoitns array
  5813. newPoint, newNextPoint;
  5814. // Loop which sort supertrend points
  5815. while (indicPointsLen--) {
  5816. point = indicPoints[indicPointsLen];
  5817. nextPoint = indicPoints[indicPointsLen - 1];
  5818. mainPoint = mainLinePoints[indicPointsLen - 1 + offset];
  5819. nextMainPoint = mainLinePoints[indicPointsLen - 2 + offset];
  5820. prevMainPoint = mainLinePoints[indicPointsLen + offset];
  5821. prevPrevMainPoint = mainLinePoints[indicPointsLen + offset + 1];
  5822. pointColor = point.options.color;
  5823. newPoint = {
  5824. x: point.x,
  5825. plotX: point.plotX,
  5826. plotY: point.plotY,
  5827. isNull: false
  5828. };
  5829. // When mainPoint is the last one (left plot area edge)
  5830. // but supertrend has additional one
  5831. if (!nextMainPoint &&
  5832. mainPoint && mainSeries.yData[mainPoint.index - 1]) {
  5833. nextMainPoint = createPointObj(mainSeries, mainPoint.index - 1, close);
  5834. }
  5835. // When prevMainPoint is the last one (right plot area edge)
  5836. // but supertrend has additional one (and points are shifted)
  5837. if (!prevPrevMainPoint &&
  5838. prevMainPoint && mainSeries.yData[prevMainPoint.index + 1]) {
  5839. prevPrevMainPoint = createPointObj(mainSeries, prevMainPoint.index + 1, close);
  5840. }
  5841. // When points are shifted (right or left plot area edge)
  5842. if (!mainPoint &&
  5843. nextMainPoint && mainSeries.yData[nextMainPoint.index + 1]) {
  5844. mainPoint = createPointObj(mainSeries, nextMainPoint.index + 1, close);
  5845. }
  5846. else if (!mainPoint &&
  5847. prevMainPoint && mainSeries.yData[prevMainPoint.index - 1]) {
  5848. mainPoint = createPointObj(mainSeries, prevMainPoint.index - 1, close);
  5849. }
  5850. // Check if points are shifted relative to each other
  5851. if (point &&
  5852. mainPoint &&
  5853. prevMainPoint &&
  5854. nextMainPoint &&
  5855. point.x !== mainPoint.x) {
  5856. if (point.x === prevMainPoint.x) {
  5857. nextMainPoint = mainPoint;
  5858. mainPoint = prevMainPoint;
  5859. }
  5860. else if (point.x === nextMainPoint.x) {
  5861. mainPoint = nextMainPoint;
  5862. nextMainPoint = {
  5863. close: mainSeries.yData[mainPoint.index - 1][close],
  5864. x: mainSeries.xData[mainPoint.index - 1]
  5865. };
  5866. }
  5867. else if (prevPrevMainPoint && point.x === prevPrevMainPoint.x) {
  5868. mainPoint = prevPrevMainPoint;
  5869. nextMainPoint = prevMainPoint;
  5870. }
  5871. }
  5872. if (nextPoint && nextMainPoint && mainPoint) {
  5873. newNextPoint = {
  5874. x: nextPoint.x,
  5875. plotX: nextPoint.plotX,
  5876. plotY: nextPoint.plotY,
  5877. isNull: false
  5878. };
  5879. if (point.y >= mainPoint.close &&
  5880. nextPoint.y >= nextMainPoint.close) {
  5881. point.color = (pointColor || indicOptions.fallingTrendColor ||
  5882. indicOptions.color);
  5883. groupedPoitns.top.push(newPoint);
  5884. }
  5885. else if (point.y < mainPoint.close &&
  5886. nextPoint.y < nextMainPoint.close) {
  5887. point.color = (pointColor || indicOptions.risingTrendColor ||
  5888. indicOptions.color);
  5889. groupedPoitns.bottom.push(newPoint);
  5890. }
  5891. else {
  5892. groupedPoitns.intersect.push(newPoint);
  5893. groupedPoitns.intersect.push(newNextPoint);
  5894. // Additional null point to make a gap in line
  5895. groupedPoitns.intersect.push(merge(newNextPoint, {
  5896. isNull: true
  5897. }));
  5898. if (point.y >= mainPoint.close &&
  5899. nextPoint.y < nextMainPoint.close) {
  5900. point.color = (pointColor || indicOptions.fallingTrendColor ||
  5901. indicOptions.color);
  5902. nextPoint.color = (pointColor || indicOptions.risingTrendColor ||
  5903. indicOptions.color);
  5904. groupedPoitns.top.push(newPoint);
  5905. groupedPoitns.top.push(merge(newNextPoint, {
  5906. isNull: true
  5907. }));
  5908. }
  5909. else if (point.y < mainPoint.close &&
  5910. nextPoint.y >= nextMainPoint.close) {
  5911. point.color = (pointColor || indicOptions.risingTrendColor ||
  5912. indicOptions.color);
  5913. nextPoint.color = (pointColor || indicOptions.fallingTrendColor ||
  5914. indicOptions.color);
  5915. groupedPoitns.bottom.push(newPoint);
  5916. groupedPoitns.bottom.push(merge(newNextPoint, {
  5917. isNull: true
  5918. }));
  5919. }
  5920. }
  5921. }
  5922. else if (mainPoint) {
  5923. if (point.y >= mainPoint.close) {
  5924. point.color = (pointColor || indicOptions.fallingTrendColor ||
  5925. indicOptions.color);
  5926. groupedPoitns.top.push(newPoint);
  5927. }
  5928. else {
  5929. point.color = (pointColor || indicOptions.risingTrendColor ||
  5930. indicOptions.color);
  5931. groupedPoitns.bottom.push(newPoint);
  5932. }
  5933. }
  5934. }
  5935. // Generate lines:
  5936. objectEach(groupedPoitns, function (values, lineName) {
  5937. indicator.points = values;
  5938. indicator.options = merge(supertrendLineOptions[lineName].styles, gappedExtend);
  5939. indicator.graph = indicator['graph' + lineName + 'Line'];
  5940. SMA.prototype.drawGraph.call(indicator);
  5941. // Now save line
  5942. indicator['graph' + lineName + 'Line'] = indicator.graph;
  5943. });
  5944. // Restore options:
  5945. indicator.points = indicPoints;
  5946. indicator.options = indicOptions;
  5947. indicator.graph = indicPath;
  5948. },
  5949. // Supertrend (Multiplier, Period) Formula:
  5950. // BASIC UPPERBAND = (HIGH + LOW) / 2 + Multiplier * ATR(Period)
  5951. // BASIC LOWERBAND = (HIGH + LOW) / 2 - Multiplier * ATR(Period)
  5952. // FINAL UPPERBAND =
  5953. // IF(
  5954. // Current BASICUPPERBAND < Previous FINAL UPPERBAND AND
  5955. // Previous Close > Previous FINAL UPPERBAND
  5956. // ) THEN (Current BASIC UPPERBAND)
  5957. // ELSE (Previous FINALUPPERBAND)
  5958. // FINAL LOWERBAND =
  5959. // IF(
  5960. // Current BASIC LOWERBAND > Previous FINAL LOWERBAND AND
  5961. // Previous Close < Previous FINAL LOWERBAND
  5962. // ) THEN (Current BASIC LOWERBAND)
  5963. // ELSE (Previous FINAL LOWERBAND)
  5964. // SUPERTREND =
  5965. // IF(
  5966. // Previous Supertrend == Previous FINAL UPPERBAND AND
  5967. // Current Close < Current FINAL UPPERBAND
  5968. // ) THAN Current FINAL UPPERBAND
  5969. // ELSE IF(
  5970. // Previous Supertrend == Previous FINAL LOWERBAND AND
  5971. // Current Close < Current FINAL LOWERBAND
  5972. // ) THAN Current FINAL UPPERBAND
  5973. // ELSE IF(
  5974. // Previous Supertrend == Previous FINAL UPPERBAND AND
  5975. // Current Close > Current FINAL UPPERBAND
  5976. // ) THAN Current FINAL LOWERBAND
  5977. // ELSE IF(
  5978. // Previous Supertrend == Previous FINAL LOWERBAND AND
  5979. // Current Close > Current FINAL LOWERBAND
  5980. // ) THAN Current FINAL LOWERBAND
  5981. getValues: function (series, params) {
  5982. var period = params.period, multiplier = params.multiplier, xVal = series.xData, yVal = series.yData, ATRData = [],
  5983. // 0- date, 1- Supertrend indicator
  5984. ST = [], xData = [], yData = [], close = 3, low = 2, high = 1, periodsOffset = (period === 0) ? 0 : period - 1, basicUp, basicDown, finalUp = [], finalDown = [], supertrend, prevFinalUp, prevFinalDown, prevST, // previous Supertrend
  5985. prevY, y, i;
  5986. if ((xVal.length <= period) || !isArray(yVal[0]) ||
  5987. yVal[0].length !== 4 || period < 0) {
  5988. return;
  5989. }
  5990. ATRData = ATR.prototype.getValues.call(this, series, {
  5991. period: period
  5992. }).yData;
  5993. for (i = 0; i < ATRData.length; i++) {
  5994. y = yVal[periodsOffset + i];
  5995. prevY = yVal[periodsOffset + i - 1] || [];
  5996. prevFinalUp = finalUp[i - 1];
  5997. prevFinalDown = finalDown[i - 1];
  5998. prevST = yData[i - 1];
  5999. if (i === 0) {
  6000. prevFinalUp = prevFinalDown = prevST = 0;
  6001. }
  6002. basicUp = correctFloat((y[high] + y[low]) / 2 + multiplier * ATRData[i]);
  6003. basicDown = correctFloat((y[high] + y[low]) / 2 - multiplier * ATRData[i]);
  6004. if ((basicUp < prevFinalUp) ||
  6005. (prevY[close] > prevFinalUp)) {
  6006. finalUp[i] = basicUp;
  6007. }
  6008. else {
  6009. finalUp[i] = prevFinalUp;
  6010. }
  6011. if ((basicDown > prevFinalDown) ||
  6012. (prevY[close] < prevFinalDown)) {
  6013. finalDown[i] = basicDown;
  6014. }
  6015. else {
  6016. finalDown[i] = prevFinalDown;
  6017. }
  6018. if (prevST === prevFinalUp && y[close] < finalUp[i] ||
  6019. prevST === prevFinalDown && y[close] < finalDown[i]) {
  6020. supertrend = finalUp[i];
  6021. }
  6022. else if (prevST === prevFinalUp && y[close] > finalUp[i] ||
  6023. prevST === prevFinalDown && y[close] > finalDown[i]) {
  6024. supertrend = finalDown[i];
  6025. }
  6026. ST.push([xVal[periodsOffset + i], supertrend]);
  6027. xData.push(xVal[periodsOffset + i]);
  6028. yData.push(supertrend);
  6029. }
  6030. return {
  6031. values: ST,
  6032. xData: xData,
  6033. yData: yData
  6034. };
  6035. }
  6036. });
  6037. /**
  6038. * A `Supertrend indicator` series. If the [type](#series.supertrend.type)
  6039. * option is not specified, it is inherited from [chart.type](#chart.type).
  6040. *
  6041. * @extends series,plotOptions.supertrend
  6042. * @since 7.0.0
  6043. * @product highstock
  6044. * @excluding allAreas, colorAxis, cropThreshold, data, dataParser, dataURL,
  6045. * joinBy, keys, navigatorOptions, negativeColor, pointInterval,
  6046. * pointIntervalUnit, pointPlacement, pointRange, pointStart,
  6047. * showInNavigator, stacking, threshold
  6048. * @requires stock/indicators/indicators
  6049. * @requires stock/indicators/supertrend
  6050. * @apioption series.supertrend
  6051. */
  6052. ''; // to include the above in the js output
  6053. });
  6054. _registerModule(_modules, 'indicators/volume-by-price.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  6055. /* *
  6056. *
  6057. * (c) 2010-2019 Paweł Dalek
  6058. *
  6059. * Volume By Price (VBP) indicator for Highstock
  6060. *
  6061. * License: www.highcharts.com/license
  6062. *
  6063. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6064. *
  6065. * */
  6066. var animObject = U.animObject, arrayMax = U.arrayMax, arrayMin = U.arrayMin, correctFloat = U.correctFloat, extend = U.extend, isArray = U.isArray;
  6067. /* eslint-disable require-jsdoc */
  6068. // Utils
  6069. function arrayExtremesOHLC(data) {
  6070. var dataLength = data.length, min = data[0][3], max = min, i = 1, currentPoint;
  6071. for (; i < dataLength; i++) {
  6072. currentPoint = data[i][3];
  6073. if (currentPoint < min) {
  6074. min = currentPoint;
  6075. }
  6076. if (currentPoint > max) {
  6077. max = currentPoint;
  6078. }
  6079. }
  6080. return {
  6081. min: min,
  6082. max: max
  6083. };
  6084. }
  6085. /* eslint-enable require-jsdoc */
  6086. var abs = Math.abs, noop = H.noop, addEvent = H.addEvent, seriesType = H.seriesType, columnPrototype = H.seriesTypes.column.prototype;
  6087. /**
  6088. * The Volume By Price (VBP) series type.
  6089. *
  6090. * @private
  6091. * @class
  6092. * @name Highcharts.seriesTypes.vbp
  6093. *
  6094. * @augments Highcharts.Series
  6095. */
  6096. seriesType('vbp', 'sma',
  6097. /**
  6098. * Volume By Price indicator.
  6099. *
  6100. * This series requires `linkedTo` option to be set.
  6101. *
  6102. * @sample stock/indicators/volume-by-price
  6103. * Volume By Price indicator
  6104. *
  6105. * @extends plotOptions.sma
  6106. * @since 6.0.0
  6107. * @product highstock
  6108. * @requires stock/indicators/indicators
  6109. * @requires stock/indicators/volume-by-price
  6110. * @optionparent plotOptions.vbp
  6111. */
  6112. {
  6113. /**
  6114. * @excluding index, period
  6115. */
  6116. params: {
  6117. /**
  6118. * The number of price zones.
  6119. */
  6120. ranges: 12,
  6121. /**
  6122. * The id of volume series which is mandatory. For example using
  6123. * OHLC data, volumeSeriesID='volume' means the indicator will be
  6124. * calculated using OHLC and volume values.
  6125. */
  6126. volumeSeriesID: 'volume'
  6127. },
  6128. /**
  6129. * The styles for lines which determine price zones.
  6130. */
  6131. zoneLines: {
  6132. /**
  6133. * Enable/disable zone lines.
  6134. */
  6135. enabled: true,
  6136. /**
  6137. * Specify the style of zone lines.
  6138. *
  6139. * @type {Highcharts.CSSObject}
  6140. * @default {"color": "#0A9AC9", "dashStyle": "LongDash", "lineWidth": 1}
  6141. */
  6142. styles: {
  6143. /** @ignore-options */
  6144. color: '#0A9AC9',
  6145. /** @ignore-options */
  6146. dashStyle: 'LongDash',
  6147. /** @ignore-options */
  6148. lineWidth: 1
  6149. }
  6150. },
  6151. /**
  6152. * The styles for bars when volume is divided into positive/negative.
  6153. */
  6154. volumeDivision: {
  6155. /**
  6156. * Option to control if volume is divided.
  6157. */
  6158. enabled: true,
  6159. styles: {
  6160. /**
  6161. * Color of positive volume bars.
  6162. *
  6163. * @type {Highcharts.ColorString}
  6164. */
  6165. positiveColor: 'rgba(144, 237, 125, 0.8)',
  6166. /**
  6167. * Color of negative volume bars.
  6168. *
  6169. * @type {Highcharts.ColorString}
  6170. */
  6171. negativeColor: 'rgba(244, 91, 91, 0.8)'
  6172. }
  6173. },
  6174. // To enable series animation; must be animationLimit > pointCount
  6175. animationLimit: 1000,
  6176. enableMouseTracking: false,
  6177. pointPadding: 0,
  6178. zIndex: -1,
  6179. crisp: true,
  6180. dataGrouping: {
  6181. enabled: false
  6182. },
  6183. dataLabels: {
  6184. allowOverlap: true,
  6185. enabled: true,
  6186. format: 'P: {point.volumePos:.2f} | N: {point.volumeNeg:.2f}',
  6187. padding: 0,
  6188. style: {
  6189. /** @internal */
  6190. fontSize: '7px'
  6191. },
  6192. verticalAlign: 'top'
  6193. }
  6194. },
  6195. /**
  6196. * @lends Highcharts.Series#
  6197. */
  6198. {
  6199. nameBase: 'Volume by Price',
  6200. bindTo: {
  6201. series: false,
  6202. eventName: 'afterSetExtremes'
  6203. },
  6204. calculateOn: 'render',
  6205. markerAttribs: noop,
  6206. drawGraph: noop,
  6207. getColumnMetrics: columnPrototype.getColumnMetrics,
  6208. crispCol: columnPrototype.crispCol,
  6209. init: function (chart) {
  6210. var indicator = this, params, baseSeries, volumeSeries;
  6211. H.seriesTypes.sma.prototype.init.apply(indicator, arguments);
  6212. params = indicator.options.params;
  6213. baseSeries = indicator.linkedParent;
  6214. volumeSeries = chart.get(params.volumeSeriesID);
  6215. indicator.addCustomEvents(baseSeries, volumeSeries);
  6216. return indicator;
  6217. },
  6218. // Adds events related with removing series
  6219. addCustomEvents: function (baseSeries, volumeSeries) {
  6220. var indicator = this;
  6221. /* eslint-disable require-jsdoc */
  6222. function toEmptyIndicator() {
  6223. indicator.chart.redraw();
  6224. indicator.setData([]);
  6225. indicator.zoneStarts = [];
  6226. if (indicator.zoneLinesSVG) {
  6227. indicator.zoneLinesSVG.destroy();
  6228. delete indicator.zoneLinesSVG;
  6229. }
  6230. }
  6231. /* eslint-enable require-jsdoc */
  6232. // If base series is deleted, indicator series data is filled with
  6233. // an empty array
  6234. indicator.dataEventsToUnbind.push(addEvent(baseSeries, 'remove', function () {
  6235. toEmptyIndicator();
  6236. }));
  6237. // If volume series is deleted, indicator series data is filled with
  6238. // an empty array
  6239. if (volumeSeries) {
  6240. indicator.dataEventsToUnbind.push(addEvent(volumeSeries, 'remove', function () {
  6241. toEmptyIndicator();
  6242. }));
  6243. }
  6244. return indicator;
  6245. },
  6246. // Initial animation
  6247. animate: function (init) {
  6248. var series = this, attr = {};
  6249. if (H.svg && !init) {
  6250. attr.translateX = series.yAxis.pos;
  6251. series.group.animate(attr, extend(animObject(series.options.animation), {
  6252. step: function (val, fx) {
  6253. series.group.attr({
  6254. scaleX: Math.max(0.001, fx.pos)
  6255. });
  6256. }
  6257. }));
  6258. // Delete this function to allow it only once
  6259. series.animate = null;
  6260. }
  6261. },
  6262. drawPoints: function () {
  6263. var indicator = this;
  6264. if (indicator.options.volumeDivision.enabled) {
  6265. indicator.posNegVolume(true, true);
  6266. columnPrototype.drawPoints.apply(indicator, arguments);
  6267. indicator.posNegVolume(false, false);
  6268. }
  6269. columnPrototype.drawPoints.apply(indicator, arguments);
  6270. },
  6271. // Function responsible for dividing volume into positive and negative
  6272. posNegVolume: function (initVol, pos) {
  6273. var indicator = this, signOrder = pos ?
  6274. ['positive', 'negative'] :
  6275. ['negative', 'positive'], volumeDivision = indicator.options.volumeDivision, pointLength = indicator.points.length, posWidths = [], negWidths = [], i = 0, pointWidth, priceZone, wholeVol, point;
  6276. if (initVol) {
  6277. indicator.posWidths = posWidths;
  6278. indicator.negWidths = negWidths;
  6279. }
  6280. else {
  6281. posWidths = indicator.posWidths;
  6282. negWidths = indicator.negWidths;
  6283. }
  6284. for (; i < pointLength; i++) {
  6285. point = indicator.points[i];
  6286. point[signOrder[0] + 'Graphic'] = point.graphic;
  6287. point.graphic = point[signOrder[1] + 'Graphic'];
  6288. if (initVol) {
  6289. pointWidth = point.shapeArgs.width;
  6290. priceZone = indicator.priceZones[i];
  6291. wholeVol = priceZone.wholeVolumeData;
  6292. if (wholeVol) {
  6293. posWidths.push(pointWidth / wholeVol * priceZone.positiveVolumeData);
  6294. negWidths.push(pointWidth / wholeVol * priceZone.negativeVolumeData);
  6295. }
  6296. else {
  6297. posWidths.push(0);
  6298. negWidths.push(0);
  6299. }
  6300. }
  6301. point.color = pos ?
  6302. volumeDivision.styles.positiveColor :
  6303. volumeDivision.styles.negativeColor;
  6304. point.shapeArgs.width = pos ?
  6305. indicator.posWidths[i] :
  6306. indicator.negWidths[i];
  6307. point.shapeArgs.x = pos ?
  6308. point.shapeArgs.x :
  6309. indicator.posWidths[i];
  6310. }
  6311. },
  6312. translate: function () {
  6313. var indicator = this, options = indicator.options, chart = indicator.chart, yAxis = indicator.yAxis, yAxisMin = yAxis.min, zoneLinesOptions = indicator.options.zoneLines, priceZones = (indicator.priceZones), yBarOffset = 0, indicatorPoints, volumeDataArray, maxVolume, primalBarWidth, barHeight, barHeightP, oldBarHeight, barWidth, pointPadding, chartPlotTop, barX, barY;
  6314. columnPrototype.translate.apply(indicator);
  6315. indicatorPoints = indicator.points;
  6316. // Do translate operation when points exist
  6317. if (indicatorPoints.length) {
  6318. pointPadding = options.pointPadding < 0.5 ?
  6319. options.pointPadding :
  6320. 0.1;
  6321. volumeDataArray = indicator.volumeDataArray;
  6322. maxVolume = arrayMax(volumeDataArray);
  6323. primalBarWidth = chart.plotWidth / 2;
  6324. chartPlotTop = chart.plotTop;
  6325. barHeight = abs(yAxis.toPixels(yAxisMin) -
  6326. yAxis.toPixels(yAxisMin + indicator.rangeStep));
  6327. oldBarHeight = abs(yAxis.toPixels(yAxisMin) -
  6328. yAxis.toPixels(yAxisMin + indicator.rangeStep));
  6329. if (pointPadding) {
  6330. barHeightP = abs(barHeight * (1 - 2 * pointPadding));
  6331. yBarOffset = abs((barHeight - barHeightP) / 2);
  6332. barHeight = abs(barHeightP);
  6333. }
  6334. indicatorPoints.forEach(function (point, index) {
  6335. barX = point.barX = point.plotX = 0;
  6336. barY = point.plotY = (yAxis.toPixels(priceZones[index].start) -
  6337. chartPlotTop -
  6338. (yAxis.reversed ?
  6339. (barHeight - oldBarHeight) :
  6340. barHeight) -
  6341. yBarOffset);
  6342. barWidth = correctFloat(primalBarWidth *
  6343. priceZones[index].wholeVolumeData / maxVolume);
  6344. point.pointWidth = barWidth;
  6345. point.shapeArgs = indicator.crispCol.apply(// eslint-disable-line no-useless-call
  6346. indicator, [barX, barY, barWidth, barHeight]);
  6347. point.volumeNeg = priceZones[index].negativeVolumeData;
  6348. point.volumePos = priceZones[index].positiveVolumeData;
  6349. point.volumeAll = priceZones[index].wholeVolumeData;
  6350. });
  6351. if (zoneLinesOptions.enabled) {
  6352. indicator.drawZones(chart, yAxis, indicator.zoneStarts, zoneLinesOptions.styles);
  6353. }
  6354. }
  6355. },
  6356. getValues: function (series, params) {
  6357. var indicator = this, xValues = series.processedXData, yValues = series.processedYData, chart = indicator.chart, ranges = params.ranges, VBP = [], xData = [], yData = [], isOHLC, volumeSeries, priceZones;
  6358. // Checks if base series exists
  6359. if (!series.chart) {
  6360. H.error('Base series not found! In case it has been removed, add ' +
  6361. 'a new one.', true, chart);
  6362. return;
  6363. }
  6364. // Checks if volume series exists
  6365. if (!(volumeSeries = (chart.get(params.volumeSeriesID)))) {
  6366. H.error('Series ' +
  6367. params.volumeSeriesID +
  6368. ' not found! Check `volumeSeriesID`.', true, chart);
  6369. return;
  6370. }
  6371. // Checks if series data fits the OHLC format
  6372. isOHLC = isArray(yValues[0]);
  6373. if (isOHLC && yValues[0].length !== 4) {
  6374. H.error('Type of ' +
  6375. series.name +
  6376. ' series is different than line, OHLC or candlestick.', true, chart);
  6377. return;
  6378. }
  6379. // Price zones contains all the information about the zones (index,
  6380. // start, end, volumes, etc.)
  6381. priceZones = indicator.priceZones = indicator.specifyZones(isOHLC, xValues, yValues, ranges, volumeSeries);
  6382. priceZones.forEach(function (zone, index) {
  6383. VBP.push([zone.x, zone.end]);
  6384. xData.push(VBP[index][0]);
  6385. yData.push(VBP[index][1]);
  6386. });
  6387. return {
  6388. values: VBP,
  6389. xData: xData,
  6390. yData: yData
  6391. };
  6392. },
  6393. // Specifing where each zone should start ans end
  6394. specifyZones: function (isOHLC, xValues, yValues, ranges, volumeSeries) {
  6395. var indicator = this, rangeExtremes = (isOHLC ? arrayExtremesOHLC(yValues) : false), lowRange = rangeExtremes ?
  6396. rangeExtremes.min :
  6397. arrayMin(yValues), highRange = rangeExtremes ?
  6398. rangeExtremes.max :
  6399. arrayMax(yValues), zoneStarts = indicator.zoneStarts = [], priceZones = [], i = 0, j = 1, rangeStep, zoneStartsLength;
  6400. if (!lowRange || !highRange) {
  6401. if (this.points.length) {
  6402. this.setData([]);
  6403. this.zoneStarts = [];
  6404. this.zoneLinesSVG.destroy();
  6405. }
  6406. return [];
  6407. }
  6408. rangeStep = indicator.rangeStep =
  6409. correctFloat(highRange - lowRange) / ranges;
  6410. zoneStarts.push(lowRange);
  6411. for (; i < ranges - 1; i++) {
  6412. zoneStarts.push(correctFloat(zoneStarts[i] + rangeStep));
  6413. }
  6414. zoneStarts.push(highRange);
  6415. zoneStartsLength = zoneStarts.length;
  6416. // Creating zones
  6417. for (; j < zoneStartsLength; j++) {
  6418. priceZones.push({
  6419. index: j - 1,
  6420. x: xValues[0],
  6421. start: zoneStarts[j - 1],
  6422. end: zoneStarts[j]
  6423. });
  6424. }
  6425. return indicator.volumePerZone(isOHLC, priceZones, volumeSeries, xValues, yValues);
  6426. },
  6427. // Calculating sum of volume values for a specific zone
  6428. volumePerZone: function (isOHLC, priceZones, volumeSeries, xValues, yValues) {
  6429. var indicator = this, volumeXData = volumeSeries.processedXData, volumeYData = volumeSeries.processedYData, lastZoneIndex = priceZones.length - 1, baseSeriesLength = yValues.length, volumeSeriesLength = volumeYData.length, previousValue, startFlag, endFlag, value, i;
  6430. // Checks if each point has a corresponding volume value
  6431. if (abs(baseSeriesLength - volumeSeriesLength)) {
  6432. // If the first point don't have volume, add 0 value at the
  6433. // beggining of the volume array
  6434. if (xValues[0] !== volumeXData[0]) {
  6435. volumeYData.unshift(0);
  6436. }
  6437. // If the last point don't have volume, add 0 value at the end
  6438. // of the volume array
  6439. if (xValues[baseSeriesLength - 1] !==
  6440. volumeXData[volumeSeriesLength - 1]) {
  6441. volumeYData.push(0);
  6442. }
  6443. }
  6444. indicator.volumeDataArray = [];
  6445. priceZones.forEach(function (zone) {
  6446. zone.wholeVolumeData = 0;
  6447. zone.positiveVolumeData = 0;
  6448. zone.negativeVolumeData = 0;
  6449. for (i = 0; i < baseSeriesLength; i++) {
  6450. startFlag = false;
  6451. endFlag = false;
  6452. value = isOHLC ? yValues[i][3] : yValues[i];
  6453. previousValue = i ?
  6454. (isOHLC ?
  6455. yValues[i - 1][3] :
  6456. yValues[i - 1]) :
  6457. value;
  6458. // Checks if this is the point with the
  6459. // lowest close value and if so, adds it calculations
  6460. if (value <= zone.start && zone.index === 0) {
  6461. startFlag = true;
  6462. }
  6463. // Checks if this is the point with the highest
  6464. // close value and if so, adds it calculations
  6465. if (value >= zone.end && zone.index === lastZoneIndex) {
  6466. endFlag = true;
  6467. }
  6468. if ((value > zone.start || startFlag) &&
  6469. (value < zone.end || endFlag)) {
  6470. zone.wholeVolumeData += volumeYData[i];
  6471. if (previousValue > value) {
  6472. zone.negativeVolumeData += volumeYData[i];
  6473. }
  6474. else {
  6475. zone.positiveVolumeData += volumeYData[i];
  6476. }
  6477. }
  6478. }
  6479. indicator.volumeDataArray.push(zone.wholeVolumeData);
  6480. });
  6481. return priceZones;
  6482. },
  6483. // Function responsoble for drawing additional lines indicating zones
  6484. drawZones: function (chart, yAxis, zonesValues, zonesStyles) {
  6485. var indicator = this, renderer = chart.renderer, zoneLinesSVG = indicator.zoneLinesSVG, zoneLinesPath = [], leftLinePos = 0, rightLinePos = chart.plotWidth, verticalOffset = chart.plotTop, verticalLinePos;
  6486. zonesValues.forEach(function (value) {
  6487. verticalLinePos = yAxis.toPixels(value) - verticalOffset;
  6488. zoneLinesPath = zoneLinesPath.concat(chart.renderer.crispLine([
  6489. 'M',
  6490. leftLinePos,
  6491. verticalLinePos,
  6492. 'L',
  6493. rightLinePos,
  6494. verticalLinePos
  6495. ], zonesStyles.lineWidth));
  6496. });
  6497. // Create zone lines one path or update it while animating
  6498. if (zoneLinesSVG) {
  6499. zoneLinesSVG.animate({
  6500. d: zoneLinesPath
  6501. });
  6502. }
  6503. else {
  6504. zoneLinesSVG = indicator.zoneLinesSVG =
  6505. renderer.path(zoneLinesPath).attr({
  6506. 'stroke-width': zonesStyles.lineWidth,
  6507. 'stroke': zonesStyles.color,
  6508. 'dashstyle': zonesStyles.dashStyle,
  6509. 'zIndex': indicator.group.zIndex + 0.1
  6510. })
  6511. .add(indicator.group);
  6512. }
  6513. }
  6514. },
  6515. /**
  6516. * @lends Highcharts.Point#
  6517. */
  6518. {
  6519. // Required for destroying negative part of volume
  6520. destroy: function () {
  6521. // @todo: this.negativeGraphic doesn't seem to be used anywhere
  6522. if (this.negativeGraphic) {
  6523. this.negativeGraphic = this.negativeGraphic.destroy();
  6524. }
  6525. return H.Point.prototype.destroy.apply(this, arguments);
  6526. }
  6527. });
  6528. /**
  6529. * A `Volume By Price (VBP)` series. If the [type](#series.vbp.type) option is
  6530. * not specified, it is inherited from [chart.type](#chart.type).
  6531. *
  6532. * @extends series,plotOptions.vbp
  6533. * @since 6.0.0
  6534. * @product highstock
  6535. * @excluding dataParser, dataURL
  6536. * @requires stock/indicators/indicators
  6537. * @requires stock/indicators/volume-by-price
  6538. * @apioption series.vbp
  6539. */
  6540. ''; // to include the above in the js output
  6541. });
  6542. _registerModule(_modules, 'indicators/vwap.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  6543. /* *
  6544. *
  6545. * (c) 2010-2019 Paweł Dalek
  6546. *
  6547. * Volume Weighted Average Price (VWAP) indicator for Highstock
  6548. *
  6549. * License: www.highcharts.com/license
  6550. *
  6551. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6552. *
  6553. * */
  6554. var isArray = U.isArray;
  6555. var seriesType = H.seriesType;
  6556. /**
  6557. * The Volume Weighted Average Price (VWAP) series type.
  6558. *
  6559. * @private
  6560. * @class
  6561. * @name Highcharts.seriesTypes.vwap
  6562. *
  6563. * @augments Highcharts.Series
  6564. */
  6565. seriesType('vwap', 'sma',
  6566. /**
  6567. * Volume Weighted Average Price indicator.
  6568. *
  6569. * This series requires `linkedTo` option to be set.
  6570. *
  6571. * @sample stock/indicators/vwap
  6572. * Volume Weighted Average Price indicator
  6573. *
  6574. * @extends plotOptions.sma
  6575. * @since 6.0.0
  6576. * @product highstock
  6577. * @requires stock/indicators/indicators
  6578. * @requires stock/indicators/vwap
  6579. * @optionparent plotOptions.vwap
  6580. */
  6581. {
  6582. /**
  6583. * @excluding index
  6584. */
  6585. params: {
  6586. period: 30,
  6587. /**
  6588. * The id of volume series which is mandatory. For example using
  6589. * OHLC data, volumeSeriesID='volume' means the indicator will be
  6590. * calculated using OHLC and volume values.
  6591. */
  6592. volumeSeriesID: 'volume'
  6593. }
  6594. },
  6595. /**
  6596. * @lends Highcharts.Series#
  6597. */
  6598. {
  6599. /**
  6600. * Returns the final values of the indicator ready to be presented on a
  6601. * chart
  6602. * @private
  6603. * @param {Highcharts.VWAPIndicator} this indicator
  6604. * @param {Highcharts.Series} series - series for indicator
  6605. * @param {object} params - params
  6606. * @return {object} - computed VWAP
  6607. **/
  6608. getValues: function (series, params) {
  6609. var indicator = this, chart = series.chart, xValues = series.xData, yValues = series.yData, period = params.period, isOHLC = true, volumeSeries;
  6610. // Checks if volume series exists
  6611. if (!(volumeSeries = (chart.get(params.volumeSeriesID)))) {
  6612. H.error('Series ' +
  6613. params.volumeSeriesID +
  6614. ' not found! Check `volumeSeriesID`.', true, chart);
  6615. return;
  6616. }
  6617. // Checks if series data fits the OHLC format
  6618. if (!(isArray(yValues[0]))) {
  6619. isOHLC = false;
  6620. }
  6621. return indicator.calculateVWAPValues(isOHLC, xValues, yValues, volumeSeries, period);
  6622. },
  6623. /**
  6624. * Main algorithm used to calculate Volume Weighted Average Price (VWAP)
  6625. * values
  6626. * @private
  6627. * @param {boolean} isOHLC - says if data has OHLC format
  6628. * @param {Array<number>} xValues - array of timestamps
  6629. * @param {Array<number|Array<number,number,number,number>>} yValues -
  6630. * array of yValues, can be an array of a four arrays (OHLC) or array of
  6631. * values (line)
  6632. * @param {Array<*>} volumeSeries - volume series
  6633. * @param {number} period - number of points to be calculated
  6634. * @return {object} - Object contains computed VWAP
  6635. **/
  6636. calculateVWAPValues: function (isOHLC, xValues, yValues, volumeSeries, period) {
  6637. var volumeValues = volumeSeries.yData, volumeLength = volumeSeries.xData.length, pointsLength = xValues.length, cumulativePrice = [], cumulativeVolume = [], xData = [], yData = [], VWAP = [], commonLength, typicalPrice, cPrice, cVolume, i, j;
  6638. if (pointsLength <= volumeLength) {
  6639. commonLength = pointsLength;
  6640. }
  6641. else {
  6642. commonLength = volumeLength;
  6643. }
  6644. for (i = 0, j = 0; i < commonLength; i++) {
  6645. // Depending on whether series is OHLC or line type, price is
  6646. // average of the high, low and close or a simple value
  6647. typicalPrice = isOHLC ?
  6648. ((yValues[i][1] + yValues[i][2] +
  6649. yValues[i][3]) / 3) :
  6650. yValues[i];
  6651. typicalPrice *= volumeValues[i];
  6652. cPrice = j ?
  6653. (cumulativePrice[i - 1] + typicalPrice) :
  6654. typicalPrice;
  6655. cVolume = j ?
  6656. (cumulativeVolume[i - 1] + volumeValues[i]) :
  6657. volumeValues[i];
  6658. cumulativePrice.push(cPrice);
  6659. cumulativeVolume.push(cVolume);
  6660. VWAP.push([xValues[i], (cPrice / cVolume)]);
  6661. xData.push(VWAP[i][0]);
  6662. yData.push(VWAP[i][1]);
  6663. j++;
  6664. if (j === period) {
  6665. j = 0;
  6666. }
  6667. }
  6668. return {
  6669. values: VWAP,
  6670. xData: xData,
  6671. yData: yData
  6672. };
  6673. }
  6674. });
  6675. /**
  6676. * A `Volume Weighted Average Price (VWAP)` series. If the
  6677. * [type](#series.vwap.type) option is not specified, it is inherited from
  6678. * [chart.type](#chart.type).
  6679. *
  6680. * @extends series,plotOptions.vwap
  6681. * @since 6.0.0
  6682. * @product highstock
  6683. * @excluding dataParser, dataURL
  6684. * @requires stock/indicators/indicators
  6685. * @requires stock/indicators/vwap
  6686. * @apioption series.vwap
  6687. */
  6688. ''; // to include the above in the js output
  6689. });
  6690. _registerModule(_modules, 'indicators/williams-r.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['mixins/reduce-array.js']], function (H, U, reduceArrayMixin) {
  6691. /* *
  6692. *
  6693. * License: www.highcharts.com/license
  6694. *
  6695. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6696. *
  6697. * */
  6698. var isArray = U.isArray;
  6699. var getArrayExtremes = reduceArrayMixin.getArrayExtremes;
  6700. /**
  6701. * The Williams %R series type.
  6702. *
  6703. * @private
  6704. * @class
  6705. * @name Highcharts.seriesTypes.williamsr
  6706. *
  6707. * @augments Highcharts.Series
  6708. */
  6709. H.seriesType('williamsr', 'sma',
  6710. /**
  6711. * Williams %R. This series requires the `linkedTo` option to be
  6712. * set and should be loaded after the `stock/indicators/indicators.js`.
  6713. *
  6714. * @sample {highstock} stock/indicators/williams-r
  6715. * Williams %R
  6716. *
  6717. * @extends plotOptions.sma
  6718. * @since 7.0.0
  6719. * @product highstock
  6720. * @excluding allAreas, colorAxis, joinBy, keys, navigatorOptions,
  6721. * pointInterval, pointIntervalUnit, pointPlacement,
  6722. * pointRange, pointStart, showInNavigator, stacking
  6723. * @requires stock/indicators/indicators
  6724. * @requires stock/indicators/williams-r
  6725. * @optionparent plotOptions.williamsr
  6726. */
  6727. {
  6728. /**
  6729. * Paramters used in calculation of Williams %R series points.
  6730. * @excluding index
  6731. */
  6732. params: {
  6733. /**
  6734. * Period for Williams %R oscillator
  6735. */
  6736. period: 14
  6737. }
  6738. },
  6739. /**
  6740. * @lends Highcharts.Series#
  6741. */
  6742. {
  6743. nameBase: 'Williams %R',
  6744. getValues: function (series, params) {
  6745. var period = params.period, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0, WR = [], // 0- date, 1- Williams %R
  6746. xData = [], yData = [], slicedY, close = 3, low = 2, high = 1, extremes, R, HH, // Highest high value in period
  6747. LL, // Lowest low value in period
  6748. CC, // Current close value
  6749. i;
  6750. // Williams %R requires close value
  6751. if (xVal.length < period ||
  6752. !isArray(yVal[0]) ||
  6753. yVal[0].length !== 4) {
  6754. return;
  6755. }
  6756. // For a N-period, we start from N-1 point, to calculate Nth point
  6757. // That is why we later need to comprehend slice() elements list
  6758. // with (+1)
  6759. for (i = period - 1; i < yValLen; i++) {
  6760. slicedY = yVal.slice(i - period + 1, i + 1);
  6761. extremes = getArrayExtremes(slicedY, low, high);
  6762. LL = extremes[0];
  6763. HH = extremes[1];
  6764. CC = yVal[i][close];
  6765. R = ((HH - CC) / (HH - LL)) * -100;
  6766. if (xVal[i]) {
  6767. WR.push([xVal[i], R]);
  6768. xData.push(xVal[i]);
  6769. yData.push(R);
  6770. }
  6771. }
  6772. return {
  6773. values: WR,
  6774. xData: xData,
  6775. yData: yData
  6776. };
  6777. }
  6778. });
  6779. /**
  6780. * A `Williams %R Oscillator` series. If the [type](#series.williamsr.type)
  6781. * option is not specified, it is inherited from [chart.type](#chart.type).
  6782. *
  6783. * @extends series,plotOptions.williamsr
  6784. * @since 7.0.0
  6785. * @product highstock
  6786. * @excluding allAreas, colorAxis, dataParser, dataURL, joinBy, keys,
  6787. * navigatorOptions, pointInterval, pointIntervalUnit,
  6788. * pointPlacement, pointRange, pointStart, showInNavigator, stacking
  6789. * @requires stock/indicators/indicators
  6790. * @requires stock/indicators/williams-r
  6791. * @apioption series.williamsr
  6792. */
  6793. ''; // adds doclets above to the transpiled file
  6794. });
  6795. _registerModule(_modules, 'indicators/wma.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  6796. /* *
  6797. *
  6798. * (c) 2010-2019 Kacper Madej
  6799. *
  6800. * License: www.highcharts.com/license
  6801. *
  6802. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6803. *
  6804. * */
  6805. var isArray = U.isArray;
  6806. var seriesType = H.seriesType;
  6807. /* eslint-disable valid-jsdoc */
  6808. // Utils:
  6809. /**
  6810. * @private
  6811. */
  6812. function accumulateAverage(points, xVal, yVal, i, index) {
  6813. var xValue = xVal[i], yValue = index < 0 ? yVal[i] : yVal[i][index];
  6814. points.push([xValue, yValue]);
  6815. }
  6816. /**
  6817. * @private
  6818. */
  6819. function weightedSumArray(array, pLen) {
  6820. // The denominator is the sum of the number of days as a triangular number.
  6821. // If there are 5 days, the triangular numbers are 5, 4, 3, 2, and 1.
  6822. // The sum is 5 + 4 + 3 + 2 + 1 = 15.
  6823. var denominator = (pLen + 1) / 2 * pLen;
  6824. // reduce VS loop => reduce
  6825. return array.reduce(function (prev, cur, i) {
  6826. return [null, prev[1] + cur[1] * (i + 1)];
  6827. })[1] / denominator;
  6828. }
  6829. /**
  6830. * @private
  6831. */
  6832. function populateAverage(points, xVal, yVal, i) {
  6833. var pLen = points.length, wmaY = weightedSumArray(points, pLen), wmaX = xVal[i - 1];
  6834. points.shift(); // remove point until range < period
  6835. return [wmaX, wmaY];
  6836. }
  6837. /* eslint-enable valid-jsdoc */
  6838. /**
  6839. * The SMA series type.
  6840. *
  6841. * @private
  6842. * @class
  6843. * @name Highcharts.seriesTypes.wma
  6844. *
  6845. * @augments Highcharts.Series
  6846. */
  6847. seriesType('wma', 'sma',
  6848. /**
  6849. * Weighted moving average indicator (WMA). This series requires `linkedTo`
  6850. * option to be set.
  6851. *
  6852. * @sample stock/indicators/wma
  6853. * Weighted moving average indicator
  6854. *
  6855. * @extends plotOptions.sma
  6856. * @since 6.0.0
  6857. * @product highstock
  6858. * @requires stock/indicators/indicators
  6859. * @requires stock/indicators/wma
  6860. * @optionparent plotOptions.wma
  6861. */
  6862. {
  6863. params: {
  6864. index: 3,
  6865. period: 9
  6866. }
  6867. },
  6868. /**
  6869. * @lends Highcharts.Series#
  6870. */
  6871. {
  6872. getValues: function (series, params) {
  6873. var period = params.period, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0, range = 1, xValue = xVal[0], yValue = yVal[0], WMA = [], xData = [], yData = [], index = -1, i, points, WMAPoint;
  6874. if (xVal.length < period) {
  6875. return;
  6876. }
  6877. // Switch index for OHLC / Candlestick
  6878. if (isArray(yVal[0])) {
  6879. index = params.index;
  6880. yValue = yVal[0][index];
  6881. }
  6882. // Starting point
  6883. points = [[xValue, yValue]];
  6884. // Accumulate first N-points
  6885. while (range !== period) {
  6886. accumulateAverage(points, xVal, yVal, range, index);
  6887. range++;
  6888. }
  6889. // Calculate value one-by-one for each period in visible data
  6890. for (i = range; i < yValLen; i++) {
  6891. WMAPoint = populateAverage(points, xVal, yVal, i);
  6892. WMA.push(WMAPoint);
  6893. xData.push(WMAPoint[0]);
  6894. yData.push(WMAPoint[1]);
  6895. accumulateAverage(points, xVal, yVal, i, index);
  6896. }
  6897. WMAPoint = populateAverage(points, xVal, yVal, i);
  6898. WMA.push(WMAPoint);
  6899. xData.push(WMAPoint[0]);
  6900. yData.push(WMAPoint[1]);
  6901. return {
  6902. values: WMA,
  6903. xData: xData,
  6904. yData: yData
  6905. };
  6906. }
  6907. });
  6908. /**
  6909. * A `WMA` series. If the [type](#series.wma.type) option is not specified, it
  6910. * is inherited from [chart.type](#chart.type).
  6911. *
  6912. * @extends series,plotOptions.wma
  6913. * @since 6.0.0
  6914. * @product highstock
  6915. * @excluding dataParser, dataURL
  6916. * @requires stock/indicators/indicators
  6917. * @requires stock/indicators/wma
  6918. * @apioption series.wma
  6919. */
  6920. ''; // adds doclet above to the transpiled file
  6921. });
  6922. _registerModule(_modules, 'indicators/zigzag.src.js', [_modules['parts/Globals.js']], function (H) {
  6923. /* *
  6924. *
  6925. * (c) 2010-2019 Kacper Madej
  6926. *
  6927. * License: www.highcharts.com/license
  6928. *
  6929. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6930. *
  6931. * */
  6932. var seriesType = H.seriesType, UNDEFINED;
  6933. /**
  6934. * The Zig Zag series type.
  6935. *
  6936. * @private
  6937. * @class
  6938. * @name Highcharts.seriesTypes.zigzag
  6939. *
  6940. * @augments Highcharts.Series
  6941. */
  6942. seriesType('zigzag', 'sma',
  6943. /**
  6944. * Zig Zag indicator.
  6945. *
  6946. * This series requires `linkedTo` option to be set.
  6947. *
  6948. * @sample stock/indicators/zigzag
  6949. * Zig Zag indicator
  6950. *
  6951. * @extends plotOptions.sma
  6952. * @since 6.0.0
  6953. * @product highstock
  6954. * @requires stock/indicators/indicators
  6955. * @requires stock/indicators/zigzag
  6956. * @optionparent plotOptions.zigzag
  6957. */
  6958. {
  6959. /**
  6960. * @excluding index, period
  6961. */
  6962. params: {
  6963. /**
  6964. * The point index which indicator calculations will base - low
  6965. * value.
  6966. *
  6967. * For example using OHLC data, index=2 means the indicator will be
  6968. * calculated using Low values.
  6969. */
  6970. lowIndex: 2,
  6971. /**
  6972. * The point index which indicator calculations will base - high
  6973. * value.
  6974. *
  6975. * For example using OHLC data, index=1 means the indicator will be
  6976. * calculated using High values.
  6977. */
  6978. highIndex: 1,
  6979. /**
  6980. * The threshold for the value change.
  6981. *
  6982. * For example deviation=1 means the indicator will ignore all price
  6983. * movements less than 1%.
  6984. */
  6985. deviation: 1
  6986. }
  6987. },
  6988. /**
  6989. * @lends Highcharts.Series#
  6990. */
  6991. {
  6992. nameComponents: ['deviation'],
  6993. nameSuffixes: ['%'],
  6994. nameBase: 'Zig Zag',
  6995. getValues: function (series, params) {
  6996. var lowIndex = params.lowIndex, highIndex = params.highIndex, deviation = params.deviation / 100, deviations = {
  6997. 'low': 1 + deviation,
  6998. 'high': 1 - deviation
  6999. }, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0, zigzag = [], xData = [], yData = [], i, j, zigzagPoint, firstZigzagLow, firstZigzagHigh, directionUp, zigzagLen, exitLoop = false, yIndex = false;
  7000. // Exit if not enught points or no low or high values
  7001. if (!xVal || xVal.length <= 1 ||
  7002. (yValLen &&
  7003. (yVal[0][lowIndex] === UNDEFINED ||
  7004. yVal[0][highIndex] === UNDEFINED))) {
  7005. return;
  7006. }
  7007. // Set first zigzag point candidate
  7008. firstZigzagLow = yVal[0][lowIndex];
  7009. firstZigzagHigh = yVal[0][highIndex];
  7010. // Search for a second zigzag point candidate,
  7011. // this will also set first zigzag point
  7012. for (i = 1; i < yValLen; i++) {
  7013. // requried change to go down
  7014. if (yVal[i][lowIndex] <= firstZigzagHigh * deviations.high) {
  7015. zigzag.push([xVal[0], firstZigzagHigh]);
  7016. // second zigzag point candidate
  7017. zigzagPoint = [xVal[i], yVal[i][lowIndex]];
  7018. // next line will be going up
  7019. directionUp = true;
  7020. exitLoop = true;
  7021. // requried change to go up
  7022. }
  7023. else if (yVal[i][highIndex] >= firstZigzagLow * deviations.low) {
  7024. zigzag.push([xVal[0], firstZigzagLow]);
  7025. // second zigzag point candidate
  7026. zigzagPoint = [xVal[i], yVal[i][highIndex]];
  7027. // next line will be going down
  7028. directionUp = false;
  7029. exitLoop = true;
  7030. }
  7031. if (exitLoop) {
  7032. xData.push(zigzag[0][0]);
  7033. yData.push(zigzag[0][1]);
  7034. j = i++;
  7035. i = yValLen;
  7036. }
  7037. }
  7038. // Search for next zigzags
  7039. for (i = j; i < yValLen; i++) {
  7040. if (directionUp) { // next line up
  7041. // lower when going down -> change zigzag candidate
  7042. if (yVal[i][lowIndex] <= zigzagPoint[1]) {
  7043. zigzagPoint = [xVal[i], yVal[i][lowIndex]];
  7044. }
  7045. // requried change to go down -> new zigzagpoint and
  7046. // direction change
  7047. if (yVal[i][highIndex] >=
  7048. zigzagPoint[1] * deviations.low) {
  7049. yIndex = highIndex;
  7050. }
  7051. }
  7052. else { // next line down
  7053. // higher when going up -> change zigzag candidate
  7054. if (yVal[i][highIndex] >= zigzagPoint[1]) {
  7055. zigzagPoint = [xVal[i], yVal[i][highIndex]];
  7056. }
  7057. // requried change to go down -> new zigzagpoint and
  7058. // direction change
  7059. if (yVal[i][lowIndex] <=
  7060. zigzagPoint[1] * deviations.high) {
  7061. yIndex = lowIndex;
  7062. }
  7063. }
  7064. if (yIndex !== false) { // new zigzag point and direction change
  7065. zigzag.push(zigzagPoint);
  7066. xData.push(zigzagPoint[0]);
  7067. yData.push(zigzagPoint[1]);
  7068. zigzagPoint = [xVal[i], yVal[i][yIndex]];
  7069. directionUp = !directionUp;
  7070. yIndex = false;
  7071. }
  7072. }
  7073. zigzagLen = zigzag.length;
  7074. // no zigzag for last point
  7075. if (zigzagLen !== 0 &&
  7076. zigzag[zigzagLen - 1][0] < xVal[yValLen - 1]) {
  7077. // set last point from zigzag candidate
  7078. zigzag.push(zigzagPoint);
  7079. xData.push(zigzagPoint[0]);
  7080. yData.push(zigzagPoint[1]);
  7081. }
  7082. return {
  7083. values: zigzag,
  7084. xData: xData,
  7085. yData: yData
  7086. };
  7087. }
  7088. });
  7089. /**
  7090. * A `Zig Zag` series. If the [type](#series.zigzag.type) option is not
  7091. * specified, it is inherited from [chart.type](#chart.type).
  7092. *
  7093. * @extends series,plotOptions.zigzag
  7094. * @since 6.0.0
  7095. * @product highstock
  7096. * @excluding dataParser, dataURL
  7097. * @requires stock/indicators/indicators
  7098. * @requires stock/indicators/zigzag
  7099. * @apioption series.zigzag
  7100. */
  7101. ''; // adds doclets above to transpiled file
  7102. });
  7103. _registerModule(_modules, 'indicators/regressions.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  7104. /**
  7105. *
  7106. * (c) 2010-2019 Kamil Kulig
  7107. *
  7108. * License: www.highcharts.com/license
  7109. *
  7110. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  7111. *
  7112. * */
  7113. var isArray = U.isArray;
  7114. var seriesType = H.seriesType;
  7115. /**
  7116. * Linear regression series type.
  7117. *
  7118. * @private
  7119. * @class
  7120. * @name Highcharts.seriesTypes.linearregression
  7121. *
  7122. * @augments Highcharts.Series
  7123. */
  7124. seriesType('linearRegression', 'sma',
  7125. /**
  7126. * Linear regression indicator. This series requires `linkedTo` option to be
  7127. * set.
  7128. *
  7129. * @sample {highstock} stock/indicators/linear-regression
  7130. * Linear regression indicator
  7131. *
  7132. * @extends plotOptions.sma
  7133. * @since 7.0.0
  7134. * @product highstock
  7135. * @requires stock/indicators/indicators
  7136. * @requires stock/indicators/regressions
  7137. * @optionparent plotOptions.linearregression
  7138. */
  7139. {
  7140. params: {
  7141. /**
  7142. * Unit (in milliseconds) for the x axis distances used to compute
  7143. * the regression line paramters (slope & intercept) for every
  7144. * range. In Highstock the x axis values are always represented in
  7145. * milliseconds which may cause that distances between points are
  7146. * "big" integer numbers.
  7147. *
  7148. * Highstock's linear regression algorithm (least squares method)
  7149. * will utilize these "big" integers for finding the slope and the
  7150. * intercept of the regression line for each period. In consequence,
  7151. * this value may be a very "small" decimal number that's hard to
  7152. * interpret by a human.
  7153. *
  7154. * For instance: `xAxisUnit` equealed to `86400000` ms (1 day)
  7155. * forces the algorithm to treat `86400000` as `1` while computing
  7156. * the slope and the intercept. This may enchance the legiblitity of
  7157. * the indicator's values.
  7158. *
  7159. * Default value is the closest distance between two data points.
  7160. *
  7161. * @sample {highstock} stock/plotoptions/linear-regression-xaxisunit
  7162. * xAxisUnit set to 1 minute
  7163. *
  7164. * @example
  7165. * // In Liniear Regression Slope Indicator series `xAxisUnit` is
  7166. * // `86400000` (1 day) and period is `3`. There're 3 points in the
  7167. * // base series:
  7168. *
  7169. * data: [
  7170. * [Date.UTC(2019, 0, 1), 1],
  7171. * [Date.UTC(2019, 0, 2), 3],
  7172. * [Date.UTC(2019, 0, 3), 5]
  7173. * ]
  7174. *
  7175. * // This will produce one point in the indicator series that has a
  7176. * // `y` value of `2` (slope of the regression line). If we change
  7177. * // the `xAxisUnit` to `1` (ms) the value of the indicator's point
  7178. * // will be `2.3148148148148148e-8` which is harder to interpert
  7179. * // for a human.
  7180. *
  7181. * @type {number}
  7182. * @product highstock
  7183. */
  7184. xAxisUnit: void 0
  7185. },
  7186. tooltip: {
  7187. valueDecimals: 4
  7188. }
  7189. },
  7190. /**
  7191. * @lends Highcharts.Series#
  7192. */
  7193. {
  7194. nameBase: 'Linear Regression Indicator',
  7195. /**
  7196. * Return the slope and intercept of a straight line function.
  7197. * @private
  7198. * @param {Highcharts.LinearRegressionIndicator} this indicator to use
  7199. * @param {Array<number>} xData - list of all x coordinates in a period
  7200. * @param {Array<number>} yData - list of all y coordinates in a period
  7201. * @return {Highcharts.RegressionLineParametersObject}
  7202. * object that contains the slope and the intercept
  7203. * of a straight line function
  7204. */
  7205. getRegressionLineParameters: function (xData, yData) {
  7206. // least squares method
  7207. var yIndex = this.options.params.index, getSingleYValue = function (yValue, yIndex) {
  7208. return isArray(yValue) ? yValue[yIndex] : yValue;
  7209. }, xSum = xData.reduce(function (accX, val) {
  7210. return val + accX;
  7211. }, 0), ySum = yData.reduce(function (accY, val) {
  7212. return getSingleYValue(val, yIndex) + accY;
  7213. }, 0), xMean = xSum / xData.length, yMean = ySum / yData.length, xError, yError, formulaNumerator = 0, formulaDenominator = 0, i, slope;
  7214. for (i = 0; i < xData.length; i++) {
  7215. xError = xData[i] - xMean;
  7216. yError = getSingleYValue(yData[i], yIndex) - yMean;
  7217. formulaNumerator += xError * yError;
  7218. formulaDenominator += Math.pow(xError, 2);
  7219. }
  7220. slope = formulaDenominator ?
  7221. formulaNumerator / formulaDenominator : 0; // don't divide by 0
  7222. return {
  7223. slope: slope,
  7224. intercept: yMean - slope * xMean
  7225. };
  7226. },
  7227. /**
  7228. * Return the y value on a straight line.
  7229. * @private
  7230. * @param {Highcharts.RegressionLineParametersObject} lineParameters
  7231. * object that contains the slope and the intercept
  7232. * of a straight line function
  7233. * @param {number} endPointX - x coordinate of the point
  7234. * @return {number} - y value of the point that lies on the line
  7235. */
  7236. getEndPointY: function (lineParameters, endPointX) {
  7237. return lineParameters.slope * endPointX + lineParameters.intercept;
  7238. },
  7239. /**
  7240. * Transform the coordinate system so that x values start at 0 and
  7241. * apply xAxisUnit.
  7242. * @private
  7243. * @param {Array<number>} xData - list of all x coordinates in a period
  7244. * @param {number} xAxisUnit - option (see the API)
  7245. * @return {Array<number>} - array of transformed x data
  7246. */
  7247. transformXData: function (xData, xAxisUnit) {
  7248. var xOffset = xData[0];
  7249. return xData.map(function (xValue) {
  7250. return (xValue - xOffset) / xAxisUnit;
  7251. });
  7252. },
  7253. /**
  7254. * Find the closest distance between points in the base series.
  7255. * @private
  7256. * @param {Array<number>} xData
  7257. list of all x coordinates in the base series
  7258. * @return {number} - closest distance between points in the base series
  7259. */
  7260. findClosestDistance: function (xData) {
  7261. var distance, closestDistance, i;
  7262. for (i = 1; i < xData.length - 1; i++) {
  7263. distance = xData[i] - xData[i - 1];
  7264. if (distance > 0 &&
  7265. (typeof closestDistance === 'undefined' ||
  7266. distance < closestDistance)) {
  7267. closestDistance = distance;
  7268. }
  7269. }
  7270. return closestDistance;
  7271. },
  7272. // Required to be implemented - starting point for indicator's logic
  7273. getValues: function (baseSeries, regressionSeriesParams) {
  7274. var xData = baseSeries.xData, yData = baseSeries.yData, period = regressionSeriesParams.period, lineParameters, i, periodStart, periodEnd,
  7275. // format required to be returned
  7276. indicatorData = {
  7277. xData: [],
  7278. yData: [],
  7279. values: []
  7280. }, endPointX, endPointY, periodXData, periodYData, periodTransformedXData, xAxisUnit = this.options.params.xAxisUnit ||
  7281. this.findClosestDistance(xData);
  7282. // Iteration logic: x value of the last point within the period
  7283. // (end point) is used to represent the y value (regression)
  7284. // of the entire period.
  7285. for (i = period - 1; i <= xData.length - 1; i++) {
  7286. periodStart = i - period + 1; // adjusted for slice() function
  7287. periodEnd = i + 1; // (as above)
  7288. endPointX = xData[i];
  7289. periodXData = xData.slice(periodStart, periodEnd);
  7290. periodYData = yData.slice(periodStart, periodEnd);
  7291. periodTransformedXData = this.transformXData(periodXData, xAxisUnit);
  7292. lineParameters = this.getRegressionLineParameters(periodTransformedXData, periodYData);
  7293. endPointY = this.getEndPointY(lineParameters, periodTransformedXData[periodTransformedXData.length - 1]);
  7294. // @todo this is probably not used anywhere
  7295. indicatorData.values.push({
  7296. regressionLineParameters: lineParameters,
  7297. x: endPointX,
  7298. y: endPointY
  7299. });
  7300. indicatorData.xData.push(endPointX);
  7301. indicatorData.yData.push(endPointY);
  7302. }
  7303. return indicatorData;
  7304. }
  7305. });
  7306. /**
  7307. * A linear regression series. If the [type](#series.linearregression.type)
  7308. * option is not specified, it is inherited from [chart.type](#chart.type).
  7309. *
  7310. * @extends series,plotOptions.linearregression
  7311. * @since 7.0.0
  7312. * @product highstock
  7313. * @excluding dataParser,dataURL
  7314. * @requires stock/indicators/indicators
  7315. * @requires stock/indicators/regressions
  7316. * @apioption series.linearregression
  7317. */
  7318. /* ************************************************************************** */
  7319. /**
  7320. * The Linear Regression Slope series type.
  7321. *
  7322. * @private
  7323. * @class
  7324. * @name Highcharts.seriesTypes.linearRegressionSlope
  7325. *
  7326. * @augments Highcharts.Series
  7327. */
  7328. seriesType('linearRegressionSlope', 'linearRegression',
  7329. /**
  7330. * Linear regression slope indicator. This series requires `linkedTo`
  7331. * option to be set.
  7332. *
  7333. * @sample {highstock} stock/indicators/linear-regression-slope
  7334. * Linear regression slope indicator
  7335. *
  7336. * @extends plotOptions.linearregression
  7337. * @since 7.0.0
  7338. * @product highstock
  7339. * @requires stock/indicators/indicators
  7340. * @requires stock/indicators/regressions
  7341. * @optionparent plotOptions.linearregressionslope
  7342. */
  7343. {},
  7344. /**
  7345. * @lends Highcharts.Series#
  7346. */
  7347. {
  7348. nameBase: 'Linear Regression Slope Indicator',
  7349. getEndPointY: function (lineParameters) {
  7350. return lineParameters.slope;
  7351. }
  7352. });
  7353. /**
  7354. * A linear regression slope series. If the
  7355. * [type](#series.linearregressionslope.type) option is not specified, it is
  7356. * inherited from [chart.type](#chart.type).
  7357. *
  7358. * @extends series,plotOptions.linearregressionslope
  7359. * @since 7.0.0
  7360. * @product highstock
  7361. * @excluding dataParser,dataURL
  7362. * @requires stock/indicators/indicators
  7363. * @requires stock/indicators/regressions
  7364. * @apioption series.linearregressionslope
  7365. */
  7366. /* ************************************************************************** */
  7367. /**
  7368. * The Linear Regression Intercept series type.
  7369. *
  7370. * @private
  7371. * @class
  7372. * @name Highcharts.seriesTypes.linearRegressionIntercept
  7373. *
  7374. * @augments Highcharts.Series
  7375. */
  7376. seriesType('linearRegressionIntercept', 'linearRegression',
  7377. /**
  7378. * Linear regression intercept indicator. This series requires `linkedTo`
  7379. * option to be set.
  7380. *
  7381. * @sample {highstock} stock/indicators/linear-regression-intercept
  7382. * Linear intercept slope indicator
  7383. *
  7384. * @extends plotOptions.linearregression
  7385. * @since 7.0.0
  7386. * @product highstock
  7387. * @requires stock/indicators/indicators
  7388. * @requires stock/indicators/regressions
  7389. * @optionparent plotOptions.linearregressionintercept
  7390. */
  7391. {},
  7392. /**
  7393. * @lends Highcharts.Series#
  7394. */
  7395. {
  7396. nameBase: 'Linear Regression Intercept Indicator',
  7397. getEndPointY: function (lineParameters) {
  7398. return lineParameters.intercept;
  7399. }
  7400. });
  7401. /**
  7402. * A linear regression intercept series. If the
  7403. * [type](#series.linearregressionintercept.type) option is not specified, it is
  7404. * inherited from [chart.type](#chart.type).
  7405. *
  7406. * @extends series,plotOptions.linearregressionintercept
  7407. * @since 7.0.0
  7408. * @product highstock
  7409. * @excluding dataParser,dataURL
  7410. * @requires stock/indicators/indicators
  7411. * @requires stock/indicators/regressions
  7412. * @apioption series.linearregressionintercept
  7413. */
  7414. /* ************************************************************************** */
  7415. /**
  7416. * The Linear Regression Angle series type.
  7417. *
  7418. * @private
  7419. * @class
  7420. * @name Highcharts.seriesTypes.linearRegressionAngle
  7421. *
  7422. * @augments Highcharts.Series
  7423. */
  7424. seriesType('linearRegressionAngle', 'linearRegression',
  7425. /**
  7426. * Linear regression angle indicator. This series requires `linkedTo`
  7427. * option to be set.
  7428. *
  7429. * @sample {highstock} stock/indicators/linear-regression-angle
  7430. * Linear intercept angle indicator
  7431. *
  7432. * @extends plotOptions.linearregression
  7433. * @since 7.0.0
  7434. * @product highstock
  7435. * @requires stock/indicators/indicators
  7436. * @requires stock/indicators/regressions
  7437. * @optionparent plotOptions.linearregressionangle
  7438. */
  7439. {
  7440. tooltip: {
  7441. pointFormat: '<span style="color:{point.color}">\u25CF</span>' +
  7442. '{series.name}: <b>{point.y}°</b><br/>'
  7443. }
  7444. },
  7445. /**
  7446. * @lends Highcharts.Series#
  7447. */
  7448. {
  7449. nameBase: 'Linear Regression Angle Indicator',
  7450. /**
  7451. * Convert a slope of a line to angle (in degrees) between
  7452. * the line and x axis
  7453. * @private
  7454. * @param {number} slope of the straight line function
  7455. * @return {number} angle in degrees
  7456. */
  7457. slopeToAngle: function (slope) {
  7458. return Math.atan(slope) * (180 / Math.PI); // rad to deg
  7459. },
  7460. getEndPointY: function (lineParameters) {
  7461. return this.slopeToAngle(lineParameters.slope);
  7462. }
  7463. });
  7464. /**
  7465. * A linear regression intercept series. If the
  7466. * [type](#series.linearregressionangle.type) option is not specified, it is
  7467. * inherited from [chart.type](#chart.type).
  7468. *
  7469. * @extends series,plotOptions.linearregressionangle
  7470. * @since 7.0.0
  7471. * @product highstock
  7472. * @excluding dataParser,dataURL
  7473. * @requires stock/indicators/indicators
  7474. * @requires stock/indicators/regressions
  7475. * @apioption series.linearregressionangle
  7476. */
  7477. ''; // to include the above in the js output
  7478. });
  7479. _registerModule(_modules, 'indicators/acceleration-bands.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['mixins/multipe-lines.js']], function (H, U, multipleLinesMixin) {
  7480. /* *
  7481. *
  7482. * License: www.highcharts.com/license
  7483. *
  7484. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  7485. *
  7486. * */
  7487. var correctFloat = U.correctFloat;
  7488. var SMA = H.seriesTypes.sma, merge = H.merge;
  7489. /* eslint-disable valid-jsdoc */
  7490. /**
  7491. * @private
  7492. */
  7493. function getBaseForBand(low, high, factor) {
  7494. return (((correctFloat(high - low)) /
  7495. ((correctFloat(high + low)) / 2)) * 1000) * factor;
  7496. }
  7497. /**
  7498. * @private
  7499. */
  7500. function getPointUB(high, base) {
  7501. return high * (correctFloat(1 + 2 * base));
  7502. }
  7503. /**
  7504. * @private
  7505. */
  7506. function getPointLB(low, base) {
  7507. return low * (correctFloat(1 - 2 * base));
  7508. }
  7509. /* eslint-enable valid-jsdoc */
  7510. /**
  7511. * The ABands series type
  7512. *
  7513. * @private
  7514. * @class
  7515. * @name Highcharts.seriesTypes.abands
  7516. *
  7517. * @augments Highcharts.Series
  7518. */
  7519. H.seriesType('abands', 'sma',
  7520. /**
  7521. * Acceleration bands (ABANDS). This series requires the `linkedTo` option
  7522. * to be set and should be loaded after the
  7523. * `stock/indicators/indicators.js`.
  7524. *
  7525. * @sample {highstock} stock/indicators/acceleration-bands
  7526. * Acceleration Bands
  7527. *
  7528. * @extends plotOptions.sma
  7529. * @mixes Highcharts.MultipleLinesMixin
  7530. * @since 7.0.0
  7531. * @product highstock
  7532. * @excluding allAreas, colorAxis, compare, compareBase, joinBy, keys,
  7533. * navigatorOptions, pointInterval, pointIntervalUnit,
  7534. * pointPlacement, pointRange, pointStart, showInNavigator,
  7535. * stacking,
  7536. * @requires stock/indicators/indicators
  7537. * @requires stock/indicators/acceleration-bands
  7538. * @optionparent plotOptions.abands
  7539. */
  7540. {
  7541. params: {
  7542. period: 20,
  7543. /**
  7544. * The algorithms factor value used to calculate bands.
  7545. *
  7546. * @product highstock
  7547. */
  7548. factor: 0.001,
  7549. index: 3
  7550. },
  7551. lineWidth: 1,
  7552. topLine: {
  7553. styles: {
  7554. /**
  7555. * Pixel width of the line.
  7556. */
  7557. lineWidth: 1
  7558. }
  7559. },
  7560. bottomLine: {
  7561. styles: {
  7562. /**
  7563. * Pixel width of the line.
  7564. */
  7565. lineWidth: 1
  7566. }
  7567. },
  7568. dataGrouping: {
  7569. approximation: 'averages'
  7570. }
  7571. },
  7572. /**
  7573. * @lends Highcharts.Series#
  7574. */
  7575. merge(multipleLinesMixin, {
  7576. pointArrayMap: ['top', 'middle', 'bottom'],
  7577. pointValKey: 'middle',
  7578. nameBase: 'Acceleration Bands',
  7579. nameComponents: ['period', 'factor'],
  7580. linesApiNames: ['topLine', 'bottomLine'],
  7581. getValues: function (series, params) {
  7582. var period = params.period, factor = params.factor, index = params.index, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0,
  7583. // Upperbands
  7584. UB = [],
  7585. // Lowerbands
  7586. LB = [],
  7587. // ABANDS array structure:
  7588. // 0-date, 1-top line, 2-middle line, 3-bottom line
  7589. ABANDS = [],
  7590. // middle line, top line and bottom line
  7591. ML, TL, BL, date, bandBase, pointSMA, ubSMA, lbSMA, low = 2, high = 1, xData = [], yData = [], slicedX, slicedY, i;
  7592. if (yValLen < period) {
  7593. return;
  7594. }
  7595. for (i = 0; i <= yValLen; i++) {
  7596. // Get UB and LB values of every point. This condition
  7597. // is necessary, because there is a need to calculate current
  7598. // UB nad LB values simultaneously with given period SMA
  7599. // in one for loop.
  7600. if (i < yValLen) {
  7601. bandBase = getBaseForBand(yVal[i][low], yVal[i][high], factor);
  7602. UB.push(getPointUB(yVal[i][high], bandBase));
  7603. LB.push(getPointLB(yVal[i][low], bandBase));
  7604. }
  7605. if (i >= period) {
  7606. slicedX = xVal.slice(i - period, i);
  7607. slicedY = yVal.slice(i - period, i);
  7608. ubSMA = SMA.prototype.getValues.call(this, {
  7609. xData: slicedX,
  7610. yData: UB.slice(i - period, i)
  7611. }, {
  7612. period: period
  7613. });
  7614. lbSMA = SMA.prototype.getValues.call(this, {
  7615. xData: slicedX,
  7616. yData: LB.slice(i - period, i)
  7617. }, {
  7618. period: period
  7619. });
  7620. pointSMA = SMA.prototype.getValues.call(this, {
  7621. xData: slicedX,
  7622. yData: slicedY
  7623. }, {
  7624. period: period,
  7625. index: index
  7626. });
  7627. date = pointSMA.xData[0];
  7628. TL = ubSMA.yData[0];
  7629. BL = lbSMA.yData[0];
  7630. ML = pointSMA.yData[0];
  7631. ABANDS.push([date, TL, ML, BL]);
  7632. xData.push(date);
  7633. yData.push([TL, ML, BL]);
  7634. }
  7635. }
  7636. return {
  7637. values: ABANDS,
  7638. xData: xData,
  7639. yData: yData
  7640. };
  7641. }
  7642. }));
  7643. /**
  7644. * An Acceleration bands indicator. If the [type](#series.abands.type) option is not
  7645. * specified, it is inherited from [chart.type](#chart.type).
  7646. *
  7647. * @extends series,plotOptions.abands
  7648. * @since 7.0.0
  7649. * @product highstock
  7650. * @excluding allAreas, colorAxis, compare, compareBase, dataParser, dataURL,
  7651. * joinBy, keys, navigatorOptions, pointInterval,
  7652. * pointIntervalUnit, pointPlacement, pointRange, pointStart,
  7653. * stacking, showInNavigator,
  7654. * @requires stock/indicators/indicators
  7655. * @requires stock/indicators/acceleration-bands
  7656. * @apioption series.abands
  7657. */
  7658. ''; // to include the above in jsdoc
  7659. });
  7660. _registerModule(_modules, 'indicators/trendline.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  7661. /* *
  7662. *
  7663. * License: www.highcharts.com/license
  7664. *
  7665. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  7666. *
  7667. * */
  7668. var isArray = U.isArray;
  7669. var seriesType = H.seriesType;
  7670. /**
  7671. * The Trend line series type.
  7672. *
  7673. * @private
  7674. * @class
  7675. * @name Highcharts.seriesTypes.trendline
  7676. *
  7677. * @augments Highcharts.Series
  7678. */
  7679. seriesType('trendline', 'sma',
  7680. /**
  7681. * Trendline (linear regression) fits a straight line to the selected data
  7682. * using a method called the Sum Of Least Squares. This series requires the
  7683. * `linkedTo` option to be set.
  7684. *
  7685. * @sample stock/indicators/trendline
  7686. * Trendline indicator
  7687. *
  7688. * @extends plotOptions.sma
  7689. * @since 7.1.3
  7690. * @product highstock
  7691. * @requires stock/indicators/indicators
  7692. * @requires stock/indicators/trendline
  7693. * @optionparent plotOptions.trendline
  7694. */
  7695. {
  7696. /**
  7697. * @excluding period
  7698. */
  7699. params: {
  7700. /**
  7701. * The point index which indicator calculations will base. For
  7702. * example using OHLC data, index=2 means the indicator will be
  7703. * calculated using Low values.
  7704. *
  7705. * @default 3
  7706. */
  7707. index: 3
  7708. }
  7709. },
  7710. /**
  7711. * @lends Highcharts.Series#
  7712. */
  7713. {
  7714. nameBase: 'Trendline',
  7715. nameComponents: false,
  7716. getValues: function (series, params) {
  7717. var xVal = series.xData, yVal = series.yData, LR = [], xData = [], yData = [], sumX = 0, sumY = 0, sumXY = 0, sumX2 = 0, xValLength = xVal.length, index = params.index, alpha, beta, i, x, y;
  7718. // Get sums:
  7719. for (i = 0; i < xValLength; i++) {
  7720. x = xVal[i];
  7721. y = isArray(yVal[i]) ? yVal[i][index] : yVal[i];
  7722. sumX += x;
  7723. sumY += y;
  7724. sumXY += x * y;
  7725. sumX2 += x * x;
  7726. }
  7727. // Get slope and offset:
  7728. alpha = (xValLength * sumXY - sumX * sumY) /
  7729. (xValLength * sumX2 - sumX * sumX);
  7730. if (isNaN(alpha)) {
  7731. alpha = 0;
  7732. }
  7733. beta = (sumY - alpha * sumX) / xValLength;
  7734. // Calculate linear regression:
  7735. for (i = 0; i < xValLength; i++) {
  7736. x = xVal[i];
  7737. y = alpha * x + beta;
  7738. // Prepare arrays required for getValues() method
  7739. LR[i] = [x, y];
  7740. xData[i] = x;
  7741. yData[i] = y;
  7742. }
  7743. return {
  7744. xData: xData,
  7745. yData: yData,
  7746. values: LR
  7747. };
  7748. }
  7749. });
  7750. /**
  7751. * A `TrendLine` series. If the [type](#series.trendline.type) option is not
  7752. * specified, it is inherited from [chart.type](#chart.type).
  7753. *
  7754. * @extends series,plotOptions.trendline
  7755. * @since 7.1.3
  7756. * @product highstock
  7757. * @excluding dataParser, dataURL
  7758. * @requires stock/indicators/indicators
  7759. * @requires stock/indicators/trendline
  7760. * @apioption series.trendline
  7761. */
  7762. ''; // to include the above in the js output
  7763. });
  7764. _registerModule(_modules, 'masters/indicators/indicators-all.src.js', [], function () {
  7765. });
  7766. }));