//+------------------------------------------------------------------+ //| for_mineerija.mq4 | //| Copyright 2015, AVG Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, AVG Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ extern int TF=PERIOD_M1; //TimeFrame datetime timePreviosBar; int OnInit() { //--- timePreviosBar=iTime(Symbol(), TF, 0); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- if (iTime(Symbol(), TF, 0)>timePreviosBar) { double lots = 0; double profit = 0; double otk=0; datetime opt=0; bool find=false; int ticket; double CO0 = Open [0]; // Current Candle Open double CO1 = Open [1]; // Previous Candle Open double CC1 = Close [1]; // Previous Candle Close double CH1 = High [1]; // Previous Candle High double CL1 = Low [1]; // Previous Candle Low double RCTS = CH1 - CC1; // Rising Candle Top Shadow double RCBS = CO1 - CL1; // Rising Candle Top Shadow double RCL = CC1 - CO1; // Rising Candle Length double FCTS = CH1 - CO1; // Falling Candle Top Shadow double FCBS = CC1 - CL1; // Falling Candle Bottom Shadow double FCL = CO1 - CC1; //Falling Candle Length for(int i = OrdersTotal() -1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) { if(OrderMagicNumber()!= 12347) continue; find=true; if(OrderOpenTime() > opt) { opt = OrderOpenTime(); otk = OrderTicket(); } } } if(otk>0) { Alert ("order 12347 found from live"); } else { if(!find) { Alert ("cant find 12347 from live"); for(int a = OrdersTotal() -1; a>=0; a--) { if(OrderSelect(a,SELECT_BY_POS,MODE_HISTORY)==true) { if(OrderMagicNumber()!= 12347) continue; find=true; if(OrderOpenTime() > opt) { opt = OrderOpenTime(); otk = OrderTicket(); lots = OrderLots(); profit = OrderProfit(); } } } if(otk>0) { if (profit > 0 && CO1 < CC1 ) { ticket=OrderSend(Symbol(),OP_BUY,0.01,Bid,3,NormalizeDouble(Ask-150*Point,Digits),NormalizeDouble(Ask+150*Point,Digits),"My order",12347,0,clrGreen); } else if (profit > 0 && CO1 > CC1) { ticket=OrderSend(Symbol(),OP_SELL,0.01,Bid,3,NormalizeDouble(Bid+150*Point,Digits),NormalizeDouble(Bid-150*Point,Digits),"My order",12347,0,clrGreen); } else if (profit < 0 && CO1 < CC1) { ticket=OrderSend(Symbol(),OP_BUY,lots*2,Bid,3,NormalizeDouble(Ask-150*Point,Digits),NormalizeDouble(Ask+150*Point,Digits),"My order",12347,0,clrGreen); } else if (profit < 0 && CO1 > CC1) { ticket=OrderSend(Symbol(),OP_SELL,lots*2,Bid,3,NormalizeDouble(Bid+150*Point,Digits),NormalizeDouble(Bid-150*Point,Digits),"My order",12347,0,clrGreen); } } else { if(!find) Alert ("cant find 12347 from history"); } } // This write your code. // Code is executed once at the beginning of each new candle (bar) timePreviosBar=iTime(Symbol(), TF, 0); }} } //+------------------------------------------------------------------+