OCO confusion

 

I am collecting a high and low for a previous period and I want to place an OCO using the high as the pending "buy" price and the low as the pending "sell" price. This works perfectly fine on my laptop

using it on 5 different instruments. It works perfectly and executes as planned in the strategy tester. I send it to my friend, and it places correct buy stop orders but the sell stop orders are bogus when he attaches the EA to several different charts in a live demo account. Can someone give me a clue how can one code work perfectly on my end but screw up half the orders on his end and place half the orders correctly.



PendingPriceGU = highGU;

SLGU = highGU - (StopLoss*PipPoint(Symbol()));
TPGU = highGU + (TakeProfit*PipPoint(Symbol()));
TicketGU = OpenBuyStopOrder(Symbol(), LotSize, PendingPriceGU, SLGU, TPGU, Slippage, MagicNumber,0, "Buy Stop Order");

PendingPriceGUs = lowGU;
SLGUs = lowGU + (StopLoss*PipPoint(Symbol()));
TPGUs = lowGU - (TakeProfit*PipPoint(Symbol()));
TicketGUs = OpenSellStopOrder(Symbol(), LotSize, PendingPriceGUs, SLGUs, TPGUs, Slippage, MagicNumber,0, "Sell Stop Order");

ordersetGU = true;

OCOsetGU = true;


I use these functions for the orders


int OpenBuyStopOrder(string argSymbol, double argLotSize, double argPendingPrice, double argStopLoss, double argTakeProfit, double argSlippage,
double argMagicNumber, datetime argExpiration = 0, string argComment = "Buy Stop Order")
{
while(IsTradeContextBusy()) Sleep(10);

// Place Buy Stop Order
int Ticket = OrderSend(argSymbol,OP_BUYSTOP,argLotSize,argPendingPrice,argSlippage,argStopLoss,argTakeProfit,argComment,argMagicNumber,argExpiration,Green);

// Error Handling
if(Ticket == -1)
{
int ErrorCode = GetLastError();
string ErrDesc = ErrorDescription(ErrorCode);

string ErrAlert = StringConcatenate("Open Buy Stop Order - Error ",ErrorCode,": ",ErrDesc);
Alert(ErrAlert);

string ErrLog = StringConcatenate("Ask: ",MarketInfo(argSymbol,MODE_ASK)," Lots: ",argLotSize,
" Price: ",argPendingPrice," Stop: ",argStopLoss," Profit: ",argTakeProfit," Expiration: ",TimeToStr(argExpiration));
Print(ErrLog);
}

return(Ticket);
}

//**********************************************************Sell Stop Order***************************************************
int OpenSellStopOrder(string argSymbol, double argLotSize, double argPendingPrice, double argStopLoss, double argTakeProfit, double argSlippage,
double argMagicNumber, datetime argExpiration = 0, string argComment = "Sell Stop Order")
{
while(IsTradeContextBusy()) Sleep(10);

// Place Sell Stop Order
int Ticket = OrderSend(argSymbol,OP_SELLSTOP,argLotSize,argPendingPrice,argSlippage,argStopLoss,argTakeProfit,argComment,argMagicNumber,argExpiration,Red);

// Error Handling
if(Ticket == -1)
{
int ErrorCode = GetLastError();
string ErrDesc = ErrorDescription(ErrorCode);

string ErrAlert = StringConcatenate("Open Sell Stop Order - Error ",ErrorCode,": ",ErrDesc);
Alert(ErrAlert);

string ErrLog = StringConcatenate("Bid: ",MarketInfo(argSymbol,MODE_BID)," Lots: ",argLotSize,
" Price: ",argPendingPrice," Stop: ",argStopLoss," Profit: ",argTakeProfit," Expiration: ",TimeToStr(argExpiration));
Print(ErrLog);
}

return(Ticket);
}
 

Please use this to post code . . . it makes it easier to read.

 
RaptorUK:

Please use this to post code . . . it makes it easier to read.




No problem
 
Are your Brokers the same ? I suspect not, are they both ECN Brokers ? what about the spread ? do they have similar spreads for the pairs you are both testing on ? or are you testing on different pairs ?
 
jeemba2012:


No problem
Thank you.
 
RaptorUK:
Are your Brokers the same ? I suspect not, are they both ECN Brokers ? what about the spread ? do they have similar spreads for the pairs you are both testing on ? or are you testing on different pairs ?

Our brokers are the same. When we attach it to the same pairs. It works perfectly on my end, and it gives bogus orders on his end.


for instance.


So here is the order it placed (pending orders) for the EURJPY and GBPJPY;
EJ
buy stop 110.974 sl 110.474 tp 111.974
sell stop 1.648 sl 2.148 tp 0.648

GJ
buy stop 126.959 sl126.459 tp 127.959
sell stop 1.648 sl 2.148 tp 0.648


the sell stop orders are bogus. but on my laptop everything is fine. how is this possible?

 

Perhaps it's an issue with the EA parameters ?

Have you tried exporting your settings (you can do it from the EA Properties) and sending them to your friend to be imported ?

 
RaptorUK:

Perhaps it's an issue with the EA parameters ?

Have you tried exporting your settings (you can do it from the EA Properties) and sending them to your friend to be imported ?


There are only two parameters. start is a variable integer input which is the time of the server that coincides with the london open. Both enter 10 since we use fxPro and there server is GMT+2.

the other parameter is an integer for the percentage of risk. so I would enter 15 if I want to risk 15%

 
The Sell Stop prices look like GBPUSD . . . can't think of much else without seeing more code maybe . .
 
jeemba2012:

I am collecting a high and low for a previous period and I want to place an OCO using the high as the pending "buy" price and the low as the pending "sell" price. This works perfectly fine on my laptop

using it on 5 different instruments. It works perfectly and executes as planned in the strategy tester. I send it to my friend, and it places correct buy stop orders but the sell stop orders are bogus when he attaches the EA to several different charts in a live demo account. Can someone give me a clue how can one code work perfectly on my end but screw up half the orders on his end and place half the orders correctly.

  1. The Mql4 model does not support OCO. You're going to have to loop and count open orders and then delete the pending.
  2. EA's must adjust 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.0015      0.00150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
        if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    
  3. On ECN brokers you must open first and THEN set stops.
 
WHRoeder:
  1. The Mql4 model does not support OCO. You're going to have to loop and count open orders and then delete the pending.
  2. EA's must adjust for 4/5 digit brokers, TP, SL, AND slippage
  3. On ECN brokers you must open first and THEN set stops.

I used this code to calculate the percentage I want to risk

RiskAmount = AccountEquity()*(EquityPercent / 100);
              TickValue = MarketInfo(Symbol(),MODE_TICKVALUE);
              if(Point == 0.001 || Point == 0.00001)TickValue *= 10;
              
              CalcLots = (RiskAmount/StopLoss) / TickValue;
              LotSize = CalcLots;


My straddle code is

          if(ordersetGU == false)
            {
                 PendingPriceGU = highGU;
                 SLGU = highGU - (StopLoss*PipPoint(Symbol()));
                 TPGU = highGU + (TakeProfit*PipPoint(Symbol()));
                TicketGU = OpenBuyStopOrder(Symbol(), LotSize, PendingPriceGU, SLGU, TPGU, Slippage, MagicNumber,0,  "Buy Stop Order");
                
                 PendingPriceGUs = lowGU;
                 SLGUs = lowGU + (StopLoss*PipPoint(Symbol()));
                 TPGUs = lowGU - (TakeProfit*PipPoint(Symbol()));
                TicketGUs = OpenSellStopOrder(Symbol(), LotSize, PendingPriceGUs, SLGUs, TPGUs, Slippage, MagicNumber,0,  "Sell Stop Order");
                 
                 ordersetGU = true;
                 OCOsetGU = true;
            }



            if(OrderSelect(TicketGU,SELECT_BY_TICKET)&&(OP_BUY == OrderType() )&&(OCOsetGU == true) )//delete order for OCO of GBPUSD
            {
              OrderDelete(TicketGUs,Red);
            }
            else if(OrderSelect(TicketGUs,SELECT_BY_TICKET)&&(OP_SELL == OrderType() )&&(OCOsetGU == true) )
            {
              OrderDelete(TicketGU,Green);
            }



I used these functions for the code


        int GetSlippage(string Currency, int SlippagePips)
        {
                int CalcDigits = MarketInfo(Currency,MODE_DIGITS);
                if(CalcDigits == 2 || CalcDigits == 4) double CalcSlippage = SlippagePips;
                else if(CalcDigits == 3 || CalcDigits == 5) CalcSlippage = SlippagePips * 10;
                return(CalcSlippage);
        } 
        
        //******************************PIP point FUNC******************************************
        double PipPoint(string Currency)
        {
                int CalcDigits = MarketInfo(Currency,MODE_DIGITS);
                if(CalcDigits == 2 || CalcDigits == 3) double CalcPoint = 0.01;
                else if(CalcDigits == 4 || CalcDigits == 5) CalcPoint = 0.0001;
                return(CalcPoint);
        }
        //**************************************************************BUY sTop Order*******************************************************
        int OpenBuyStopOrder(string argSymbol, double argLotSize, double argPendingPrice, double argStopLoss, double argTakeProfit, double argSlippage,  
        double argMagicNumber, datetime argExpiration = 0, string argComment = "Buy Stop Order")
        {
                while(IsTradeContextBusy()) Sleep(10);

                // Place Buy Stop Order
                int Ticket = OrderSend(argSymbol,OP_BUYSTOP,argLotSize,argPendingPrice,argSlippage,argStopLoss,argTakeProfit,argComment,argMagicNumber,argExpiration,Green);

                // Error Handling
                if(Ticket == -1)
                        {
                                int ErrorCode = GetLastError();
                                string ErrDesc = ErrorDescription(ErrorCode);

                                string ErrAlert = StringConcatenate("Open Buy Stop Order - Error ",ErrorCode,": ",ErrDesc);
                                Alert(ErrAlert);

                                string ErrLog = StringConcatenate("Ask: ",MarketInfo(argSymbol,MODE_ASK)," Lots: ",argLotSize,
                                        " Price: ",argPendingPrice," Stop: ",argStopLoss," Profit: ",argTakeProfit," Expiration: ",TimeToStr(argExpiration));
                                Print(ErrLog);
                        }
        
                return(Ticket);
        } 
        
        //**********************************************************Sell Stop Order***************************************************
        int OpenSellStopOrder(string argSymbol, double argLotSize, double argPendingPrice,      double argStopLoss, double argTakeProfit, double argSlippage,  
        double argMagicNumber, datetime argExpiration = 0, string argComment = "Sell Stop Order")
        {
                while(IsTradeContextBusy()) Sleep(10);

                // Place Sell Stop Order
                int Ticket = OrderSend(argSymbol,OP_SELLSTOP,argLotSize,argPendingPrice,argSlippage,argStopLoss,argTakeProfit,argComment,argMagicNumber,argExpiration,Red);

                // Error Handling
                if(Ticket == -1)
                        {
                                int ErrorCode = GetLastError();
                                string ErrDesc = ErrorDescription(ErrorCode);

                                string ErrAlert = StringConcatenate("Open Sell Stop Order - Error ",ErrorCode,": ",ErrDesc);
                                Alert(ErrAlert);

                                string ErrLog = StringConcatenate("Bid: ",MarketInfo(argSymbol,MODE_BID)," Lots: ",argLotSize,
                                        " Price: ",argPendingPrice," Stop: ",argStopLoss," Profit: ",argTakeProfit," Expiration: ",TimeToStr(argExpiration));
                                Print(ErrLog);
                        }
                        
                return(Ticket);
        }




AM i MISSING ANYTHING IMPORTANT TO PLACE THE ORDERS?
Reason: