simple program to trade using MA signals

 

Hello all,


First post so please direct me to the right place if you need to. Im not sure if I need a script to do this but please let me know if I do (and provide solution if possible).


I am trying to create a simple mql4 program or script that will place trades based on the MA. There is an example in the book on using the MA to produce alerts but I need to understand what else needs to be added to place trades based on the MA. The code should buy if above the MA and sell if below the MA. The code for callindicator.mq4 is below:

What lines need to be added to this file (and where) to initiate the trades?

Thanks in advance.

//--------------------------------------------------------------------
// callindicator.mq4
// The code should be used for educational purpose only.
//--------------------------------------------------------------------
extern int Period_MA = 21;            // Calculated MA period
bool Fact_Up = true;                  // Fact of report that price..
bool Fact_Dn = true;                  //..is above or below MA
//--------------------------------------------------------------------
int start()                           // Special function start()
  {
   double MA;                         // MA value on 0 bar    
//--------------------------------------------------------------------
                                      // Tech. ind. function call
   MA=iMA(NULL,0,Period_MA,0,MODE_SMA,PRICE_CLOSE,0); 
//--------------------------------------------------------------------
   if (Bid > MA && Fact_Up == true)   // Checking if price above
     {
      Fact_Dn = true;                 // Report about price above MA
      Fact_Up = false;                // Don't report about price below MA
      Alert("Price is above MA(",Period_MA,").");// Alert 
     }
//--------------------------------------------------------------------
   if (Bid < MA && Fact_Dn == true)   // Checking if price below
     {
      Fact_Up = true;                 // Report about price below MA
      Fact_Dn = false;                // Don't report about price above MA
      Alert("Price is below MA(",Period_MA,").");// Alert 
     }
//--------------------------------------------------------------------
   return;                            // Exit start()
  }
//--------------------------------------------------------------------
 
zmalick:

Hello all,


First post so please direct me to the right place if you need to. Im not sure if I need a script to do this but please let me know if I do (and provide solution if possible).


I am trying to create a simple mql4 program or script that will place trades based on the MA. There is an example in the book on using the MA to produce alerts but I need to understand what else needs to be added to place trades based on the MA. The code should buy if above the MA and sell if below the MA. The code for callindicator.mq4 is below:

What lines need to be added to this file (and where) to initiate the trades?

You need to read more of the Book, in particular: Book - OrderSend
 
RaptorUK:
You need to read more of the Book, in particular: Book - OrderSend


Thanks for your help I got this working.