Close Position(s) when Price hits MA

 

Hello, Sirs

Does any expert know how to close the current position when the price hits a moving average?

Thank you!

 
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:

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[/CODE]

then:

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);[/CODE]

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.

 

Is any expert to make it become an EA?

Thanks so much!!!!!!!!