- With OrderCloseBy command
- By checking the previous Highs and Lows..
Use High[1] or Low[1] or iHigh[..] and iLow[..]
- With OrderCloseBy command
- By checking the previous Highs and Lows..
Use High[1] or Low[1] or iHigh[..] and iLow[..]
Thank you James
But isn't OrderCloseBy command used to close two trades (BUY and SELL)
OrderCloseBy(order_id,opposite_id);
Because it requires id's of both the trades!
I tried to use the following logic but it didn't help. It should ideally reverse the trade, but it doesn't....
//for buy
if(Ask<OrderOpenPrice())
{
close BUY & open SELL
}
//for SELL
if(Bid>OrderOpenPrice)
{
close SELL & Open BUY
}
OR
//BUY && SELL
if(orderprofit()<0)
{
close and open opposite
}
I even tried using Close[] and Open[].
Thank you James
But isn't OrderCloseBy command used to close two trades (BUY and SELL)
OrderCloseBy(order_id,opposite_id);
Because it requires id's of both the trades!
I tried to use the following logic but it didn't help. It should ideally reverse the trade, but it doesn't....
I even tried using Close[] and Open[].
//for buy
if(Ask<OrderOpenPrice())
{
close BUY & open SELL
}
//for SELL
if(Bid>OrderOpenPrice)
{
close SELL & Open BUY
}
OR
//BUY && SELL
if(orderprofit()<0)
{
close and open opposite
}
i hope this is not actually the code u used
i hope this is not actually the code u used
Why do you say so Sir?
Actually I'm learning to code and I'm also new to forex! If anything is wrong or missing guidance would be much appriciated.
Thank you
if(Bid>OrderOpenPrice)
{
close SELL & Open BUY
1) OrderOpenPrice comes with () (OrderOpenPrice())
& Order must be first selected by the OrderSelect() function.
2) no such thing close SELL & Open BUY
3) i would highly recommend you read it first
if(Bid>OrderOpenPrice)
{
close SELL & Open BUY
1) OrderOpenPrice comes with () (OrderOpenPrice())
& Order must be first selected by the OrderSelect() function.
2) no such thing close SELL & Open BUY
3) i would highly recommend you read it first
Sir, I've used code above just to explain the logic!
The EA compiles without errors.
I wanted to know if there is any other method that can determine the profit or loss.
for (.....) { OrderSelect(....); if (OrderProfit() > X) { //do X; } if (OrderProfit() < X) { //do Y; } }this is the idea (I tired to write the whole code)
Sir, I've used code above just to explain the logic!
The EA compiles without errors.
I wanted to know if there is any other method that can determine the profit or loss.
Hi, Ksrohit
A few suggestions:
- set a static datetime variable, e.g LastStoredTime, to memorize the last opened trade time, each time you generate a trade. [EDITED]
- grab each order with OrderTotals() as the maximum counter loop (use SELECT_BY_POS) & compare it with the last stored LastStoredTime, if it is our last trade... check its profit state & type. Use the OrderProfit() & OrderType(). If it is negative or met any other criteria of your choice, then generate a trade with opposite type. Hope this helps.
Hi, Ksrohit
A few suggestions:
- set a static datetime variable, e.g LastStoredTime, to memorize the last opened trade time, accessible with OrderOpenTime() (after grabbing with OrderSelect() of course).
- grab all orders with OrderTotals() as the maximum counter loop (use SELECT_BY_POS) & compare it with the last stored LastStoredTime, if it is our last trade... check its profit state & type. Use the OrderProfit() & OrderType(). If it is negative or met any other criteria of your choice, then generate a trade flag and opposite type. Hope that helps.
Thank you sir.
That definitely helps.
@gjol: Sir, I missed the part you have in the code. That would refine the code more.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
How can change a trade that is gong on with the opposite one e.g. BUY with SELL(if BUY is in loss and vice-versa...).
How can we make EA detect the direction of the graph?