mt4 Level Stop Reversal Ea
mt4 Level Stop Reversal Ea
// Indicator configuration
string IndicatorName = "MT4-LevelStop-Reverse";
int SignalBufferUp = 1; // Buffer for buy signals
int SignalBufferDown = 2; // Buffer for sell signals
// Indicator parameters
input bool UseVTDefaultOptimal = false;
input bool UseATRMode = true;
input int NonATRStopPips = 40;
input int ATRPeriod = 14;
input double ATRMultiplier = 3.0;
input color UpArrowColor = DodgerBlue;
input color DnArrowColor = OrangeRed;
input int ArrowDistance = 25;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Verify indicator is available
if (iCustom(NULL, 0, IndicatorName, UseVTDefaultOptimal, UseATRMode,
NonATRStopPips, ATRPeriod, ATRMultiplier, UpArrowColor, DnArrowColor,
ArrowDistance) == INVALID_HANDLE)
{
Print("Error: Indicator not found - ", IndicatorName);
return(INIT_FAILED);
}
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
static datetime lastSignalTime = 0;
//+------------------------------------------------------------------+
//| Function to open orders |
//+------------------------------------------------------------------+
void OpenOrder(int type)
{
double price = (type == OP_BUY) ? Ask : Bid;
double stopLoss = 0; // Add SL logic if needed
double takeProfit = 0; // Add TP logic if needed
//+------------------------------------------------------------------+
//| Function to close all orders of a specific type |
//+------------------------------------------------------------------+
void CloseOrders(int type)
{
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
if (OrderSelect(i, SELECT_BY_POS) && OrderMagicNumber() == MagicNumber &&
OrderSymbol() == Symbol() && OrderType() == type)
{
double price = (type == OP_BUY) ? Bid : Ask;
if (!OrderClose(OrderTicket(), OrderLots(), price, Slippage, clrRed))
{
Print("Error closing order: ", GetLastError());
}
else
{
Print((type == OP_BUY ? "Buy" : "Sell"), " order closed
successfully. Ticket: ", OrderTicket());
}
}
}
}