When you detect the cross, specify the order you want to close, and use OrderClose().

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Newbie question this, but how can I set an order so it closes when one MA crosses another MA?
For example here's my code to open a trade:
----------
if ((CurrentMA1 > CurrentMA2) && (PriorMA1 <= PriorMA2))
{
{
StopLossLevel = Bid-(10*Point);
TakeProfitLevel = Bid+(10*Point);
Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy", MagicNumber, 0, Blue);
OrderCount++;
ObjectCreate("e" + OrderCount, OBJ_ARROW, 0, Time, Bid);
ObjectSet("e" + OrderCount, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
ObjectSet("e" + OrderCount, OBJPROP_COLOR, Green);
PlaySound("news.wav");
Alert(Symbol()," Buy Order Triggered");
InBuyTrade = true;
InSellTrade = false;
}
}
----------
This works fine, but the Take Profit level is a fixed number.
I don't want to use a fixed number, I want to Take Profit when CurrentMA1 crosses CurrentMA2.
How can I do this?
Many thanks for your help.