Amps

Thursday, January 28, 2016

Moving Average EA Open Order Function

Moving Average EA Open Order Function

Check open order EA MQL4 moving average have new function use as below

Function used for open order MQL4 moving average EA

long Volume[] Series array that contains tick volumes of each bar of the current chart
double Open[] Series array that contains open prices of each bar of the current chart.
double Close[] Series array that contains close prices for each bar of the current chart.
string  Symbol() Returns a text string with the name of the currency pair

int OrderSend
string NULL
Int cmd
0 OP_BUY
1 OP_SELL
2 OP_BUYLIMIT
3 OP_SELLLIMIT
4 OP_BUYSTOP
5 OP_SELLSTOP
double volume Number of lots
Double price Order price (double Bid price for Sell, double Ask price for buy)
Int slippage Maximum price slippage for buy or sell orders
double stoploss
double takeprofit
string comment=NULL Order comment text. Last part of the comment may be changed by server
Int magic=0 Order magic number. May be used as user defined identifier
Datetime expiration=0 Order expiration time (for pending orders only)
color arrow_color=clrNONE Color of open order
Mention to this EA example not have EA Setting properties for Take Profit and Stop Loss, so at first we would add this parameter in to EA properties as below, which TP and Stop Loss that for broker 5 digits that need specify Point*10 and broker 4 digits would specify Point.
Incase no TP and SL that we would specify 0 in to these part.

Properties for Moving Average Parameter as below

extern string TP_SL = " --- TP and Stop Loss ---";
extern bool Broke3_5Digits = True;
extern double My_TP = 10;
extern double My_SL = 10;

//Add extern parameter as Label
extern string MovingAvr = " --- Moving Average parameter ---";
//Change from original
extern int    MovingPeriod  =12;
extern int    MovingShift   =6;
//Add properties
extern ENUM_TIMEFRAMES TimeFrameUsed = PERIOD_CURRENT;
extern ENUM_MA_METHOD   EMA_method1 = MODE_SMA;
extern ENUM_APPLIED_PRICE Applied_Price1 = PRICE_CLOSE;


//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   double ma;
   int    res;
//--- go trading only for first tiks of new bar
   if(Volume[0]>1) return;

//--- get Moving Average 
  // original ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
  //new
  ma=iMA(NULL,TimeFrameUsed,MovingPeriod,MovingShift,EMA_method1,Applied_Price1,0);

//--- sell conditions
   if(Open[1]>ma && Close[1]<ma)
     {
      // old send sell order: res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red);
res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red);
      return;
     }
//--- buy conditions
   if(Open[1]<ma && Close[1]>ma)
     {
      res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Blue);
      return;
     }
//---
  }

This Moving Average function that sell condition is Open[1]>ma && Close[1]<ma
Buy condition is Open[1]<ma && Close[1]>ma

in the next chapster would explain about auto close order part in case open order is not the right way.

No comments:

Post a Comment