//+------------------------------------------------------------------+ //| 3.0mql5.mq5 | //| Copyright 2022, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2022, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" //+------------------------------------------------------------------+ //| Global variables | //+------------------------------------------------------------------+ // Scalping settings double ScalpThreshold = 0.0; double StopLoss = 0.0; double TakeProfit = 0.0; double Point = 0.0; // Trade tracking variables int buyTicket = 0; int sellTicket = 0; double openPrice = 0.0; double dailyProfit = 0.0; bool dailyProfitThresholdReached = false; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { // Reset the daily profit variable dailyProfit = 0.0; // Reset the daily profit threshold reached flag dailyProfitThresholdReached = false; // Return success return (INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { // Reset the daily profit variable dailyProfit = 0.0; // Reset the daily profit threshold reached flag dailyProfitThresholdReached = false; } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ int OnTick() { // Check if the daily profit threshold has been reached if(dailyProfitThresholdReached) { // If the daily profit threshold has been reached, close any open trades and return if(buyTicket > 0) { OrderClose(buyTicket, OrderLots(), Bid, 10, Violet); } if(sellTicket > 0) { OrderClose(sellTicket, OrderLots(), Ask, 10, Violet); } return; // Set the default leverage for the trade int leverage = 100; // Check if the spread is less than the scalp threshold and there are no open orders if(SymbolInfoDouble(Symbol(), SYMBOL_SPREAD) < ScalpThreshold && buyTicket == 0 && sellTicket == 0) { // Open a buy order buyTicket = OrderSend(Symbol(), OP_BUY, 1.0, Ask, 10, 0, 0, "scalp-buy", leverage, 0, Green); // Set the stop loss and take profit for the buy order OrderModify(buyTicket, Ask - StopLoss * Point, Ask + TakeProfit * Point, 0, Blue); // Set the open price for the buy order openPrice = Ask; } // Check if there is a buy order open if(buyTicket > 0) { // Check if the order has hit the take profit or the market has moved in favor of the order if(OrderProfit() > 0 || Ask > openPrice + TrailingStop * Point) { // If either condition is true, close the order and reset the buy ticket variable OrderClose(buyTicket, OrderLots(), Bid, 10, Violet); buyTicket = 0; // Update the daily profit variable dailyProfit += OrderProfit(); // Check if the daily profit has reached or exceeded the threshold if(dailyProfit >= 50) { // If the daily profit has reached or exceeded the threshold, set the daily profit threshold reached flag to true // and return dailyProfitThresholdReached = true; return; } } } // Check if the spread is less than the scalp threshold and there are no open orders if(SymbolInfoDouble(Symbol(), SYMBOL_SPREAD) < ScalpThreshold && buyTicket == 0 && sellTicket == 0) { // Open a sell order sellTicket = OrderSend(Symbol(), OP_SELL, 1.0, Bid, 10, 0, 0, "scalp-sell", leverage, 0, Green); // Set the stop loss and take profit for the sell order OrderModify(sellTicket, Bid + StopLoss * Point, Bid - TakeProfit * Point, 0, Blue); // Set the open price for the sell order openPrice = Bid; } // Check if there is a sell order open if(sellTicket > 0) { // Check if the order has hit the take profit or the market has moved in favor of the order if(OrderProfit() > 0 || Bid < openPrice - TrailingStop * Point) { // If either condition is true, close the order and reset the sell ticket variable OrderClose(sellTicket, OrderLots(), Ask, 10, Violet); sellTicket = 0; // Update the daily profit variable dailyProfit += OrderProfit(); // Check if the daily profit has reached or exceeded the threshold if(dailyProfit >= 50) { // If the daily profit has reached or exceeded the threshold, set the daily profit threshold reached flag to true // and return dailyProfitThresholdReached = true; return; } } } } } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+