Hello,
When you post code please use Alt+S
Hello,
When you post code please use Alt+S
Done, thanks for the tip.
//+------------------------------------------------------------------+ //| Check for open order conditions | //+------------------------------------------------------------------+ void CheckForOpen() { bool res=false; //--- go trading only for first tiks of new bar if(Volume[0]>1) return; //--- get Moving Average double HA1 = iCustom(NULL,TrendPeriod,"Heiken Ashi MA",MAMethod,HAPeriod,0,0); //--- sell condition if(Open[1]>HA1 && Close[1]<HA1) res=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,0,"",MAGICMA,0,Red); if(!res) { Print("Order send error"); return; } //--- buy conditions if(Open[1]<HA1 && Close[1]>HA1) res=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,0,0,"",MAGICMA,0,Blue); if(!res) { Print("Order send error"); return; } }
i edited your code a little bit, try this one ;-)
i edited your code a little bit, try this one ;-)
Hi Kenneth,
thanks for your prompt assist. i added the print command to help me differentiate the BUY and SELL order errors. Looks like there is no BUY order error at all. Instead, there were plenty of SELL Order errors. Very strange.\
void CheckForOpen() { bool res=false; //--- go trading only for first tiks of new bar if(Volume[0]>1) return; //--- get Moving Average double HA1 = iCustom(NULL,TrendPeriod,"Heiken Ashi MA",MAMethod,HAPeriod,0,0); //--- sell condition if(Open[1]>HA1 && Close[1]<HA1) res=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,0,"",MAGICMA,0,Red); if(!res) { Print("Sell Order send error"); return; } //--- buy conditions if(Open[1]<HA1 && Close[1]>HA1) res=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,0,0,"",MAGICMA,0,Blue); if(!res) { Print("Buy Order send error"); return; } }
Hi Kenneth,
thanks for your prompt assist. i added the print command to help me differentiate the BUY and SELL order errors. Looks like there is no BUY order error at all. Instead, there were plenty of SELL Order errors. Very strange.\
void CheckForOpen() { bool res=false; //--- go trading only for first tiks of new bar if(Volume[0]>1) return; //--- get Moving Average double HA1 = iCustom(NULL,TrendPeriod,"Heiken Ashi MA",MAMethod,HAPeriod,0,0); //--- sell condition if(Open[1]>HA1 && Close[1]<HA1) { res=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,0,"",MAGICMA,0,Red); if(!res) { Print("Sell Order send error"); return; } } //--- buy conditions if(Open[1]<HA1 && Close[1]>HA1) { res=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,0,0,"",MAGICMA,0,Blue); if(!res) { Print("Buy Order send error"); return; } } } //+------------------------------------------------------------------+
this one should work
- Why did you post your MT4 question in the Root / MT5 EA
section instead of the MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. -
if(Volume[0]>1) return;
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
New candle - MQL4 programming forum - You are reading buffer zero from "Heiken Ashi MA." Do you expect us to know which specific version you are using, and where that can be found? There are no mind readers here and our crystal balls are cracked.
-
double HA1 = iCustom(NULL,TrendPeriod,"Heiken Ashi MA",MAMethod,HAPeriod,0,0);
On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4 -
if(Open[1]>HA1 && Close[1]<HA1) res=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,0,"",MAGICMA,0,Red); if(!res)
Why are you looking at your res variable if you havent't tried to open?
- Why did you post your MT4 question in the Root / MT5 EA
section instead of the MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. -
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
New candle - MQL4 programming forum - You are reading buffer zero from "Heiken Ashi MA." Do you expect us to know which specific version you are using, and where that can be found? There are no mind readers here and our crystal balls are cracked.
- On MT4: Unless the current chart is that specific
symbol(s)/TF(s) referenced, you must handle 4066/4073
errors before accessing candle/indicator values.
Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4 - Why are you looking at your res variable if you havent't tried to open?
Hi William,
Thank you for your advise. I am still learning the coding and am taking the sample EA from the default MT4 to try to learn on the run. I will look into your tips and improve on the coding to make it work.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear Forumers,
I am beginning my EA codng journey by using the sample Moving Average given in the default MT4 to modify some basic functions. However, i am facing a problem when I ran the Strategy Tester. It seems like the BUY trade is not happening and only SELL trades are occurring. Can anyone help me to identify what seems to be the issue?