Array Programming
Forums › ProRealTime English forum › ProBuilder support › Array Programming
- This topic has 12 replies, 5 voices, and was last updated 3 years ago by Hasardeur.
-
-
01/18/2021 at 7:46 PM #158371Array programming / optimizing1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071IF barindex >= 2 thenPDmin= 8LBmax= 48 -1For LB= 0 to LBmax DOFor PD= LBmax DownTo PDmin DO$HP1[LB*LBmax+PD]= $HP1[(LB+1)*LBmax+PD]$HP2[LB*LBmax+PD]= $HP2[(LB+1)*LBmax+PD]$HP[LB*LBmax+PD]= $HP[(LB+1)*LBmax+PD]$BP1[LB*LBmax+PD]= $BP1[(LB+1)*LBmax+PD]$BP2[LB*LBmax+PD]= $BP2[(LB+1)*LBmax+PD]$BP[LB*LBmax+PD]= $BP[(LB+1)*LBmax+PD]$SS1[LB*LBmax+PD]= $SS1[(LB+1)*LBmax+PD]$SS2[LB*LBmax+PD]= $SS2[(LB+1)*LBmax+PD]$SS[LB*LBmax+PD]= $SS[(LB+1)*LBmax+PD]NEXTNEXTFor PD= PDmin to LBmax DOLB2= (LB-2)*LBmax+PDLB1= (LB-1)*LBmax+PDLB0= (LB-0)*LBmax+PDREM High Pass FilterHPPrice= close // WhiteNoise //ZerosHPPeriod= PD // (20)HPBandwidth= 0.3 // (0.1) 2013--> 0.3 (0.10-0.50)HPbeta= 0.25*HPBandwidth*360/HPPeriodHPalpha= (COS(HPbeta) + SIN(HPbeta)-1) / COS(HPbeta)//HP1= (1+HPalpha/2) * (HPPrice-HPPrice[1]) + (1-HPalpha)*HP1[1]$HP1[LB0]= (1+HPalpha/2) * (HPPrice-HPPrice[1]) + (1-HPalpha)*$HP1[LB1]$HP2[LB0]= (1+HPalpha/2) * ($HP1[LB*LBmax+PD]-$HP1[(LB-1)*LBmax+PD]) + (1-HPalpha)*$HP2[LB1]$HP[LB0]= 2*$HP1[LB0] - $HP2[LB0]REM BandPass FilterBPPeriod= PD // (20)BPBandwidth= HPBandwidth // 2013 => 0.3 (0.10-0.50)BPbeta= COS(360/BPPeriod)BPgamma= 1/COS(360*BPBandwidth/BPPeriod) // (720) 2013 => 360,BPalpha= BPgamma - SQRT(BPgamma*BPgamma-1)//BP1= 0.5*(1-BPalpha)*(HP1[0]-HP1[2]) + BPbeta*(1+BPalpha)*BP1[1] - BPalpha*BP1[2]$BP1[LB0]= 0.5*(1-BPalpha)*($HP[LB0]-$HP[LB2]) + BPbeta*(1+BPalpha)*$BP1[LB1] - BPalpha*$BP1[LB2]$BP2[LB0]= 0.5*(1-BPalpha)*($BP1[LB0]-$BP1[LB2]) + BPbeta*(1+BPalpha)*$BP2[LB1] - BPalpha*$BP2[LB2]$BP[LB0]= 2*$BP1[LB0] - $BP2[LB0]BP= $BP[LB0]REM super smoother filterSSPrice= $HP[LB0]SSPeriod= PDSSa1= exp(-1.414*3.14159/SSPeriod)SSb1= 2*SSa1*Cos(1.414*180/SSPeriod)SScoef2= SSb1SScoef3= -SSa1*SSa1SScoef1= 1-SScoef2-SScoef3//SS1= SScoef1*SSPrice + SScoef2*SS1[1] + SScoef3*SS1[2]$SS1[LB0]= SScoef1*SSPrice + SScoef2*$SS1[LB1] + SScoef3*$SS1[LB2]$SS2[LB0]= SScoef1*$SS1[LB0] + SScoef2*$SS2[LB1] + SScoef3*$SS2[LB2]$SS[LB0]= 2*$SS1[LB0] - $SS2[LB0]SS= $SS[LB0]Power= 0For LBP= 0 to PD-1 DOLBP0= LBP*LBmax+PDPower= Power + square($BP[LBP0]) + square($BP[LBP0+ROUND(PD/4)])NEXTNEXTENDIFreturn BP as "Band Pass", SS as "Super Smother Filter", Power as "Power"
Dear Nicolas,
I would like to ask you for an array programming support.
For each day a 2 pole bandpass filters shall be calculated for periods from PD= 8 to 48 (swami).
The Bandpass filter looks back 1 and 2 days “BP= ….. + ……. BP[1] + …….BP[2]“.
By using the normal programming, the BP[i] is always stored from the last calculated Period.
That is not correct for swami.
Correct would be for example:BP[0] at Period 3 has to be calculated as BP[0]= ….. + ……. BP[51] + …….BP[99]
BP[0] at Period 48 BP has to be calculated as BP[0]= ….. + ……. BP[96] + …….BP[144]
In order to calculate the Peak to Peak cycle amplitude wave the following loop is required:
1234Power= 0FOR count=0 to Period-1 DOPower= Power + square(BP[count]) + square(BP[count+ROUND(count/4)])NEXTFor this the array has to be designed for 48-1 look back days as follows (0 to 47=48 steps)
By the above the calculating time of my code is very very long (not practicable for using).
Do you have an idea for optimising the code in order to speed it up?
An adjustable PD calculation step (for example 2) could also be helpful to optimize the calculating time.Many thanks for your support in advance.
Best regards
Hasardeur01/18/2021 at 8:07 PM #15838101/18/2021 at 8:50 PM #15839301/18/2021 at 9:51 PM #15840201/18/2021 at 10:08 PM #158403Cutting and pasting from other websites often causes issues as well as trying to edit code that has already been inserted in the text box from within the text box.
You have five minutes to edit your post after hitting submit. If it looks like a total mess that will take a lot of work to correct then you are better to delete and start again. This save moderators an awful lot of work! 🙂
01/18/2021 at 11:10 PM #158412ok, understood. Next time i will not copy past and i have learned that there is a time slot of 5 minutes. Could you please say me how to enter the textbox within the 5 minutes after submitting. I have not found these function. Many thanks in advance.
01/19/2021 at 12:36 AM #15841801/19/2021 at 2:05 PM #158507Hello Hasardeur,
Did you try to replace this line :
1Power= Power + square(BP[count]) + square(BP[count+ROUND(count/4)])with your complete Indicator code ?
I know it will be “bad programming” like that, but you should at least test the speed one time because proceeding by impossible (?) means might not lead anywhere anyway. If the speed now suits you, you can proceed from there.How long does it take currently ? What do you want to achieve regarding “speed up” ? (2x faster etc. is an answer)
Can’t you use less wave cycles ? -> obviously not. … I suppose I now like to look into Swami (sorry to be unexperienced) – but not easy to find quickly in this context.
Peter
01/19/2021 at 3:56 PM #158521Sorry, i’m lost in your code. I’m not sure about the nested loops, are they mandatory in order to achieve your calculation?
A better way to code with arrays, and make it faster, is to calculate what you need at first read of history and store the value in an array with BARINDEX as column number.
Then, on the current bar, do your calculation included into an IsLastBarUpdate in order to fill your array with the results (result of the current bar or back in history).
Keep in mind that it is better to loop through arrays on the last bar only, than loop through candlesticks to fill an array on each bar. To be clear, you can make your code do what is needed, but in multiple steps.
01/21/2021 at 10:13 PM #158868HalloNicolas,hallo allmay thanks to for your assistance.Nicolas, do you have a sample foryouraboveexplanation.The lines of array organisation is enough, i will be able to fill it with the required code by my own. Hopefully.Many thanks for your replay in advanced.Best regardsHasardeur01/21/2021 at 10:45 PM #15886901/22/2021 at 10:29 AM #158891This is what I’m doing in this example: https://www.prorealcode.com/topic/array-variables-availability-in-prorealtime/#post-118817
While the chart history is loaded (at start of the code and then on each new bar created), I store fractals points into arrays, so that I can use that complete set of values but only when the current bar is updated (with IsLastBarUpdate).
1 user thanked author for this post.
01/22/2021 at 2:25 PM #158910 -
AuthorPosts
Find exclusive trading pro-tools on