//+------------------------------------------------------------------+ //| P&P_EA_MACD.mq4 | //| Copyright © 2013, P&P Investment Strategies sagl | //| http://www.ppinvestment.ch | //+------------------------------------------------------------------+ #property copyright "P&P Investment Strategies © 2013" #property link "http://www.ppinvestment.ch" static datetime lastBar; extern double StopLose = 290; extern double TakeProfit = 350; extern double Lots = 0.75; extern double MACDBuyLow = 0.00021; extern double MACDBuyHigh = 0.000155; extern double MACDSellLow = 0.00022; extern double MACDSellHigh = 0.00015; extern double FastEmaPeriod= 2; extern double SlowEmaPeriod= 3; extern double SignalPeriod = 20; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { lastBar= Time[ 0]; return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { if(Bars< 10) { Print("bars less than 10"); return(0); } // si attiva subito dopo la chiusura della candela if( lastBar!= Time[ 0]) { lastBar= Time[ 0]; // apre posizione di BUY quando MACD attraversa lo zero dal basso verso l'alto if( iMACD(NULL, 0, FastEmaPeriod, SlowEmaPeriod, SignalPeriod, PRICE_CLOSE, MODE_MAIN, 1)> MACDBuyHigh && iMACD(NULL, 0, FastEmaPeriod, SlowEmaPeriod, SignalPeriod, PRICE_CLOSE, MODE_MAIN, 3)< -MACDBuyLow) { OrderSend( Symbol(), OP_BUY, Lots, Ask, 3, Ask- ( StopLose* Point), Ask+ ( TakeProfit* Point), "P&P_EA_MACD", 803, 0, Red); } // apre posizione di SELL quando MACD attraversa lo zero dll'alto verso il basso else if( iMACD(NULL, 0, FastEmaPeriod, SlowEmaPeriod, SignalPeriod, PRICE_CLOSE, MODE_MAIN, 1)< -MACDSellLow && iMACD(NULL, 0, FastEmaPeriod, SlowEmaPeriod, SignalPeriod, PRICE_CLOSE, MODE_MAIN, 3)> MACDSellHigh) { OrderSend( Symbol(), OP_SELL, Lots, Bid, 3, Bid+ ( StopLose* Point), Bid- ( TakeProfit* Point), "P&P_EA_MACD", 803, 0, Blue); } } return(0); } //+------------------------------------------------------------------+