Help with error on rectangle for EA - if expression are not allowed on global scale.. where does my curly bracket go?

 

Can somebody check my code and tell me what i need to change?

My if statements are within the ontick function so i didnt think they were on the global scope...
but without the closed bracket before the if statements i get alot more errors. 34 as opposed to 3 ha ha


Thought Process based on previous tutorials/doco

Definately could be overthinking... 

Define Candles OHLC to be able to use these for working out whether BULL or BEAR
Define BULL or BEAR candles
Create variable for FVGHighs and FVGLows
Create array to store the price of the highs and lows and sort these from candle 0 to previous candles
Fill the arrays with the price data for the last 3 candles
Use those ArrayPrices for our FVGHighs and Lows
Store price data in Price and sort from current candle backwards
Delete any rectangles already present (if i want multiple rectangles... this step shouldn't be here)
Define what constitutes our FVG Gap for the Rectangle
Then create our rectangle with our designated settings


void OnTick(){
//A - Candle 3's low is higher than candle 1's high so there is a gap which needs to have a rectangle drawn there
//B - Candles 3's high is lower than candle 1's low so there is a gap which needs to have a rectangle drawn there

//define Candle OHLC Prices
  double CLow = PRICE_LOW;
  double CHigh = PRICE_HIGH;
  double COpen = PRICE_OPEN;
  double CClose = PRICE_CLOSE;

//define Bull and Bear Candles
  double Bull = PRICE_OPEN<PRICE_CLOSE;
  double Bear = PRICE_OPEN>PRICE_CLOSE;
  
  // Create variable for Highs and Lows for A or B Scenario
  int FVGHigh,FVGLow;
  
  // create array for Candle Highs and Lows
  double High[],Low[];
  
  // sort arrays downwards from the current candle
  ArraySetAsSeries(High,true);
  ArraySetAsSeries(Low,true);
 
  //Fill arrays with data for FVGs for 3 candles for FVG idenitification
  CopyHigh(_Symbol,_Period,0,3,High);
  CopyLow(_Symbol,_Period,0,3,Low); 
  
  //calculate the high and lows for the FVGs
  FVGHigh = ArrayMaximum(High,0,3);     // uses data for the last 3 candles
  FVGLow = ArrayMaximum(Low,0,3);       // uses data for the last 3 candles

  //Create an array for prices and sort it from current to oldest candles
  MqlRates Price[];
  ArraySetAsSeries(Price,true);
  
  //Copy price data into the array
  int Data=CopyRates(_Symbol,_Period,0,Bars(_Symbol,_Period),Price);
  
  // delete any previous rectangles
  ObjectDelete(_Symbol,"Rectangle");
  }		//bracket that causes alot of errors if it isnt there
  
  // if candle 3 is a bear and candle 2 and candle 1 are both bulls.. and if there is a gap 
  if(Bear[3] and Bull[2] and Bull[1] and CHigh[3]<CLow[1]){
  
  //create the new rectangle using candle3s low, starting at candle 2, using candle 1s high and ending at candle 0
  ObjectCreate(_Symbol,"Rectangle",OBJ_RECTANGLE,0,Price[2].time,Price[FVGHigh].High[3],Price[0].time,Price[FVGLow].CLow[1]);

  //set Object line color
  ObjectSetInteger(0,"Rectangle",OBJPROP_COLOR,clrLime);
  
  //Set the Object fill color
  ObjectSetInteger(0,"Rectangle",OBJPROP_FILL,clrLime);
   } 

  //check if we have a Bull FVG
  // if candle 3 is a Bull and candle 2 and candle 1 are both bears.. and if there is a gap 
  if(Bull[3] and Bear[2] and Bear[2] and Low[3] > High[1]){
  
  //create the new rectangle using candle3s high, starting at candle 2, using candle 1s low and ending at candle 0
  ObjectCreate(_Symbol,"Rectangle",OBJ_RECTANGLE,0,Price[2].time,Price[FVGLow].CLow[3],Price[0].time,Price[FVGHigh].CHigh[1]);

  //set Object line color
  ObjectSetInteger(0,"Rectangle",OBJPROP_COLOR,clrRed);
  
  //Set the Object fill color
  ObjectSetInteger(0,"Rectangle",OBJPROP_FILL,clrRed);
   } 
  
}


where i want the rectangle to draw (pretend the last 2 candles arent there)


Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_RECTANGLE
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_RECTANGLE
  • www.mql5.com
OBJ_RECTANGLE - Object Types - Objects Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

A curly bracket is missing.

Run the Tools=> Styler of the Editor to find it easier. BTW MT5 prints in the log which { has no }

 
Carl Schreiber #:

A curly bracket is missing.

Run the Tools=> Styler of the Editor to find it easier. BTW MT5 prints in the log which { has no }

i think my code is wrong... i dont think i should need that curly bracket
im basically asking how to draw a rectangle where i want it cause when i try its not working and its erroring, and i dont know why

 

Look for examples: https://www.mql5.com/en/search#!keyword=rectangle%20box

This way is much, much faster!

 
  1. Stop using ChatGPT.
              Help needed to debug and fix an AI EA - Trading Systems - MQL5 programming forum #2 (2023)

  2.   double CLow = PRICE_LOW;
      double CHigh = PRICE_HIGH;
      double COpen = PRICE_OPEN;
      double CClose = PRICE_CLOSE;

    Those red symbols are constants 3, 2, 1, and zero. Not prices, not doubles.

  3.   double Bull = PRICE_OPEN<PRICE_CLOSE;
      double Bear = PRICE_OPEN>PRICE_CLOSE;

    One is always more than zero. Therefor Bear will always be true.

  4.   if(Bear[3] and Bull[2] and Bull[1] and CHigh[3]<CLow[1]){

    You declared them as a variable, not an array. Don't post code that will not compile.

  5. 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.


 
Carl Schreiber #:

Look for examples: https://www.mql5.com/en/search#!keyword=rectangle%20box

This way is much, much faster!

i have searched for something specific relating to what im trying to do... theres lots of freelance jobs that are completed... but not useful for me cause i want to learn how to do this haha

My problem is i can follow tutorials relating to drawing a rectangle and drawing parallel lines or trend lines etc..
but when im trying to alter that slightly to suit my own requirements... eg.. using specific candles... i cant seem to figure it out.
Once im shown, im good though... So is there a way you can dumb it down for me

As per this code here....The place i am getting stuck is the defining the bullFVG highs and lows and where to add them for drawing the rectangle?
the syntax is incorrect but i cant find how to fix it

void OnTick(){

//Create an array for prices and sort it from current to oldest candles
  MqlRates Price[];
  ArraySetAsSeries(Price,true);
  
 //Copy price data into the array
  int Data=CopyRates(_Symbol,_Period,0,Bars(_Symbol,_Period),Price);  
  
 // Create variable bearFVG or bullFVG and highs and lows
  int bullFVG, bearFVG;
  
 // create array for Candle Highs and Lows of candles and sort from current to earliest 
  double High[],Low[],Open[],Close[];
  ArraySetAsSeries(High,true);
  ArraySetAsSeries(Low,true);
  ArraySetAsSeries(Open,true);
  ArraySetAsSeries(Close,true);

 //Fill arrays with data of highs and lows for the last 5 candles
  CopyHigh(_Symbol,_Period,0,5,High);
  CopyLow(_Symbol,_Period,0,5,Low); 
  CopyOpen(_Symbol,_Period,0,5,Open); 
  CopyClose(_Symbol,_Period,0,5,Close); 
  
 // How do i do this part??
 // bullFVG is an up candle and high of 3 bigger than low of 1
 // How do i define the specific high and low?
 
 //Calculate the High and low for the bullFVG 
  bullFVG = Open[2] < Close[2] & High[3] < Low[1];
  
  //create new rectangle for bullFVG using candle3s low, starting at candle 2, 
  //using candle 1s high and ending at candle 0
  ObjectCreate(_Symbol,"Rectangle",OBJ_RECTANGLE,0,Price[2].time,Price[bullFVG].High[3],Price[0].time,Price[bullFVG].Low[1]);
  ObjectSetInteger(0,"Rectangle",OBJPROP_COLOR,clrLime);    //set Object line color
  ObjectSetInteger(0,"Rectangle",OBJPROP_FILL,clrLime);   //Set the Object fill color
   
 //Calculate the High and low for the bullFVG 
 bearFVG = Price.Open[2] > Price.Close[2] and Price.Low[3] > Price.High[1];

//create new rectangle for bearFVG using candle3s high, starting at candle 2, using candle 1s low and ending at candle 0
  ObjectCreate(_Symbol,"Rectangle",OBJ_RECTANGLE,0,Price[2].time,Price[bullFVG].Low[3],Price[0].time,Price[bullFVG].High[1]);
  ObjectSetInteger(0,"Rectangle",OBJPROP_COLOR,clrRed);  //set Object line color
  ObjectSetInteger(0,"Rectangle",OBJPROP_FILL,clrRed);   //Set the Object fill color

 
William Roeder #:
  1. Stop using ChatGPT.
              Help needed to debug and fix an AI EA - Trading Systems - MQL5 programming forum #2 (2023)

  2. Those red symbols are constants 3, 2, 1, and zero. Not prices, not doubles.

  3. One is always more than zero. Therefor Bear will always be true.

  4. You declared them as a variable, not an array. Don't post code that will not compile.

  5. 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.


i didnt use chatGPT... i used this tutorial... https://youtu.be/Y3e1zVROJlY&nbsp;
I am trying to learn... and i am trying to figure it out but nobody actually answers so i can learn
im using MT5.. not MT4 so im using mql5 

It wont compile no... but im asking for help. 

MQL5 TUTORIAL - SIMPLE RECTANGLE Object
MQL5 TUTORIAL - SIMPLE RECTANGLE Object
  • 2018.02.23
  • www.youtube.com
https://mql5tutorial.com/?s=objectWith MQL5 for Metatrader5 we create an Expert Advisor that will draw a rectangle on the chart. This object will show you th...
 
pebs85 #: i didnt use chatGPT... i used this tutorial... https://youtu.be/Y3e1zVROJlY;

I call BS. A mixture of MT4, MT5, and some other (Pine?) means you didn't try to learn the language.

 
William Roeder #:

I call BS. A mixture of MT4, MT5, and some other (Pine?) means you didn't try to learn the language.

Thanks for being the most unhelpful person.
I didn’t use chatgpt..
I used the ide from mt5 and changed things.. so I don’t know how it has other code in there 

I also tried again…. With exactly what you guys ask… I added my new code.. I commented where exactly I’m having the issues.. I explained where I am up to with comments in the code and what I need exact help with.

I would actually pay for somebody to tutor me… but freelance section they just do it for u and then u have to work out what their code means. 

Why be a jerk. If u don’t want to help scroll on!

If you actually want to help.. I replied to Carl with my new attempt which has comments within the code and exactly what part I need help with
 
pebs85 #:

...

It wont compile no... but im asking for help. 

  ObjectCreate(_Symbol,"Rectangle",OBJ_RECTANGLE,0,Price[2].time,Price[bullFVG].Low[3],Price[0].time,Price[bullFVG].High[1]);
Just one example of wrong code.

1. You should check the documentation of ObjectCreate(). What are the parameters ?

2. What is the suppose to mean ?

Price[bullFVG].Low[3]
Price is an array of MqlRates. This structure is well defined in the documentation, is there a "Low[]" array member ?
Reason: