i got array out of range can any one help me

 
//+------------------------------------------------------------------+
//|                                                ALGO INTRADAY.mq5 |
//|                        Copyright 2023, harish.trader99@gmail.com |
//|                                        harish.trader99@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, harish.trader99@gmail.com"
#property link      "harish.trader99@gmail.com"
#property version   "1.00"
#define MAX_PERCENT 10

//+-----------------------------------------------------+
//|              INCLUDE FILES                          |
//+-----------------------------------------------------+



//+-----------------------------------------------------+
//|             INPUT PARAMETERS                        |
//+-----------------------------------------------------+

input int      stoploss         = 20;
input int      takeprofit       = 40;
input int      trailingStop     = 20;
input int      minimumProfit    = 15;
input int      Step             = 05;
input double   RiskPerent       = 2;
input double   FixedVolume      = 0.1;
 
bool glBuyPlaced , glSellPlaced;
//+----------------------------------------------------+
//|                 MA INPUT                           |
//+----------------------------------------------------+

input int MAPeriod                 = 20;
input int MAShift                  = 0;
input ENUM_MA_METHOD MAMethod      = MODE_SMA;
input ENUM_APPLIED_PRICE MAPrice   = PRICE_CLOSE;


//+----------------------------------------------------+
//|                  RSI INPUT                         |
//+----------------------------------------------------+

input int RSIPeriod                = 14;
input ENUM_APPLIED_PRICE RSIprice  = PRICE_CLOSE;

//+----------------------------------------------------+
//|                  MACD INPUT                        |
//+----------------------------------------------------+

input int fast_ema_period              = 12;
input int slow_ema_period              = 26;
input int signal_period                = 9;
input ENUM_APPLIED_PRICE MACDPrice     = PRICE_CLOSE;

//+----------------------------------------------------+
//|                  ISAR INPUT                        |
//+----------------------------------------------------+

input double  step         = 0.02;
input double  maximum      = 0.2;

//+----------------------------------------------------+
//|               CUSTOM AROON INPUT                   |
//+----------------------------------------------------+

input int AroonPeriod = 14;                 
input int AroonShift  = 0; 

//+----------------------------------------------------+
//|           OnTick() event handler                   |
//+----------------------------------------------------+

void OnTick()
  {
  
//+----------------------------------------------------+
//|            TRADE STRUCTURE                         |
//+----------------------------------------------------+

   MqlTradeRequest request;
   MqlTradeResult result;
   ZeroMemory(request);
   MqlTradeCheckResult CheckResult;
   

  
//+----------------------------------------------------+
//|                RSI CALCULATION                     |
//+----------------------------------------------------+

   double myRSIArray [];
   ArraySetAsSeries(myRSIArray,true);
   
   int RSI_handle = iRSI(_Symbol,PERIOD_CURRENT,RSIPeriod,RSIprice);
   CopyBuffer(RSI_handle,0,0,3,myRSIArray);
  
   double rsi = myRSIArray[0];
   double lastrsi = myRSIArray[1];
   double prevrsi = myRSIArray[2];
   
 
   
   
//+----------------------------------------------------+
//|                MA CALCULATION                      |
//+----------------------------------------------------+

   double myMAArray[];
   ArraySetAsSeries(myMAArray,true);
   
   int MA_Handle = iMA(_Symbol,PERIOD_CURRENT,MAPeriod,MAShift,MAMethod,MAPrice);
   CopyBuffer(MA_Handle,0,0,3,myMAArray);
   
   double currentMA = myMAArray[0];
   double prevMA    = myMAArray[1];
   
   
//+---------------------------------------------------+
//|              SAR CALCULATION                      |
//+---------------------------------------------------+

   double mySARArray[];
   ArraySetAsSeries(mySARArray,true);
   
   int SAR_Handle = iSAR(_Symbol,PERIOD_CURRENT,step,maximum);
   CopyBuffer(SAR_Handle,0,0,3,mySARArray);
   
   double currentSAR = mySARArray[0];
   double prevSAR    = mySARArray[1];
   
//+---------------------------------------------------+
//|                MACD CALCULATION                   |
//+---------------------------------------------------+

   double myMACDArray[];
   ArraySetAsSeries(myMACDArray,true);
   
   int MACD_Handle = iMACD(_Symbol,PERIOD_CURRENT,fast_ema_period,slow_ema_period,signal_period,MACDPrice);
   CopyBuffer(MACD_Handle,0,0,4,myMACDArray);
   
   double ExtMacdBuffer[];
   double ExtSignalBuffer[];
   double ExtFastMaBuffer[];
   double ExtSlowMaBuffer[];
   
   
   double macd = myMACDArray[0];
   double lastmacd = myMACDArray[1];
   
//+---------------------------------------------------+
//|         CUSTOM AROON CALCULATION                  |
//+---------------------------------------------------+
   double aroonArray[];
   
   
   ArraySetAsSeries(aroonArray,true);
   
   
   int AROON_Handle = iCustom(_Symbol,PERIOD_CURRENT,"Examples\\AroonOscillator",AroonPeriod,AroonShift);
   
   CopyBuffer(AROON_Handle,0,0,1,aroonArray);
   
      
  double ExtLineBuffer[]; 
   double aroon1       = aroonArray[0];
   double aroon2       =aroonArray[1];
   

double close[];
ArraySetAsSeries(close,true);
CopyClose(_Symbol,PERIOD_CURRENT,0,0,close);

   
   
//+---------------------------------------------------+
//|        CURRENT PRICE INFORMATION                  |
//+---------------------------------------------------+

bool openPosition = PositionSelect(_Symbol);
long positionType = PositionGetInteger(POSITION_TYPE);

double currentVolume = 0;
if(openPosition == true) currentVolume = PositionGetDouble(POSITION_VOLUME);

 

Forum on trading, automated trading systems and testing trading strategies

Some operator expected

Fernando Carreiro, 2023.02.26 14:10

Please edit your post (don't create a new post) and replace your code properly (with "</>" or Alt-S), or attach the original file directly with the "+ Attach file" button below the text box.

NB! Very important! DO NOT create a new post. EDIT your original post.


 

You seem to be using ChatGPT.

We cannot help you if you used ChatGPT.

It produces horrible code, and since you don't know anything about programming in MQL yourself, you will not understand our advice, nor will you be able to fix it either since you don't know how to code.

So, either learn to code yourself or hire a human coder to do it for you.

If you are however, not using ChatGPT , then your code is incomplete and has many errors and cannot be compiled.

 
  1. 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 (2019)
              Messages Editor

  2. ChatGPT (the worst), EA builder, EA Builder Pro, EATree, Etasoft forex generator, Forex Strategy Builder, ForexEAdvisor (aka. ForexEAdvisor STRATEGY BUILDER, and Online Forex Expert Advisor Generator), ForexRobotAcademy.com, forexsb, FX EA Builder, fxDreema, Forex Generator, FxPro, Molanis, Octa-FX Meta Editor, Strategy Builder FX, Strategy Quant, Visual Trader Studio, MQL5 Wizard, etc., are all the same. You will get something quick, but then you will spend a much longer time trying to get it right, than if you learned the language up front, and then just wrote it.

    Since you haven't learned MQL4/5, therefor there is no common language for us to communicate.
    If we tell you what you need, you can't code it.
    If we give you the code, you don't know how to integrate it into yours.

    We are willing to HELP you when you post your attempt (using Code button) and state the nature of your problem, but we are not going to debug your hundreds of lines of code. You are essentially going to be on your own.

  3. ChatGPT
    1. Mixing MT4 and MT5 code together.
    2. Creating multiple OnCalculate/OnTick functions.
    3. OnCalculate returning a double.
    4. Filling buffers with zero in OnInit (they have no size yet). Setting buffer elements to zero but not setting Empty Value to correspond.
    5. Calling undefined functions.
    6. Sometimes, not using strict (MT4 code).
    7. Code that will not compile.
    8. Creating code outside of functions.
    9. Creating incomplete code.
    10. Initialization of Global variables with non-constants.
    11. Assigning a MT5 handle to a double or missing the buffer and bar indexes in a MT4 call.
    12. Useing MT4 Trade Functions without first selecting an order.
    13. Even it says do not use it
                for coding. (2023)
    EA builder
    1. Counting up while closing multiple orders.
    2. New bar code: Bars is unreliable (Max bars in chart), volume is unreliable (miss ticks.) Always use time.
    3. Not adjusting for 4/5 digit brokers, TP/SL and slippage.
    4. Not checking return codes.
    EATree Uses objects on chart to save values — not persistent storage (files or GV+Flush.) No recovery (crash/power failure.)
    ForexEAdvisor
    1. Non-updateing global variables.
    2. Compilation errors.
    3. Not checking return codes.
    4. Not reporting errors.
    FX EA Builder
    1. Not checking return codes.
    2. Loosing open tickets on terminal restart. No recovery (crash/power failure.)
    3. Not adjusting stops for the spread.
    4. Using OrdersTotal directly.
  4. Do not post code that will not even compile.

              MT4: Learn to code it.
              MT5: Begin learning to code it.

    If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.

  5.     int RSI_handle = iRSI(_Symbol,PERIOD_CURRENT,RSIPeriod,RSIprice);
       CopyBuffer(RSI_handle,0,0,3,myRSIArray); 

    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)

 
I'm glad someone is saying it! Don't believe the hype around ChatGPT and it's ability to "write code for you". Youtubers are just farming clicks with this nonsense but if any of them knows how to actually code, they should know that this is complete BS. Even if an AI could code for you, it would be more difficult to give it the correct prompts than to learn to write the code yourself. Maybe you can use ChatGPT to write single lines of code, but you are going to get better results if you just search for the documentation on Google and learn the language because over time it will become easier since you'll have a better understanding of what keywords to use. Don't waste time working on ChatGPT prompt optimization when what you need is to learn to ask the right questions on Google. If you build the skill of searching with the correct key words in order to learn what you need, you can learn anything you want.