-
- //+------------------------------------------------------------------+
- //| My_First_EA_edits.mq4 |
- //| Agent86's Dirty Rat Trade |
- //| http://www.iclbiz.com/joomla |
- //+------------------------------------------------------------------+
- #property copyright "Agent86 My First EA"
- #property link "www.iclbiz.com/joomla"
-
- //---- input parameters
- extern double TakeProfit=1000.0;
- extern double Lots=0.1;
- extern double StopLoss=500.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);
- }
- }
-
- int Crossed_2 (double line1 , double line2) //i'll use this later for my macd agreement
- {
- static int last_direction_2 = 0;
- static int current_direction_2 = 0;
-
- if(line1>line2)current_direction_2 = 1; //up
- if(line1<line2)current_direction_2 = 2; //down
-
-
-
- if(current_direction_2 != last_direction_2) //changed
- {
- last_direction_2 = current_direction_2;
- return (last_direction_2);
- }
- else
- {
- return (0);
- }
- }
-
-
-
- //+------------------------------------------------------------------+
- //| expert start function |
- //+------------------------------------------------------------------+
- int start()
- {
- //----
-
-
- int cnt, ticket, total;
- double faster, slower, faster_2, slower_2;
-
-
- 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_MAIN,0); //MODE_MAIN
- slower = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0); //MODE_SIGNAL
- faster_2 = iMACD(NULL,PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_UPPER,0); //MODE_MAIN
- slower_2 = iMACD(NULL,PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_UPPER,0); //MODE_SIGNAL
-
- int isCrossed = Crossed (faster,slower);
- int isCrossed_2 = Crossed_2 (faster_2,slower_2); // i'll use this later
-
- 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);
- }
- for(cnt=0;cnt<total;cnt++)
- {
- OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
- if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
- {
- if(OrderType()==OP_BUY) // long position is opened
- {
- // should it be closed?
- if(isCrossed == 2)
- {
- OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
- return(0); // exit
- }
-
- // should it be closed?
- if(isCrossed == 1)
- {
- OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
- return(0); // exit
- }
- }
- }
- }
- return(0);
- }
- //+------------------------------------------------------------------+
-