Guest User

WAVEPM MT4 to PineScript

a guest
Feb 4th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. contact burner email: dcurafagget@gmail.com
  2.  
  3. #property indicator_separate_window
  4. #property indicator_buffers 6
  5. #property indicator_maximum 1
  6. #property indicator_minimum 0
  7. #property indicator_color5 Blue
  8. #property indicator_color6 Red  
  9.  
  10. //---- indicator parameters
  11. extern int    ShortBandsPeriod=14;
  12. extern int    ShortBandsShift=0;
  13. extern double ShortBandsDeviations=2.2;
  14. extern int    LongBandsPeriod=55;
  15. extern int    LongBandsShift=0;
  16. extern double LongBandsDeviations=2.2;
  17. extern int PERIODS_CHARACTERISTIC=100;
  18.  
  19. //---- buffers
  20. double ShortMovingBuffer[];
  21. double LongMovingBuffer[];
  22. double ShortDev[];
  23. double LongDev[];
  24. double Shortoscillator[];
  25. double Longoscillator[];
  26.  
  27. //+---------------------------------------------------+
  28. //| Custom indicator initialization function         |
  29. //+---------------------------------------------------+
  30. int init()  
  31. {
  32.  
  33. //---- indicators   
  34. SetIndexStyle(0,DRAW_NONE);   
  35. SetIndexBuffer(0,ShortMovingBuffer);   
  36. SetIndexStyle(1,DRAW_NONE);   
  37. SetIndexBuffer(1,LongMovingBuffer);   
  38. SetIndexStyle(2,DRAW_NONE);   
  39. SetIndexBuffer(2,ShortDev);   
  40. SetIndexStyle(3,DRAW_NONE);   
  41. SetIndexBuffer(3,LongDev);   
  42. SetIndexStyle(4,DRAW_LINE);   
  43. SetIndexBuffer(4,Shortoscillator);   
  44. SetIndexStyle(5,DRAW_LINE);   
  45. SetIndexBuffer(5,Longoscillator);
  46.  
  47. //----   
  48. SetIndexDrawBegin(0,ShortBandsPeriod+ShortBandsShift);
  49. SetIndexDrawBegin(1,LongBandsPeriod+LongBandsShift);
  50. SetIndexDrawBegin(2,ShortBandsPeriod+ShortBandsShift);   
  51. SetIndexDrawBegin(3,LongBandsPeriod+LongBandsShift);   
  52. SetIndexDrawBegin(4,ShortBandsPeriod+ShortBandsShift);
  53. SetIndexDrawBegin(5,LongBandsPeriod+LongBandsShift);
  54.  
  55. //----   
  56. return(0);  
  57. }
  58. //+---------------------------------------------------+
  59. //| Bollinger Bands                                  |
  60. //+---------------------------------------------------+  
  61.  
  62. int start()  
  63. {   
  64. int    i,k,counted_bars=IndicatorCounted();   
  65. double deviation;   
  66. double sum,oldval,newres;
  67. //----   
  68. if(Bars<=LongBandsPeriod) return(0);
  69. //---- initial zero   
  70. if(counted_bars<1)     
  71. {      
  72. for(i=1;i<=ShortBandsPeriod;i++)     
  73. {         
  74. ShortMovingBuffer[Bars-i]=EMPTY_VALUE;        
  75. }      
  76. for(i=1;i<=LongBandsPeriod;i++)        
  77. {         
  78. LongMovingBuffer[Bars-i]=EMPTY_VALUE;        
  79. }     
  80. }
  81.  
  82. //----   
  83. int limit=Bars-counted_bars;   
  84. if(counted_bars>0) limit++;   
  85. for(i=0; i<limit; i++)     
  86. {       
  87. ShortMovingBuffer[i]=iMA(NULL,0,ShortBandsPeriod,ShortBandsShift,MODE_SMA,PRICE_CLOSE,i);
  88.  
  89. LongMovingBuffer[i]=iMA(NULL,o,LongBandsPeriod,LongBandsShift,MODE_SMA,PRICE_CLOSE,i);
  90.   }
  91.  
  92. //----   
  93. i=Bars-ShortBandsPeriod+1;   
  94. if(counted_bars>ShortBandsPeriod-1) i=Bars-counted_bars-1;  
  95. while(i>=0)     
  96. {      
  97. sum=0.0;      
  98. k=i+ShortBandsPeriod-1;      
  99. oldval=ShortMovingBuffer[i];      
  100. while(k>=i)        
  101. {         
  102. newres=Close[k]-oldval;         
  103. sum+=newres*newres;         
  104. k--;        
  105. }
  106. ShortDev[i]=ShortBandsDeviations*MathSqrt(sum/ShortBandsPeriod);
  107. Shortoscillator[i]=OscillatorLine(ShortDev,i);
  108. //UpperBuffer[i]=oldval+deviation;      
  109. //LowerBuffer[i]=oldval-deviation;      
  110. i--;     
  111. }
  112.  
  113. //----   
  114. i=Bars-LongBandsPeriod+1;   
  115. if(counted_bars>LongBandsPeriod-1) i=Bars-counted_bars-1;
  116. while(i>=0)     
  117. {      
  118. sum=0.0;      
  119. k=i+LongBandsPeriod-1;      
  120. ldval=LongMovingBuffer[i];      
  121. while(k>=i)        
  122. {
  123. newres=Close[k]-oldval;         
  124. sum+=newres*newres;         
  125. k--;        
  126. }      
  127.  
  128. LongDev[i]=LongBandsDeviations*MathSqrt(sum/LongBandsPeriod);
  129. Longoscillator[i]=OscillatorLine(LongDev,i);
  130. //UpperBuffer[i]=oldval+deviation;      
  131. //LowerBuffer[i]=oldval-deviation;      
  132. i--;     
  133. }
  134. //----   
  135. return(0);  
  136. }  
  137.  
  138. double OscillatorLine(double indicator[], int StartBar)  
  139. {
  140.  
  141. double S=0;      
  142. int ArrayLong=PERIODS_CHARACTERISTIC;      
  143. double Result;       
  144. for(int j=StartBar;j<ArrayLong+StartBar;j++) 
  145. {S+=MathPow((indicator[j]/Point),2);}            
  146.  
  147. S/=ArrayLong;      
  148. S=MathSqrt(S)*Point;      
  149. if(S!=0)        
  150. {Result=indicator[StartBar]/S;}      
  151. Result=MathTanh(Result);      
  152. return (Result);  
  153. }
  154. double MathTanh(double x)
  155. {   
  156. double exp;   
  157. double returnNum;
  158. if(x>0)     
  159. {       
  160. exp=MathExp(-2*x);       
  161. returnNum= (1-exp)/(1+exp);       
  162. return (returnNum);     
  163. }   
  164. else     
  165. {       
  166. exp=MathExp(2*x);       
  167. returnNum=(exp-1)/(1+exp);       
  168. return (returnNum);     
  169. }
  170. }
Add Comment
Please, Sign In to add comment