-
Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
Messages Editor -
double MACDC = iMACD(NULL, 0, 34, 89, 9, PRICE_CLOSE, MODE_MAIN,0); double MACDP1 = iMACD(NULL, 0, 34, 89, 9, PRICE_CLOSE, MODE_MAIN,1);
Where is this code? Global or in OnTick?
How To Ask Questions The Smart Way. 2004
Be precise and informative about your problem - ckm Forex: Close must happen when MACD Cross zero line from below, or when MACD turns down signal line when below zero
Your if((close… is not testing that.
-
bool close_sell_condition_1 = MACDC > 0; bool close_sell_condition_2 = MACDP1 <= 0;
Use meaningful variable names. 1,2,3 are not.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Need to code a simple MACD Cross over and U turn of MACD.......however EA is not picking the right spots for closing the trades.
Sell trade opens, when MACD cross below Signal line while MACD is above zero line
Close must happen when MACD Cross zero line from below, or when MACD turns down signal line when below zero
while sell entries open correctly the closing is happening at the wrong spots
pls suggest the solution
double MACDC = iMACD(NULL, 0, 34, 89, 9, PRICE_CLOSE, MODE_MAIN,0);
double MACDP1 = iMACD(NULL, 0, 34, 89, 9, PRICE_CLOSE, MODE_MAIN,1);
double MACDP2 = iMACD(NULL, 0, 34, 89, 9, PRICE_CLOSE, MODE_MAIN,2);
double MACDS = iMACD(NULL, 0, 34, 89, 9, PRICE_CLOSE, MODE_SIGNAL,0);
double MACDSP1 = iMACD(NULL, 0, 34, 89, 9, PRICE_CLOSE, MODE_SIGNAL,1);
double MACDSP2 = iMACD(NULL, 0, 34, 89, 9, PRICE_CLOSE, MODE_SIGNAL,2);
//----------------------------+
//Close Short Position /
//----------------------------+
if (OrdersTotal() > 0)
{
bool close_sell_condition_1 = MACDC > 0;
bool close_sell_condition_2 = MACDP1 <= 0;
bool close_sell_condition_3 = MACDP2 < 0;
bool close_sell_condition_4 = MACDC < 0;
bool close_sell_condition_5 = MACDC < MACDS;
bool close_sell_condition_6 = MACDP1 > MACDSP1;
if((close_sell_condition_1 && close_sell_condition_2 && close_sell_condition_3)|| (close_sell_condition_4 && close_sell_condition_5 && close_sell_condition_6))
{
OrderSelect(ShortTicket,SELECT_BY_TICKET);
if(OrderCloseTime() == 0 && ShortTicket > 0)
{
Closed = OrderClose(ShortTicket,OrderLots(),Ask,0,Red);
ShortTicket = 0;
}
}
}