Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.
From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.
please help. i would like to find or need help creating an ea with the following input parameters. four separate trade entries each having no. of lots, stop loss, trailing stop, break even, and profit target. trades will open upon clicking on expert advisor button.
i have a problem with the EA that i wrote.. actually, the EA based on MACD indicator.. when the MACD become like 'n' shape, open post Sell, and when MACD become like 'u' shape, the EA will open Buy..
the problem is, the EA didn't open any post.. after i doing some backtest also, there no open post by this EA.. can someone please help me find what's wrong with the code??
here is the code..
Code:
extern double TakeProfit = 20;
extern double Lots = 0.1;
extern double StopLoss = 20;
extern double MagicNumber = 17384;
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
double MacdBuffer1[];
double MacdBuffer2[];
double MacdBuffer3[];
double MacdBuffer4[];
double MacdBuffer5[];
double MacdBuffer6[];
double MacdBuffer7[];
double MacdBuffer8[];
int init()
{
//----
//SetIndexBuffer(0, lag1_buffer);
//SetIndexBuffer(1, lag2_buffer);
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
for(int i=0; i<limit; i++)
MacdBuffer1[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
MacdBuffer2[i-1]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i-1)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i-1);
MacdBuffer3[i+1]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i+1)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i+1);
MacdBuffer4[i-2]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i-2)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i-2);
MacdBuffer5[i+2]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i+2)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i+2);
MacdBuffer6[i-3]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i-3)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i-3);
MacdBuffer7[i+3]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i+3)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i+3);
/*Alert( "MacdBuffer7[i+3] =",MacdBuffer7[i+3]);
Alert( "MacdBuffer5[i+2] =",MacdBuffer5[i+2]);
Alert( "MacdBuffer3[i+1] =",MacdBuffer3[i+1]);
Alert( "MacdBuffer1[i] =",MacdBuffer1[i]);
Alert( "MacdBuffer2[i-1] =",MacdBuffer2[i-1]);
Alert( "MacdBuffer4[i-2] =",MacdBuffer4[i-2]);
Alert( "MacdBuffer6[i-3] =",MacdBuffer6[i-3]);*/
//----
int ticket_buy, ticket_sell, total;
total=OrdersTotal();
//MACD become 'u' shape
if (MacdBuffer7[i+3]>MacdBuffer5[i+2]&&MacdBuffer5[i+2]>MacdBuffer3[i+1]&&MacdBuffer3[i+1]>MacdBuffer1[i]
&&MacdBuffer1[i]<MacdBuffer2[i-1]&&MacdBuffer2[i-1]<MacdBuffer4[i-2]&&MacdBuffer4[i-2]<MacdBuffer6[i-3])
{
if (total < 1) {
ticket_buy=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"scalp 1 min - buy",MagicNumber,0,Green);
if(ticket_buy>0)
{
if(OrderSelect(ticket_buy,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
} else {
}
}
//MACD become 'n' shape
if(MacdBuffer7[i+3]<MacdBuffer5[i+2]&&MacdBuffer5[i+2]<MacdBuffer3[i+1]&&MacdBuffer3[i+1]<MacdBuffer1[i]
&&MacdBuffer1[i]>MacdBuffer2[i-1]&&MacdBuffer2[i-1]>MacdBuffer4[i-2]&&MacdBuffer4[i-2]>MacdBuffer6[i-3])
{
if (total < 1) {
ticket_sell=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"scalp 1 min - sell",MagicNumber,0,Red);
if(ticket_sell>0)
{
if(OrderSelect(ticket_sell,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
} else {
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
hope someone can help me solve the problem.. i'm not a good in programming codes.. thanks..
Try looking at a few of the EA's you already have. Study the code and try to see if you can figure out some of the logic. Try speaking the flow of the program out loud. It helps a lot!
Try looking at a few of the EA's you already have. Study the code and try to see if you can figure out some of the logic. Try speaking the flow of the program out loud. It helps a lot!
Good Luck
i have 7 buffer.. buffer1 until buffer7.. each buffer will save MACD bar value.. the EA will open
BUY post when the MACD become 'u' shape..
the condition when..
Code:
if (MacdBuffer7[i+3]>MacdBuffer5[i+2]&&MacdBuffer5[i+2]>MacdBuffer3[i+1]&&MacdBuffer3[i+1]>MacdBuffer1[i]
&&MacdBuffer1[i]<MacdBuffer2[i-1]&&MacdBuffer2[i-1]<MacdBuffer4[i-2]&&MacdBuffer4[i-2]<MacdBuffer6[i-3])
SELL post when the MACD become 'n' shape..
the condition when..
:: if it's suitable then try to form it in a EA, there you can loop & use sleep function, I've tried several simple setups to have only processes/calculations not related to ticks, but then you have the refresh screen issue ... so ... I've changed everything back to normal ... the importance to do so was not that great ... perhaps in MQL5 coming up
:: indicators can't deal with sleep() function
:: you can write a dll, fetch all the windows in your terminal... then do/send a "refresh screen/window" to every child window. But then you have to send dll file together with your indicator to others ... again ... making it complicated ...
Quote:
Originally Posted by TheRumpledOne
Is there a way to force the program to calculate?
Right now it waits for the next tick.
I have 6 charts open and the same indicator is on all six charts.
If one chart receives a tick, it updates but the other charts don't so they are "stale".
I hope you don't mind me butting in here, I'm looking at a similar situation and I have a thaught on the issue... what about if you code a loop at the end of your program that says "if no order is open run through again". and let it loop maybe 3 or 4 times.
If it does that then any missed orders (which happens quite often) should surely get picked up. or is there something wrong with my thinking.
I think it would look something like this...
Quote:
for (int k = OrdersTotal() ==0; k >=2; k++)
{
if ( ! OrderSelect ( k, SELECT_BY_POS, MODE_TRADES ))continue;
if (k > 2) break;
}
return(0);
}
I'm still new to this so if it doesn't make sense please explain to me why.