hi guys, i have convert this indicator to an Expert but it doesnt work on backtest and it doesnt trade:
Can anyone Fix this problem?
//+------------------------------------------------------------------+//| Find Swing High_SwingLow.mq5 |//| Copyright 2024, MetaQuotes Ltd. |//| https://www.mql5.com |//+------------------------------------------------------------------+inputdouble LotSize = 0.25; // Lot size for tradesinputdouble StopLoss = 50; // Stop loss in pointsinputdouble TakeProfit = 100; // Take profit in pointsinputint InpRangeBars = 12; // Number of bars to check for swings#include <Trade\Trade.mqh> // Include the Trade library
CTrade trade; // Create an instance of the CTrade class// Function to get the signal from your custom indicatordouble GetIndicatorSignal()
{
// Replace "Find Swing High_SwingLow" with the name of your indicator// Assuming it returns 1 for buy, -1 for sell, and 0 for no actiondouble signal = iCustom(_Symbol, 0, "Meghdad Profit");
return signal;
}
// Function to open a buy positionvoid OpenBuy(double lotSize)
{
double askPrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
if (trade.Buy(lotSize, _Symbol, askPrice))
{
Print("Buy order placed at price: ", askPrice);
}
else
{
Print("Error placing buy order: ", GetLastError());
}
}
// Function to open a sell positionvoid OpenSell(double lotSize)
{
double bidPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID);
if (trade.Sell(lotSize, _Symbol, bidPrice))
{
Print("Sell order placed at price: ", bidPrice);
}
else
{
Print("Error placing sell order: ", GetLastError());
}
}
// Main function that runs on each tickvoidOnTick()
{
double SwingHigh = iCustom(NULL, 0, "Find Swing High_SwingLow", InpRangeBars, 0, 1);
double SwingLow = iCustom(NULL, 0, "Find Swing High_SwingLow", InpRangeBars, 1, 1);
// Check for existing positionsbool hasPosition = false;
for (int i = PositionsTotal() - 1; i >= 0; i--)
{
if (PositionGetSymbol(i) == Symbol())
{
hasPosition = true;
break;
}
}
staticdouble previousSignal = 0; // To keep track of the last signaldouble currentSignal = GetIndicatorSignal(); // Get the current signal// Buy condition based on SwingLow and currentSignalif (SwingLow != EMPTY_VALUE && !hasPosition && currentSignal == 1 && previousSignal != 1)
{
OpenBuy(LotSize); // Use input LotSize
}
// Sell condition based on SwingHigh and currentSignalif (SwingHigh != EMPTY_VALUE && !hasPosition && currentSignal == -1 && previousSignal != -1)
{
OpenSell(LotSize); // Use input LotSize
}
previousSignal = currentSignal; // Update previous signal
}
//+------------------------------------------------------------------+
Hi Philani, Just wondering if it is possible to add an Alert System to the code. Also, could you place the Arrows and "H" or "L" a little further away from the wicks of the Low and High of the candle.
Hello. Thnks so much for the swinghigh swinglow indicator. However,whenever there are 2 candles near each with either equal lows or equal highs,the indicator is not able to capture the swing low/high in that area.
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.
here's another (maybe better) way to optimize, when the buffers are very custom:
hi guys, i have convert this indicator to an Expert but it doesnt work on backtest and it doesnt trade:
Can anyone Fix this problem?
Hi,
Thanks looking forward to the EA for this indicator. Cus I'm not on the pc all the time and I can't see it on my mobile so would be great.
So far the arrows are oke sometimes it shows sell but the market is buying this is based on previous timecharts.
How do you recommend to apply this indicator at its best?
here's another (maybe better) way to optimize, when the buffers are very custom:
Find Swing Highs Swing Lows:
Author: Philani Mthembu
Also, could you place the Arrows and "H" or "L" a little further away from the wicks of the Low and High of the candle.
hi guys, i have convert this indicator to an Expert but it doesnt work on backtest and it doesnt trade:
Can anyone Fix this problem?
you need to call your sell and buy position properly under on tick function