Professional Documents
Culture Documents
Pro Builder
Pro Builder
') 026T16(5..............................................................................................................2
a. <ith <)175..................................................................................................................2 /. <ith F2:......................................................................................................................2
6) 2605......................................................................................................................2#
9athematical Functions..............................................................................................$%
1) 0ommon (nar" and Binar" Functions.....................................................................$% 2) 0ommon mathematical 2perators...........................................................................$% $) 0harting comparison Functions...............................................................................$1 &) Summation Functions..............................................................................................$1 ') Statistical Functions.................................................................................................$1
Chapter I : E!ercises___________________________________________
0andlestic@s patterns..................................................................................................&$ 1ndicators.....................................................................................................................&6
"lossar#_______________________________________________________
Introduction to ProBuilder
INT$O%&CTION TO P$OB&IL%E$
ProBuilder is a BAS10+t"pe programming language3 ver" eas" to handle and e,haustive in terms of availa/le possi/ilities. Aou *ill /e a/le to create "our o*n programs using the 8uotes from an" instrument. Some /asic availa/le elements include? 2pening of each /ar ? 2pen 0losing of each /ar ? 0lose )ighest price of each /ar ? )igh 7o*est price of each /ar ? 7o* .olume of each /ar ? .olume
ProBuilder evaluates the data of each price /ar starting *ith the oldest one to the most recent one3 and then e,ecutes the formula developed in the language in order to determine the value of the indicators on the current /ar. The indicators coded in ProBuilder can /e displa"ed either in the price chart or in an individual one. 1n this document3 "ou *ill learn3 step /" step3 ho* to use the availa/le commands necessar" to program in this language than@s to a clear theoretical overvie* and concrete e,amples. 1n the end of the manual3 "ou *ill find a Blossar" *hich *ill give "ou an overall vie* of all the ProBuilder commands3 pre+e,isting indicators and other functions completing *hat "ou *ould have learned after reading the previous parts. (sers more confident in their programming s@ills can s@ip directl" to chapter 11 or Cust refer to the Blossar" to 8uic@l" find the information the" *ant.
1 > '6
Chapter I: Fundamentals
C'APTE$ I: F&N%AMENTALS
Accessin( ProBuilder
The programming Eone of an indicator is availa/le /" clic@ing the /utton F1ndicator>Bac@testF *hich can /e found in the upper right corner of each graphic of the platform.
The indicators management *indo* *ill /e displa"ed. Aou *ill then /e a/le to? !ispla" a pre+e,isting indicator 0reate a personaliEed indicator3 *hich can /e used after*ards on an" securit"
2 > '6
Chapter I: Fundamentals
1f "ou choose the second possi/ilit"3 clic@ on F6e* indicatorF to access the programming *indo*. At that time3 "ou *ill /e a/le to choose /et*een? programming directl" an indicator in the te,t Eone designed for *riting code or use the help function /" clic@ing on F1nsert FunctionF. This *ill open a ne* *indo* in *hich "ou can find all the functions availa/le. This li/rar" is separated in 7 categories3 to give "ou constant assistance *hile programming.
$ > '6
Chapter I: Fundamentals
7etGs ta@e for e,ample the first specific ProBuilder element? the F $ET&$NF function 4availa/le in the H=e"*ordsI categor" 4see the image /elo*).
Select the *ord F$ET&$NF and clic@ on FAddF. The command *ill /e added to the programming Eone.
Chapter I: Fundamentals
Suppose *e *ant to create an indicator displa"ing the .olume. 1f "ou have alread" inserted the function F$ET&$NF3 then "ou Cust need to clic@ one more time on F1nsert functionF. 6e,t3 clic@ on F0onstantsF in the F0ategoriesF section3 then in the right side of the *indo*3 in the section named FFunctionsF3 clic@ on F olumeF. Finall"3 clic@ on FAddF.
Before clic@ing on F.alidate programF3 "ou need to enter the name of "our indicator. )ere3 *e named it F.olume 9icrosoftF. To finish3 clic@ on F.alidate programF and "ou *ill see "our indicator displa"ed /elo* the price chart.
Chapter I: Fundamentals
The main ideas to @no* in the ProBuilder language are? 1t is not necessar# to declare *aria+les 1t is not necessar# to t#pe *aria+les There is no di))erence +et,een capital letters and small letters 4/ut3 as *e *ill see later3 there is one e,ception) -e use the same s#m+ol ./. )or mathematic e0ualit# and to attri+ute a *alue to a *aria+le
<hat does that mean !eclare a varia/le ; means indicating its e,istence. 1n ProBuilder3 "ou can directl" use ; *ithout having to declare it. 7etGs ta@e an e,ample? <ith declaration? let /e varia/le ;3 *e attri/ute to ; the value ' <ithout declaration? <e attri/ute to ; the value ' 4therefore3 implicitl"3 ; e,ists and the value ' is attri/uted to it) 1n ProBuilder "ou Cust need to *rite? ;J'
6 > '6
Chapter I: Fundamentals
T"pe a varia/le means defining its nature. For e,ample? is the varia/le a natural num/er 4e,? $K K 21K 6&$K L)3 a *hole num/er *hich can /e negative or positive 4e,? $K 6$2K +$7K L)3 a decimal num/er 4e,? 1.76&'$'$&'$'L)3 a /oolean 4:1B)TJ13 <:26BJ%)3L-
1n ProBuilder3 "ou can *rite "our command *ith capital letters or small letters. For e,ample3 the group of commands 1F > T)56 > 57S5 > 56!1F can /e *ritten iF > t)e6 > 57se > end1f 4and man" other possi/ilitiesD) 5,ception? <hen "ou decide to create a varia/le and re+use it later in the program3 "ou must not contradict the spelling "ou used during its creation. 1f "ou started to name "our varia/le? FvA:iaB7eF and *ish to re+use it in "our program3 then "ou must refer to it as FvA:iaB7eF3 not as Hvaria/leI not an"thing else.
Affect a value to a varia/le means give the varia/le a value. 1n order to understand this principle3 "ou must assimilate a varia/le *ith an empt" /o, *hich "ou can fill *ith an e,pression 4e,? a num/er). The follo*ing diagram illustrate the Affectation :ule *ith the .olume value affected to the varia/le ;?
olume
As "ou can see3 *e must read from right to left? .olume is affected to ;. 1f "ou *ant to *rite it under ProBuilder3 "ou Cust need to replace the arro* *ith an e8ual sign?
1 / olume
The same J s"m/ol is used? For the affectation of a varia/le 4li@e the previous e,ample) As the mathematical /inar" operator 41M 1J 2 is e8uivalent to 2 J 1 M 1).
7 > '6
Chapter I: Fundamentals
Aou *ill then /e a/le to com/ine them in order to dra* out some information provided /" financial mar@ets. <e can group them together in ' categories?
E!ample: :ange of the current /ar a / 'i(h + / Lo, M#$an(e / a 4 + $ET&$N M#$an(e
1f "ou *ant to use the information of previous /ars rather than the current /ar3 "ou Cust need to add /et*een s8uare /rac@ets the num/er of /ars that "ou *ant to go /ac@ into the past.
Lets take for example the closing price term: Value of the closing price of the current bar: Value of the closing price preceding the current bar: Value of the closing price preceding the nth bar preceding the current one: Close Close[1] Close [n]
This rule is valid for an" term. For e,ample3 the opening price of the 2nd /ar preceding the current can /e e,pressed as? 2penN2O. The reported value *ill depend on the displa"ed timeframe of the chart.
> '6
Chapter I: Fundamentals
F20(S ? OpenO)Ne!tBar 2pen2f6e,tBar can /e used the same *a" as the 2pen constant. 1t follo*s this rule? OpenO)Ne!tBar5n627 / Open5n7 For e,ample? 2pen2f6e,tBarN1O J 2pen 2pen2f6e,tBarN2O J 2penN1O 2pen2f6e,tBarN$O J 2penN2O ,here n89
6ote? FnF can /e e8ual to % if *e *ant to call the value for toda" as sho*n in the e,ample /elo*. !a"+traders @no* the importance of the close of the da" /efore and of the open that is a moment of emotion *hen the novices enter or e,it the mar@et. The high and lo* of the previous da"s can indicate the price changes of the ne,t da".
The terms adapted to the timeframe of the chart use s8uare /rac@ets *hile the dail" price terms use /rac@ets. 0lose N$O !close4$) The closing price $ periods ago The closing price $ da"s ago
# > '6
Chapter I: Fundamentals
=3 Temporal Terms
Time is often a neglected component of technical anal"sis. )o*ever traders @no* ver" *ell the importance of some time periods in the da" or dates in the "ear. 1t is possi/le in "our programs to ta@e into account time and date and improve the efficienc" of "our indicators. The Temporal Terms are descri/ed hereafter? %ate : indicates the date of the close of each /ar in the format Aear9onth!a" 4AAAA99!!)
Temporal Terms are considered /" ProBuilder as *hole num/ers. The !ate term3 for e,ample3 must /e used as one num/er made up of figures.
Suppose toda" is the &th of Pul" 2%% 3 the program a/ove *ill return the value 2%% %7%& for toda" and 2%% %7%$ for "esterda" and so on for previous da"s. !ate under ProBuilder is then /ased on the follo*ing scale of value? 2ne millennium is e8uivalent to 1% %%% %%% date units 2ne centur" is e8uivalent to 1 %%% %%% date units 2ne decade is e8uivalent to 1%% %%% date units 2ne "ear is e8uivalent to 1% %%% date units Ten months are e8uivalent to 1 %%% date units 4do not e,ceed 12 months) 2ne month is e8uivalent to 1%% date units 4do not e,ceed 12 months) Ten da"s are e8uivalent to1% date units 4do not e,ceed $1 seconds) 2ne da" is e8uivalent to 1 date unit 4do not e,ceed $1 seconds)
Time : indicates the hour of the closing price of each /ar in the format )our9inuteSecond 4))99SS)
1% > '6
Chapter I: Fundamentals
5,ample? $ET&$N Time This indicator sho*s us the closing time of each /ar in the format ))99SS?
1t is also possi/le to use Time and %ate in the same indicator to do anal"sis or displa" results at a precise moment. 1n the follo*ing e,ample3 *e *ant to limit our indicator to the date of 2cto/er 1st at precisel" #am and 1 second? a / ;%ate / :99>29923 + / ;Time / 9?99923 $ET&$N ;a AN% +3
11 > '6
Chapter I: Fundamentals
Similar to %ate3 Time uses the follo*ing scale of value? Ten hours are e8uivalent to 1%% %%% time units 4do not e,ceed 2$ hours) 2ne hour is e8uivalent to 1% %%% units 4do not e,ceed 2$ hours) Ten minutes are e8uivalent to 1 %%% time units 4do not e,ceed '# minutes) 2ne minute is e8uivalent to 1%% time units 4do not e,ceed '# minutes) Ten seconds are e8uivalent to 1% time units 4do not e,ceed '# seconds) 2ne second is e8uivalent to 1 time unit 4do not e,ceed '# seconds)
The follo*ing terms *or@ the same *a"? Minute : 9inute of the close of each /ar 4from % to '#)? 2nl" for intrada" charts. 'our : )our of the close of each /ar 4from % to 2$)? 2nl" for intrada" charts. %a# : !a" of the months of the closing price of each /ar 4from 1 to 2 or 2# or $% or $1) Month : 9onth of the closing price of each /ar 4from 1 to 12) @ear : Aear of the closing price of each /ar %a#O)-eeA : !a" of the <ee@ of the close of each /ar 4does not use *ee@end!a"s) 41Jmonda"3 2Jtuesda"3 $J*ednesda"3 &Jthursda"3 'Jfrida")
Current'our : 0urrent )our 4of the local mar@et) CurrentMinute : 0urrent 9inute 4of the local mar@et) CurrentMonth : 0urrent 9onth 4of the local mar@et) CurrentSecond : 0urrent Second 4of the local mar@et) Toda# : 0urrent !ate 4of the local mar@et) CurrentTime : 0urrent )our9inuteSecond 4of the local mar@et) Current@ear : 0urrent Aear 4of the local mar@et) Current%a#O)-eeA : 0urrent !a" of the *ee@ *ith the mar@et time Eone as a reference
The di))erence /et*een the F0urrentF terms and the Fnon+0urrentF terms presented a/ove is the F0urrentF aspect.
12 > '6
Chapter I: Fundamentals
The follo*ing picture /rings to light that difference 4applied on the CurrentTime and Time terms). <e can highlight the fact that for F0urrentI terms3 *e must set aside the time a,is and onl" ta@e in consideration the displa"ed value 4the value of the current time is displa"ed over the *hole histor" of the chart).
Time indicates the closing time of each /ar. CurrentTime indicates the current mar@et time. 1f "ou *ant to set up "our indicators *ith counters 4num/er of da"s passed3 num/er of /ars passed etcL)3 "ou can use the %a#s3 BarInde! and Intrada#BarInde! terms. %a#s : 0ounter of da"s since 1#%%
This term is 8uite useful *hen "ou *ant to @no* the num/er of da"s that have passed. 1t is particularl" relevant *hen "ou *or@ *ith an 4,) tic@ or 4,) volume vie*.
The follo*ing e,ample sho*s "ou the num/er of da"s passed since 1#%%. $ET&$N %a#s
1$ > '6
Chapter I: Fundamentals
BarInde! : 0ounter of /ars since the /eginning of the displa"ed historic The counter starts from left to right and counts each /ar3 including the current /ar. The first /ar loaded is considered /ar num/er %. 9ost of the time3 BarInde! is used *ith the IF instruction presented later in the manual 4see page 22 for use e,amples). Intrada#BarInde! : 0ounter of intrada" /ars The counter displa"s the num/er of /ars since the /eginning of the da" and then resets to Eero at the /eginning of ever" ne* da". The first /ar of the counter is considered /ar num/er %.
7etGs compare the t*o counter terms *ith t*o separated indicators? $ET&$N BarInde! and $ET&$N Intrada#BarInde!
<e can clearl" see the difference /et*een them? Intrada#BarInde! reset itself to Eero at the /eginning of ever" ne* da".
Chapter I: Fundamentals
7e $an(e sho*s the volatilit" of the current /ar3 *hich is an estimation of ho* nervous investors are. Aou can create an indicator *ith one of the terms a/ove onl" /" creating a one+line indicator F:5T(:6 :angeF for e,ample or use the terms to create a more complicated indicator. The -ei(htedClose focuses on the importance of the closing price /ar 4even more important *hen applied to dail" /ars or *ee@l" /ars). The T#picalPrice and TotalPrice emphasiEe intrada" financial mar@et ps"cholog" since the" ta@e $ or & predominant prices of the current /ar into account 4see a/ove). MedianPrice uses the 9edian concept 4the middle num/er) instead of the Average concept *hich is 8uite useful *hen tr"ing to create theoretical models that donGt ta@e investors ps"cholog" into account.
Chapter I: Fundamentals
ProBuilder indicators are made up of three elements *hich s"nta, is? NameO)Function 5calculated o*er n periods7 ;applied to ,hich price or indicator3 <hen using the F1nsert FunctionF /utton to loo@ for a ProBuilder function and then enter it into "our program 4see page $ and &)3 default values are given for /oth the period and the price or indicator argument.
A*era(e5:97;Close3
<e can of course modif" these values according to our preferencesK for e,ample3 *e can replace the 2% /ars defined /" default *ith 1%% /ars. 1n the same *a"3 *e can change the price argument F0loseF *ith F2penF or F%open;I3F Q the open of the dail" /ar 6 da"s ago ?
A*era(e5:97;%open;I33
)ere are some sample programs?
Pro(ram calculatin( the e!ponential mo*in( a*era(e o*er :9 periods applied to the closin( price: $ET&$N E!ponentialA*era(e5:97;Close3
Pro(ram calculatin( the ,ei(hted mo*in( a*era(e o*er :9 +ars applied to the t#pical price mm / -ei(htedA*era(e5:97;T#picalPrice3 $ET&$N mm
Pro(ram calculatin( the -ilder a*era(e o*er 299 candlesticAs applied to the olume mm / -ilderA*era(e52997; olume3 $ET&$N mm
Program calculating the 9A0! 4histogram) applied to the closing price. The 9A0! is /uilt *ith the difference /et*een the 12+period e,ponential moving average 459A) minus the 26+period 59A. Then3 *e ma@e a smoothing *ith an e,ponential moving average over # periods and applied to the 9A0! line to get the Signal line. Finall"3 the 9A0! is the difference /et*een the 9A0! line and the Signal line. $EM Calculation o) the MAC% line MAC%Line / E!ponentialA*era(e52:7;Close3 < E!ponentialA*era(e5:I7;Close3 $EM Calculation o) the MAC% Si(nal line MAC%Si(nalLine / E!ponentialA*era(e5?7;MAC%Line3 $EM Calculation o) the di))erence +et,een the MAC% line and its Si(nal MAC%'isto(ramme / MAC%Line 4 MAC%Si(nalLine $ET&$N MAC%'isto(ramme
16 > '6
Chapter I: Fundamentals
aria+les
<hen "ou code an indicator3 "ou ma" *ant to introduce varia/les. The varia/les option in the upper+right corner of the *indo* allo*s "ou to attri/ute a default value to an undefined term and manipulate it in the FsettingsF *indo* of the indicator *ithout modif"ing the code of "our program. 7etGs calculate a simple moving average on 2% periods? $ET&$N A*era(e5:97;Close3
1n order to modif" the num/er of periods for the calculation directl" from the indicator FSettingsF interface3 replace 2% *ith the varia/le FnF? $ET&$N A*era(e5n7;Close3 Then3 clic@ on FAddF in F.aria/lesF and another *indo* named F.aria/le definitionF *ill /e displa"ed. Fill it in as follo*s?
17 > '6
Chapter I: Fundamentals
0lic@ on the F2=F /utton. Then3 in the FSettingsF *indo* 4in this case FSettings 9"9ovingAverageF) "ou *ill see a ne* parameter *hich *ill allo* "ou to modif" the num/er of periods in the calculation of the moving average?
2f course3 it is possi/le to do the same *ith man" varia/les giving "ou the possi/ilit" to manipulate multiple parameters at the same time for the same indicator.
1 > '6
<e can loo@ for a condition and define an action if that condition is true. 2n the other hand3 if the condition is not valid3 then nothing *ill happen 4B" default3 :esult J %). 1n this e,ample3 if current price is greater than the 2%+period moving average3 then *e displa"? :esult J 1 and displa" this on the chart.
1F Price R 2%+period moving average then :esult J 13 other*ise :esult J% end of the 1F condition !ispla" the value of result on the chart
$ET&$N must al*a"s /e follo*ed *ith the storage varia/le containing the result in order to displa" the result on the chart 4in the last e,ample *e use the varia/le F:esultF).
<e can also define a different result if the condition is not true. 7et us go /ac@ to the previous e,ample? if the price is greater than the moving average on 2% periods3 then displa" 13 else3 displa"s +1.
NB:
e ha!e created a binar" indicator# $or more information% read page &'
1# > '6
cJ Se0uential IF conditions
Aou can create su/+conditions after the validation of the main condition3 meaning conditions *hich must /e validated one after another. For that3 "ou need to /uild a se8uence of IF structures3 one included in the other. Aou should /e careful to insert in the code as man" EN%IF as IF. 5,ample? %ou+le conditions on mo*in( a*era(es : IF ;A*era(e52:7;Close3 < A*era(e5:97;Close3 8 93 T'EN IF E!ponentialA*era(e52:7;Close3 < E!ponentialA*era(e5:97;Close3 8 9 T'EN $esult / 2 ELSE $esult / <2 EN%IF EN%IF $ET&$N $esult
Aou can define a specific result for a specific condition. The indicator reports man" states? if 0ondition 1 is valid then do Action1K else3 if 0ondition 2 is valid3 then do Action 2 Lif none of the previousl" mentioned conditions are valid then do Action n. This structure uses the follo*ing instructions? IF3 T'EN3 ELSIF3 T'EN.... ELSE3 EN%IF. The s"nta, is ? IF ;Condition23 T'EN ;Action23 ELSIF ;Condition:3 T'EN ;Action:3 ELSIF ;Condition=3 T'EN ;Action=3 JJJ JJJ JJJ ELSE ;Action n3 EN%IF
Aou can also replace ELSIF *ith ELSE IF /ut "our program *ill ta@e longer to *rite. 2f course3 "ou *ill have to end the loop *ith as man" instance of EN%IF as IF. 1f "ou *ant to ma@e multiple conditions in "our program3 *e advise "ou to use ELSIF rather than ELSE IF for this reason.
2% > '6
E!ample: detection of /earish and /ullish engulfing lines using the 5lsif instruction This indicator displa"s 1 if a /ullish engulfing line is detected3 +1 if a /earish engulfing line is detected3 and % if neither of them is detected. EE%etection o) a +ullish en(ul)in( line Condition2 / Close527 LOpen527 Condition: / OpenLClose527 Condition= / Close8Open527 ConditionC / OpenL Close
EE%etection o) a +earish en(ul)in( line ConditionG / Close5278Open527 ConditionI / CloseL Open ConditionB / Open8Close527 Condition> / CloseLOpen527
IF Condition2 AN% Condition: AN% Condition= AN% ConditionC T'EN a/2 ELSIF ConditionG AN% ConditionI AN% ConditionB AN% Condition> T'EN a/<2 ELSE a/9 EN%IF $ET&$N a E!ample: :esistance !emar@s pivot IF %close;23 8 %open;23 T'EN Phi(h / %hi(h;23 6 ;%close;23 < %lo,;233 E : Plo, / ;%close;23 6 %lo,;233E: ELSIF %close;23 L %open;23 T'EN Phi(h / ;%hi(h;23 6 %close;233 E : Plo, / %lo,;23 < ;%hi(h;23 < %close;233E: ELSE Phi(h / %close;23 6 ;%hi(h;23 < %lo,;233 E : Plo, / %close;23 < ;%hi(h;23 < %lo,;233 E : EN%IF $ET&$N Phi(h K Plo,
21 > '6
E!ample : Bar1nde, 1n the chapter 1 of our manual3 *e presented BarInde! as a counter of /ars loaded. BarInde! is often used *ith IF. For e,ample3 if *e *ant to @no* if the num/er of /ars in "our chart e,ceeds 2$ /ars3 then *e *ill *rite? IF BarInde! L/ := T'EN a/ 9 ELSIF BarInde! 8 := T'EN a/2 EN%IF $ET&$N a
22 > '6
E!ample: Smoothing of a 12+period moving average 7etGs create a storage varia/le 4:esult) *hich *ill sum the 113 12 and 1$+period moving averages. $esult/9 FO$ Period / 22 TO 2= %O $esult/ A*era(e5Period7;Close3 6 $esult NE1T $EM LetMs create a stora(e *aria+le ;A*era(e$esult3 ,hich ,ill di*ide $esult +# = and displa# a*era(e resultJ A*ear(e result is a smoothin( o) the 2:<period mo*in( a*era(eJ A*era(e$esult / $esultE= $eturn A*era(e$esult
7etGs see step /" step ho* the program does the calculation? 9athematicall"3 *e *ant to calculate the average of the moving averages calculated on 113 12 and 1$ periods. Period *ill then get successivel" the values 113 12 and 1$ 4F2: al*a"s *or@s *ith *hole num/ers onl"). :esult J % <hen Period J 11 ? The ne* :esult J the 11 + period moving average M the previous value of result 4%). The counter receives its ne,t value <hen Period J 12 ? The ne* :esult J the 12 + period moving average M the previous value of result. The counter receives its ne,t value <hen Period J 1$ ? The ne* :esult J the 1$ + period moving average M the previous value of result. 1$ is the last value of the counter. <e end the HFO$I loop *ith the HNE1TI instruction. <e then displa" Average:esult
To sum it up3 varia/le *ill3 first of all3 get the /eginning value of the series3 then varia/le *ill receive the ne,t one 4the last one M 1) and so on until the ver" last value of the series. To finish3 *e end the loop.
2$ > '6
E!ample: Average of the highest price over the 2% last /ars MAhi(h/9 S&Mhi(h/9 IF BarInde! L :9 T'EN MAhi(h / &nde)ined 1f there are not "et 2% periods displa"ed Then *e attri/ute to 9Ahigh value F(ndefinedF 4not displa"ed) ELSE FO$ i / 9 TO :9 %O 57S5 F2: values of i /et*een 1 to 2%
S&Mhi(h / 'i(h5i76S&Mhi(h <e sum the 2% last F)1ghF values NE1T EN%IF MAhi(h / S&Mhi(hE:9 <e calculate the average for the last 2% periods and store the result in 9Ahigh $ET&$N MAhi(h <e displa" 9Ahigh
To ma@e a descending loop3 *e use? FO$3 %O-NTO3 %O3 NE1T. 1ts s"nta, is? FO$ ; aria+le / Endin( alueO)TheSeries3 %O-NTO Be(innin( alueO)TheSeries %O ;Action3 NE1T
7et us go /ac@ to the previous e,ample 4the 2%+period moving average of F)ighF) ? <e can notice that *e have Cust inverted the e,tremities of the scanned interval. MAhi(h/9 S&Mhi(h/9 IF BarInde! / 9 T'EN MAhi(h / &nde)ined ELSE FO$ i / :9 %O-NTO 2 %O S&Mhi(h / 'i(h5i76S&Mhi(h NE1T EN%IF MAhi(h / S&Mhi(hE:9 $ET&$N MAhi(h
E!ample: indicator calculating the num/er of consecutive increases Increase / ;Close 8 Close5273 Count / 9 -'ILE Increase5Count7 %O Count / Count 6 2 -EN% $ET&$N Count
(eneral comment on the conditional instruction WHILE )imilarl" to IF% the program *ill not process the conditional loop if the condition is unkno*n# For e!ample: Count / 9 -'ILE i L8 22 %O i/i62 Count / Count 6 2 -EN% $ET&$N Count
The -'ILE instruction does not recogniEe the value of i. Therefore3 it cannot test *hether i is e8ual to 1% or not and the loop *ill not /e processed3 hence the count is e8ual to %. The correct code *ould /e? i/9 Count / 9 -'ILE i L8 22 %O i/i62 Count / Count 6 2 -EN% $ET&$N Count
1n this code3 i is initialiEed. The loop *ill then *or@ correctl" since the condition for /eginning the loop is valid.
C3 B$EAO
The B$EAO instruction allo*s "ou to ma@e a forced e,it out of a -'ILE loop or a FO$ loop. 0om/inations are possi/le *ith the IF command3 inside a -'ILE loop or a FO$ loop.
aJ -ith -'ILE
<hen *e tr" to get out of a conditional -'ILE loop *ithout *aiting for a situation *here the condition is not valid3 *e use B$EAO. 1ts s"nta, is? -'ILE ;Condition3 %O ;Action3 B$EAO -EN%
26 > '6
7etGs ta@e for e,ample an indicator sho*ing increases of the price? $EM Trend indicator: indicates increases $EM -hen the indicator is e0ual to 2 then an increase is detectedK elseK the indicator is e0ual to 9J Increase / ;Close 4 Close527389 Indicator / 9 i/9 -'ILE Increase5i7 %O Indicator / Indicator 6 2 i/i62 B$EAO -EN% $ET&$N Indicator 1n this code3 if B$EAO *asnGt used3 the loop *ould have resumed and the result *ould /e another trend indicator *hich *ould have cumulated increases.
+J -ith FO$
<hen *e tr" to get out of an iterative FO$ loop3 *ithout reaching the last 4or first) value of the series3 *e use B$EAO. FO$ ; aria+le / Be(innin( alueO)TheSeries3 TO Endin( alueO)TheSeries %O ;Action3 B$EAO NE1T 7etGs ta@e for e,ample an indicator cumulating increases of the volume of the last 1# periods. This indicator *ill /e e8ual to % if the volume decreases. Count / 9 FO$ i / 9 TO 2? %O IF ; olume5i78 olume5i6273 T'EN Count / Count 6 2 ELSE B$EAO EN%IF NE1T $ET&$N Count 1n this code3 if B$EAO *erenGt used3 the loop *ould have continued until 1# 4last element of the series) even if the condition count is not valid. )o*ever3 *ith B$EAO3 as soon as the condition is valid3 the result /ecomes %.
27 > '6
G3 CONTIN&E
The CONTIN&E instruction allo*s "ou to resume the program reader at the line *here -'ILE or FO$ is *ritten3 thus *ithout restarting completel" the loop 4an" incremented counter *ill thus @eep its value and not /e reset to %). This command is often used *ith B$EAO3 either to leave the loop 4B$EAO) or to sta" in the loop 4CONTIN&E).
aJ -ith -'ILE
7etGs create a program counting the num/er of candlestic@s *hose close and open are greater than those of the candlestic@ preceding them. 1f the condition is not valid3 then the counter *ill /e reset to %. Increase / Close 8 Close527 Count/9 -'ILE OpenLOpen527 %O IF Increase5Count7 T'EN Count / Count 6 2 CONTIN&E EN%IF B$EAO -EN% $ET&$N Count <hen using CONTIN&E3 if the IF condition is not valid3 then the -'ILE loop is not ended. This allo*s us to count the num/er of patterns detected *ith this condition. <ithout the CONTIN&E instruction3 the program *ould leave the loop3 even if the IF condition is validated. Then3 *e *ould not /e a/le to continue counting the num/er of patterns detected and the result *ould /e /inar" 413 %).
+J -ith FO$
7etGs create a program counting the num/er of candlestic@s *hose close and open are greater than those of the candlestic@ preceding them. 1f the condition is not valid3 then the counter *ill /e reset to %. Increase / Close 8 Close527 Count/9 FO$ i / 2 TO BarInde! %O IF Increase5Count7 T'EN Count / Count 6 2 CONTIN&E EN%IF B$EAO NE1T $ET&$N Count
2 > '6
FO$ gives "ou the possi/ilit" to test the condition over all the data loaded. <hen used *ith CONTIN&E3 if the IF condition is validated3 then *e do not leave the FO$ loop and resume it *ith the ne,t value of i. This is ho* *e count the num/er of patterns detected /" this condition. <ithout CONTIN&E3 the program *ould leave the loop3 even if the IF condition is validated. Then3 *e *ould not /e a/le to count the num/er of patterns detected and the result *ould /e /inar" 413 %).
I3 ONCE
The ONCE instruction is used to initialiEe a varia/le at a certain value Fonl# ONE TIMEF. =no*ing that for the *hole program3 the language *ill read the code for each /ar displa"ed on the chart /efore returning the result3 "ou must then @eep in mind that ONCE ? 1s processed onl" one time /" the program including the second reading. !uring the second reading of the program3 it *ill stoc@ the values calculated in the previous reading.
To )ull# understand ho, this command ,orAsK #ou need to percei*e ho, the lan(ua(e processes the codeK hence the use)ulness o) the ne!t e!ampleJ
These are t*o programs returning respectivel" % and 1' and *hich onl" difference is the ONCE command added? Pro(ram 2 71 Count / 9 72 i/9 7$ IF iL/G T'EN 7& 7' 76 EN%IF 77 $ET&$N Count Count / Count 6 i i/i62 71 ONCE Count / 9 72 ONCE i/9 7$ IF iL/G T'EN 7& 7' 76 EN%IF 77 $ET&$N Count Count / Count 6 i i/i62 Pro(ram :
LetMs see ho, the lan(ua(e read the codeJ Pro(ram 2 : For the first /ar3 the language *ill read line 1 471? 0ount J %K i J %)3 then 723 7$3 7&3 7' and 76 40ount J %K i J 1). For the ne,t /ar3 the program starts at the /eginning and /oth i and count are set to %3 so count *ill al*a"s return % for ever" /ar. Pro(ram : : For the first /ar3 the language *ill read 71 40ount J %K i J %)3 then 723 7$3 7&3 7'3 76 40ount J %K i J 1). <hen it arrives at the line F$ET&$NF3 it restarts the loop to calculate the value of the ne,t /ar starting from 7$ 4the lines ,ith ONCE are processed onl# one time )3 7&3 7'3 76 40ount J 1K i J 2)3 then go /ac@ again 40ount J $K i J $) and so forth to 40ount J 1'K i J 6). Arrived at this result3 the IF loop is not processed an"more /ecause the condition is not valid an"moreK the onl" line left to read is 773 hence the result is 1' for the remaining /ars loaded.
2# > '6
Mathematical Functions
23 Common &nar# and Binar# Functions
7etGs focus no* on the 9athematical Functions. Aou *ill find in ProBuilder the main functions @no*n in mathematics. Please note that a and / are e,amples and can /e num/ers or an" other varia/le in "our program. MIN4a3 /) ? calculate the minimum of a and / MA14a3 /) ? calculate the ma,imum of a and / $O&N%4a) ? round a to the nearest *hole num/er ABS4a) ? calculate the a/solute value of a S"N4a) ? sho*s the sign of a 41 if positive3 +1 if negative) SP&A$E4a) ? calculate a s8uared SP$T4a) ? calculate the s8uare root of a LO"4a) ? calculate the 6eperian logarithm of a E1P4a) ? calculate the e,ponent of a COS4a) ? calculate the cosine of a SIN4a) ? calculate the sine of a TAN4a) ? calculate the tangent of a ATAN4a) ? calculate the arc+tangent of a 7etGs code the e,ample of the normal distri/ution in mathematics. 1tGs interesting /ecause it use the s8uare function3 the s8uare root function and the e,ponential function at the same time? $EM Normal La, applied to ! / 29K Standard%e*iation / I and MathE!pectation / > $EM LetMs de)ine the )ollo,in( *aria+les in the *aria+le option: Standard%e*iation / I MathE!pectation / > ! / 29 Indicator/E1P;;2E:3F;SP&A$E;!4MathE!pectation3EStandard%e*iation33E;Standard%e*iationFSP$T;:E=J2C33 $ET&$N Indicator
$% > '6
C3 Summation Functions
Cumsum : 0alculates the sum of a price or indicator over all /ars loaded on the chart The s"nta, of Cumsum is? Cumsum ;price or indicator3 5, ? 0umsum40lose) calculates the sum of the close of all the /ars loaded on the chart. Summation : 0alculates the sum of a price or indicator over the last n /ars The sum is calculated starting from the most recent value 4from right to left) The s"nta, of Summation is? Summation5num+er o) +ars7;price or indicator3 5,? SummationN2%O42pen) calculates the sum of the open of the last 2% /ars.
G3 Statistical Functions
The s"nta, of all these functions is the same as the s"nta, for the Summation function3 that is? Lo,est5num+er o) +ars7;price or indicator3 Lo,est : displa"s the lo*est value of the price or indicator *ritten /et*een /rac@ets3 over the num/er of periods defined 'i(hest : displa"s the highest value of the price or indicator *ritten /et*een /rac@ets3 over the num/er of periods defined ST% : displa"s the standard deviation of a price or indicator3 over the num/er of periods defined STE : displa"s the standard error of a price or indicator3 over the num/er of periods defined
$1 > '6
Lo(ical Operators
As an" programming language3 it is necessar" to have at our disposal some 7ogical 2perators to create relevant indicators. These are the & 7ogical 2perators of ProBuilder? NOT4a) ? logical 62 a O$ / ? logical 2: a AN% / ? logical A6! a 1O$ / ? e,clusive 2:
Calculation o) the trend indicator: On Balance olume ;OB 3 : IF NOT;;Close 8 Close5273 O$ ;Close / Close52733 T'EN M#OB / M#OB 4 olume ELSE M#OB / M#OB 6 olume EN%IF $ET&$N M#OB
ProBuilder Instructions
$ET&$N : displa"s the result CustomClose : displa"s a customiEa/le price valueK /" default3 this price is F0loseF CALL : calls another ProBuilder indicator to use in "our current program AS : names the result displa"ed COLO&$E% : colors the displa"ed curve in *ith the color of "our choice
23 $ET&$N
<e have alread" seen in chapter 1 ho* important the $ET&$N instruction *as. 1t has some specific properties *e need to @no* to avoid programming errors. The main points to @eep in mind *hen using $ET&$N in order to *rite a program correctl" are that :eturn is used? 2ne and onl" one time in each ProBuilder program Al*a"s at the last line of code 2ptionall" *ith other functions such as AS and 0272(:5! To displa" man" resultsK *e *rite :5T(:6 follo*ed *ith *hat *e *ant to displa" and separated *ith a comma 4e,ample ? :5T(:6 a3/)
$2 > '6
:3 $EM or EE
$EM allo*s "ou to *rite remar@s or comments inside the code. The" are mainl" useful to remem/er ho* a function "ou coded *or@s. These remar@s *ill /e read /ut of course not processed /" the program. 7etGs illustrate the concept *ith the follo*ing e,ample ?
$EM This pro(ram returns the simple mo*in( a*era(e o*er :9 periods applied to the closin( price $ET&$N A*era(e5:97;Close3
!onSt use special characters 4e,amples? T3U3V3WL) in ProBuilder3 even in the $EM section
=3 CustomClose
CustomClose is a term allo*ing "ou to displa" the terms Close3 Open3 'i(h3 Lo, and man" others3 *hich can /e customiEed in the Settings *indo* of the indicator. 1ts s"nta, is the same as the one of the terms adapted to the timeframe of the chart? CustomClose5n7 5,ample? EE %ispla#s the a*era(e o*er :9 periods applied to CustomClose $ET&$N A*era(e5:97;CustomClose3 B" clic@ing on the *rench in the upper left corner of the chart3 "ou *ill see that it is possi/le to customiEe the prices used in the calculation 4on the diagram3 circled in /lue).
$$ > '6
C3 CALL
CALL allo*s "ou to use a personal indicator "ou have coded /efore in the platform. The 8uic@est method is to clic@ H1nsert FunctionI then select the F(ser 1ndicatorsF categor" and then select the name of the indicator "ou *ant to use and clic@ FAddF. For e,ample3 imagine "ou have coded the )istogram 9A0! and named it )isto9A0!. Select "our indicator and clic@ on FAddF. Aou *ill see in the programming Eone? m#'istoMAC% / CALL 'istoMAC%
The soft*are gave the name Fm")isto9A0!F to the indicator F)isto9A0!F. This means that for the rest of "our program3 if "ou *ant to use the )isto9A0! indicator3 "ou *ill have to call it Fm")isto9A0!F.
G3 AS
The @e"*ord AS allo*s "ou to name the different results displa"ed. This instruction is used *ith $ET&$N and its s"nta, is? $ET&$N $esult2 AS .Cur*e Name.K $esult: AS .Cur*e Name.K N
The advantage of this command is that it ma@es it easier to identif" the different curves on "our chart.
5,ample? a / E!ponentialA*era(e5:997;Close3 + / -ei(htedA*era(e5:997;Close3 c / A*era(e5:997;Close3 $ET&$N a AS .E!ponential A*era(e. K + AS .-ei(hted A*era(e. K c AS .Arithmetical A*era(e.
I3 COLO&$E%
COLO&$E% is used after the $ET&$N command to color the curve displa"ed *ith the color of "our choice3 defined *ith the :BB norm 4red3 green3 /lue). These are the main colors of this norm?
Color
$"B alue ;redK (reenK +lue3 4%3 %3 %) 42''3 2''3 2'') 42''3 %3 %) 4%3 2''3 %) 4%3 %3 2'') 42''3 2''3 %) 4%3 2''3 2'') 42''3 %3 2'')
The s"nta, of the 0oloured command is? $ET&$N Indicator COLO&$E%;$edK "reenK Blue3
The AS command can /e associated *ith the COLO&$E%4. 3 . 3 .) command. This association must /e used in this order? $ET&$N Indicator COLO&$E%;$edK "reenK Blue3 AS .Name O) The Cur*e.
7etGs go /ac@ to the previous e,ample and insert COLO&$E% in the F$ET&$NF line. a / E!ponentialA*era(e5:997;Close3 + / -ei(htedA*era(e5:997;Close3 c / A*era(e5:997;Close3 $ET&$N a COLO&$E%;:GGK9K93 AS .E!ponential Mo*in( A*era(e. K + COLO&$E%;9K:GGK93 AS .-ei(hted Mo*in( A*era(e. K c COLO&$E%;9K 9K :GG3 AS .Simple Mo*in( A*era(e.
$6 > '6
$7 > '6
Note: *e ha!e displa"ed the exponential mo!ing a!erage o!er 1+ and ,+ periods both applied to the close in order to highlight the results of the indicator# -ou can find other candlestick pattern indicators starting on page .&#
<ith the /ac@testing module ProBac@Test3 *hich is the su/Cect of another programming manual3 "ou can also define the stop levels of a /ac@test. )o*ever3 programming a stop as an indicator is interesting /ecause? 1t allo*s to visualiEe the stop as a line *hich updates in real+time on the chart 4e,? trailing stop) 1t is possi/le to place real+time alerts to /e immediatel" informed of the situation 1t is not necessar" to create long or short orders 4contrar" to ProBac@Test)
Programming Stops is also a means to master the commands "ou sa* in the previous chapters.
$ > '6
These are the & categories of stop *e *ill focus on? StaticTaAe Pro)it STOP Static STOP Loss Inacti*it# STOP Trailin( STOP ;trailin( stop loss or trailin( taAe pro)it3 The indicators presented in the follo*ing e,amples are possi/le codes to create stop indicators. Aou *ill most pro/a/l" personaliEe them using the instructions "ou learned in the previous chapters.
EE-e de)ine in the *aria+le option: EEStartin(Time / 299999 ;this is an e!ample )or 29 amQ set this to the time #ou entered #our position3 EEPrice/ Price ,hen #ou tooA #our position EE@ou can looA at StopLON" i) looAin( at a lon( position and StopShort i) #ou are looAin( at a short positionJ @ou can also remo*e StopLON" or StopS'O$T i) #ou onl# ,orA ,ith lon( positions or onl# ,orA ,ith short positionsJ EEAmplitude&p represents the *ariation rate o) Price used to dra, the TaAe Pro)it )or lon( position ;de)ault: 2J23 EEAmplitude%o,n represents the *ariation rate o) Price used to dra, the TaAe Pro)it )or short position ;de)ault: 9J?3 IF Time / Startin(Time T'EN StopLON" / Amplitude&pFPrice StopS'O$T / Amplitude%o,nFPrice EN%IF $ET&$N StopLON" COLO&$E%;9K9K93 AS .TaAePro)it LON" 29D. K StopS'O$T COLO&$E%;9K:GGK93 AS .TaAePro)it S'O$T 29D.
$# > '6
The code of this indicator is? EE-e de)ine in the *aria+le option: EEStartin(Time / 299999 ;this is an e!ample )or 29 amQ set this to the time #ou entered #our position3 EEPrice/ Price ,hen #ou tooA #our position EE @ou can looA at StopLON" i) looAin( at a lon( position and StopShort i) #ou are looAin( at a short positionJ @ou can also remo*e StopLON" or StopS'O$T i) #ou onl# ,orA ,ith lon( positions or onl# ,orA ,ith short positionsJ EEAmplitude&p represents the *ariation rate o) Price used to dra, the Stop Loss )or short position ;de)ault: 9J?3 EEAmplitude%o,n represents the *ariation rate o) Price used to dra, the Tsop Loss )or lon( position ;de)ault: 2J23 IF Time / Startin(Time T'EN StopLON" / Amplitude&pFPrice StopS'O$T / Amplitude%o,n FPrice EN%IF $ET&$N StopLON" COLO&$E%;9K9K93 AS .StopLoss LON" 29D. K StopS'O$T COLO&$E%;9K:GGK93 AS .StopLoss S'O$T 29D.
=3 Inacti*it# STOP
An inactivit" ST2P closes the position *hen the gains have not o/tained a certain o/Cective 4defined in X or in points) over a certain period 4defined in num/er of /ars). :emem/er to define the varia/les in the F.aria/lesF section. 5,ample of 1nactivit" Stop on 1ntrada" 0harts? This stop must /e used *ith those t*o indicators? The first indicator Cu,taposed to the curve of the price The second indicator must /e displa"ed in a separated chart
Indicator2 EE-e de)ine in the *aria+le option: EEM# olatilit# / 9J92 represents *ariation rate +et,een the each part o) the ran(e and the close IF Intrada#BarInde! / 9 T'EN ShortTar(et / ;2<M# olatilit#3FClose Lon(Tar(et / ;26M# olatilit#3FClose EN%IF $ET&$N ShortTar(et AS .ShortTar(et.K Lon(Tar(et AS .Lon(Tar(et.
Indicator: EE-e de)ine in the *aria+le option: $EM -e supposed that #ou taAe an .On MarAet Price. position EEM# olatilit# / 9J92 represents *ariation rate +et,een the each part o) the ran(e and the close EENum+erO)Bars/:9 : the close can )luctuate ,ithin the ran(e de)ined durin( a ma!imum o) Num+erO)Bars +e)ore the position is cut ;$esult / 23 $esult / 9 Cpt/9 IF Intrada#BarInde! / 9 T'EN ShortTar(et / ;2<M# olatilit#3FClose Lon(Tar(et / ;26M# olatilit#3FClose EN%IF FO$ i/Intrada#BarInde! %O-NTO 2 %O IF Close5i78/ShortTar(et AN% Close5i7L/Lon(Tar(et T'EN Cpt/Cpt62 ELSE Cpt/9 EN%IF IF Cpt / Num+erO)Bars T'EN $esult / 2 EN%IF NE1T $ET&$N $esult
C3 Trailin( Stop
A trailing )/21 follo*s the evolution of the price d"namicall" and indicates *hen to close a position. <e suggest "ou t*o *a"s to code the trailing ST2P3 the first one representing a !"namic Trailing Stop 7oss3 and the other one a !"namic Trailing Ta@e Profit.
%#namic Trailin( STOP LOSS ;to +e used in intrada# tradin(3 EE%e)ine the )ollo,in( *aria+les in the *aria+le section: EEStartin(Time / 9?9999 ;this is an e!ample )or ? amQ set this to the time #ou entered #our position3 $EM -e supposed that #ou taAe an .On MarAet Price. position EEAmplitude represents the *ariation rate o) the .Cut. cur*e compared to the .Lo,est. cur*es ;)or e!ampleK ,e can taAe Amplitude / 9J?G3 IF Time / Startin(Time T'EN IF Lo,est5G7;Close3L2J:FLo, T'EN IF Lo,est5G7;Close3 8/ Close T'EN Cut / AmplitudeFLo,est5G7;Close3 ELSE Cut / AmplitudeFLo,est5:97;Close3 EN%IF ELSE Cut / AmplitudeFLo,est5:97;Close3 EN%IF EN%IF $ET&$N Cut AS .Trailin( Stop Loss.
%#namic Trailin( STOP Pro)it ;to +e used in intrada# tradin(3 EE%e)ine the )ollo,in( *aria+les in the *aria+le section: EEStartin(Time / 9?9999 ;this is an e!ample )or ? amQ set this to the time #ou entered #our position3 $EM @ou taAe an ROn MarAet PriceS position EEAmplitude represents the *ariation rate o) the .Cut. cur*e compared to the .Lo,est. cur*es ;)or e!ampleK ,e can taAe Amplitude / 2J92G3 IF Time / Startin(Time T'EN Startin(Price / Close EN%IF Price / Startin(Price < A*era(eTrue$an(e5297 Trailin(Stop / AmplitudeF'i(hest52G7;Price3 $ET&$N Trailin(Stop COLO&$E% ;:GGK 9K 93 AS .Trailin( taAe pro)it.
Chapter I
: E!ercises
C'APTE$ I : E1E$CISES
CandlesticAs patterns "AP &P or %O-N
A gap is defined /" these t*o conditions? 4the current lo* is strictl" greater than the high of the previous /ar) or 4the current high is strictl" lesser than the lo* of the previous /ar) the a/solute value of 44the current lo* Q the high of the previous /ar)>the high of the previous /ar) is strictl" greater than amplitude) or 44the current high Q the lo* of the previous /ar)>the lo* of the previous /ar) is strictl" greater than amplitude)
Chapter I
: E!ercises
EEInitialiTation o) Amplitude Amplitude / 9J992 EEInitialiTation o) detector %etector / 9 EE"ap &p EE2st condition o) the e!istence o) a (ap IF Lo, 8 'i(h527 T'EN EE:nd condition o) the e!istence o) a (ap IF ABS;;Lo, < 'i(h5273E'i(h5273 8 Amplitude T'EN EEBeha*ior o) the detector %etector / 2 EN%IF EN%IF EE"ap %o,n EE2st condition o) the e!istence o) a (ap IF hi(h L lo,527 T'EN EE:nd condition o) the e!istence o) a (ap IF ABS;;'i(h < Lo,5273ELo,5273 8 Amplitude T'EN EEBeha*ior o) the detector %etector / <2 EN%IF EN%IF EE$esult displa# $ET&$N %etector AS ."ap detection.
Chapter I
: E!ercises
1n this code3 *e define a doCi to /e a candlestic@ *ith a range 4)igh Q 0lose) is greater than ' times the a/solute value of 42pen Q 0lose).
Chapter I
: E!ercises
ELLIOT -A E OSCILLATO$
The 5lliot *ave oscillator sho*s the difference /et*een t*o moving averages. Parameters? a? short 9A periods 4' /" default) /? long 9A periods 4$' /" default) This oscillator permits to distinguish /et*een *ave $ and *ave ' using elliot *ave theor". The short 9A sho*s short+term price action *hereas the long 9A sho*s the longer term trend. <hen the prices form *ave $3 the prices clim/ strongl" *hich sho*s a high value of the 5lliot <ave 2scillator. 1n *ave '3 the prices clim/ more slo*l"3 and the oscillator *ill sho* a lo*er value. $ET&$N A*era(e5G7;MedianPrice3 < A*era(e5=G7;MedianPrice3 AS .Elliot -a*e Oscillator.
Chapter I
: E!ercises
-illiams D$
This is an indicator ver" similar to the Stochastic oscillator. To dra* it3 *e define 2 curves? 1) The curve of the highest of high over 1& periods 2) The curve of the lo*est of lo* over 1& periods The X: curve is defined /" this formula? 40lose Q 7o*est 7o* ) > 4)ighest )igh Q 7o*est 7o*) Y 1%%
'i(hest' / 'i(hest52C7;'i(h3 Lo,estL / Lo,est52C7;Lo,3 M#-illiams / ;Close 4 Lo,estL 3 E ; 'i(hest' 4 Lo,estL 3F 299 $ET&$N M#-illiams AS .-illiams D$.
Bollin(er Bands
The middle /and is a simple 2%+period moving average applied to close. The upper /and is the middle /and plus 2 times the standard deviation over 2% periods applied to close. The lo*er /and is the middle /and minus 2 times the standard deviation over 2% periods applied to close.
a / A*era(e5:97;Close3 EE-e de)ine the standard de*iationJ Std%e*iation / ST%5:97;Close3 Bsup / a 6 : F Std%e*iation Bin) / a < : F Std%e*iation $ET&$N a AS .A*era(e.K Bsup AS .Bollin(er &p. K Bin) AS .Bollin(er %o,n.
"lossar#
"LOSSA$@
A
CO%E A+s Accum%istr A%1 A%1$ AN% Aroon%o,n Aroon&p Atan AS A*era(e A*era(eTrue$an(e S@NTA1 A/s4a) Accum!istr4close) A!;N6O A!;:N6O a A6! / Aroon!o*nN6O Aroon(pN6O Atan4a) :5T(:6 :esult AS F:esult6ameF AverageN6O4price) AverageTrue:angeN6O4price) F&NCTION 9athematical function FA/solute .alueF of a 0lassical Accumulation>!istri/ution indicator 1ndicator Average !irectional 1nde, or FA!;F of n periods 1ndicator Average !irectional 1nde, :ate or FA!;:F of n periods 7ogical A6! 2perator Aroon !o*n indicator of n periods Aroon (p indicator of n periods mathematical function FArctangentF of a 1nstruction used to name a line or indicator displa"ed on chart. (sed *ith F:5T(:6F Simple 9oving Average of n periods FAverage True :angeF + True :ange smoothed *ith the <ilder method
B
CO%E BarInde! Bollin(erBand-idth Bollin(er%o,n Bollin(er&p B$EAO S@NTA1 Bar1nde, BollingerBand<idthN6O4price) Bollinger!o*nN6O4price) Bollinger(pN6O4price) 4F2:...!2...B:5A=...65;T) or 4<)175...!2...B:5A=...<56!) F&NCTION counts ho* man" /ars are displa"ed on all the data loaded Bollinger Band*idth indicator 7o*er Bollinger /and (pper Bollinger /and 1nstruction forcing the e,it of F2: loop or <)175 loop
"lossar#
C
CO%E CALL CCI ChaiAinOsc Chandle ChandeOrollStop&p ChandeOrollStop%o,n Close COLO&$E% COS Crosses O*er Crosses &nder C&MS&M Current%a#O)-eeA Current'our CurrentMinute CurrentMonth CurrentSecond CurrentTime Current@ear CustomClose C#cle S@NTA1 m":esult J 0A77 m"Function 001N6O4price) or 001N6O 0hai@in2scN0h13 0h2O4price) 0handleN6O4price) 0hande=rollStop(pNPp3 Z83 ;O 0hande=rollStop!o*nNPp3 Z83 ;O 0loseN6O :5T(:6 :esult 0272(:5!4:3B3B) 02S4a) a 0rosses 2ver / a 0rosses (nder / 0(9S(94price) 0urrent!a"2f<ee@ 0urrent)our 0urrent9inute 0urrent9onth 0urrentSecond 0urrentTime 0urrentAear 0ustom0loseN6O 0"cle4price) F&NCTION 0alls a user indicator to /e used in the program "ou are coding 0ommodit" 0hannel 1nde, indicator 0hai@in oscillator 0hande 9omentum 2scillator 0hande and =roll Protection Stop on long positions 0hande and =roll Protection Stop on short positions 0losing price of the current /ar or of the n+th last /ar 0olors a curve *ith the color "ou defined using the :BB convention 0osine Function Boolean 2perator chec@ing *hether a curve has crossed over another one Boolean 2perator chec@ing *hether a curve has crossed under another one Sums a certain price on the *hole data loaded :epresents the current da" of the *ee@ :epresents the current hour :epresents the current minute :epresents the current month :epresents the current second :epresents the current time 4))99SS) :epresents the current "ear Term customiEa/le in the settings *indo* of the chart 4default? 0lose) 0"cle 1ndicator
"lossar#
%
CO%E %ate %a# %a#s %a#O)-eeA %close %EMA %hi(h %I %Iminus %iplus %lo, %O %open %O-NTO %PO S@NTA1 !ateN6O !a"N6O !a"sN6O !a"2f<ee@N6O !close46) !59AN6O4price) !high46) !1N6O4price) !iminusN6O4price) !iplusN6O4price) !lo*46) See F2: and <)175 !open46) See F2: !P2N6O4price) F&NCTION :eports the date of each /ar loaded on the chart :eports the da" of each /ar loaded in the chart 0ounter of da"s since 1#%% !a" of the *ee@ of each /ar 0lose of the n+th da" /efore the current one !ou/le 5,ponential 9oving Average )igh of the n+th /ar /efore the current /ar :epresents !1M minus !1+ :epresents the !1+ indicator :epresents the !1M indicator 7o* of the n+th da" /efore the current one 2ptional instruction in F2: loop and <)175 loop to define the loop action 2pen of the n+th da" /efore the current one 1nstruction used in F2: loop to process the loop *ith a descending order !etrented Price 2scillator
E
CO%E EaseO)Mo*ement ELSE ELSEIF EM EN%IF EndPointA*era(e E!p E!ponentialA*era(e S@NTA1 5ase2f9ovementN1O See 1F>T)56>57S5>56!1F See 1F>T)56>57S1F>57S5>56!1F 59.N6O See 1F>T)56>57S5>56!1F 5ndPointAverageN6O4price) 5,p4a) 5,ponentialAverageN6O 4price) F&NCTION 5ase of 9ovement indicator 1nstruction used to call the second condition of 1f+conditional statements Stands for 5lse 1f 4to /e used inside of conditional loop) 5ase of 9ovement .alue indicator 5nding 1nstruction of 1F+conditional statement 5nd Point 9oving Average of a 9athematical Function F5,ponentialF 5,ponential 9oving Average
"lossar#
F<"
CO%E FO$ETOENE1T S@NTA1 F2: iJa T2 / !2 a 65;T F&NCTION F2: loop 4processes all the values *ith an ascending 4T2) or a descending order 4!2<6T2)) Force 1nde, indicator 4determines *ho controls the mar@et 4/u"er or seller)
ForceInde!
Force1nde,4price)
'
CO%E 'i(h 'i(hest 'istoric olatilit# 'our S@NTA1 )ighN6O )ighestN6O4price) )istoric.olatilit"N6O4price) )ourN6O F&NCTION )igh of the current /ar or of the n+th last /ar )ighest price over a num/er of /ars to /e defined )istoric .olatilit" 4or statistic volatilit") :epresents the hour of each /ar loaded in the chart
I<V<O
CO%E IFET'ENEEN%IF IFET'ENEELSEEEN%IF Intrada#BarInde! S@NTA1 1F a T)56 / 56!1F 1F a T)56 / 57S5 c 56!1F 1ntrada"Bar1nde,N6O F&NCTION Broup of conditional instructions *ithout second instruction Broup of conditional instructions 0ounts ho* man" /ars are displa"ed in one da" on the *hole data loaded
L
CO%E Linear$e(ression Linear$e(ressionSlope Lo( Lo, Lo,est S@NTA1 7inear:egressionN6O4price) 7inear:egressionSlopeN6O 4price) 7og4a) 7o*N6O 7o*estN6O4price) F&NCTION 7inear :egression inidcator Slope of the 7inear :egression inidcator 9athematical Function F6eperian logarithmF of a 7o* of the current /ar or of the n+th last /ar 7o*est price over a num/er of /ars to /e defined
"lossar#
M
CO%E MAC% MAC%line MassInde! Ma! MedianPrice Min Minute Mod Momentum Mone#Flo, Mone#Flo,Inde! Month S@NTA1 9A0!NS373SiO4price) 9A0!7ineNS37O4price) 9ass1nde,N6O 9a,4a3/) 9edianPrice 9in4a3/) 9inute a 9od / 9omentumN6O 9one"Flo*N6O4price) 9one"Flo*1nde,N6O 9onthN6O F&NCTION 9oving Average 0onvergence !ivergence 49A0!) in histogram 9A0! line indicator 9ass 1nde, 1ndicator applied over 6 /ars 9athematical Function F9a,imumF Average of the high and the lo* 9athematical Function F9inimumF :epresents the minute of each /ar loaded in the chart 9athematical Function Fremainder of the divisionF 9omentum indicator 4close Q close of the n+th last /ar) 9one"Flo* indicator 4result /et*een +1 and 1) 9one"Flo* 1nde, indicator :epresents the month of each /ar loaded in the chart
N
CO%E Ne!t Not S@NTA1 See F2:>T2>65;T 6ot A F&NCTION 5nding 1nstruction of F2: loop 7ogical 2perator 62T
O
CO%E OB ONCE Open OpenO)Ne!tBar O$ S@NTA1 2B.4price) 2605 .aria/le6ame J .aria/le.alue 2penN6O 2pen2f6e,tBarN6O a 2: / F&NCTION 2n+Balance+.olume indicator 1ntroduces a definition statement *hich *ill /e processed onl" once 2pen of the current /ar or of the n+th last /ar 2pen of the /ar follo*ing the n+th last /ar 7ogical 2perator 2:
"lossar#
P<P
CO%E PriceOscillator Positi*e olumeInde! P T S@NTA1 Price2scillatorNS37O4price) Price.olume1nde,4price) P.T4price) F&NCTION Percentage Price oscillator Positive .olume 1nde, indicator Price .olume Trend indicator
$
CO%E $: $an(e $EM $epulse $ET&$N $OC $SI $ound S@NTA1 :2N6O4price) :angeN6O :59 comment :epulseN6O4price) :5T(:6 :esult :20N6O4price) :S1N6O4price) :ound4a) F&NCTION :+S8uared indicator 4error rate of the linear regression on price) calculates the :ange 4)igh minus 7o*) 1ntroduces a remar@ 4non prise en compte dans le code mais facilitant une relecture) :epulse indicator 4measure the /u"ers and sellers force for each candlestic@) 1nstruction returning the result Price :ate of 0hange indicator :elative Strength 1nde, indicator 9athematical Function F:ound a to the nearest *hole num/erF
S
CO%E SA$ SA$atdm) Sin S(n SMI SmoothedStochastic S0uare S@NTA1 SA:NAt3St37imO SA:atdmfNAt3St37imO4price) Sin4a) Sgn4a) S91N63SS3!SO4price) SmoothedStochasticN63=O 4price) S8uare4a) F&NCTION Para/olic SA: indicator Smoothed Para/olic SA: indicator 9athematical Function FSineF 9athematical Function FSign ofF a 4it is positive or negative) Stochastic 9omentum 1nde, indicator Smoothed Stochastic 9athematical Function Fa S8uaredF
"lossar#
9athematical Function FS8uared :ootF of a Statistical Function FStandard !eviationF Statistical Function FStandard 5rrorF X= 7ine of the Stochastic indicator Sums a certain price over the 6 last candlestic@s Super Trend indicator
T
CO%E Tan TEMA T'EN Time TimeSeriesA*era(e TO Toda# TotalPrice T$ Trian(ularA*era(e T$I1 T#picalPrice S@NTA1 Tan4a) T59AN6O4price) See 1F>T)56>57S5>56!1F TimeN6O TimeSeriesAverageN6O4price) See F2:>T2>65;T Toda"N6O TotalPriceN6O T:4price) TriangularAverageN6O4price) T:1;N6O4price) T"picalPriceN6O F&NCTION 9athematical Function FTangentF of a Triple 5,ponential 9oving Average 1nstruction follo*ing the first condition of F1FF :epresents the time of each /ar loaded in the chart Temporal series moving average !irectional 1nstruction in the FF2:F loop !ate of the /ar n+periods /efore the current /ar 40lose M 2pen M )igh M 7o*)>& True :ange indicator Triangular 9oving Average Triple Smoothed 5,ponential 9oving Average :epresents the T"pical Price 4Average of the )igh3 7o* and 0lose)
&
CO%E &nde)ined S@NTA1 a J (ndefined F&NCTION Sets a the value of a varia/le to undefined
"lossar#
F&NCTION !ifference /et*een the close of the last /ar and the close of the current /ar in X 0hai@in volatilit" .olume indicator .olume 2scillator .olume of the Price :ate 2f 0hange
CO%E -ei(htedA*era(e -ei(htedClose -EN% -'ILEE%OE-EN% -ilderA*era(e -illiams -illiamsAccum%istr S@NTA1 <eightedAverageN6O4price) <eighted0loseN6O See <)175>!2><56! <)175 4condition) !2 4action) <56! <ilderAverageN6O4price) <illiamsN6O4close) <illiamsAccum!istr4price) F&NCTION :epresents the <eighted 9oving Average Average of 42Y0lose)3 41Y)igh) and 41Y7o*) 5nding 1nstruction of <)175 loop <)175 loop :epresents <ilder 9oving Average X: de <illiams indicator Accumulation>!istri/ution of <illiams 1ndicator
1
CO%E 1O$ S@NTA1 a ;2: / F&NCTION 7ogical 2perator e;clusive 2:
"lossar#
@
CO%E @ear @esterda# S@NTA1 AearN6O Aesterda"N6O F&NCTION Aear of the /ar n periods /efore the current /ar !ate of the da" preceeding the /ar n periods /efore the current /ar
W
CO%E Wi(Wa( Wi(Wa(Point S@NTA1 [ig[agN[rO4price) [ig[agPointN[pO4price) F&NCTION :epresents the [ig+[ag indicator introduced in the 5liott *aves theor" :epresents the [ig+[ag indicator in the 5liott *aves theor" calculated on [p points
Other
CO%E 6 < F E / L8 L 8 L/ 8/ EE F&NCTION Addition 2perator Su/straction 2perator 9ultiplication 2perator !ivision 2perator 58ualit" 2perator !ifference 2perator Strict 1nferiorit" 2perator Strict Superiorit" 2perator 1nferiorit" 2perator Superiorit" 2perator 1ntroduces a commentar" line