Topic: Off quote error throws FST off track/bug report!

Hi Miroslav,

I had another off quotes error encounter, and again it failed to modify TP/SL after this error.

This is how it happened:

http://s3.postimage.org/2vusznc04/error.jpg

It opened the position, then started modifing it -> off quotes error which ended in lefting the trade WITHOUT TP or SL.

What's even worse - closing point was Stop Limit indicator, as I have experienced this behaviour before I used permanent stop as well, which was set +1 point compared to the SL in Stop Limit, but it wasn't set either.

FST expert is programmed to send OrderModify again after errors including off quotes etc, but it clearly fails in that part, apart from that the second bug lies in the handling of permanent SL, as it is also not set up when off quotes error occur.

Hope this critical errors can be fixed.

Re: Off quote error throws FST off track/bug report!

Hello Footon,
This situation is clearly not a bug in FST but another problem of broker execution model. It consider MT4 work no matter how you trade - via FST or with a regular EA. As you see from both logs the order modification command was properly sent to broker but the broker failed to execute it.

In any execution error FST repeats the order up to TRADE_RETRY_COUNT times.
The current value of TRADE_RETRY_COUNT is 4.
If you want, you can increase this value to 6 or 10 or even more. I cannot do anything when the broker fails or does not want to execute a command.

Another problem is that during the tries, price can change and the SL or TP to be too close to it. From the logs I see that TP is already very close to the market price. Eventually a modification of the expert can be added with purpose to expand SL or TR over the MODE_STOPLEVEL.

Probably  you can check in the MQL4 forums for some other solution or better to send the MT log to your broker for explanation. I found that in the MQL4 forum http://forum.mql4.com/20679

Anyway I'll try to make something in the expert to check for such situation and to repeats setting of SL / TP attempts.

Re: Off quote error throws FST off track/bug report!

One more comment which I think is necessary to this issue - both stops were more than 30 points, so permanent SL should have been set independently of off quote error. I believe TP triggered this error, but permanent SL wasn't attempted to be set at all - all in all it's the latter part which is most unfortunate.

Anyway thanks for the clarification, I'll increase the retry number to see whether it makes a difference.

Re: Off quote error throws FST off track/bug report!

Better ask the broker. I and no one can help in a case when the broker doesn't execute commands.

My FST works none stop. See this log how many modifications it makes within 2 seconds without an error.

http://s3.postimage.org/2xcyu9i84/05_07_2011_13_54_04.jpg

Re: Off quote error throws FST off track/bug report!

I believe TP triggered this error, but permanent SL wasn't attempted to be set at all - all in all it's the latter part which is most unfortunate.

Both SL and TP are sent with one command. Even if one of the parameters is too close to market, broker should execute the other. But as we see from the log the error is not:

ERR_TRADE_MODIFY_DENIED
145
Modification denied because order too close to market.

but "off quote".

FST checks and adjusts SL and TP before sending an order.

Order was sent correctly. The broker doesn't execute it. The expert tries 4 times and no success. What we can do in that case?

Re: Off quote error throws FST off track/bug report!

One more issue - I can see only one order modification, but there should be 4 of them, right?

Re: Off quote error throws FST off track/bug report!

Attempts must be 4.

for (int attempt = 0; attempt < TRADE_RETRY_COUNT; attempt++)
{
    if (!GetTradeContext())
        return (-1);
    bool rc = OrderModify(orderTicket, orderOpenPrice, stopLossPrice, takeProfitPrice, 0);
    ReleaseTradeContext();

    if (rc)
    {   // Modification was successful
        return (1);
    }
    else
    {
        LastError = GetLastError();
        Print("Error with OrderModify(", orderTicket, ", ", orderOpenPrice, ", ", stopLossPrice, ", ", takeProfitPrice, ") ", GetErrorDescription(LastError), ".");
    }

    Sleep(TRADE_RETRY_WAIT);
}

There are three cases when program exits from that cycle:
1. Successful modification;
2. Reached number of TRADE_RETRY_COUNT;
3. MT4 doesn't respond: if (!GetTradeContext()) return (-1);

In cases 2 and 3 FST reports the error.

...

I also noticed that there is only one attempt but decided that you have posted only the last one.
Can you check in the Expert tab of the MT Terminal for error messages from the TradeContext.

Re: Off quote error throws FST off track/bug report!

No, there is only one attempt. No TradeContext messages either.

When I first had "off quote error=trade without TP/SL" couple of weeks ago, there's was only one modification too.

Re: Off quote error throws FST off track/bug report!

Hmm..

I see only two reasons the ModifyPositionByTicket cycle to exit without message:

1. Expert Advisor is stopped
- GetTradeContext() returns false when Expert Advisor is stopped

 
       if (IsStopped())
            return (false);

2. OrderModify is successful:

if (rc)
{   // Modification was successful
    return (1);
}

In all other cases the cycle will print error message.
If error is in the TradeContext, GetTradeContext() will print the error and the cycle will be stopped.
If error is in execution, expert will print the message (as in your case), will wait TRADE_RETRY_WAIT time and will retry execution.

Re: Off quote error throws FST off track/bug report!

I'll change

        if (IsStopped())
            return (false);

to

        if (IsStopped())
        {
            Print("GTC: Expert was stopped!");
            return (false);
        }

in

bool GetTradeContext() function in order to monitor this event.

Re: Off quote error throws FST off track/bug report!

I can make FST to check SL and TP of the reported position. If they are zeroes or beyond Permanent SL and TP, FST to resend OrderModify with Permanent SL and TP.

Re: Off quote error throws FST off track/bug report!

EA was not stopped, and OrderModify was not successful - at least journals in MT and FST tell me this.

If I raise TRADE_RETRY_WAIT time, will it make a difference? At the moment it is 100, which is less than a second, 1/10 of a second I think, maybe this is causing problems? It takes 4-5 seconds to process a modification order, so will a ten second sleep (TRADE_RETRY_WAIT = 10000) for example have an impact?

Re: Off quote error throws FST off track/bug report!

Popov wrote:

I can make FST to check SL and TP of the reported position. If they are zeroes or beyond Permanent SL and TP, FST to resend OrderModify with Permanent SL and TP.

That would help, at least 2 modification orders would be sent instead of one.

Re: Off quote error throws FST off track/bug report!

EA was not stopped, and OrderModify was not successful - at least journals in MT and FST tell me this.

I'm not sure what MT reports. It was designed to protect brokers, not the traders. That is the reason I wrote FSB and FST. As you see the expert is 1700 lines and its purpose is only to execute trades. How many expert have you seen with such depth?

footon wrote:

If I raise TRADE_RETRY_WAIT time, will it make a difference? At the moment it is 100, which is less than a second, 1/10 of a second I think, maybe this is causing problems? It takes 4-5 seconds to process a modification order, so will a ten second sleep (TRADE_RETRY_WAIT = 10000) for example have an impact?

TRADE_RETRY_WAIT  acts after broker returns error. This is the delay to next attempt excluding the order proceeding time.

Re: Off quote error throws FST off track/bug report!

Check this expert. It corrects SL and TP if "Invalid Stops" error occurred during retries.


http://s3.postimage.org/31pxxmdms/05_07_2011_19_18_48.jpg

Post's attachments

MT4-FST Expert.mq4 67.38 kb, 3 downloads since 2011-07-05 

You don't have the permssions to download the attachments of this post.

Re: Off quote error throws FST off track/bug report!

Popov wrote:

Check this expert. It corrects SL and TP if "Invalid Stops" error occurred during retries.


http://s3.postimage.org/31pxxmdms/05_07_2011_19_18_48.jpg

Will try it out, if something significant comes up, I'll post.

Re: Off quote error throws FST off track/bug report!

I made some modifications of the expert.
Now it accepts two new parameters:

Protection_Min_Account
If account equity drops below this value, the expert will close out all positions and stop automatic trade.
The value must be set in account currency. Example:
Protection_Min_Account = 700 will close positions if the equity drops below 700 USD (EUR if you account is in EUR).

Protection_Max_StopLoss
The expert checks the open positions at every tick and if found no SL or SL lower (higher for short) than selected, it sets SL to the defined value. The value is in points. Example:
Protection_Max_StopLoss = 200 means 200 pips for 4 digit broker and 20 pips for 5 digit broker.

http://s3.postimage.org/94tgrvt0/expert_options_safety.jpg

Re: Off quote error throws FST off track/bug report!

These are good additions, hopefully these will help avoiding disasters I've experienced in terms of my account equity. Thank you!

Re: Off quote error throws FST off track/bug report!

I also made FST to check for zero SL or TP after an error and to send a new OrderModify.

http://s3.postimage.org/hzq9j3yc/07_07_2011_07_04_31.jpg

This feature will be available in new FST 1.4 (within next few days).

Re: Off quote error throws FST off track/bug report!

this has happened to me twice in the last 2 days! It has never happened before that. I am running FST on a 4 digit account and a 5 digit account. it has only happened on the 5 digit account. I think its a situation that happens when price moves while the order is in progress. I increased the Deviation by default to 5 pips it was set to zero. I think on the 5 digit account an order was getting rejected if price moved a fraction of a pip. on the 4 digit account price would have to move a whole pip in the time the order was processing to cause an error.  I can still see situations where price could gap even 5 pips and I could get left with no stops. I am going to test the above mt4 expert also. Thanks!

edit >>the post above appeared as I was posting looks like a good idea to resend the orders after errors.  I am looking forward to getting the update.

Re: Off quote error throws FST off track/bug report!

I went through the mt4 log to try and figure out what is going on. My strat is on a m5 chart and its using an ATR stop. at times the ATR stop level is tighter then the broker allows this causes errors. I also have a hard stop at 20 pips set in the strat properties. the hard stop is not getting set at all that I can see.  I can see in the log an order is placed with no SL ot TP then its modified. if the modification fails the trade gets left open with no SL or TP yikes!! I am going to test out the new FST or the mt4 expert above with the stop level input. I think this will always get me a trade with a stop. could the mt4 expert be modified to check for TP also. I had a trade that was modified by the breakeven setting it lost its TP.  This was the mt4 expert I changed to allow a breakeven offset. I dont think the 3 lines of code I changed would cause it to lose a TP.

22 (edited by Shr1k 2011-07-11 04:02:21)

Re: Off quote error throws FST off track/bug report!

this EA will place and check for TP and SL its set to retry 4 times. I am going to increase the number of tries on my real test account. it also has a profit offset on the breakeven. I just ran it for a while on a m1 chart trading almost every bar. seems to work as expected.
http://i54.tinypic.com/261jdjp.jpg

edit >>>> its not working 100% can someone take a look at this I need the EA to check for SL and TP and drop one on an open trade if its running without SL or TP  its almost working it is pushing the TP out as the trade moves it will never hit it.


edit >>> removed broken EA link

Re: Off quote error throws FST off track/bug report!

Shr1k, adding Protection_Max_TakeProfit and BreakEven_Offset makes sense.

You can check the expert on heavy load when set TP and SL to 1 point on Operation tab and start executing orders every 5-10 seconds. In that conditions the expert has to calculate stops first according to the current price and broker's MODE_STOPLEVEL.

I would recommend to use the latest Expert v1.4 from 2011-07-07 as a base for your modifications.

Re: Off quote error throws FST off track/bug report!

I would recommend to use the latest Expert v1.4 from 2011-07-07 as a base for your modifications.

I am running FST on a VPS I don't have admin privileges so I haven't done the update yet. I am running on a live account and its making money so I don't want to change up to much big_smile . I can modify and save the mt4-expert on the VPS myself. I have had some trades drop the SL and TP I am just trying to add some redundant safety measures for my equity. I know I cant backtest the Breakeven but it does seem to be saving some trades on my forward test. I got it working its not moving the TP anymore. here is the fixed EA (not the latest version EA)

Post's attachments

MT4-FST Expert.mq4 72.05 kb, 1 downloads since 2011-07-11 

You don't have the permssions to download the attachments of this post.

Re: Off quote error throws FST off track/bug report!

I tested this Protection_Max_StopLoss feature, but I couldn't get it working properly.

In 5 digit broker I set Protection_Max_StopLoss = 500 (50 pips).
Now if I manually modified an open order and cleared a stoploss, then the expert set a new stoploss for 50 (5 pips) not 500 (50 pips). It did the same when I opened an order through FST Operation tab.

On the second attempt to test this feature I set initial stop loss = 1000 (100 pips) and Protection_Max_StopLoss feature also failed to set 500 (50 pip) stoploss.

Popov wrote:

Protection_Max_StopLoss
The expert checks the open positions at every tick and if found no SL or SL lower (higher for short) than selected, it sets SL to the defined value. The value is in points. Example:
Protection_Max_StopLoss = 200 means 200 pips for 4 digit broker and 20 pips for 5 digit broker.