Guest User

Untitled

a guest
Jul 24th, 2012
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1.  
  2. extern int TakeProfit = 20;
  3. extern double Lot = 0.5;
  4. extern int Slippage = 3;
  5. extern int Magic = 050120120031;
  6.  
  7.  
  8. bool modify = false;
  9. //+------------------------------------------------------------------+
  10. //| expert initialization function |
  11. //+------------------------------------------------------------------+
  12. int init()
  13. {
  14. //----
  15.  
  16. //----
  17. return(0);
  18. }
  19. //+------------------------------------------------------------------+
  20. //| expert deinitialization function |
  21. //+------------------------------------------------------------------+
  22. int deinit()
  23. {
  24. //----
  25.  
  26. //----
  27. return(0);
  28. }
  29. //+------------------------------------------------------------------+
  30. //| expert start function |
  31. //+------------------------------------------------------------------+
  32. int start()
  33. {
  34. //----
  35. if (all () == 0) two_orders ();
  36.  
  37. if (all () == 2 && all_type (0) == 1 && all_type (1) == 0) return (0);
  38.  
  39. if (all () == 1 && all_type (0) == 1 && !modify)
  40. {
  41. two_orders ();
  42. modify_profit (0);
  43. }
  44.  
  45. if (all () == 1 && all_type (0) == 1 && modify)
  46. {
  47. close ();
  48. two_orders ();
  49. modify = false;
  50. }
  51.  
  52. if(all () == 1 && all_type (1) == 1 && !modify)
  53. {
  54. two_orders ();
  55. modify_profit (1);
  56. }
  57.  
  58. if(all () == 1 && all_type (1) == 1 && modify)
  59. {
  60. close ();
  61. two_orders ();
  62. modify = false;
  63. }
  64.  
  65. if (all () > 1 && all_type (0) == 0 && all_type (1) > 1)
  66. {
  67. two_orders ();
  68. modify_profit (1);
  69. }
  70.  
  71. if (all () > 1 && all_type (1) == 0 && all_type (0) > 1)
  72. {
  73. two_orders ();
  74. modify_profit (0);
  75. }
  76. //----
  77. return(0);
  78. }
  79. //+------------------------------------------------------------------+
  80. void two_orders ()
  81. {
  82. double ask = NormalizeDouble (Ask, Digits);
  83. OrderSend (Symbol (), OP_BUY, /*lot_buy ()*/Lot, ask, Slippage, 0, NormalizeDouble (ask + TakeProfit*Point, Digits), "", Magic, 0, CLR_NONE);
  84. double bid = NormalizeDouble (Bid, Digits);
  85. OrderSend (Symbol (), OP_SELL, /*lot_sell ()*/Lot, bid, Slippage, 0, NormalizeDouble (bid - TakeProfit*Point, Digits), "", Magic, 0, CLR_NONE);
  86. }
  87.  
  88. void modify_profit (int type)
  89. {
  90. double average_price, lots;
  91. int b, s;
  92.  
  93. for (int i = OrdersTotal () - 1; i >= 0 ; i --)
  94. {
  95. if (OrderSelect (i, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber () == Magic && OrderSymbol () == Symbol () && OrderType () == type)
  96. {
  97. average_price += OrderOpenPrice() * OrderLots();
  98. lots += OrderLots();
  99. }
  100. }
  101. average_price = NormalizeDouble (average_price/lots, Digits);
  102.  
  103. for (i = OrdersTotal () - 1; i >= 0 ; i --)
  104. {
  105. if (OrderSelect (i, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber () == Magic && OrderSymbol () == Symbol () && OrderType () == type)
  106. {
  107. OrderModify (OrderTicket (), 0, 0, average_price, 0, CLR_NONE);
  108. modify = true;
  109. }
  110. }
  111. }
  112.  
  113. void close ()
  114. {
  115. for (int i = OrdersTotal () - 1; i >= 0; i --)
  116. {
  117. if (OrderSelect (i, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber () == Magic && OrderSymbol () == Symbol ())
  118. {
  119. if (OrderType () == 0)
  120. OrderClose (OrderTicket (), OrderLots (), NormalizeDouble (Bid, Digits), Slippage, CLR_NONE);
  121.  
  122. if (OrderType () == 1)
  123. OrderClose (OrderTicket (), OrderLots (), NormalizeDouble (Ask, Digits), Slippage, CLR_NONE);
  124. }
  125. }
  126. }
  127.  
  128. int all ()
  129. {
  130. int a;
  131. for (int i = OrdersTotal () - 1; i >= 0; i --)
  132. if (OrderSelect (i, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber () == Magic && OrderSymbol () == Symbol ())
  133. a ++;
  134. return (a);
  135. }
  136.  
  137. int all_type (int type)
  138. {
  139. int a;
  140. for (int i = OrdersTotal () - 1; i >= 0; i --)
  141. {
  142. if (OrderSelect (i, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber () == Magic && OrderSymbol () == Symbol () && OrderType () == type)
  143. a ++;
  144. }
  145. return (a);
  146. }
  147.  
  148. /*double Lot_open (int type)
  149. {
  150. for (int i = OrdersTotal () - 1; i >= 0; i --)
  151. {
  152. if (OrderSelect (i, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber () == Magic && OrderSymbol () == Symbol () && OrderType () == type)
  153. return (OrderLots ());
  154. }
  155. }
  156.  
  157. double lot_buy ()
  158. {
  159. if (all_type (0) == 0) return (Lot);
  160. if (all_type (0) == 1 && all () == 1) return (NormalizeDouble (Lot + Lot, 2));
  161. if (all_type (1) == 0 && all_type (0) > 1) return (NormalizeDouble (Lot_open (0) + Lot, 2));
  162.  
  163. return (Lot);
  164. }
  165.  
  166. double lot_sell ()
  167. {
  168. if (all_type (1) == 0) return (Lot);
  169. if (all_type (1) == 1 && all () == 2) return (NormalizeDouble (Lot + Lot, 2));
  170. if (all_type (0) == 1 && all_type (1) > 1) return (NormalizeDouble (Lot_open (1) + Lot, 2));
  171.  
  172. return (Lot);
  173. }*/
Advertisement
Add Comment
Please, Sign In to add comment