EA with SMAs not placing orders

 

Hello everyone!

I'm starting to learn mt4 coding and working on an EA that is using iHighest and iLowest to plot these lines on the chart and I'm using these lines to calculate if the variable "Ranging" is either ZERO or ONE.
This part of the code, to my knowledge, is working fine.

The problem is  that somehow I cannot manage to place ORDERS, neither BUY nor SELL and I don't manage to find the reason why!!!
NOTE - I wish the EA to place a single order at a time and only when "Ranging == 0".
As such I need some guidance from you guys to get this EA going.

The source code is attached and when I compile I get no ERRORS but this WARNING "return value of 'OrderClose' should be checked"

Can someone pls help me to resolve this issue?
Thank you very much in advance!!

Files:
test_00.mq4  5 kb
 
Mosamba:I'm starting to learn mt4 coding and working on an EA that is using iHighest and iLowest to plot these lines on the chart and I'm using these lines to calculate if the variable "Ranging" is either ZERO or ONE. This part of the code, to my knowledge, is working fine. The problem is  that somehow I cannot manage to place ORDERS, neither BUY nor SELL and I don't manage to find the reason why!!!

NOTE - I wish the EA to place a single order at a time and only when "Ranging == 0". As such I need some guidance from you guys to get this EA going. The source code is attached and when I compile I get no ERRORS but this WARNING "return value of 'OrderClose' should be checked". Can someone pls help me to resolve this issue?

  1. In future please post in the MQL4 and MetaTrader 4 section of the forum (at the very end), as the rest of the forum is for MQL5 related issues. A moderator will most probably move it for you in due time.
  2. The warning is important! You should always check the result of the functions to make sure they were carried out correctly and if not, react to or printout the error that occurred.
  3. You should not retrieve Indicator data, such as iMA(), before a tick has arrived. Assigning them in the declaration of global variables is totally useless.
    double sma_7     = iMA (_Symbol,_Period,7,0,MODE_SMA, PRICE_CLOSE,0);    //magenta
    double sma_9     = iMA (_Symbol,_Period,9,0,MODE_SMA, PRICE_CLOSE,0);    //cyan ##### REVER!!! Acho que deve ser mantida nas entradas!!!!!!!
    double sma_16    = iMA (_Symbol,_Period,16,0,MODE_SMA, PRICE_CLOSE,0);   //orange
    double sma_38    = iMA (_Symbol,_Period,38,0,MODE_SMA, PRICE_CLOSE,0);   //dash green
    double sma_80    = iMA (_Symbol,_Period,80,0,MODE_SMA, PRICE_CLOSE,0);   //dash white
    You should be collecting these values inside the OnTick() event handler. These are functions that need to be called on regular basis to get the latest value, preferably in the start of a new bar instead of on every tick, but it depends on your strategy.

    This point, is the main reason your code is not working as you expect it to. Your whole program logic needs to be totally reconsidered or else you will have many problems with it.

    Also consider reading the following about detecting a new bar ... Detecting the start of a new bar or candle, in an expert advisor.
 
Fernando Carreiro #:
  1. In future please post in the MQL4 and MetaTrader 4 section of the forum (at the very end), as the rest of the forum is for MQL5 related issues. A moderator will most probably move it for you in due time.
  2. The warning is important! You should always check the result of the functions to make sure they were carried out correctly and if not, react to or printout the error that occurred.
  3. You should not retrieve Indicator data, such as iMA(), before a tick has arrived. Assigning them in the declaration of global variables is totally useless.
    You should be collecting these values inside the OnTick() event handler. These are functions that need to be called on regular basis to get the latest value, preferably in the start of a new bar instead of on every tick, but it depends on your strategy.

    This point, is the main reason your code is not working as you expect it to. Your whole program logic needs to be totally reconsidered or else you will have many problems with it.

    Also consider reading the following about detecting a new bar ... Detecting the start of a new bar or candle, in an expert advisor.

Hello Fernando,

Thanks for your hints.

I'm going to start looking at them and see if I manage to implement them correctly!

Cheers