//+------------------------------------------------------------------+ //| Moving Average.mq4 | //| Copyright 2005-2014, MetaQuotes Software Corp. | //| http://www.mql4.com | //+------------------------------------------------------------------+ #property copyright "2005-2014, MetaQuotes Software Corp." #property link "http://www.mql4.com" #property description "Moving Average sample expert advisor" #define MAGICMA 20131111 //--- Inputs input double Lots =0.1; input double TakeProfit =1000; input double TrailingStop =0; input double StopLoss =10000; input int RSIPeriod =14; input int RSIUpperLevel =70; input int RSILowerLevel =30; //+------------------------------------------------------------------+ //| Calculate open positions | //+------------------------------------------------------------------+ int CalculateCurrentOrders(string symbol) { int buys=0,sells=0; //--- for(int i=0;i0) return(buys); else return(-sells); } //+------------------------------------------------------------------+ //| Calculate optimal lot size | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Check for open order conditions | //+------------------------------------------------------------------+ void CheckForOpen() { double RSICurrent,RSIPrevious; int ticket,total; //--- go trading only for first tiks of new bar //if(Volume[0]>1) return; //--- get Moving Average RSICurrent=iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,0); RSIPrevious=iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,1); //--- sell conditions if(RSICurrentRSIUpperLevel) { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+StopLoss*Point,Bid-TakeProfit*Point,"",MAGICMA,0,Red); return; } //--- buy conditions if(RSICurrent>RSILowerLevel && RSIPrevious1) return; //--- get Moving Average // ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0); //--- for(int i=0;iClose[1] && Open[1]Close[1] && Open[1]