//+------------------------------------------------------------------+ //| P&P_EA_MA.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 = 280; extern double TakeProfit = 480; extern double Lots = 1; extern int MAFastPeriod = 29; extern int MASlowPeriod = 41; extern int MinWidth = 10; extern int MaxWidth = 11; static int hLog; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { double MaFast; double MaSlow; int ticket; // si attiva subito dopo la chiusura della candela if( lastBar!= Time[ 0]) { lastBar= Time[ 0]; // calcola ordini aperti int numOrdersSell= 0; int numOrdersBuy= 0; int numOrders= OrdersTotal(); for( int i= 0; i< numOrders; i++) { if( OrderSelect( i, SELECT_BY_POS)) { switch( OrderType()) { case OP_BUY: numOrdersBuy++; break; case OP_SELL: numOrdersSell++; break; } } } MaFast= iMA(NULL,0, MAFastPeriod,0,MODE_SMA,PRICE_CLOSE, 1); MaSlow= iMA(NULL,0, MASlowPeriod,0,MODE_SMA,PRICE_CLOSE, 1); // verifica prezzo rispetto alla medie mobile per posizione BUY if( MaFast< MaSlow && MaSlow< Close[ 1] && numOrdersBuy== 0) { // apre BUY se nel periodo MinWidh / MaxWidh c'è un'inversione di posizione del prezzo rispetto alle medie mobili for( i= MinWidth; i<= MaxWidth; i++) { MaSlow= iMA(NULL,0, MASlowPeriod,0,MODE_SMA,PRICE_CLOSE, i); MaFast= iMA(NULL,0, MAFastPeriod,0,MODE_SMA,PRICE_CLOSE, i); if( MaFast< MaSlow && Close[ i]< MaFast) { ticket= OrderSend( Symbol(), OP_BUY, Lots, Ask, 3, Ask- ( StopLose* Point), Ask+ ( TakeProfit* Point), "P&P_EA_MA", 803, 0, Red); break; } } } // verifica prezzo rispetto alla medie mobile per posizione SELL else if( Close[ 1]< MaSlow && MaSlow< MaFast && numOrdersSell== 0) { // apre SELL se nel periodo MinWidh / MaxWidh c'è un'inversione di posizione del prezzo rispetto alle medie mobili for( i= MinWidth; i<= MaxWidth; i++) { MaSlow= iMA(NULL,0, MASlowPeriod,0,MODE_SMA,PRICE_CLOSE, i); MaFast= iMA(NULL,0, MAFastPeriod,0,MODE_SMA,PRICE_CLOSE, i); if( MaSlow< MaFast && MaFast< Close[ i]) { ticket= OrderSend( Symbol(), OP_SELL, Lots, Bid, 3, Bid+ ( StopLose* Point), Bid- ( TakeProfit* Point), "P&P_EA_MA", 803, 0, Blue); break; } } } } return(0); } //+------------------------------------------------------------------+