what error u get ? always check for errors !
Hi gjol...
I have tested for errors with Alert (GetLastError()) and it alerts me with "0" .
I have also used alert to check the prices of the support and resistance lines...and it turned out correct.
This is why I am really confused - can't explain why the Buy orders never get executed, even when
conditions are met.
This is why I am really confused - can't explain why the Buy orders never get executed, even when
R = iCustom(NULL,0,"S_R_Indi",R,0,0); S = iCustom(NULL,0,"S_R_Indi",S,0,0);
double iCustom( | string symbol, int timeframe, string name, ..., int mode, int shift) |
symbol | - | Symbol the data of which should be used to calculate indicator. NULL means current symbol. |
timeframe | - | Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. |
name | - | Custom indicator compiled program name. |
... | - | Parameters set (if necessary). The passed parameters and their order must correspond with the desclaration order and the type of extern variables of the custom indicator. |
mode | - | Line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions. |
shift | - | Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). |
Sample: double val=iCustom(NULL, 0, "SampleInd",13,1,0);
Your iCustom function is wrong.......
Thank you very much for taking the time to respond. Raptor, you were correct, changing the Bid to Ask fixed the problem.
deVries, the iCustom set up that I have seems to work for now, but no doubt it will give me problems as the EA evolves :)
- 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 All,
I am busy learning MQL4 and have been trying to create a simple EA that places a Sell order when the price gets to the resistance line
and places a Buy order when the price gets to the support line. The EA gets the values for the support and resistance lines from a custom indicator.
The problem I am having is that the EA does not place the Buy orders (when the conditions are clearly met). The EA code is below, if anyone can
let me know what the problem with it is, it would be greatly appreciated - Thanks.
#property copyright "Test"
#property link "test.com.au"
extern double MaxSpread = 3.0;
extern double LotSize = 0.05;
extern int Stoploss = 15;
extern int TakeProfit = 15;
extern int Magic_Num = 2828;
extern double Slippage = 3;
string Symb;
double S2,S3;
double xPoint;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
// Detect 2/3/4/5 digit brokers
if (Point == 0.00001) xPoint = 0.0001;
else {
if (Point == 0.001) xPoint = 0.01;
else xPoint = Point;
}
//Getting Support and Resistance lines from indicator (S_R_Indi)
op_0 = iOpen(Symbol(),0,0);
cl_1 = iClose(Symbol(),0,1);
hg_1 = iHigh(Symbol(),0,1);
lw_1 = iLow(Symbol(),0,1);
R = iCustom(NULL,0,"S_R_Indi",R,0,0);
S = iCustom(NULL,0,"S_R_Indi",S,0,0);
return(0);
}
int deinit()
{
return(0);
}
int start()
{
//new order takeprofit and stoploss ------
int ticket,pos;
double Sell_SL, Sell_TP;
Sell_SL=Bid + Stoploss*xPoint;
Sell_TP=Bid - TakeProfit*xPoint;
//Getting Line Prices from Chart -----------------
double R_P,S_P;
R_P = ObjectGet("R_Line",OBJPROP_PRICE1); //resistance line price
S_P = ObjectGet("S_Line",OBJPROP_PRICE1); //support line price
//Trading Criteria
RefreshRates();
//Price Between S1 and R1 ----------------------------------------------------------------------
if ((Bid > S_P) && (Bid < R_P)&& OrderCount() == 0)
{
if ((hg_1 >= R_P) && (cl_1 <= R_P) && (op_0 <= R_P))
OrderSend(Symbol(),OP_SELL,LotSize,Bid,Slippage,Sell_SL,Sell_TP,"Gypo_Sell_Order",Magic_Num,0,Red);
if ((lw_1 <= S_P) && (cl_1 >= S_P) && (op_0 >= S_P))
OrderSend(Symbol(),OP_BUY,LotSize,Bid,Slippage,Sell_SL,Sell_TP,"Gypo_Sell_Order",Magic_Num,0,Blue);
}
//Orders Accounting Function
int OrderCount()
{
Symb=Symbol();
int count = 0 ;
for (int i=1; i>=OrdersTotal(); i++)
{
if (OrderSelect(i-1,SELECT_BY_POS)==true)
{
if ((OrderSymbol()==Symb) && (OrderMagicNumber()==Magic_Num))
{
count++;
}
}
return(count);
}
}