Please can anyone add stoploss and take profit in this script .. i will be very thankful to you
externintBuyThreshold=40;externintSellThreshold=30;externdoubleLots=1;externintMagicNumber=33;externstringcomment="by example script";externintmaxOpenPositions=3;externintshift=1;intRSILength=14;intTimeOfFirstBar=0;intinit(){}intstart(){doubleRSI=0.0;if(isFirstTickOfCurrentBar()){RSI=iRSI(NULL,PERIOD_H1,RSILength,PRICE_CLOSE,shift);Print("Got RSI value for period H1 and shift ",shift," equals to ",RSI);// Buy Condition
if(RSI>=BuyThreshold&&OrdersTotal()<maxOpenPositions){if(doBuy()==false){return(0);}}// Close condition
if(RSI<=SellThreshold&&OrdersTotal()>0){if(doClose()==false){return(0);}}}}// Figures out the first tick of a new bar
boolisFirstTickOfCurrentBar(){if(TimeOfFirstBar!=Time[1]){TimeOfFirstBar=Time[1];return(true);}return(false);}// Close an order checking magic number to make sure it is generated from current script
booldoClose(){OrderSelect(0,SELECT_BY_POS,MODE_TRADES);if(OrderClose(OrderTicket(),OrderLots(),Ask,0,White)==-1){Print("Failed to close trade ",OrderTicket(),", error # ",GetLastError());return(false);}Print("Successfully closed trade ",OrderTicket(),", error # ",GetLastError());return(true);}// Open a new order
booldoBuy(){intticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,0,0.0,0.0,comment,MagicNumber,0,Lime);if(ticket<0){Print("Failed to open trade, error # ",GetLastError());return(false);}Print("Successfully opened ticket ",ticket);return(true);}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Please can anyone add stoploss and take profit in this script .. i will be very thankful to you