Download MetaTrader 5

No EAs buying or selling automatically in demo account but working in the strategy tester..

To add comments, please log in or register
JohnXXL
10
JohnXXL 2011.07.27 10:40 

Basically I just started coding my own eas but noticed that they only seemed to show some signs of life in manual mode and with the stategy tester. I leave any of them (even the default ones and 3rd party EAs made by others) and they won't buy or sell anything unless they are set to manual, where they will pop up a window asking for me to do it for them. 

I've tried setting all sorts of options to get this to work, I tried changing the slippage to a high value to see if it was some sort of network connection problem but that didn't solve anything..

I'm using the GO Trader and Trading Point broker demo accounts to do my testing and the results are exactly the same in both.

 

Help! 

HongDi s& t development co.,ltd.
1605
hongbin fei 2011.07.27 11:22  

I think you should attached the expert, then I can help you.

JohnXXL
10
JohnXXL 2011.07.27 12:49  

It could be any, I will attach this 3d party one since they are supposed to have been thoroughly tested and tried.

 

//+------------------------------------------------------------------+
//| gazonkos expert.mq4 |
//| 1H EUR/USD |
//| Smirnov Pavel |
//| www.autoforex.ru |
//+------------------------------------------------------------------+

#property copyright "Smirnov Pavel"
#property link "www.autoforex.ru"

extern int magic = 12345;
extern int TakeProfit = 16; // Óðîâåíü òåéêïðîôèò â ïóíêòàõ
extern int Otkat = 16;// Âåëè÷èíà îòêàòà â ïóíêòàõ
extern int StopLoss = 40; // óðîâåíü ñòîïëîññ â ïóíêòàõ

extern int t1=3;
extern int t2=2;
extern int delta=40;

extern double lot = 0.1;// Ðàçìåð ïîçèöèè
extern int active_trades=1;//Ìàêñèìàëüíîå êîëè÷åñòâî îäíîâðåìåííî îòêðûòûõ îðäåðîâ

int STATE=0;
int Trade=0;
double maxprice=0.0;
double minprice=10000.0;
int ticket;
bool cantrade=true;
int LastTradeTime=0;
int LastSignalTime=0;

int OpenLong(double volume=0.1)
{
int slippage=10;
string comment="gazonkos expert (Long)";
color arrow_color=Blue;

ticket=OrderSend(Symbol(),OP_BUY,volume,Ask,slippage,Ask-StopLoss*Point,
Ask+TakeProfit*Point,comment,magic,0,arrow_color);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
Print("Buy order opened : ",OrderOpenPrice());
return(0);
} 
}
else 
{
Print("Error opening Buy order : ",GetLastError()); 
return(-1);
}
}

int OpenShort(double volume=0.1)
{
int slippage=10;
string comment="gazonkos expert (Short)";
color arrow_color=Red;

ticket=OrderSend(Symbol(),OP_SELL,volume,Bid,slippage,Bid+StopLoss*Point,
Bid-TakeProfit*Point,comment,magic,0,arrow_color);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
Print("Sell order opened : ",OrderOpenPrice());
return(0);
} 
}
else 
{
Print("Error opening Sell order : ",GetLastError()); 
return(-1);
}
}

int OrdersTotalMagic(int MagicValue)//ôóíêöèÿ âîçâðàùàåò êîëè÷åñòâî îòêðûòûõ îðäåðîâ ñ magic = MagicValue
{
int j=0;
int i;
for (i=0;i<OrdersTotal();i++)//Ïðîèçâîäèì ïðîñìîòð ñðåäè âñåõ îòêðûòûõ îðäåðîâ
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))//Âûáèðàåì ïî-ïîðÿäêó îðäåðà
{
if (OrderMagicNumber()==MagicValue) j++; //Ïîäñ÷èòûâàåì òîëüêî òå ó êîòðîûõ íóæíûé magic 
}
else 
{ 
Print("gazonkos expert: OrderSelect() â OrdersTotalMagic() âåðíóë îøèáêó - ",GetLastError()); 
return(-1);
}
} 
return(j);//Âîçâðàùàåì êîëè÷åñòâî ïîäñ÷èòàííûõ îðäåðîâ ñ magic = MagicValue. 
}

int init()
{
return(0);
}

int deinit()
{ 
return(0);
}

int start()
{

// STATE = 0 Æäåì ñèãíàëà ê íà÷àëó ðàáîòû ñîâåòíèêà ------------------------------------------------------------

if (STATE==0)
{
bool cantrade=true;
if(TimeHour(TimeCurrent())==LastTradeTime) cantrade=false;//çàïðåùàåì òîðãîâàòü ïîêà íå íàñòóïèò íîâûé ÷àñ ïîñëå ïîñëåäíåé 
//îòêðûòîé ñäåëêè (÷òîáû èçáåæàòü ìíîæåñòâåííûõ îòêðûâàíèé ñäåëîê íà îäíîì è òîì æå ÷àñîâîì áàðå) 
if(OrdersTotalMagic(magic)>=active_trades) cantrade=false;// ïðîâåðÿåì íà äîïóñòèìîå êîëè÷åñòâî îòêðûòûõ îðäåðîâ
if(cantrade) // åñëè íå áûëî íè îäíîãî çàïðåòà íà îòêðûòèå ñäåëîê, òî ïåðåõîäèì ê îæèäàíèþ ñèãíàëîâ ñèñòåìû íà îòêðûòèå îðäåðîâ
STATE=1;
}

// STATE = 1 Æäåì èìïóëüñà (äâèæåíèÿ) öåíû ----------------------------------------------------------------------

if (STATE==1)
{
if((Close[t2]-Close[t1])>delta*Point)// ñèãíàë äëÿ âõîäà â äëèííóþ ïîçèöèþ
{
Trade = 1; //èäåíòèôèêàòîð ïîçèöèè, äëÿ êîòîðîé ïîëó÷åí ñèãíàë íà îòêðûòèå "-1" - êîðîòêàÿ ïîçèöèÿ, "1"-äëèííàÿ
maxprice=Bid;// çàïîìèíàåì òåêóùåå ïîëîæåíèå öåíû (íåîáõîäèìî äëÿ îïðåäåëåíèÿ îòêàòà â STATE=2)
LastSignalTime=TimeHour(TimeCurrent());//Çàïîìèíàåì âðåìÿ ïîëó÷åíèÿ ñèãíàëà
STATE = 2; // ïåðåéòè â ñëåäóþùåå ñîñòîÿíèå
}

if((Close[t1]-Close[t2])>delta*Point)// ñèãíàë äëÿ âõîäà â êîðîòêóþ ïîçèöèþ
{
Trade = -1; // èäåíòèôèêàòîð ïîçèöèè, äëÿ êîòîðîé ïîëó÷åí ñèãíàë íà îòêðûòèå "-1" - êîðîòêàÿ ïîçèöèÿ, "1"-äëèííàÿ
minprice=Bid;// çàïîìèíàåì òåêóùåå ïîëîæåíèå öåíû (íåîáõîäèìî äëÿ îïðåäåëåíèÿ îòêàòà â STATE=2)
LastSignalTime=TimeHour(TimeCurrent());//Çàïîìèíàåì âðåìÿ ïîëó÷åíèÿ ñèãíàëà
STATE = 2; // ïåðåéòè â ñëåäóþùåå ñîñòîÿíèå
}
}

// STATE = 2 - Æäåì îòêàòà öåíû -------------------------------------------------------------------------------- 

if (STATE==2)
{
if(LastSignalTime!=TimeHour(TimeCurrent()))//Åñëè íà áàðå íà êîòîðîì ïîëó÷åí ñèãíàë íå ïðîèçîøëî îòêàòà,òî ïåðåõîäèì â ñîñòîÿíèå STATE=0
{ 
STATE=0;
return(0); 
}
if(Trade==1)// îæèäàåì îòêàòà äëÿ äëèííîé ïîçèöèè
{
if(Bid>maxprice) maxprice=Bid;//åñëè öåíà ïîøëà åùå âûøå, òî ìåíÿåì çíà÷åíèå maxprice íà òåêóùåå çíà÷åíèå öåíû
if(Bid<(maxprice-Otkat*Point))// ïðîâåðÿåì íàëè÷èå îòêàòà öåíû ïîñëå èìïóëüñà 
STATE=3;//åñëè ïðîèçîøåë îòêàò íà âåëè÷èíó Otkat, òî ïåðåõîäèì â ñîñòîÿíèå îòêðûòèÿ äëèííîé ïîçèöèè
}

if(Trade==-1)// îæèäàåì îòêàòà äëÿ êîðîòêîé ïîçèöèè
{
if(Bid<minprice) minprice=Bid;//åñëè öåíà ïîøëà åùå íèæå, òî ìåíÿåì çíà÷åíèå minprice íà òåêóùåå çíà÷åíèå öåíû
if(Bid>(minprice+Otkat*Point))// ïðîâåðÿåì íàëè÷èå îòêàòà öåíû ïîñëå èìïóëüñà
STATE=3;//åñëè ïðîèçîøåë îòêàò íà âåëè÷èíó Otkat, òî ïåðåõîäèì â ñîñòîÿíèå îòêðûòèÿ êîðîòêîé ïîçèöèè
}
} 

// STATE = 3 - îòêðûâàåì ïîçèöèè ñîãëàñíî ïåðåìåííîé Trade ("-1" - êîðîòêóþ, "1" - äëèííóþ) -------------------- 

if(STATE==3)
{
if(Trade==1)// îòêðûâàåì äëèííóþ ïîçèöèþ
{
OpenLong(lot);// îòêðûâàåì äëèííóþ ïîçèöèþ
LastTradeTime=TimeHour(TimeCurrent());//çàïîìèíàåì âðåìÿ ñîâåðøåíèÿ ïîñëåäíåé ñäåëêè
STATE=0; //ïåðåõîäèì â ñîñòîÿíèå îæèäàíèÿ
}
if(Trade==-1)// îòêðûâàåì êîðîòêóþ ïîçèöèþ
{
OpenShort(lot);// îòêðûâàåì êîðîòêóþ ïîçèöèþ 
LastTradeTime=TimeHour(TimeCurrent());//çàïîìèíàåì âðåìÿ ñîâåðøåíèÿ ïîñëåäíåé ñäåëêè
STATE=0; //ïåðåõîäèì â ñîñòîÿíèå îæèäàíèÿ
} 
} 
return(0);
}

 

Rashid Umarov
Admin
11988
Rashid Umarov 2011.07.27 14:38  
Please insert code properly
MQL5.community - User Memo
  • 2010.02.25
  • MetaQuotes Software Corp.
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
JohnXXL
10
JohnXXL 2011.07.27 16:22  
Rosh:

Please insert code properly
Sorry about that, I think it's formatted correctly now.
To add comments, please log in or register