-
- //+------------------------------------------------------------------+
- //| My_First_EA_edits.mq4 |
- //| Agent86's Dirty Rat Trade |
- //| http://www.iclbiz.com/joomla |
- //+------------------------------------------------------------------+
- #property copyright "Agent86 Dirty Rat Trade"
- #property link "www.iclbiz.com/joomla"
-
- //---- input parameters
- extern double TakeProfit=200.0;
- extern double Lots=0.1;
- extern double StopLoss=120.0;
- //+------------------------------------------------------------------+
- //| expert initialization function |
- //+------------------------------------------------------------------+
- int init()
- {
- //----
-
- //----
- return(0);
- }
- //+------------------------------------------------------------------+
- //| expert deinitialization function |
- //+------------------------------------------------------------------+
- int deinit()
- {
- //----
-
- //----
- return(0);
- }
-
- int Crossed (double line1 , double line2)
- {
- static int last_direction = 0;
- static int current_direction = 0;
-
- if(line1>line2)current_direction = 1; //up
- if(line1<line2)current_direction = 2; //down
-
-
-
- if(current_direction != last_direction) //changed
- {
- last_direction = current_direction;
- return (last_direction);
- }
- else
- {
- return (0);
- }
- }
- //+------------------------------------------------------------------+
- //| expert start function |
- //+------------------------------------------------------------------+
- int start()
- {
- //----
-
-
- int cnt, ticket, total;
- double faster, slower;
-
-
- if(Bars<100)
- {
- Print("bars less than 100");
- return(0);
- }
- if(TakeProfit<10)
- {
- Print("TakeProfit less than 10");
- return(0); // check TakeProfit
- }
-
-
- faster = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_UPPER,0); //MODE_MAIN
- slower = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_LOWER,0); //MODE_SIGNAL
-
- int isCrossed = Crossed (faster,slower);
-
- total = OrdersTotal();
- if(total < 1)
- {
- if(isCrossed == 1)
- {
- ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"Agent86",12345,0,Green);
- if(ticket>0)
- {
- if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
- }
- else Print("Error opening BUY order : ",GetLastError());
- return(0);
- }
- if(isCrossed == 2)
- {
-
- ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+StopLoss*Point,Bid-TakeProfit*Point,"Agent86",12345,0,Red);
- if(ticket>0)
- {
- if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
- }
- else Print("Error opening SELL order : ",GetLastError());
- return(0);
- }
- return(0);
- }
- if(total >=1)
- {
- OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES);
- OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
- return(0); // exit
- }
- return(0);
- }
- //+------------------------------------------------------------------+
-