Location not found

 

Good evening, First of all, thank you for taking your time on this topic. I have problems with this code. The EA is programmed to insert stoploss automatically once a trade is opened in the same exchange (both automatic and manual). With some brokers I have no problem while with others it returns the following error:

Small note:


on the account where it works it is NO HEDGE while on the other it is HEDGING


how can i solve ?? Thank you!!!



input int SL = 100; //15 pip

void OnTradeTransaction(const MqlTradeTransaction &txs, const MqlTradeRequest &req, const MqlTradeResult &res)
{
    MqlTradeRequest rq = {1};
    MqlTradeResult tr = {0};
    
    double sl = 0;
    if (HistoryDealGetInteger(txs.deal, DEAL_ENTRY) == DEAL_ENTRY_IN)
        if (txs.volume != 0 && txs.type != TRADE_TRANSACTION_HISTORY_UPDATE)
        {
            PositionSelect(txs.symbol);
            if (PositionGetDouble(POSITION_SL) == 0)
            {
                rq.action = TRADE_ACTION_SLTP;
                rq.symbol = PositionGetString(POSITION_SYMBOL);
                rq.type_filling = ORDER_FILLING_IOC;
                if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
                {
                    sl = PositionGetDouble(POSITION_PRICE_OPEN) - SL * SymbolInfoDouble(txs.symbol, SYMBOL_POINT);
                    rq.sl = NormalizeDouble(sl, SymbolInfoInteger(txs.symbol, SYMBOL_DIGITS));
                    rq.tp = 0;
                    OrderSend(rq, tr);
                }    
                else if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
                {
                    sl = PositionGetDouble(POSITION_PRICE_OPEN) + SL * SymbolInfoDouble(txs.symbol, SYMBOL_POINT);
                    rq.sl = NormalizeDouble(sl, SymbolInfoInteger(txs.symbol, SYMBOL_DIGITS));
                    rq.tp = 0;
                    OrderSend(rq, tr);
                }    
            }
        }

}
 
Nothing?
 
Andrea Fontanini #: Nothing?

You have provided insufficient information and/or code for us to reach a proper conclusion. All we can do is speculate:

  1. Are you checking if the position is still open?
    Is the deal being tracked by the event the one creating the position or is it perhaps closing the position?
    If you don't verify this, you will get an error if the position is no longer open ("doesn't exist").
  2. Are you checking if the resulting stop-loss or take-profit is a valid price quote?
    It does not seem like you are doing that, given that one of your errors was a stop-loss with a price of "-0.001" which obviously is not valid ("invalid request").
  3. Are you verifying that the "new" stop-loss or take-profit is different from the previous ones set?
    If not, and they are the same, you will get an error.
  4. Are you verifying that the distance of the stops are outside the Stops Level?
    If not, you will get an error?
There are other possibilities too, but again, without enough information or code, it would be guessing.
 
Andrea Fontanini #:
Nothing?

The first log message points to an invalid ticket and ordersize.

Also this

rq.type_filling = ORDER_FILLING_IOC;

could be a problem as filling type can differ by broker.

 

Thanks for your attention. The code was taken from the internet as a free resource. the code is not a part but all. The algorithm starts when an operation is opened automatically or manually. As soon as the trade is opened, set the stop loss (the idea would be to put the possibility to also make the take profit in the same EA. Here I put the stamps of the two accounts where the netting account works on the hedge account no. NETTING: OK HEDGE: NO

 
No? 
 
Andrea Fontanini #: No? 

I've already given you an answer, listing several points of importance, telling you what is needed to clarify the issue.

What else do you want us to say, if you choose to ignore every one of those points and requests?