MQL4 - automated forex trading   /  

Forum

LOOKING FOR EXP. M/A EA!!

Back to topics list  | 1 2 To post a new topic, please log in or register

avatar
45
criss73 2006.07.19 17:38 
Hi, does anyone have an EA for a 2 line exp m/a crossover entry and exit signals?

thnx
Secrets of MetaTrader 4 Client Terminal: File Library in MetaEditor

Secrets of MetaTrader 4 Client Terminal: File Library in MetaEditor

When creating custom programs, code editor is of great importance. The more functions are available in the editor, the faster and more convenient is creation of the program. Many programs are created on basis of an already existing code. Do you use an indicator or a script that does not fully suit your purposes? Download the code of this program from our website and customize it for yourselves.


avatar
Moderator
5198
stringo 2006.07.19 19:47 
//+------------------------------------------------------------------+
//|                                                 MA8-13 cross.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                         http://www.metaquotes.net/ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
 
extern int ExtPeriod1=8;
extern int ExtPeriod2=13;
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   static datetime PrevTime=0;
   double Ma8Current, Ma8Previous, Ma8Previous2;
   double Ma13Current, Ma13Previous, Ma13Previous2;
   bool   IsCrossDown, IsCrossUp;
//---- если на текущем баре предыдущий бар уже обработан, выходим.
   if (PrevTime==Time[0]) return(0);
   PrevTime=Time[0];
//---- возьмём значения мувингов
   Ma8Current=iMA(NULL,0,ExtPeriod1,0,MODE_EMA,PRICE_CLOSE,1);
   Ma8Previous=iMA(NULL,0,ExtPeriod1,0,MODE_EMA,PRICE_CLOSE,2);
   Ma8Previous2=iMA(NULL,0,ExtPeriod1,0,MODE_EMA,PRICE_CLOSE,3);
   Ma13Current=iMA(NULL,0,ExtPeriod2,0,MODE_EMA,PRICE_CLOSE,1);
   Ma13Previous=iMA(NULL,0,ExtPeriod2,0,MODE_EMA,PRICE_CLOSE,2);
   Ma13Previous2=iMA(NULL,0,ExtPeriod2,0,MODE_EMA,PRICE_CLOSE,3);
//---- и проверим условие пересечения
   IsCrossDown=(Ma8Current<Ma13Current && Ma8Previous>=Ma13Previous &&
                Ma8Previous2>Ma13Previous2);
   IsCrossUp  =(Ma8Current>Ma13Current && Ma8Previous<=Ma13Previous &&
                Ma8Previous2<Ma13Previous2);
//----
   if(IsCrossDown)
     {
      for(int i=OrdersTotal()-1; i>=0; i--)
        {
         //---- exit longs
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderSymbol()==Symbol() && OrderType()==OP_BUY)
            OrderClose(OrderTicket(),OrderLots(),Bid,3);
        }
      //---- entry short
      OrderSend(Symbol(),OP_SELL,1.0,Bid,3,0.0,0.0);
     }
//----
   if(IsCrossUp)
     {
      for(i=OrdersTotal()-1; i>=0; i--)
        {
         //---- exit shorts
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderSymbol()==Symbol() && OrderType()==OP_SELL)
            OrderClose(OrderTicket(),OrderLots(),Ask,3);
        }
      //---- entry long
      OrderSend(Symbol(),OP_BUY,1.0,Ask,3,0.0,0.0);
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+


avatar
45
criss73 2006.07.20 01:14 
hey stringo, thnx but i dont know how to program this. can you please guide me somehow?

thnx

avatar
Moderator
5198
stringo 2006.07.20 11:11 
First read our documentation and articles

avatar
45
criss73 2006.07.20 16:50 
hey stringo, within the codes there's stuff in Russian. i dont know if it matters but do i need to know what it says?

thnx

avatar
45
criss73 2006.07.20 17:02 
another thing stringo, i opened the metaeditor and do i start the coding where it says "expert start function'' or ''expert deintialization function"?

thnx

avatar
Moderator
5198
stringo 2006.07.20 18:22 

there are simple comments

Process bar only once at beginning
Get MA values
Check crossing



avatar
Moderator
5198
stringo 2006.07.20 18:23 
criss73 wrote:
another thing stringo, i opened the metaeditor and do i start the coding where it says "expert start function'' or ''expert deintialization function"?

thnx

http://docs.mql4.com/basis/functions/special

avatar
45
criss73 2006.07.20 18:38 
ok stringo, i managed to write in the codes and compile them but i want to be able to add lots.  in the "input" all i can do is change the ema values.  

avatar
45
criss73 2006.07.20 21:03 
another thing stringo, i want to add Gridsize,Gridstep and Extendgrid!

thnx

avatar
45
criss73 2006.07.21 06:30 
hey stringo, forget about the Gridsize, Gridstep, and Extendgrid. i still want to know how to code the lots but, also, say the trend is up and i open my charts and turn on the EA, i want it to automatically enter me in the trade in the direction of the ema average; which is in this ex., up. do you know what i mean?

thnx
Back to topics list   | 1 2  

To add comments, please log in or register