View Single Post
  #2 (permalink)  
Old 01-16-2007, 12:29 PM
newdigital newdigital is online now
Administrator
 
Join Date: Sep 2005
Posts: 16,818
Blog Entries: 146
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
Quote:
Originally Posted by zhu28ming
Hello, Sirs
Does any expert know how to close the current position when the price hits a moving average?

Thank you!
I am not an expert on this subject but I know the following.

In the settings of EA write:

Code:
extern int Current=1;
extern string PARAMETERS_INDICATOR_ONE  = "Moving Average for close";
extern int CloseEMA_Period = 21;
extern int MAcloseMode =  1; //0=sma, 1=ema, 2=smma, 3=lwma
then:

Code:
double Buy1_2 = iMA(NULL, 0, CloseEMA_Period, 0, MAcloseMode, PRICE_CLOSE, Current);
     
double Sell1_2 = iMA(NULL, 0, CloseEMA_Period, 0, MAcloseMode, PRICE_CLOSE, Current);
the condition for close buy and sell:

Code:
if (iClose(NULL,0,Current) <= Buy1_2) Order = SIGNAL_CLOSEBUY;
if (iClose(NULL,0,Current) >= Sell1_2) Order = SIGNAL_CLOSESELL;
and finally:

Code:
if (Order == SIGNAL_CLOSESELL) 
               {
               OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
                              return(0);
               }
and so on.
Reply With Quote