//+------------------------------------------------------------------+ //| Moving Average.mq4 | //| Copyright © 2005, MetaQuotes Software Corp. | //| http://www.metaquotes.net/ | //+------------------------------------------------------------------+ #define MAGICMA 20050610 extern double Lots = 0.1; extern double MaximumRisk = 0.02; extern double DecreaseFactor = 3; extern double MovingPeriod = 12; extern double MovingShift = 6; //+------------------------------------------------------------------+ //| Calculate open positions | //+------------------------------------------------------------------+ int CalculateCurrentOrders(string symbol) { int buys=0,sells=0; //---- for(int i=0;i0) return(buys); else return(-sells); } //+------------------------------------------------------------------+ //| Check for open order conditions | //+------------------------------------------------------------------+ void CheckForOpen() { double blue; int res; //---- go trading only for first tiks of new bar if(Volume[0]>1) return; //---- get Moving Average (example) blue=iMA(NULL,0,12,0,MODE_SMA,PRICE_CLOSE,0); //---- sell conditions if(first condition) { res=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,0,0,"",MAGICMA,0,Red); return; } //---- buy conditions if(second condition) { res=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,0,0,"",MAGICMA,0,Blue); return; } //---- } //+------------------------------------------------------------------+ //| Check for close order conditions | //+------------------------------------------------------------------+ void CheckForClose() { double blue; //---- go trading only for first tiks of new bar if(Volume[0]>1) return; //---- get Moving Average (for exemple) blue=iMA(NULL,0,12,0,MODE_SMA,PRICE_CLOSE,0); //---- for(int i=0;i