First of all I've not been coding in MQL for more than 2 weeks. So I am pretty sure I qualify as a newbie. Secondly I've been looking at example code all over the net and seeing great things but it wasn't until I google "Best EA template" that I came upon this fantastic website.
I've been a long time lurker but this is my first time posting because I wanted to be a little smarter before looking dumb or asking a dumb question, which this may very well be, but I am going ahead and asking it anyway since I've been searching the forum and trying for hours without success to close this stupid order.
I'm using the basic Shell Auto from Steve and all you great coders here (fantastic job!) And I've managed to create long positions based on my criteria to create a long entry with candle stops etc.
But for the life of me I cannot figure out how to close an open order where the trade is going against me.
The situation is simply this "If indicator indicates a long position take it. If indicator turns sour, close the open order"
I've been back and forth through the code and I recall seeing if a Long or Short was taken that it won't look for trade opportunities because it is in one. And naturally that wouldn't make any logical sense.
Also I tried following the CloseOrder on page 1 of the forum posting but I get an incorrect parameter count for CloseOrder();
On other EAs this is done like
Code: Select all
CloseOrder(OP_BUY);So this is what I basically have done:
Code: Select all
bool IsBuyingOp()
{
//Open Buy Trade Order
if(((MACDM5>MACD_SIGM5) && (MACDM5>0)) &&
((rsi_m5>50) && (stoc_M5>40) && (cci_MM5>0)) &&
(EMA_M5>ema_m5))
{
return(true);
}
} // End IsBuyingOp()Code: Select all
//Trading decision.
bool SendLong=false,SendShort=false;
//Long trade
if(IsBuyingOp()){SendLong=true;}
//End Long TradeNow I have this condition:
Code: Select all
bool IsCloseTrade()
{
//Rules for closing trades go here
if(MACDM5<0)
{
(?) CloseOrder(OrderTicket());
}
return;
}//End IsCloseTrade();Could someone be kind enough to explain how to close an order without entering a new long or short position? I would be very greatful!
Best regards,
David