indicators-all.src.js 322 KB

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