Advertisement
Guest User

new formula

a guest
Mar 28th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.20 KB | None | 0 0
  1. #property copyright "modified vertex by eR"
  2. #property link "modified vertex by eR"
  3.  
  4. #property indicator_separate_window
  5. #property indicator_buffers 8
  6. #property indicator_color1 Red
  7. #property indicator_color2 clrNONE
  8. #property indicator_color3 clrNONE
  9. #property indicator_color4 clrNONE
  10. #property indicator_levelcolor MediumOrchid
  11. #property indicator_maximum 12.0
  12. #property indicator_minimum -12.0
  13. #property indicator_level1 -6.0
  14. #property indicator_level2 6.0
  15. #property indicator_level3 -10.0
  16. #property indicator_level4 10.0
  17. #property indicator_levelstyle 2
  18.  
  19. extern int Processed = 1000;
  20. extern int Control_Period = 14;
  21.  
  22. //int Signal_Period = 5;
  23. //int Signal_Method = MODE_SMA;
  24.  
  25. //int BB_Up_Period = 12;
  26. //int BB_Up_Deviation = 2;
  27.  
  28. //int BB_Dn_Period = 12;
  29. //int BB_Dn_Deviation = 2;
  30.  
  31. double levelOb = 6;
  32. double levelOs = -6;
  33. double extremelevelOb = 10;
  34. double extremelevelOs = -10;
  35.  
  36. extern bool alertsOn = true;
  37. bool alertsOnObOs = false;
  38. bool alertsOnExtremeObOs = true;
  39. bool alertsOnCurrent = false;
  40. bool alertsMessage = true;
  41. bool alertsSound = true;
  42. bool alertsEmail = false;
  43. bool alertsNotify = false;
  44. string soundfile = "alert2.wav";
  45.  
  46. bool arrowsVisible = true;
  47. string arrowsIdentifier = "wpr arrows1";
  48. double arrowsUpperGap = 1.0;
  49. double arrowsLowerGap = 0.1;
  50. /*
  51. bool arrowsOnFiftyCross = false;
  52. color arrowsOnFiftyCrossUpColor= LimeGreen;
  53. color arrowsOnFiftyCrossDnColor= Red;
  54. int arrowsOnFiftyCrossUpCode = 241;
  55. int arrowsOnFiftyCrossDnCode = 242;
  56. int arrowsOnFiftyCrossSize = 2;
  57. */
  58. bool arrowsOnLeavingObOs = true;
  59. color arrowsLeavingObOsUpColor = DodgerBlue;
  60. color arrowsLeavingObOsDnColor = OrangeRed;
  61. int arrowsLeavingObOsUpCode = 241;
  62. int arrowsLeavingObOsDnCode = 242;
  63. int arrowsLeavingObOsSize = 1;
  64.  
  65. double values[];
  66. double signal[];
  67. double band_up[];
  68. double band_dn[];
  69. double trend1[];
  70. double trend2[];
  71.  
  72. double x1 = 76;
  73. double x2 = 24;
  74. int WprPrice = 1;
  75. int Risk = 0;
  76. double ArrowsGap = 1.0;
  77. double arrDn[];
  78. double arrUp[];
  79. double wpr[];
  80. double price[];
  81. double trend[];
  82. int init()
  83. {
  84. IndicatorBuffers(6);
  85. SetIndexBuffer(0, values);
  86. SetIndexStyle(0,DRAW_LINE);
  87. //SetIndexBuffer(1, signal);
  88. //SetIndexBuffer(2, band_up);
  89. //SetIndexBuffer(3, band_dn);
  90. //SetIndexBuffer(1, trend1);
  91. SetIndexBuffer(2, trend2);
  92. IndicatorShortName( "");
  93. SetIndexLabel(0,"");
  94. SetIndexLabel(1,"");
  95. SetIndexLabel(2,"");
  96. SetIndexLabel(3,"");
  97. SetIndexLabel(4,"");
  98. SetIndexLabel(5,"");
  99. SetIndexBuffer(4,price);
  100. SetIndexStyle(4,DRAW_NONE);
  101.  
  102.  
  103. return (0);
  104. }
  105.  
  106. int deinit() {
  107. //deleteArrows();
  108. ObjectDelete("ss");
  109. ObjectDelete("bs");
  110. return (0);
  111. }
  112.  
  113. int start()
  114. {
  115. datetime bar_time;
  116. int idx, counter, offset, bar_shft, bar_cont;
  117. double price_high, price_close, price_low, trigger_high, trigger_low;
  118. double sum_up, sum_dn, complex_up, complex_dn;
  119.  
  120. int counted = IndicatorCounted();
  121. if (counted < 0) return (-1);
  122. if (counted > 0) counted--;
  123. int limit = Bars - counted;
  124. if (limit > Processed) limit = Processed;
  125.  
  126. for (idx = limit; idx >= 0; idx--) {
  127. counter = 0;
  128. complex_up = 0; complex_dn = 0;
  129. trigger_high = -999999; trigger_low = 999999;
  130.  
  131. while (counter < Control_Period) {
  132. sum_up = 0; sum_dn = 0;
  133.  
  134. offset = idx + counter;
  135. bar_time = iTime(Symbol(), 0, offset);
  136. bar_shft = iBarShift(Symbol(), 0, bar_time, FALSE);
  137. bar_cont = bar_shft - Period(); if (bar_cont < 0) bar_cont = 0;
  138. x1 = x1 + Risk;
  139. x2 = x2 - Risk;
  140.  
  141. for (int jdx = bar_shft; jdx >= bar_cont; jdx--) {
  142. int period = 3 + Risk * 2;
  143. double range = 0; for (int k = 0; k < 10; k++) range += High[jdx+k] - Low[jdx+k]; range /= 10.0;
  144. bool found1 = false; for (k = 0; k < 6 && !found1; k++) found1 = (MathAbs(Open[jdx+k] - Close[jdx+k+1])>= range * 2.0);
  145. bool found2 = false; for (k = 0; k < 9 && !found2; k++) found2 = (MathAbs(Close[jdx+k+3] - Close[jdx+k]) >= range * 4.6);
  146. if (found1) period = 3;
  147. if (found2) period = 4;
  148. price[jdx] = getPrice(WprPrice,jdx);
  149. double hi = High[Highest(NULL, 0, MODE_HIGH,period,jdx+1)];
  150. double lo = Low[Lowest(NULL, 0, MODE_LOW, period,jdx+1)];
  151. if (hi!=lo)
  152. wpr[jdx] = 100+(-100)*(hi - price[jdx]) / (hi - lo);
  153. else wpr[jdx] = 0;
  154.  
  155. //double r1 = iRSI(NULL,0,RSI,PRICE_OPEN,jdx+1);
  156. //double r2 = iRSI(NULL,0,RSI,PRICE_OPEN,jdx);
  157. price_high = price[jdx];//iHigh(Symbol(), 0, jdx);
  158. price_close = Open[jdx];//iClose(Symbol(), 0, jdx);
  159. price_low = price[jdx];//iLow(Symbol(), 0, jdx);
  160.  
  161. if (price_high > trigger_high) {trigger_high = price_high; sum_up += price_close;}
  162. if (price_low < trigger_low) {trigger_low = price_low; sum_dn += price_close;}
  163. }
  164.  
  165. counter++;
  166. complex_up += sum_up; complex_dn += sum_dn;
  167. }
  168. if (complex_dn != 0.0 && complex_up != 0.0)
  169. values[idx] = complex_dn / complex_up - complex_up / complex_dn;
  170. }
  171.  
  172. for (idx = limit; idx >= 0; idx--)
  173. {
  174. //signal[idx] = iMAOnArray(values, 0, Signal_Period, 0, Signal_Method, idx);
  175. //band_up[idx] = iBandsOnArray(values, 0, BB_Up_Period, BB_Up_Deviation, 0, MODE_UPPER, idx);
  176. //band_dn[idx] = iBandsOnArray(values, 0, BB_Dn_Period, BB_Dn_Deviation, 0, MODE_LOWER, idx);
  177. trend1[idx] = trend1[idx+1];
  178. trend2[idx] = trend2[idx+1];
  179.  
  180. if (values[idx+1]<levelOb && values[idx]>levelOb) trend1[idx] =-1;
  181. if (values[idx+1]>levelOs && values[idx]<levelOs) trend1[idx] = 1;
  182. if (values[idx]>extremelevelOb) trend2[idx] =-1;
  183. if (values[idx]<extremelevelOs) trend2[idx] = 1;
  184. //manageArrow(idx);
  185.  
  186.  
  187. }
  188.  
  189.  
  190. //
  191. //
  192. //
  193. //
  194. //
  195.  
  196.  
  197.  
  198.  
  199.  
  200. if (alertsOn)
  201. {
  202. if (alertsOnCurrent)
  203. int whichBar = 0;
  204. else whichBar = 1;
  205.  
  206. //
  207. //
  208. //
  209. //
  210. //
  211.  
  212. static datetime time1 = 0;
  213. static string mess1 = "";
  214. if (alertsOnObOs && trend1[whichBar] != trend1[whichBar+1])
  215. {
  216. if (trend1[whichBar] == 1 && trend1[idx] !=-1) doAlert(time1,mess1,whichBar,"crossing oversold");
  217. if (trend1[whichBar] == -1 && trend1[idx] != 1) doAlert(time1,mess1,whichBar,"crossing overbought");
  218. }
  219. static datetime time2 = 0;
  220. static string mess2 = "";
  221. if (alertsOnExtremeObOs && trend2[whichBar] != trend2[whichBar+1])
  222. {
  223. if (trend2[whichBar] == 1) doAlert(time2,mess2,whichBar,"crossing extreme oversold");
  224. if (trend2[whichBar] == -1) doAlert(time2,mess2,whichBar,"crossing extreme overbought");
  225. }
  226.  
  227. }
  228. return (0);
  229. }
  230.  
  231. /*
  232. void Tulis(string namateks, string teks, color warna, int pojok, int posx, int posy,int size)
  233. {
  234. ObjectCreate(namateks, OBJ_LABEL, 0, 0, 0);
  235. ObjectSetText(namateks, teks, size, teks, warna);
  236. ObjectSet(namateks, OBJPROP_CORNER, pojok);
  237. ObjectSet(namateks, OBJPROP_XDISTANCE, posx);
  238. ObjectSet(namateks, OBJPROP_YDISTANCE, posy);
  239. }
  240. */
  241. ////////////////////////////////////////////////////////////////
  242. double getPrice(int type, int i)
  243. {
  244. switch (type)
  245. {
  246. case 1: return((Open[i+1]));
  247. case 7: return((Open[i]+Close[i])/2.0);
  248. case 8: return((Open[i]+High[i]+Low[i]+Close[i])/4.0);
  249. default : return(iMA(NULL,0,1,0,MODE_SMA,type,i+1));
  250. }
  251. }
  252. //
  253. //
  254. //
  255. //
  256. /*
  257. void manageArrow(int idx)
  258. {
  259. if (arrowsVisible)
  260. {
  261. ObjectDelete(arrowsIdentifier+":1:"+Time[idx]);
  262. ObjectDelete(arrowsIdentifier+":2:"+Time[idx]);
  263. string lookFor = arrowsIdentifier+":"+Time[idx]; ObjectDelete(lookFor);
  264. if (arrowsOnLeavingObOs && trend1[idx] != trend1[idx+1])
  265. {
  266. if (trend1[idx+1] == -1 && trend1[idx] !=-1) drawArrow("2",0.5,idx,arrowsLeavingObOsUpColor,arrowsLeavingObOsUpCode,arrowsLeavingObOsSize,false);
  267. if (trend1[idx+1] == 1 && trend1[idx] != 1) drawArrow("2",0.5,idx,arrowsLeavingObOsDnColor,arrowsLeavingObOsDnCode,arrowsLeavingObOsSize, true);
  268. }
  269.  
  270. }
  271. }
  272. */
  273. //
  274. //
  275. //
  276. //
  277. //
  278. /*
  279. void drawArrow(string nameAdd, double gapMul, int idx,color theColor,int theCode,int theWidth,bool up)
  280. {
  281. string name = arrowsIdentifier+":"+nameAdd+":"+Time[idx];
  282. double gap = iATR(NULL,0,20,idx)*gapMul;
  283.  
  284. //
  285. //
  286. //
  287. //
  288. //
  289.  
  290. ObjectCreate(name,OBJ_ARROW,0,Time[idx],0);
  291. ObjectSet(name,OBJPROP_ARROWCODE,theCode);
  292. ObjectSet(name,OBJPROP_COLOR,theColor);
  293. ObjectSet(name,OBJPROP_WIDTH,theWidth);
  294. if (up)
  295. ObjectSet(name,OBJPROP_PRICE1,High[idx] + arrowsUpperGap * gap);
  296. else ObjectSet(name,OBJPROP_PRICE1,Low[idx] - arrowsLowerGap * gap);
  297. }
  298. */
  299. //
  300. //
  301. //
  302. //
  303. //
  304. /*
  305. void deleteArrows()
  306. {
  307. string lookFor = arrowsIdentifier+":";
  308. int lookForLength = StringLen(lookFor);
  309. for (int idx=ObjectsTotal()-1; idx>=0; idx--)
  310. {
  311. string objectName = ObjectName(idx);
  312. if (StringSubstr(objectName,0,lookForLength) == lookFor) ObjectDelete(objectName);
  313. }
  314. }
  315. */
  316. //
  317. //
  318. //
  319.  
  320. void doAlert(datetime& previousTime, string& previousAlert, int forBar, string doWhat)
  321. {
  322. string message;
  323.  
  324. if (previousAlert != doWhat || previousTime != Time[forBar]) {
  325. previousAlert = doWhat;
  326. previousTime = Time[forBar];
  327.  
  328. //
  329. //
  330. //
  331. //
  332. //
  333.  
  334. message = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," Vertex ",doWhat);
  335. if (alertsMessage) Alert(message);
  336. if (alertsNotify) SendNotification(message);
  337. if (alertsEmail) SendMail(StringConcatenate(Symbol()," Vertex "),message);
  338. if (alertsSound) PlaySound(soundfile);
  339. }
  340. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement