'iRSI' - wrong parameters count My EA.mq5 55 25

 

Whats wrong with this code? 

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit()

{

    // Indikátorok inicializálása

    return(INIT_SUCCEEDED);

}



//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

{

}



//+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+

void OnTick()

{

    checkFVGAndRSI();

}



//+------------------------------------------------------------------+

//| Check for FVG and RSI divergence                                 |

//+------------------------------------------------------------------+

void checkFVGAndRSI()

{

    if (checkFairValueGap(PERIOD_M15) || checkFairValueGap(PERIOD_M5) || checkFairValueGap(PERIOD_M1))

    {

        checkRSIDivergenceAndTrade();

    }

}



// Globális változók

input int RSI_Length = 5; // RSI periódus hossza

double entryPrice = 0.0; // Belépési ár

double stopLoss = 0.0; // Stop loss szint

double takeProfit = 0.0; // Take profit szint



// Trend irányának tárolása

enum TrendDirection {

    None,

    Bullish,

    Bearish

};

TrendDirection trendDirection = None; // Alapértelmezett trend irány



//+------------------------------------------------------------------+

//| Check for RSI divergence and place trades                        |

//+------------------------------------------------------------------+

void checkRSIDivergenceAndTrade()

{

    double rsiCurrent = iRSI(Symbol(), PERIOD_M1, RSI_Length, PRICE_CLOSE, 0);

    double rsiPrevious = iRSI(Symbol(), PERIOD_M1, RSI_Length, PRICE_CLOSE, 1);

    double lastLow = iLow(Symbol(), PERIOD_M1, 1);

    double lastHigh = iHigh(Symbol(), PERIOD_M1, 1);



    if (trendDirection == Bearish && rsiPrevious < rsiCurrent)

    {

        // Bullish RSI divergencia

        openLongPosition(lastLow);

    }

    else if (trendDirection == Bullish && rsiPrevious > rsiCurrent)

    {

        // Bearish RSI divergencia

        openShortPosition(lastHigh);

    }

}



//+------------------------------------------------------------------+

//| Check for Fair Value Gap (FVG)                                    |

//+------------------------------------------------------------------+

bool checkFairValueGap(ENUM_TIMEFRAMES period)

{

    double high1 = iHigh(Symbol(), period, 1);

    double low1 = iLow(Symbol(), period, 1);

    double high2 = iHigh(Symbol(), period, 2);

    double low2 = iLow(Symbol(), period, 2);

    double high3 = iHigh(Symbol(), period, 3);

    double low3 = iLow(Symbol(), period, 3);



    if ((high1 > high2 && high2 > high3) && (low1 > low2 && low2 > low3))

    {

        if (high3 < low1)

        {

            trendDirection = Bullish;

            return true;

        }

    }

    else if ((low1 < low2 && low2 < low3) && (high1 < high2 && high2 < high3))

    {

        if (low3 > high1)

        {

            trendDirection = Bearish;

            return true;

        }

    }

    trendDirection = None;

    return false;

}



//+------------------------------------------------------------------+

//| Open a long position                                             |

//+------------------------------------------------------------------+

void openLongPosition(double lastLow)

{

    MqlTradeRequest request = {};

    MqlTradeResult result = {};



    stopLoss = lastLow - 10 * _Point; // Stop loss 10 ponttal az alj pont alatt

    takeProfit = SymbolInfoDouble(Symbol(), SYMBOL_ASK) + 2 * (SymbolInfoDouble(Symbol(), SYMBOL_ASK) - stopLoss); // 2RR take profit



    request.symbol = Symbol();

    request.action = TRADE_ACTION_DEAL;

    request.volume = 0.01;

    request.price = SymbolInfoDouble(Symbol(), SYMBOL_ASK);

    request.sl = stopLoss;

    request.tp = takeProfit;

    request.type = ORDER_TYPE_BUY;

    request.type_filling = ORDER_FILLING_FOK;



    if (!OrderSend(request, result))

    {

        Print("OrderSend failed: ", GetLastError());

    }

}



//+------------------------------------------------------------------+

//| Open a short position                                            |

//+------------------------------------------------------------------+

void openShortPosition(double lastHigh)

{

    MqlTradeRequest request = {};

    MqlTradeResult result = {};



    stopLoss = lastHigh + 10 * _Point; // Stop loss 10 ponttal a magaslati pont felett

    takeProfit = SymbolInfoDouble(Symbol(), SYMBOL_BID) - 2 * (stopLoss - SymbolInfoDouble(Symbol(), SYMBOL_BID)); // 2RR take profit



    request.symbol = Symbol();

    request.action = TRADE_ACTION_DEAL;

    request.volume = 0.01;

    request.price = SymbolInfoDouble(Symbol(), SYMBOL_BID);

    request.sl = stopLoss;

    request.tp = takeProfit;

    request.type = ORDER_TYPE_SELL;

    request.type_filling = ORDER_FILLING_FOK;



    if (!OrderSend(request, result))

    {

        Print("OrderSend failed: ", GetLastError());

    }

}


 
  1. Patrik Simon: Whats wrong with this code?

    Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
          General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
              Messages Editor
          Forum rules and recommendations - General - MQL5 programming forum (2023)

  2.   double rsiCurrent = iRSI(Symbol(), PERIOD_M1, RSI_Length, PRICE_CLOSE, 0);
    
      double rsiPrevious = iRSI(Symbol(), PERIOD_M1, RSI_Length, PRICE_CLOSE, 1);

    Those are MT4 calls.

    Perhaps you should read the manual, especially the examples.
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
              How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
              MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
              How to call indicators in MQL5 - MQL5 Articles (2010)

  3. takeProfit = SymbolInfoDouble(Symbol(), SYMBOL_ASK) + 2 * (SymbolInfoDouble(Symbol(), SYMBOL_ASK) - stopLoss); // 2RR take profit

    You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)

      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
      My GBPJPY shows average spread = 26 points, average maximum spread = 134.
      My EURCHF shows average spread = 18 points, average maximum spread = 106.
      (your broker will be similar).
                Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)

 

Use the documentation reference. Or press F1 key after highlighting the function name

https://www.mql5.com/en/docs/indicators/irsi

Documentation on MQL5: Technical Indicators / iRSI
Documentation on MQL5: Technical Indicators / iRSI
  • www.mql5.com
The function returns the handle of the Relative Strength Index indicator. It has only one buffer. Parameters symbol [in] The symbol name of the...