Advertisement
Guest User

RSIoMA 50cross level

a guest
Feb 27th, 2018
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.87 KB | None | 0 0
  1. */
  2. #property copyright "RSIoMA V2 TSI"
  3. #property link "RSIoMA V2 TSI"
  4.  
  5. #property indicator_separate_window
  6. #property indicator_minimum 0
  7. #property indicator_maximum 100
  8. #property indicator_buffers 6
  9. #property indicator_color1 Blue
  10. #property indicator_color2 Red
  11. #property indicator_color3 Blue
  12. #property indicator_color4 Magenta
  13. #property indicator_color5 DodgerBlue
  14. #property indicator_color6 BlueViolet
  15.  
  16. //---- input parameters
  17. extern int RSIOMA = 14;
  18. extern int RSIOMA_MODE = MODE_EMA;
  19. extern int RSIOMA_PRICE = PRICE_CLOSE;
  20.  
  21. extern int Ma_RSIOMA = 21,
  22. Ma_RSIOMA_MODE = MODE_EMA;
  23.  
  24. extern int BuyTrigger = 70;
  25. extern int SellTrigger = 30;
  26.  
  27. extern color BuyTriggerColor = Blue;
  28. extern color SellTriggerColor = Red;
  29.  
  30. extern int MainTrendLong = 50;
  31. extern int MainTrendShort = 50;
  32.  
  33. extern color MainTrendLongColor = Red;
  34. extern color MainTrendShortColor = Blue;
  35.  
  36. input int TriggerCandle=1;
  37. input bool EnableNativeAlerts = true;
  38. input bool EnableSoundAlerts = true;
  39. input bool EnableEmailAlerts = true;
  40. input bool EnablePushAlerts=true;
  41. input string AlertEmailSubject="";
  42. input string AlertText="";
  43. input string SoundFileName="alert.wav";
  44.  
  45. datetime LastAlertTime = D'01.01.1970';
  46. int LastAlertDirection = 0;
  47.  
  48. //---- buffers
  49. double RSIBuffer[];
  50. double PosBuffer[];
  51. double NegBuffer[];
  52.  
  53. double bdn[],bup[];
  54. double sdn[],sup[];
  55.  
  56. double marsioma[];
  57. string short_name;
  58. //+------------------------------------------------------------------+
  59. //| Custom indicator initialization function |
  60. //+------------------------------------------------------------------+
  61. int init()
  62. {
  63. short_name=StringConcatenate("RSIOMA(",RSIOMA,")");
  64. IndicatorBuffers(8);
  65.  
  66. SetIndexBuffer(0,RSIBuffer);
  67. SetIndexBuffer(2,bup);
  68. SetIndexBuffer(1,bdn);
  69. SetIndexBuffer(3,sdn);
  70. SetIndexBuffer(4,sup);
  71. SetIndexBuffer(5,marsioma);
  72.  
  73. SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3);
  74. SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,4);
  75. SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,4);
  76. SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,4);
  77. SetIndexStyle(4,DRAW_HISTOGRAM,STYLE_SOLID,4);
  78. SetIndexStyle(5,DRAW_LINE,STYLE_SOLID,1);
  79.  
  80. SetIndexBuffer(6,PosBuffer);
  81. SetIndexBuffer(7,NegBuffer);
  82.  
  83. IndicatorShortName(short_name);
  84.  
  85. SetIndexDrawBegin(0,RSIOMA);
  86. SetIndexDrawBegin(1,RSIOMA);
  87. SetIndexDrawBegin(2,RSIOMA);
  88. SetIndexDrawBegin(3,RSIOMA);
  89. SetIndexDrawBegin(4,RSIOMA);
  90. SetIndexDrawBegin(5,RSIOMA);
  91. SetIndexDrawBegin(6,RSIOMA);
  92. SetIndexDrawBegin(7,RSIOMA);
  93. //----
  94.  
  95. drawLine(BuyTrigger,"BuyTrigger",BuyTriggerColor);
  96. drawLine(SellTrigger,"SellTrigger",SellTriggerColor);
  97. drawLine(MainTrendLong,"MainTrendLong",MainTrendLongColor);
  98. drawLine(MainTrendShort,"MainTrendShort",MainTrendShortColor);
  99.  
  100. return(0);
  101. }
  102. //+------------------------------------------------------------------+
  103. //| Relative Strength Index |
  104. //+------------------------------------------------------------------+
  105. int start()
  106. {
  107.  
  108.  
  109. int i,counted_bars=IndicatorCounted();
  110. double rel,negative,positive;
  111. //----
  112. if(Bars<=RSIOMA) return(0);
  113. //---- initial zero
  114. if(counted_bars<1)
  115. for(i=1;i<=RSIOMA;i++) RSIBuffer[Bars-i]=0.0;
  116. //----
  117. i=Bars-RSIOMA-1;
  118. int ma=i;
  119. if(counted_bars>=RSIOMA) i=Bars-counted_bars-1;
  120. while(i>=0)
  121. {
  122. double sumn=0.0,sump=0.0;
  123. if(i==Bars-RSIOMA-1)
  124. {
  125. int k=Bars-2;
  126. //---- initial accumulation
  127. while(k>=i)
  128. {
  129.  
  130. double cma = iMA(Symbol(),0,RSIOMA,0,RSIOMA_MODE,RSIOMA_PRICE,k);
  131. double pma = iMA(Symbol(),0,RSIOMA,0,RSIOMA_MODE,RSIOMA_PRICE,k+1);
  132.  
  133. rel=cma-pma;
  134.  
  135. if(rel>0) sump+=rel;
  136. else sumn-=rel;
  137. k--;
  138. }
  139. positive=sump/RSIOMA;
  140. negative=sumn/RSIOMA;
  141. }
  142. else
  143. {
  144. //---- smoothed moving average
  145. double ccma = iMA(Symbol(),0,RSIOMA,0,RSIOMA_MODE,RSIOMA_PRICE,i);
  146. double ppma = iMA(Symbol(),0,RSIOMA,0,RSIOMA_MODE,RSIOMA_PRICE,i+1);
  147.  
  148. rel=ccma-ppma;
  149.  
  150. if(rel>0) sump=rel;
  151. else sumn=-rel;
  152. positive=(PosBuffer[i+1]*(RSIOMA-1)+sump)/RSIOMA;
  153. negative=(NegBuffer[i+1]*(RSIOMA-1)+sumn)/RSIOMA;
  154. }
  155. PosBuffer[i]=positive;
  156. NegBuffer[i]=negative;
  157. if(negative==0.0) RSIBuffer[i]=0.0;
  158. else
  159. {
  160. RSIBuffer[i]=100.0-100.0/(1+positive/negative);
  161.  
  162. bdn[i] = 0;
  163. bup[i] = 0;
  164. sdn[i] = 0;
  165. sup[i] = 0;
  166.  
  167. if(RSIBuffer[i]>MainTrendLong)
  168. bup[i]=-10;
  169.  
  170. if(RSIBuffer[i]<MainTrendShort)
  171. bdn[i]=-10;
  172.  
  173. if(RSIBuffer[i]<20 && RSIBuffer[i]>RSIBuffer[i+1])
  174. sup[i]=-10;
  175.  
  176. if(RSIBuffer[i]>80 && RSIBuffer[i]<RSIBuffer[i+1])
  177. sdn[i]=-10;
  178.  
  179. }
  180. i--;
  181. }
  182.  
  183. while(ma>=0)
  184. {
  185. marsioma[ma]=iMAOnArray(RSIBuffer,0,Ma_RSIOMA,0,Ma_RSIOMA_MODE,ma);
  186. ma--;
  187. }
  188.  
  189. if(((TriggerCandle>50) && (Time[0]>LastAlertTime)) || (TriggerCandle==50))
  190. {
  191. string Text;
  192. // Above Zero Alert
  193. if(((RSIBuffer[TriggerCandle]>50) && (RSIBuffer[TriggerCandle+1]<=50)) && ((TriggerCandle>50) || ((TriggerCandle==50) && (LastAlertDirection!=1))))
  194. {
  195. Text=AlertText+"RSIBuffer: "+Symbol()+" - "+EnumToString((ENUM_TIMEFRAMES)Period())+" - Above Zero.";
  196. if(EnableNativeAlerts) Alert(Text);
  197. if(EnableEmailAlerts) SendMail(AlertEmailSubject+"RSIBuffer Alert",Text);
  198. if(EnableSoundAlerts) PlaySound(SoundFileName);
  199. if(EnablePushAlerts) SendNotification(Text);
  200. LastAlertTime=Time[0];
  201. LastAlertDirection=1;
  202. }
  203. // Below Zero Alert
  204. if(((RSIBuffer[TriggerCandle]<50) && (RSIBuffer[TriggerCandle+1]>=50)) && ((TriggerCandle>50) || ((TriggerCandle==50) && (LastAlertDirection!=-1))))
  205. {
  206. Text=AlertText+"RSIBuffer: "+Symbol()+" - "+EnumToString((ENUM_TIMEFRAMES)Period())+" - Below Zero.";
  207. if(EnableNativeAlerts) Alert(Text);
  208. if(EnableEmailAlerts) SendMail(AlertEmailSubject+"RSIBuffer Alert",Text);
  209. if(EnableSoundAlerts) PlaySound(SoundFileName);
  210. if(EnablePushAlerts) SendNotification(Text);
  211. LastAlertTime=Time[0];
  212. LastAlertDirection=-1;
  213. }
  214. }
  215.  
  216. return(0);
  217. }
  218. //+------------------------------------------------------------------+
  219. void drawLine(double lvl,string name,color Col)
  220. {
  221.  
  222. ObjectDelete(name);
  223. ObjectCreate(name,OBJ_HLINE,WindowFind(short_name),Time[0],lvl,Time[0],lvl);
  224.  
  225. ObjectSet(name,OBJPROP_STYLE,STYLE_DOT);
  226.  
  227. ObjectSet(name,OBJPROP_COLOR,Col);
  228. ObjectSet(name,OBJPROP_WIDTH,1);
  229.  
  230. }
  231. //+------------------------------------------------------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement