#define NAME MQLInfoString(MQL_PROGRAM_NAME) #property copyright "Copyright 6 January 2019, R.M." #property link "https://www.mql5.com/en/users/beerrun" #property version "1.5" #property description "Pickup Breakeven-Trailing-Stop Script will:\n-- detect existing open orders as well as orders opened during its operation" #property description "-- if selected, prevent the script from unloading itself (sticks to chart)" #property description "-- apply a stoploss if none exists for the open order\n-- adjust only profitable open orders\n-- allow for common BE+1 method\n-- place a hidden pending order (market order)\n-- operate on ALL OPEN ORDERS ON THE CURRENT SYMBOL!" #property description " " #property description "Please contact Beerrun at ForexFactory.com or MQL5.com with any errors or questions." #property show_inputs #property strict enum scn {n,//0 Seconds s1,//1 Second s3=3,//3 Seconds s10=10,//10 Seconds s30=30,//30 Seconds m1=60,//1 Minute m5=300,//5 Minutes m15=900,//15 Minutes }; enum ynbool {No,Yes}; enum _type_ {Buy,Sell,None}; input string bets="-----------------------------------";//---Breakeven & Trailing Stop--------------------- input int BE=8;//Points to BE input int bep=3;//BE+ in Point input int bStep=10;//Points to Begin Trail After BE input int Trail=7;//Points to Trail Price input scn Scan=1;//Time Between Stoploss Scans input ynbool Sticky=Yes;//Script Sticks to Chart? input string hidden="-----------------------------------";//---Hidden Order---------------------------------- input _type_ hiddentype=None;//Type input double hiddenprice;//Price input double hiddenlots=0.03;//Lots input int hiddenslip=2;//Slippage input double hiddensl;//StopLoss input double hiddentp;//TakeProfit input int hiddenmagic=99;//Magic Number int trades,initsw=1,hiddensw=1; int scnint=(Scan>=60)?(Scan/60):Scan; int sleep=Scan*1000; string comm,space=" ",nl="\n"+" "; string tradecnt=nl+"Trade Count: "; string scntime=(Scan>=60)?" mins":" secs"; string scantime=(Scan==1)?" sec":scntime; string _scantime=(Scan==60)?" min":scantime; string name=space+NAME+nl+"Scan: "+IntegerToString(scnint)+_scantime; //+------------------------------------------------------------------+ int start(){ for(;;){ if(initsw==0)Sleep(sleep); initsw=0; int tsl=0; comm=((hiddentype!=None)&&(hiddensw==1))?name+tradecnt+IntegerToString(trades,0)+nl+"Hidden "+EnumToString(hiddentype)+": "+DoubleToString(hiddenprice,_Digits):name+tradecnt+IntegerToString(trades,0); Comment(comm); if(hiddentype!=None&&hiddensw==1){ Comment(comm+nl+"Attempting Hidden "+EnumToString(hiddentype)+" @ "+DoubleToString(hiddenprice,_Digits)+"..."); if((hiddentype==Sell&&(Bid>=hiddenprice))|| (hiddentype==Buy&&(Ask<=hiddenprice))){ int res=OrderSend(_Symbol,hiddentype,hiddenlots,hiddenprice,hiddenslip,hiddensl,hiddentp,NAME,hiddenmagic); if(res==-1)Print("OrderSend failure, error#",GetLastError()); if(res>0){ hiddensw=0; Comment(comm+nl+"Hidden "+EnumToString(hiddentype)+" successful!"); Sleep(800);}} if(hiddensw==1)Sleep(500);} TradeCount(); if(Sticky==No) if(trades==0)break; Comment(comm+nl+"Scanning StopLosses..."); Sleep(500); for(int oc=OrdersTotal()-1;oc>=0;oc--){ RefreshRates(); if(OrderSelect(oc,SELECT_BY_POS,MODE_TRADES)){ if(OrderSymbol()==_Symbol){ double OOP=OrderOpenPrice(),SL=OrderStopLoss(); if(OrderType()==0) if(Bid>=(OOP+(BE*_Point))){ if(SL=(OOP+((BE+bStep)*_Point))) if(Trail>0) if(SLOOP||SL==0)SL=OOP-(bep*_Point); if(Ask<=(OOP-((BE+bStep)*_Point))) if(Trail>0) if(SL>=Ask+(Trail*_Point))SL=Ask+(Trail*_Point); if(SL==OrderStopLoss())continue; tsl+=OrderMod(OrderTicket(),OOP,SL);} if(TradeCount()==0)break;}} if(IsStopped())return(0);} if(tsl==0){ comm=((hiddentype!=None)&&(hiddensw==1))? name+tradecnt+IntegerToString(trades,0)+nl+"Hidden "+EnumToString(hiddentype)+": "+DoubleToString(hiddenprice,_Digits): name+tradecnt+IntegerToString(trades,0); Comment(comm+nl+"Finished Scan");} if(tsl>0)Comment(comm+nl+"Finished Scan"+nl+" StopLosses Adjusted:"+IntegerToString(tsl,0)); TradeCount(); if(IsStopped())return(0);} return(0);} int deinit(){ Comment(space+"Thank you for using PickupBETS"+nl+"Bye Bye..."); Sleep(870); Comment(""); return(0);} //---------------------------------------------------------------------------------------------------------------------------------------------------------- int TradeCount(){ int tradescnt=0; for(int otcnt=OrdersTotal()-1;otcnt>=0;otcnt--){ if(OrderSelect(otcnt,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==_Symbol){tradescnt++;}} int tradechange=MathAbs(tradescnt-trades); comm=((hiddentype!=None)&&(hiddensw==1))? name+tradecnt+IntegerToString(trades,0)+nl+"Hidden "+EnumToString(hiddentype)+": "+DoubleToString(hiddenprice,_Digits): name+tradecnt+IntegerToString(trades,0); if(tradestradescnt)Comment(comm+nl+"Trades decreased by ",tradechange,""); if(tradescnt==0)Comment(comm+nl+"No trades found"); Sleep(500); trades=tradescnt; return(tradescnt);} //----------------------------------------------------- int OrderMod(int ticket,double price,double Stoploss){ static double stoploss; Stoploss=((MathFloor((Stoploss*MathPow(10,_Digits))))*(MathPow(10,-_Digits))); if(Stoploss!=stoploss){ if(!OrderModify(ticket,price,Stoploss,0,0)){ Print("OrderModify failure, Ticket#",ticket,"/ error#",GetLastError()," StopLoss:",Stoploss," OOP",price); return(0);} stoploss=Stoploss; return(1);} return(0);} //-----------------------------------------------------