void OnTick() { static double lastHigh = 0.0; static double lastLow = 0.0; static double trailingStop = 0.0; static bool reversed = false; double currentHigh, currentLow; double point = SymbolInfoDouble(_Symbol, SYMBOL_POINT); double reverseLevel = 500 * point; if (!CopyHigh(_Symbol, 0, 1, 1, currentHigh) || !CopyLow(_Symbol, 0, 1, 1, currentLow)) { Print("Error copying high/low prices"); return; } if (!reversed) { if (lastHigh == 0.0 || currentHigh > lastHigh) { lastHigh = currentHigh; trailingStop = lastHigh - reverseLevel; } if (lastLow == 0.0 || currentLow < lastLow) { lastLow = currentLow; trailingStop = lastLow + reverseLevel; } double currentPrice = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID), Digits); double stopLoss = NormalizeDouble(trailingStop, Digits); if (currentPrice >= stopLoss) { // Place reverse trade logic here // For example: // OrderSend(Symbol(), OP_BUY, 1.0, currentPrice, 3, 0, 0, "Reverse Trade", 0, 0, Green); // Reset variables lastHigh = 0.0; lastLow = 0.0; trailingStop = 0.0; reversed = true; } } else { // Add logic for managing the reverse trade // This could include setting a take profit or trailing stop for the reverse trade } }