//+------------------------------------------------------------------+ //| Trade_repeater.mq4 | //| Copyright 2020, Mike Robertson | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, Mike Robertson" #property link "https://www.mql5.com" #property version "2.00" #property strict int ticket ; int Ticket[126] ; extern int MagicNumber = 625 ; extern int ExpirationMinutes = 5555555 ; extern int Slippage = 2 ; extern int Chusion = 10 ; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //initializing Note Alert(" Trade Repeater Activated. Happy Trading :) ") ; return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { // Closing Note. Alert(" Expert Closed.! ") ; } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { string symbol = ChartSymbol(0) ; // Defining Counter for array static int Counter = 125 ; if(Counter<1 ) Counter=125; // Selecting and storing order if ( OrderStoring()) { Ticket[Counter]= Ticket[Counter-1] ; Ticket[Counter]= ticket ; Counter -- ; } Print ( "ticket at Index 0 =" +Ticket[0] ) ; Print ( "ticket at Index 1 =" +Ticket[1] ) ; Print ( "ticket at Index 123 =" +Ticket[123] ) ; Print ( "ticket at Index 5 =" +Ticket[5] ) ; Print ( "ticket at Index 95 =" +Ticket[95] ) ; Print ( "ticket at Index 100 =" +Ticket[100] ) ; Print ( "ticket at Index 122 =" +Ticket[122] ) ; Print ( "ticket at Index 0 =" +Ticket[0] ) ; Print ( "ticket at Index 120 =" +Ticket[120] ) ; Print ( "ticket at Index 125 =" +Ticket[125] ) ; // Preventing sending Multiple orders // Selecting last closed order int hstTotal=OrdersHistoryTotal(); for ( int i=0 ; i0; i--) { if(Ticket[i] == Lastticket) { Ticket[i] =0 ; int Type = OrderType() ; // 0= buy , 1 = Sell double SL = OrderStopLoss() ; double TP = OrderTakeProfit() ; string comment = OrderComment() ; double Price = OrderOpenPrice() ; double Closeprice = OrderClosePrice() ; double LotSize = OrderLots() ; Print("Price" + Price) ; Print("Closeprice" + Closeprice) ; Print("Type" + Type) ; Print("SL" + SL) ; Print("TP" + TP) ; Print(" COMMENT = " + comment) ; if(comment == "[tp]") // Checking if order was closed with tp { if(Type == 0) { int Eticket = OrderSend(symbol,OP_BUYLIMIT,LotSize,Price,Slippage,SL,TP,NULL,MagicNumber,TimeCurrent()+ExpirationMinutes*60) ; if(Eticket < 0) { Print("order rejected. Order error: " + GetLastError()); // Error Handling double level = (MarketInfo(Symbol(),MODE_STOPLEVEL)+20) * Point() ; double Entryprice = Price - Chusion * Point() ; int Eticket = OrderSend(symbol,OP_BUYLIMIT,LotSize,Entryprice,Slippage,0,0,NULL,MagicNumber,TimeCurrent()+ExpirationMinutes*60) ; if(Eticket < 0) { Print("order rejected. Order error: " + GetLastError()); } else Alert("Order Sent Succsessfully with modified Parameters ") ; } } if(Type == 1) { int Eticket = OrderSend(symbol,OP_SELLLIMIT,LotSize,Price,Slippage,SL,TP,NULL,MagicNumber,TimeCurrent()+5555555*60) ; if(Eticket < 0) { Print("order rejected. Order error: " + GetLastError()); // Error Handling double level = (MarketInfo(Symbol(),MODE_STOPLEVEL)+20) * Point() ; double Entryprice = Price + Chusion * Point() ; int Eticket = OrderSend(symbol,OP_BUYLIMIT,LotSize,Entryprice,Slippage,0,0,NULL,MagicNumber,TimeCurrent()+5555555*60) ; if(Eticket < 0) { Print("order rejected. Order error: " + GetLastError()); } else Alert("Order Sent Succsessfully with modified Parameters ") ; } } } } } } } } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ // Function to prevent Multiple order sending error //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool Checkorders(int magicnumber) { int openorders= OrdersTotal() ; for(int i= 0 ; i