//+------------------------------------------------------------------+ //| RaviEA.mq4 | //| @2009 Desynced Tech | //| http://desynced.no-ip.org/fx | //+------------------------------------------------------------------+ #property copyright "@2009 Desynced Tech" #property link "http://desynced.no-ip.org/fx" #include <mysql.mqh> datetime lastOrder ; int ticket = -1; extern int takeprofit = 50; int orderTik; int hedgeTik; int MAGIC = 1666; extern double lots = 0.1; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } int decision () { double x0=iCustom(NULL, 0, "ravi",0,0); double x1=iCustom(NULL, 0, "ravi",0,1); double y0 = iCustom(NULL, 0, "fractal_dimension",0,0); double y1 = iCustom(NULL, 0, "fractal_dimension",1,0); double y2 = iCustom(NULL, 0, "fractal_dimension",2,0); if ( x0 > 0 && x1 < 0 ) { if ( y0 < 2 ) Print("buy " , y0); else Print("outros " , y1 , y2 ); return(1); } if ( x1>0 && x0 < 0 ) { if ( y0 < 2 ) Print("sell " , y0); else Print("outros " , y1 , y2 ); return(-1); } return (0); // Comment( x0 , " " , x1 ) ; } void getTrades() { int total = OrdersTotal(); int numords = 0; int tickets[10]; int ticketsFound = 0; for(int cnt=0; cnt<total; cnt++) { OrderSelect(cnt, SELECT_BY_POS); if(OrderSymbol() == Symbol() && OrderMagicNumber() == MAGIC) tickets[ticketsFound] = OrderTicket(); ticketsFound++; } if ( ticketsFound == 2 ) { if ( tickets[0] < tickets[1] ) { orderTik = tickets[0]; hedgeTik = tickets[1]; // Print("orignal é " , tickets[0] , " hedge " , tickets[1] ) ; } else { //Print("orignal é " , tickets[1] , " hedge " , tickets[0] ) ; orderTik = tickets[1]; hedgeTik = tickets[0]; } } else if ( ticketsFound == 1 ) { orderTik = tickets[0]; hedgeTik = -1; } else if ( ticketsFound < 1 ) { orderTik = -1; hedgeTik = -1; } else if ( ticketsFound > 2 ) { Print("FODDASE NAO PODE HAVER MAIS QUE 2 "); } } int closeOrder(int ticket,int orderType, double lts) { if ( orderType == OP_BUY ) { OrderClose(ticket,lts,Bid,3,Green); return(0); } else { OrderClose(ticket, lts, Ask, 3, Green); return(0); } } datetime checkTicket (int tik) { int hstTotal=OrdersHistoryTotal(); datetime ret = 0; if(OrderSelect(tik,SELECT_BY_TICKET,MODE_HISTORY) !=false ) { ret = OrderCloseTime(); return(ret); } return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { orderTik = -1; hedgeTik = -1; getTrades(); if ( orderTik != -1 ) { OrderSelect(orderTik, SELECT_BY_TICKET); //if ( (TimeCurrent() - OrderOpenTime() ) > (60*60*4) ) closeOrder(orderTik,OrderType(),OrderLots()); return(0); } int decision = decision(); if ( ticket > 0 ) { datetime lastOrder = checkTicket(ticket); if ( (TimeCurrent() - lastOrder) < (60*60*1) ) return(0); } if ( decision == 1 ) { ticket = OrderSend(Symbol(),OP_BUY, lots, Ask, 3, 0, Ask+takeprofit*Point,"", MAGIC, 0, Red); if ( ticket > 0 ) { /* mysql_connect("192.168.0.3","forex","forex","forex",3306); insertOrderDb(ticket,Symbol(),Ask,0, Ask+takeprofit*Point,MAGIC,"RAVIEA",OP_BUY, TimeCurrent()); mysql_close(mysql); */ lastOrder = TimeCurrent(); } } else if ( decision == -1 ) { ticket = OrderSend(Symbol(),OP_SELL, lots, Bid, 3, 0, Bid-takeprofit*Point,"", MAGIC, 0, Red); if ( ticket > 0 ) { /* mysql_connect("192.168.0.3","forex","forex","forex",3306); insertOrderDb(ticket,Symbol(),Bid,0, Bid-takeprofit*Point,MAGIC,"RAVIEA",OP_SELL, TimeCurrent()); mysql_close(mysql); lastOrder = TimeCurrent(); */ } } return(0); } //+------------------------------------------------------------------+
Sample
Analysis
Market Information Used:
Indicator Curves created:
Indicators Used:
Custom Indicators Used:
ravi
fractal_dimension
Order Management characteristics:
Checks for the total of open orders
It Closes Orders by itself
Checks for the total of closed orders
It automatically opens orders when conditions are reached
Other Features: