Advertisement
Guest User

Untitled

a guest
Feb 5th, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. //+------------------------------------------------------------------+
  2. //| Confidence.mq4 |
  3. //| Copyright © 2010, Sina Sadeghi. |
  4. //| http://www.launchpad.net/~sina-sa |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright © 2010, MetaQuotes Software Corp."
  7. #property link "http://www.metaquotes.net"
  8.  
  9. //Params
  10. int n=2;
  11. int s=120;
  12.  
  13. //State
  14. double cmd;
  15.  
  16. bool newBar()
  17. {
  18. static datetime lastbar;
  19. datetime curbar = Time[0];
  20. if(lastbar!=curbar)
  21. {
  22. lastbar=curbar;
  23. return (true);
  24. }
  25. else
  26. {
  27. return(false);
  28. }
  29. }
  30.  
  31. //+------------------------------------------------------------------+
  32. //| expert initialization function |
  33. //+------------------------------------------------------------------+
  34. int init()
  35. {
  36. //----
  37.  
  38. //----
  39. return(0);
  40. }
  41. //+------------------------------------------------------------------+
  42. //| expert deinitialization function |
  43. //+------------------------------------------------------------------+
  44. int deinit()
  45. {
  46. //----
  47.  
  48. //----
  49. return(0);
  50. }
  51.  
  52. double calculatePosSize()
  53. {
  54. double x = iWPR(NULL,0,s,1);
  55. double y = 0.1;
  56.  
  57. if(x >= -100 && x < -90) {
  58. y = 0.5;
  59. }
  60. if(x >= -90 && x < -80) {
  61. y = 0.4;
  62. }
  63. if(x >= -80 && x < -70) {
  64. y = 0.3;
  65. }
  66. if(x >= -70 && x < -60) {
  67. y = 0.2;
  68. }
  69. if(x >= -60 && x < -50) {
  70. y = 0.1;
  71. }
  72. if(x >= -50 && x < -40) {
  73. y = 0.1;
  74. }
  75. if(x >= -40 && x < -30) {
  76. y = 0.2;
  77. }
  78. if(x >= -30 && x < -20) {
  79. y = 0.3;
  80. }
  81. if(x >= -20 && x < -10) {
  82. y = 0.4;
  83. }
  84. if(x >= -10 && x < 0) {
  85. y = 0.5;
  86. }
  87. //return(0.1);
  88. return(y);
  89. }
  90. //+------------------------------------------------------------------+
  91. //| expert start function |
  92. //+------------------------------------------------------------------+
  93. int start()
  94. {
  95. //----
  96. if(!newBar()) return(0);
  97.  
  98. //ORDER MAINTENANCE
  99. for(int cnt=OrdersTotal();cnt>=0;cnt--) {
  100.  
  101. OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
  102.  
  103. if( OrderSymbol()==Symbol() ) {
  104. cmd=OrderType();
  105.  
  106. //EXIT LONGS
  107. if(cmd==OP_BUY && OrderMagicNumber() == 11){
  108. if(Close[1] > Close[n] || Close[1] < Close[s]) {
  109. OrderClose(OrderTicket(),OrderLots(),Bid,0,Blue);
  110. }
  111. }
  112.  
  113. //EXIT SHORTS
  114. if(cmd==OP_SELL && OrderMagicNumber() == 21) {
  115. if(Close[1] < Close[n] || Close[1] > Close[s]) {
  116. OrderClose(OrderTicket(),OrderLots(),Ask,0,Red);
  117. }
  118. }
  119. }
  120. }
  121.  
  122. //ORDER ENTRY
  123. if(OrdersTotal() < 1){
  124. //BUY
  125. if(Close[1] < Close[n] && Close[1] > Close[s]) {
  126. OrderSend(Symbol(),OP_BUY,calculatePosSize(),Ask,0.3,0,0,NULL,11,0,Blue);
  127. }
  128. //SELL
  129. if(Close[1] > Close[n] && Close[1] < Close[s]) {
  130. OrderSend(Symbol(),OP_SELL,calculatePosSize(),Bid,0.3,0,0,NULL,21,0,Red);
  131. }
  132. }
  133. //----
  134. return(0);
  135. }
  136.  
  137.  
  138.  
  139. //+------------------------------------------------------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement