Please help me solve this mystery!!

 

I cannot understand why the program skips the lines after a successful previous line and ignores the instructions on those lines.

If you look at the code below you will see that there is a Sell transaction that is carried out successfully in the Strategy Tester, but the Sell transaction is never recorded in the Journal and the lines of code after the OrderSend is also ignored and also not recorded in the Journal.

What is going on?

(I do have some problems with the data as can be seen from one of the many lines: 2012.12.31 11:21:27    TestGenerator: unmatched data error (volume limit 2430 at 2012.11.05 06:00 exceeded))

Here is the snippet of code I am referring to:

if(IsTradeContextBusy()) Sleep(10);
      SellTicket = OrderSend(Symbol(),OP_SELL,LotSize,SellPrice,UseSlippage,SellStopLoss,SellTakeProfit,"CCITrendReversal",MagicNumber,0,Red);
        Print("SellTicket is ",SellTicket);  
           if (SellTicket >= 0) 
           {
             PlaySound("news.wav");
             SellTime = OrderOpenTime();
             SellSignal = false;
           }
          Print("SellSignal2 is ", SellSignal);
 
ernest02:

I cannot understand why the program skips the lines after a successful previous line and ignores the instructions on those lines.

If you look at the code below you will see that there is a Sell transaction that is carried out successfully in the Strategy Tester, but the Sell transaction is never recorded in the Journal and the lines of code after the OrderSend is also ignored and also not recorded in the Journal.

What is going on?

The Sell did not work . . . add code to print the error when any OrderXxxx()  function fails,  such as OrderSend(), OrderModify(), OrderClose(), etc . . . for more info:  What are Function return values ? How do I use them ?
 

ernest02,

Maybe this will be of use to you?

Print("Error description",GetLastError());

Thank you.

 

Thanks guys....but...

The strategy Tester shows several Sell transactions - - and I do have an error routine in the event of an error in the transaction (code shown below) but there are no errors reported.


  // Error handling
             if(SellTicket == -1)
               {
                ErrorCode = GetLastError();
                ErrDesc = ErrorDescription(ErrorCode);

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

                ErrLog = StringConcatenate("Ask: ",Ask," Lots: ",LotSize," Price: ",SellPrice," Stop: ",SellStopLoss," Profit: ",SellTakeProfit);
                Print(ErrLog);
               }
 
ernest02:

Thanks guys....but...

The strategy Tester shows several Sell transactions - - and I do have an error routine in the event of an error in the transaction (code shown below) but there are no errors reported.

Is SellTicket a double or an int ?  can you show the 2 bits of code you have posted with all the bits of code in between please . . . 
 

SellTicket is an Integer.

Here is more of the code:

if (SellSignal == true && CCIReal < (CCILevel - SellLevel) && TotalSellOrders <= MaxTrans && SellTrans == true)

      {
       Print("CCI is ",CCIReal);
       
       for (Count = OrdersTotal()-1; Count >= 0; Count--)
                    if (OrderSelect(Count, SELECT_BY_POS)
                    && OrderType() == OP_BUY
                    && OrderMagicNumber() == MagicNumber)
                    
                    {
                    int BuyOrder = OrderTicket();
                    
                    while(IsTradeContextBusy()) Sleep(10);
                
                    bool Closed = OrderClose(BuyOrder, OrderLots(), Bid, UseSlippage, Blue);
                                            
                            // Error handling
                  if(Closed == false)
                     {
                        ErrorCode = GetLastError();
                        string ErrDesc = ErrorDescription(ErrorCode);

                        string ErrAlert = StringConcatenate(" Close Buy Order Error - Error ",ErrorCode,": ",ErrDesc, " Bid is ", Bid, " SellTakeProfit is ", SellTakeProfit);
                        Alert(ErrAlert);

                        string ErrLog = StringConcatenate("OrderTicket: ",OrderTicket());
                        Print(ErrLog);
                        
                     }
                      
                            }
                       
      
      RefreshRates();
      
      SellPrice = Bid;
      
      if (TrailingStopFunc == false)
      
         
         SellStopLoss = Bid + (StopLoss * UsePoint);
         else SellStopLoss = 0;
           
      
      SellTakeProfit = Bid - (TakeProfit * UsePoint);
      
      if(IsTradeContextBusy()) Sleep(10);
      SellTicket = OrderSend(Symbol(),OP_SELL,LotSize,SellPrice,UseSlippage,SellStopLoss,SellTakeProfit,"CCITrendReversal",MagicNumber,0,Red);
        Print("SellTicket is ",SellTicket);  
           if (SellTicket >= 0) 
           {
             PlaySound("news.wav");
             SellTime = OrderOpenTime();
             SellSignal = false;
           }
          Print("SellSignal2 is ", SellSignal);
          
          // Error handling
             if(SellTicket == -1)
               {
                ErrorCode = GetLastError();
                ErrDesc = ErrorDescription(ErrorCode);

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

                ErrLog = StringConcatenate("Ask: ",Ask," Lots: ",LotSize," Price: ",SellPrice," Stop: ",SellStopLoss," Profit: ",SellTakeProfit);
                Print(ErrLog);
               }
         
         }
 

ernest02,

I do not understand what is causing the error you speak of but you could consider rewriting your code in a such way for the error to not exist.

With that said, if you could post a description of the action you wish for your EA to perform, it would be easier for me (and/or others) to provide you a solution.

Instead of trying to isolate the error, if the error costs too much time to find, consider rewriting the code to remove the error. It is completely up to you. Hope this is useful.

Thank you.

 
ernest02:

SellTicket is an Integer.

Here is more of the code:

Thank you . . .  just to be clear on what should happen if the Sell worked  . . .

Print("SellTicket is ",SellTicket);    //  <---  this will be printed to the journal
           if (SellTicket >= 0) 
           {
             PlaySound("news.wav");    //  <---  PlaySound does not work in the Strategy Tester 
             SellTime = OrderOpenTime();   //  <---  if the Sell worked this variable will be set (or do we first need an OrderSelect() ?)
             SellSignal = false;           //  <---  if the Sell worked this variable will be set
           }
          Print("SellSignal2 is ", SellSignal);    //  <---  this will be printed to the journal
 

This is what is so strange!

The Strategy Tester records many Sell transactions but nothing is shown in the Journal.

I am going to work through the code from the start again, make a few changes and see what happens.

Thanks for all the help guys. Much appreciated.

(If I find the cause of the error i will report back - otherwise i will just rewrite the code.)

 
ernest02:

This is what is so strange!

The Strategy Tester records many Sell transactions but nothing is shown in the Journal.

I am going to work through the code from the start again, make a few changes and see what happens.

Thanks for all the help guys. Much appreciated.

(If I find the cause of the error i will report back - otherwise i will just rewrite the code.)

Weird . . .  unless you are looking at the Experts tab by mistake ?  have you had a look at the log  in tester/logs/  ?
 
ernest02: The Strategy Tester records many Sell transactions but nothing is shown in the Journal.
Unless you are using visual mode in the tester, there will never be anything in the journal.