Possible problem with Ctrade, trade.Buy

 

Hey, thanks for taking the time to read my question,

I don’t have any problems compiling the entire EA, but I noticed my EA was showing up as an indicator in the MetaTrader environment and not as an EA. 

Could this be because my Buy and Sell orders are incorrect? 

CTrade            m_trade;                      // trading object
.....

double   slL         =     slLong;          	// Stoploss long

bool CNbpExpert::LongOpened(void)
{
   //---    Opening position long 
   bool res = false; 
   if(BreakoutL == true)
     {
         while(OpenOrders<=6)
           {
           trade.Buy(
               //---    Buying at the specified symbol with specified SL and TP
               double volume= 0.156;                                           // specify a trade operation volume
               string symbol= _Symbol;                                        //specify the symbol, for which the operation is performed
               //double point=  SymbolInfoDouble(symbol,SYMBOL_POINT);          // point
               double bid=    SymbolInfoDouble(symbol,SYMBOL_BID);            // current price for closing LONG
               double SL=     slLong;                                         // unnormalized SL value
               SL=NormalizeDouble(SL,digits);                                 // normalizing Stop Loss
               double TP=     tpLong;                                         // unnormalized TP value
               TP=NormalizeDouble(TP,digits);                                 // normalizing Take Profit
            //--- receive the current open price for LONG positions
               double open_price=SymbolInfoDouble(symbol,SYMBOL_ASK);
               string comment=StringFormat("Buy %s %G lots at %s, SL=%s TP=%s",
                                           symbol,volume,
                                           DoubleToString(open_price,digits),
                                           DoubleToString(SL,digits),
                                           DoubleToString(TP,digits));
               if(!m_trade.Buy(volume,symbol,open_price,SL,TP,comment))
                 {
                  //--- failure message
                  Print("Buy() method failed. Return code=",m_trade.ResultRetcode(),
                        ". Code description: ",m_trade.ResultRetcodeDescription());
                 }
               else
                 {
                  //---    Completion message               
                  Print("Buy() method executed successfully. Return code=",m_trade.ResultRetcode(),
                        " (",m_trade.ResultRetcodeDescription(),")");
                   OpenOrders++;
                 }          
           )}
       res=true;
       };
       
//--- result
   return(res);
}  

Thanks in advance! 

Have a great rest of your Sunday, 

 
Foenkelito:

Hey, thanks for taking the time to read my question,

I don’t have any problems compiling the entire EA, but I noticed my EA was showing up as an indicator in the MetaTrader environment and not as an EA. 

Could this be because my Buy and Sell orders are incorrect? 

Thanks in advance! 

Have a great rest of your Sunday, 

Do you have OnTick() or OnCalculate() in your code?

 
Keith Watford #:

Do you have OnTick() or OnCalculate() in your code?

I have OnTick() like this:

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }

So it doesn’t have anything in it.

OnCalculate() is in a script which is included in the main file (so the file with the trade.Buy), this does have quite a few things in it. 

 
Foenkelito #:

OnCalculate() is in a script which is included in the main file (so the file with the trade.Buy), this does have quite a few things in it. 

I don't know what that means and why you are talking about a script and main file.

If you have OnCalculate() in an EA, it should not be there. Indicators use it, not EAs.

 
Keith Watford #:

I don't know what that means and why you are talking about a script and main file.

If you have OnCalculate() in an EA, it should not be there. Indicators use it, not EAs.

I included a file in the main EA file, and this file has the OnCalculate() in it. Does that make sense? 

 
Foenkelito #: I included a file in the main EA file, and this file has the OnCalculate() in it. Does that make sense? 

It is nonsense.

 
William Roeder #:

It is nonsense.

Okay, good to know. I have overlooked that part. 
I will work on that then. Thanks allot for your help!