Enormous Technical Problems - 5 Digit Broker Execution of Trades - Limit Orders same line or Order Modify second line

 

It seems No what I do with the code I am getting inconsistancy with Orders being executed or just Nothing at all. Almost like the Broker just seems to like NO Target

Prices or stops. Only signal closing and profits.(Moving ave. etc.) I can't change Brokers right now even though I would like to. Any help on this is Greatly appreciated. I am putting in a simple sample MACD that is modified for now. Until I get this figured out, there is No sense in using fancy EA'S that I have built or anyone else.

Thanks,

JimsTradingMachine

Files:
 

What errors are you getting reported back ?

Is your Broker an ECN Broker ? ECN

When you have a loop going through the open orders and closing any you MUST count down not up.

 

Your 30 point trailing stop is unpleasantly close to the market. You really ought to be checking it against MODE_STOPLEVEL.

There are also quite a few unchecked actions like OrderSelect, OrderModify and OrderClose.

 
dabbler:

Your 30 point trailing stop is unpleasantly close to the market. You really ought to be checking it against MODE_STOPLEVEL.

There are also quite a few unchecked actions like OrderSelect, OrderModify and OrderClose.


How do I check it against MODE_STOPLEVEL? Will this give me an error if too close? Just wanted to mention

sometimes even with the 5 digit for pips code I still have to put in 30 for 3 or 100 for 10. Not working right I guess.

JimsTradingMachine

 
RaptorUK:

What errors are you getting reported back ?

Is your Broker an ECN Broker ? ECN

When you have a loop going through the open orders and closing any you MUST count down not up.

Yes, it sure is an ECN Broker.

Yes I agree with you on the count down. I didn't build this one though.Just the MACD Sample with the 5 digits for Pips code plugged in and changed to Limit order .

I have noticed this ++ on a lot of EA'S on the Code base where it is on the closing section or block.??? Maybe I am not reading it right.

I think I am going to send you another one with the OrderModify code and see what you see there. This IS an older one but should help to determine

Order execution problems.(have learned quite a bit since this one) Note: Like I say, they do work Ok sometimes and I havn't checked this one lately. Have

had way too many OrderModify errors in the journal though. When using Market Orders for this. Seems like more inconsistancy with Limit Orders and TP or SL in the same line. Some have not put the TP or SL on the pending order after it is executed. Also I am very aware that the Trailing stops and static stops can not be used at the same time for the orders on the MetaTrader.

JimsTradingMachine

Files:
 

jimtrader1:

Yes I agree with you on the count down. I didn't build this one though.Just the MACD Sample with the 5 digits for Pips code plugged in and changed to Limit order .

I have noticed this ++ on a lot of EA'S on the Code base where it is on the closing section or block.??? Maybe I am not reading it right.

I think I am going to send you another one with the OrderModify code and see what you see there. This IS an older one but should help to determine

Order execution problems.(have learned quite a bit since this one) Note: Like I say, they do work Ok sometimes and I havn't checked this one lately. Have

had way too many OrderModify errors in the journal though


What errors ?

This will cause you issue in some circumstances . . .

 if ((adx>adxx) && (ma>maa) && (sto<20 && rsi<30) && (val>val21) && (cci<-125))//Signal Buy
        {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"macd sample",16384,0,Green);   //  what if this Send fails ?
         
                OrderModify(ticket,OrderOpenPrice(),Bid-StopLoss,Ask+TakeProfit*Point,0,White);  //  you still do the Modify,  and the Modify then fails
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
         else Print("Error opening BUY order : ",GetLastError());                                           //  and then the error is in relation to the Modify
         return(0); 

. . . check return values after each function and report any errors before calling the next function.

Also, a Buy Order is placed at Ask, a Buy is closed with a Sell and that is executed at Bid . . . in your Modify you are setting your SL relative to Bid and your TP relative to Ask . . . . whichever way you slice and dice it you are going to have to pay the Spread and make sure your TP and SL fit in with the Freezelevel and Stoplevels . . . there is comprehensive info here that is worth spending some time with and getting a thorough understanding of: Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial

 
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"macd sample",16384,0,Green);
                OrderModify(ticket,OrderOpenPrice(),Bid-StopLoss,Ask+TakeProfit*Point,0,White);
         if(ticket>0)

You can NOT call OrderModify if the OrderSend fails - check your return codes - ALL of them.

You can NOT call OrderOpenPrice() until you do a successful orderSelect()

You must modify EA's for 4/5 digit brokers (tp, sl, AND SLIPPAGE)

//++++ These are adjusted for 5 digit brokers.
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){                                                     OptParameters();
     if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 https://www.mql5.com/en/forum/135345
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
//---- These are adjusted for 5 digit brokers.
    /* On ECN brokers you must open first and THEN set stops
    int ticket = OrderSend(..., 0,0,...)
    if (ticket < 0)
       Alert("OrderSend failed: ", GetLastError());
    else if (!OrderSelect(ticket, SELECT_BY_TICKET))
       Alert("OrderSelect failed: ", GetLastError());
    else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0)
       Alert("OrderModify failed: ", GetLastError());
     */
 
WHRoeder:

You must modify EA's for 4/5 digit brokers (tp, sl, AND SLIPPAGE)

and trailing stop
 
jimtrader1:


How do I check it against MODE_STOPLEVEL? Will this give me an error if too close?

   if( TrailingStop <= MarketInfo(Symbol(),MODE_STOPLEVEL) ){
      WarnTheUserAndDoNotContinueToRunTheEA();
   }
That is a minimum necessary test but frankly if you do it that way it is almost guaranteed to fail. There is no allowance for movement of the price when setting the trailing stop. You should ideally be at least several points away from the broker's stoplevel. 30 points on a 5 digit broker is only 3 pips; that's very tight. Perhaps you meant 30 pips and forgot to multiply that one by 10 like you did with all the rest.
 
RaptorUK:

What errors ?

This will cause you issue in some circumstances . . .

. . . check return values after each function and report any errors before calling the next function.

Also, a Buy Order is placed at Ask, a Buy is closed with a Sell and that is executed at Bid . . . in your Modify you are setting your SL relative to Bid and your TP relative to Ask . . . . whichever way you slice and dice it you are going to have to pay the Spread and make sure your TP and SL fit in with the Freezelevel and Stoplevels . . . there is comprehensive info here that is worth spending some time with and getting a thorough understanding of: Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial


Havn't ru
 
WHRoeder:

You can NOT call OrderModify if the OrderSend fails - check your return codes - ALL of them.

You can NOT call OrderOpenPrice() until you do a successful orderSelect()

You must modify EA's for 4/5 digit brokers (tp, sl, AND SLIPPAGE)


Error I am getting is: OrderModify 130 many times on the journal.

Here is a recent trade that was made on the EURUSD. Notice it put in this
crazy stop loss digit number but seemed to ignore it and
apply the trailing stp. Ok. What's going on here? Do I need NormalizeDouble
or Market Info or something?
S/L T/P CloseP. Prof/Loss
BUY 1.29400 0.78589 0.00000 1.29414 .98

Here is my 5 Digit code and down below one from the code base.
That one is done under the Start Function instead of the Initialization?
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

if (Digits == 5 || Digits == 3) // Adjust for five (5) digit brokers.
{
pips2dbl = Point*10;
}
else
{
pips2dbl = Point;
}

TrailingStop = pips2dbl*trailingStop;
Slippage = pips2dbl*slippage;
}

Taken from code base:

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----

int digits=MarketInfo("EURUSD",MODE_DIGITS);
if(digits==5){int StopMultd=10;} else{StopMultd=1;}
int Slippage=Slip*StopMultd;

}

Reason: