I just changed the code to if(OrderOpenPrice < bid) (for a buying order), it closed earlier and with profit.
Is there more lag associated with the earlier statement?
Also there was lag with this one too but I think in both cases the slippage may be to blame.
It's still not fast enough, might lag be the issue?
Play videoPlease edit your post.
For large amounts of code, attach it.
OrderClose(OrderTicket(), OrderLots(), bid,3,Yellow);
Is your close even being called? What are Function return values ? How do I use them ? - MQL4 forum- Not adjusting slippage for 4/5 digit brokers.
if(direction==4)
How does the variable direction get the value 4?
So this code below will gives information to a void OrderEntry(int direction) function and the if(direction==3) is fulfilled, or at least that was is meant to happen, it is for a sell order and links to the order close for a sell order.
if(ask>=OrderOpenPrice()+NormalizeDouble((iHigh(Symbol(),0,1)-iOpen(Symbol(),0,1)),4) && HighPrice > OpenPrice)OrderEntry(3);
I'm getting stopped out way beyond the what is expected.
Hopefully from the picture it can be seen that the stop is way out, now I tried adding some pips to the NormalizeDouble((iHigh(Symbol(),0,1)-iOpen(Symbol(),0,1)),4) in order to avoid and orderclose error 138.
My attempt to avoid such an error has failed.
This is a semidynamic stoploss in that it does not change during the order like a trialing stop but is different for each order, I've constructed it so that my order criteria may become suited to market fluctuations.
Lol fixed it, once again I made my coding too cumbersome.
OrderSend(Symbol(),OP_BUY,LotSize,ask,5,ask-(Open[1]-Low[1]),.....
Seems to do the trick and so does the correctly adjusted sell version.
Lol fixed it, once again I made my coding too cumbersome.
OrderSend(Symbol(),OP_BUY,LotSize,ask,5,ask-(Open[1]-Low[1]),.....
Seems to do the trick and so does the correctly adjusted sell version.
Please start using the SRC button . . . or do I have to start removing your code ? How to use the SRC button.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I wanted to test out a simple closing condition
if(accountbalance()<accountequity()) (then I use the close trade close after order select ect, I also used the for loop counting down)
I used a guaranteed calling condition, if(60==60) because I am calling the function which contains the if statement above.
My orders are closing but they are taking way too long to close sometimes more than 20 periods, during which my account equity was greater than the balance on 2 or three bars, I tried using orderprofit() instead but I got the exact same result.
I'm using this condition to minimize risk so it's ability to close a trade is not enough, I need it to close the trade as soon as possible (if certain conditions are not met, which is what the if(60==60) is for) .
I'll post a broken up section of the code.
for(int l=OrdersTotal()-1;l>=0;l--)
{
if(OrderSelect(l,SELECT_BY_POS,MODE_TRADES))
if(OrderMagicNumber()==MagicNumber)
if(OrderSymbol()==Symbol())
if(60==60)OrderEntry(4);
.
.
.
.
.
.
.
.
.
if(direction==4)
{
for(int O=OrdersTotal()-1;O>=0;O--)
{
if(OrderSelect(O,SELECT_BY_POS,MODE_TRADES))
if(OrderMagicNumber()==MagicNumber)
if(OrderSymbol()==Symbol())
if(OrderType()==OP_BUY)
{
if(AccountBalace()<AccountEquity())
OrderClose(OrderTicket(), OrderLots(), bid,3,Yellow);
}
else
{
if(OrderProfit()+OrderCommission()>0)
OrderClose(OrderTicket(), OrderLots(), ask,3,Yellow);
Print("Hi");
}
}
}
Help would be greatly appreciated