Advertisement
Guest User

Untitled

a guest
Feb 5th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 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. bool trend=true;
  13. bool volfilter=true;
  14.  
  15. //State
  16. double cmd;
  17.  
  18. bool newBar()
  19. {
  20. static datetime lastbar;
  21. datetime curbar = Time[0];
  22. if(lastbar!=curbar)
  23. {
  24. lastbar=curbar;
  25. return (true);
  26. }
  27. else
  28. {
  29. return(false);
  30. }
  31. }
  32.  
  33. //+------------------------------------------------------------------+
  34. //| expert initialization function |
  35. //+------------------------------------------------------------------+
  36. int init()
  37. {
  38. //----
  39.  
  40. //----
  41. return(0);
  42. }
  43. //+------------------------------------------------------------------+
  44. //| expert deinitialization function |
  45. //+------------------------------------------------------------------+
  46. int deinit()
  47. {
  48. //----
  49.  
  50. //----
  51. return(0);
  52. }
  53.  
  54. double calculatePosSize()
  55. {
  56. double x = iWPR(NULL,0,s,1);
  57. double y = 1;
  58.  
  59. if(x >= -100 && x < -90) {
  60. y = 3;
  61. }
  62. if(x >= -90 && x < -80) {
  63. y = 2.5;
  64. }
  65. if(x >= -80 && x < -70) {
  66. y = 2;
  67. }
  68. if(x >= -70 && x < -60) {
  69. y = 1.5;
  70. }
  71. if(x >= -60 && x < -50) {
  72. y = 1;
  73. }
  74. if(x >= -50 && x < -40) {
  75. y = 1;
  76. }
  77. if(x >= -40 && x < -30) {
  78. y = 1.5;
  79. }
  80. if(x >= -30 && x < -20) {
  81. y = 2;
  82. }
  83. if(x >= -20 && x < -10) {
  84. y = 2.5;
  85. }
  86. if(x >= -10 && x < 0) {
  87. y = 3;
  88. }
  89.  
  90. //;
  91. //if(AccountFreeMargin() < 10000) { return(0.1); }
  92.  
  93. //return( NormalizeDouble(y*(AccountFreeMargin()/100000),2) );
  94. return(0.01);
  95. }
  96. //+------------------------------------------------------------------+
  97. //| expert start function |
  98. //+------------------------------------------------------------------+
  99. int start()
  100. {
  101. //----
  102. if(!newBar()) return(0);
  103. //ORDER MAINTENANCE
  104. for(int cnt=OrdersTotal();cnt>=0;cnt--) {
  105.  
  106. OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
  107.  
  108. if( OrderSymbol()==Symbol() ) {
  109. cmd=OrderType();
  110.  
  111. //EXIT LONGS
  112. if(cmd==OP_BUY && OrderMagicNumber() == 11){
  113. if(trend == true && (Close[1] > Close[n] || Close[1] < Close[s]) ) {
  114. OrderClose(OrderTicket(),OrderLots(),Bid,0,Blue);
  115. }
  116. if(trend == false && Close[1] > Close[n]) {
  117. OrderClose(OrderTicket(),OrderLots(),Bid,0,Blue);
  118. }
  119. }
  120.  
  121. //EXIT SHORTS
  122. if(cmd==OP_SELL && OrderMagicNumber() == 21) {
  123. if(trend == true && (Close[1] < Close[n] || Close[1] > Close[s]) ) {
  124. OrderClose(OrderTicket(),OrderLots(),Ask,0,Red);
  125. }
  126. if(trend == false && (Close[1] < Close[n]) ) {
  127. OrderClose(OrderTicket(),OrderLots(),Ask,0,Red);
  128. }
  129. }
  130. }
  131. }
  132.  
  133. double atr=iATR(NULL,0,10,1);
  134. double atr2=-1;
  135. if(volfilter==true){
  136. atr2=iATR(NULL,0,s,1);
  137. }
  138. double fact=1;
  139. //ORDER ENTRY
  140. if(OrdersTotal() < 1 && atr > atr2){
  141.  
  142. //BUY
  143. if(trend ==true && Close[1] > Close[s] && Close[1] < Close[n]) {
  144. OrderSend(Symbol(),OP_BUY,calculatePosSize(),Ask,0.00003,0,0,NULL,11,0,Blue);
  145. }
  146. if(trend == false && Close[1] < Close[n]) {
  147. OrderSend(Symbol(),OP_BUY,calculatePosSize(),Ask,0.00003,0,0,NULL,11,0,Blue);
  148. }
  149.  
  150. //SELL
  151. if(trend == true && Close[1] < Close[s] && Close[1] > Close[n]) {
  152. OrderSend(Symbol(),OP_SELL,calculatePosSize(),Bid,0.00003,0,0,NULL,21,0,Red);
  153. }
  154. if(trend == false && Close[1] > Close[n]) {
  155. OrderSend(Symbol(),OP_SELL,calculatePosSize(),Bid,0.00003,0,0,NULL,21,0,Red);
  156. }
  157.  
  158. }
  159. //----
  160. return(0);
  161. }
  162. //+------------------------------------------------------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement