Hi Guys,
Can someone help me to go through my macd ea and advice me on how to perfect the following?
1. The macd indicator is not indicating when the line crossed
2. The ordersend failed with error #3
Thanks and appreciate your help.
The ordersend failed with error #3 :
3 | ERR_INVALID_TRADE_PARAMETERS | Invalid trade parameters |
For pending orders, should not use expiration = NULL.
it should be 0 (zero).
The ordersend failed with error #3 :
3 | ERR_INVALID_TRADE_PARAMETERS | Invalid trade parameters |
For pending orders, should not use expiration = NULL.
it should be 0 (zero).
Thank you. Roberto
Do you know anything about the MACD, why the cross over didnt work out?
Thank you. Roberto
Do you know anything about the MACD, why the cross over didnt work out?
I see your code is old code with syntax MQL4 obsolete that you've modified into 2017.
And I can see, that's something easy like MACD indicator, you make it difficult and complicated in your EA code.
To learn about EA base on MACD indicator, you can see in the folder MQL4/Experts/MACD Sample.mq4 (this is a very good example made by MQL)
Your code is complicated, example:
int start() { GlobalVariablesDeleteAll(); // Deleting of all GVs // GlobalVariablesDeleteAll() is the function for Deletes global variables of the client terminal. // by calling this function: You've deleted all the variables used by the indicator in the input parameters. // then, how the indicators will provide value in your EA code below? double ema = iMA(NULL,0,60,0,MODE_EMA,PRICE_MEDIAN,lastbar); double close=iClose(NULL,0,lastbar); double past20macd=iMACD(Symbol(), 0, FAST_EMA_PERIOD, SLOW_EMA_PERIOD, MACD_SIGNAL_PERIOD, PRICE_TYPICAL, MODE_MAIN, macdbarinterval+1);
I see your code is old code with syntax MQL4 obsolete that you've modified into 2017.
And I can see, that's something easy like MACD indicator, you make it difficult and complicated in your EA code.
To learn about EA base on MACD indicator, you can see in the folder MQL4/Experts/MACD Sample.mq4 (this is a very good example made by MQL)
Your code is complicated, example:
Yes, you are right. I had deleted the code Global variable delete.
I still have 2 questions,
1. do you have the macd 2 line indicator or place to look for it?
I used a macd indicator as attached, the indicator lines crossed, but not in iMACD, it might be due to the indicator is wrong or my coding is wrong.
2. How do i use the buylimit, the limit was deleted once it created.
Or can you show me a sample of BuyLimit with Close[1] as entry, then take profit and stoploss modification.
static datetime Time0Buy; if (buysignal==true && TotalNumberOfOrders<maxorders && enableopen == true && enableopentime == true && Time0Buy != Time[0]) { ticket=OrderSend(Symbol(),OP_BUYLIMIT,lotsize,close,slippage,0,0,NULL,Magic,0,Green); if(ticket<0) { Print("OrderSend failed with error #",GetLastError()); } else Time0Buy = Time[0]; //reset global variable to 0 and prevent further signal in bar // If there are order then modify position for sl and tp { entrytoday++; bool res = OrderModify(ticket, 0, close-stoploss, close+takeprofit, 0); if(!res) { Alert("OrderModify Error: ", GetLastError()); Alert("IMPORTANT: ORDER #", ticket, " HAS NO STOPLOSS AND TAKEPROFIT"); } } return(ticket); }
tonyming:
I still have 2 questions,
1. do you have the macd 2 line indicator or place to look for it?
== in CodeBase I've MACD_2ToneColor - indicator for MetaTrader 4
I used a macd indicator as attached, the indicator lines crossed, but not in iMACD, it might be due to the indicator is wrong or my coding is wrong.
== you code is wrong
2. How do i use the buylimit, the limit was deleted once it created.
== buy_limit is the pending order, price for buy_limit pending onder should be further away below from the market price at the closest distance is the distance stop_level. (example = 15 Point)
Or can you show me a sample of BuyLimit with Close[1] as entry, then take profit and stoploss modification.
== pending orders should have expiration time, for example for 1hour = 1x60x60, if 0, means it will never expiration.
== buy_limit price must be below the market price (NOT at Close[1] as entry), take profit = buy_limit price + (your tp value x Point), and stop loss = buy_limit price - (your sl value x Point).
ticket=OrderSend(Symbol(),OP_SELLLIMIT,lotsize,close,slippage,0,0,NULL,NULL,Magic,Red); //entry market sell
You can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, MarketInfo does not. OrderSend does not.
Don't use NULL (except for pointers where you explicitly check for it.) Use
_Symbol and _Period, that is minimalist
as possible and more efficient.
Zero is the same as PERIOD_CURRENT which means _Period.
No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[]
tonyming:
I still have 2 questions,
1. do you have the macd 2 line indicator or place to look for it?
== in CodeBase I've MACD_2ToneColor - indicator for MetaTrader 4
I used a macd indicator as attached, the indicator lines crossed, but not in iMACD, it might be due to the indicator is wrong or my coding is wrong.
== you code is wrong
2. How do i use the buylimit, the limit was deleted once it created.
== buy_limit is the pending order, price for buy_limit pending onder should be further away below from the market price at the closest distance is the distance stop_level. (example = 15 Point)
Or can you show me a sample of BuyLimit with Close[1] as entry, then take profit and stoploss modification.
== pending orders should have expiration time, for example for 1hour = 1x60x60, if 0, means it will never expiration.
== buy_limit price must be below the market price (NOT at Close[1] as entry), take profit = buy_limit price + (your tp value x Point), and stop loss = buy_limit price - (your sl value x Point).
Hi Roberto,
I had use the code from macd sample. But I still cant find what is wrong in my macd crossing, it is still not functioning well.
My crossing is actually the crossing between the macd line and signal line. I found out that they didnt work is because the value is actually not crossing while in the graph they do crossed over as ex4 attached.
Or is it the lines in the indicator is wrong?
//MACD signal double MacdCurrent,MacdPrevious; double SignalCurrent,SignalPrevious; double macdzone; MacdCurrent=iMACD(NULL,0,FAST_EMA_PERIOD, SLOW_EMA_PERIOD, MACD_SIGNAL_PERIOD,PRICE_CLOSE,MODE_MAIN,0); MacdPrevious=iMACD(NULL,0,FAST_EMA_PERIOD, SLOW_EMA_PERIOD, MACD_SIGNAL_PERIOD,PRICE_CLOSE,MODE_MAIN,1); SignalCurrent=iMACD(NULL,0,FAST_EMA_PERIOD, SLOW_EMA_PERIOD, MACD_SIGNAL_PERIOD,PRICE_CLOSE,MODE_SIGNAL,0); SignalPrevious=iMACD(NULL,0,FAST_EMA_PERIOD, SLOW_EMA_PERIOD, MACD_SIGNAL_PERIOD,PRICE_CLOSE,MODE_SIGNAL,1); { if(MacdCurrent>SignalCurrent && MacdPrevious<=SignalPrevious) { macdsignal=1; } if(MacdCurrent<SignalCurrent && MacdPrevious>=SignalPrevious) { macdsignal=2; } else macdsignal=0; }
Secondly, since what i actually want is to buy at the close of previous bar, and limit didnt allow me to do it.(must be 15 pip further)
Is there any function that i can make it continue to retry ordersend at the price until it execute, or until no signal?Sample?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi Guys,
Can someone help me to go through my macd ea and advice me on how to perfect the following?
1. The macd indicator is not indicating when the line crossed
2. The ordersend failed with error #3
Thanks and appreciate your help.