AK-47 Scalper EA - MetaTrader 4 Expert | Scalping EA Download - MT4/MT5 Resources
1. Enter parameters
#Define external robot name "AK-47 Scalper EA" //Robot name #define version "1.00" //--- input parameters External string ESettings = "——————————————————" ; //---------------- Input integer InpMagicNumber = 124656 ; //magic number outer string trade settings = "——————————————————" ; //-------- <trade settings> -------- Enter double Inpuser_lot = 0.01 ; //a lot Enter double InpSL_Pips = 3.5 ; //Stop loss (in pips) Enter double InpMax_spread = 0.5 ; //Maximum spread allowed in pips (0 = float) outer string money settings = "——————————————————" ; //-------- <currency settings> -------- Input Boolean value isVolume_Percent= True ; //Allow volume percentage Enter double InpRisk = 3 ; //Balance risk percentage (%) Input string time setting = "——————————————————" ; //-------- <Trading time setting> -------- Input boolean InpTimeFilter = true ; //Trading time filter Input integer InpStartHour = 2 ; //Start time Enter an integer InpStartMinute = 30 ; //Start minute Input integer InpEndHour = 21 ; //End time Input integer InpEndMinute = 0 ; //End minute
//--- variables Integer Pips2Points; // Slippage 3 points 3=points 30=points Double points 2 pairs; // Stop loss 15 points 0.015 0.0150 Integer InpMax_slippage = 3 ; // Maximum slippage allow_Pips. Boolean value isOrder = false ; // Only open 1 order integer slip; string strComment = ”” ;
3. Main code
a/ expert initialization function
Integer initialization () { //--- //3-digit or 5-digit detection // dot and dot if ( number % 2 == 1 ) { Pips2Double= _View * 10 ; Pips2Points = 10 ; Slippage = 10 * InpMax_slippage; } other { Pips2Double= _View ; Pips2Points = 1 ; Slippage = InpMax_slippage; } //--- return ( initialization successful ); }
b/ Expert check function
Blank check () { //--- if (IsTradeAllowed() == false ) { comment ( "AK-47 EA\nTrading not allowed." ); return ; } Mql datetime structure time; timecurrent (structTime); structuretime.sec = 0 ; //Set the start time structTime.hour = InpStartHour; structTime.min = InpStartMinute; datetime starttime = struct to time (struct time); //Set the end time structTime.hour = InpEndHour; structTime.min = InpEndMinute; datetimetimeend = struct to time (struct time); double acSpread = market_information( symbol (), pattern_spread ); Stop loss = market information( symbol (), MODE_STOPLEVEL); string comment = "\n" + external robot name + "-v" + ( string ) version; str comment += "\nGMT time = " + string time ( timeGMT (), TIME_DATE | TIME_SECONDS ); str comment += "\nTrading time = [" + ( thin string )InpStartHour + "h" + ( thin string )Inp start minute + "-->" + ( thin string )InpEndHour + "h" + ( thin string )InpEndMinute + "]" ; str comment += "\nCurrent spread = " + ( thin string ) acSpread + "Points" ; str comment += "\nCurrent stop loss level = " + ( thin string ) stop loss level + "points" ; Comment (strComment); //update value update order(); TrailingStop(); //View transaction time if (Inp time filter) { if ( timecurrent () >= start time&& timecurrent () < timeend) { if (!isOrder) OpenOrder(); } } other { if (!isOrder) OpenOrder(); } }
3.1 Calculating signals to send orders
BlankOpenOrder (){ //int OrdType = OP_SELL; //-1; Double TP = 0 ; double SL = 0 ; string comment = ExtBotName; //Calculate the double lot size 1 = Calculate the trading volume(); //if(OrdType == OP_SELL) { Double the opening price = normalized double (Bid - (Stop* _View ) - (InpSL_Pips/ 2 ) * Pips2Double, number ); SL = Normalized Double (Ask+Stop* _View +InpSL_Pips/ 2 *Pips2Double, number ); if (check SpreadAllow()) //check spread { if (! OrderSend ( _Token , OP_SELLSTOP, Lot1, OpenPrice, Slippage, SL, TP, Comments, InpMagicNumber, 0 , RBC )) Print ( __Function__ , "-->Order sending error" , get the last error ()); } //} }
3.2 Calculate volume
Double calculated volume() { Double lot size = 0 ; if (isVolume_Percent == false ) { Lot size = Inpuser_lot; } other { Lot size = (InpRisk) * AccountFreeMargin(); Lot size = Lot size/ 100000 ; Double n = MathFloor (Number of Lots/Inpuser_lot); //Comment((string)n); Lot size = n * Inpuser_lot; if (lot<Inpuser_lot) Lot size = Inpuser_lot; if (lot size > market information( symbol (),MODE_MAXLOT)) lot size = market information( symbol (),MODE_MAXLOT); if (lot size < market information ( symbol (),MODE_MINLOT)) lot size = market information( symbol (),MODE_MINLOT); } return (lot size); }
3.3 EA has a "trailing stop loss" function, SL changes every time the price changes (falls)
Blank Trailing Stop() { for ( integer i = total number of orders () - 1 ; i >= 0 ; i -) { if ( order select (i, select by POS, MODE_TRADES)) { if ((OrderMagicNumber() == InpMagicNumber) && (OrderSymbol() == symbol ())) //_symbol)) { //For sell orders if (order type() == OP_SELL) { //-- Calculate stop loss double when price changes SL_in_Pip = normalized double (orderStopLoss() - (StopLossLevel* _View ) - Q, number ) / Pips2Double; if (SL_in_Pips > InpSL_Pips){ Double's new SL = Normalized Double (Ask + (Stop* _View ) + InpSL_Pips * Pips2Double, Number ); if (!OrderModify(OrderTicket(), OrderOpenPrice(), newSL, OrderTakeProfit(), 0 , red blood cells )) { Print ( __Function__ , "-->Order modification error" , get the last error ()); continue ; } } } //For stop loss orders , if (order type () == OP_SELLSTOP) { Double SL_in_Pip = Normalized Double (OrderStop() - (StopLevel* _View ) - Q, Number ) / Pips2Double; if (SL_in_Pips < InpSL_Pips/ 2 ){ new operation Double = Normalized Double (Bid - (Stop* _View ) - (InpSL_Pips/ 2 ) * Pips2Double, Number ); Double's new SL = Normalized Double (Ask + (Stop* _View ) + (InpSL_Pips/ 2 ) * Pips2Double, Number ); if (!OrderModify(OrderTicket(), newOP, newSL, OrderTakeProfit(), 0 , red blood cells )) { Print ( __Function__ , "--> Modify PendingOrder error!" , Get the last error ()); continue ; } } } } } } }
Attachment download
📎 ak-47_scalper_ea_-_mt4.mq4 (43.86 KB)
Source: MQL5 #42236
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •