spacepaste

  1.  
  2. //+------------------------------------------------------------------+
  3. //| My_First_EA_edits.mq4 |
  4. //| Agent86's Dirty Rat Trade |
  5. //| http://www.iclbiz.com/joomla |
  6. //+------------------------------------------------------------------+
  7. #property copyright "Agent86 Dirty Rat Trade"
  8. #property link "www.iclbiz.com/joomla"
  9. //---- input parameters
  10. extern double TakeProfit=200.0;
  11. extern double Lots=0.1;
  12. extern double StopLoss=12.0;
  13. //+------------------------------------------------------------------+
  14. //| expert initialization function |
  15. //+------------------------------------------------------------------+
  16. int init()
  17. {
  18. //----
  19. //----
  20. return(0);
  21. }
  22. //+------------------------------------------------------------------+
  23. //| expert deinitialization function |
  24. //+------------------------------------------------------------------+
  25. int deinit()
  26. {
  27. //----
  28. //----
  29. return(0);
  30. }
  31. int Crossed (double line1 , double line2)
  32. {
  33. static int last_direction = 0;
  34. static int current_direction = 0;
  35. if(line1>line2)current_direction = 1; //up
  36. if(line1<line2)current_direction = 2; //down
  37. if(current_direction != last_direction) //changed
  38. {
  39. last_direction = current_direction;
  40. return (last_direction);
  41. }
  42. else
  43. {
  44. return (0);
  45. }
  46. }
  47. //+------------------------------------------------------------------+
  48. //| expert start function |
  49. //+------------------------------------------------------------------+
  50. int start()
  51. {
  52. //----
  53. int cnt, ticket, total;
  54. double faster, slower;
  55. if(Bars<100)
  56. {
  57. Print("bars less than 100");
  58. return(0);
  59. }
  60. if(TakeProfit<10)
  61. {
  62. Print("TakeProfit less than 10");
  63. return(0); // check TakeProfit
  64. }
  65. faster = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
  66. slower = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
  67. int isCrossed = Crossed (faster,slower);
  68. total = OrdersTotal();
  69. if(total < 1)
  70. {
  71. if(isCrossed == 1)
  72. {
  73. ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"Agent86",12345,0,Green);
  74. if(ticket>0)
  75. {
  76. if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
  77. }
  78. else Print("Error opening BUY order : ",GetLastError());
  79. return(0);
  80. }
  81. if(isCrossed == 2)
  82. {
  83. ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+StopLoss,Bid-TakeProfit*Point,"Agent86",12345,0,Red);
  84. if(ticket>0)
  85. {
  86. if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
  87. }
  88. else Print("Error opening SELL order : ",GetLastError());
  89. return(0);
  90. }
  91. return(0);
  92. }
  93. for(cnt=0;cnt<total;cnt++)
  94. {
  95. OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
  96. if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
  97. {
  98. if(OrderType()==OP_BUY) // long position is opened
  99. {
  100. // should it be closed?
  101. if(isCrossed == 2)
  102. {
  103. OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
  104. return(0); // exit
  105. }
  106. // should it be closed?
  107. if(isCrossed == 1)
  108. {
  109. OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
  110. return(0); // exit
  111. }
  112. }
  113. }
  114. }
  115. return(0);
  116. }
  117. //+------------------------------------------------------------------+
  118.