Warning Expression is always false - page 2

 
angevoyageur:
The code posted is for closing order, not to open. So you can post the relevant code if you need help.


Thanks angevoyageur.. Here is the code for opening a Buy order... all other code for opening a trade is identical except for the " Buy order ", just substitute OpenBuyLimitOrder, or OpenSellLimitOrder, or Open SellStopOrder etc, in the appropriate spot.

int OpenBuyOrder(string argSymbol, double argLotSize, double argSlippage,
  double argMagicNumber, string argComment = "Buy Order")
  {
    while(IsTradeContextBusy()) Sleep(10);
    
    // Place Buy Order
    int Ticket = OrderSend(argSymbol,OP_BUY,argLotSize,MarketInfo(argSymbol,MODE_ASK),
      argSlippage,0,0,argComment,argMagicNumber,0,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("Bid: ",MarketInfo(argSymbol,MODE_BID),
          " Ask: ",MarketInfo(argSymbol,MODE_ASK)," Lots: ",argLotSize);
        Print(ErrLog);
      }
    return(Ticket);
  }

 
REH:


Thanks angevoyageur.. Here is the code for opening a Buy order... all other code for opening a trade is identical except for the " Buy order ", just substitute OpenBuyLimitOrder, or OpenSellLimitOrder, or Open SellStopOrder etc, in the appropriate spot.

I guess you don't have anything printed in the log ? so we can suppose this code is not executed if you don't get trades.

The relevant code would be where you are calling this OpenBuyOder (or similar function).

 
angevoyageur:

I guess you don't have anything printed in the log ? so we can suppose this code is not executed if you don't get trades.

The relevant code would be where you are calling this OpenBuyOder (or similar function).


That is correct, there is nothing printed in the log other then it saying the EA loaded successfully...

 
REH:


That is correct, there is nothing printed in the log other then it saying the EA loaded successfully...


Code for calling a buy order...

// Open buy Order
     BuyTicket = OpenBuyOrder(Symbol(),LotSize,UseSlippage,MagicNumber);
     
     // Order Modification
     if(BuyTicket> 0 && (StopLoss > 0 || TakeProfit > 0))
       {
         OrderSelect(BuyTicket,SELECT_BY_TICKET);
         double OpenPrice = OrderOpenPrice();
         
         //Calculate and verify stop loss and take profit
         double BuyStopLoss = CalcBuyStopLoss(Symbol(),StopLoss,OpenPrice);
         if(BuyStopLoss > 0)
           {
             BuyStopLoss = AdjustBelowStopLevel(Symbol(),BuyStopLoss,5);
           }
           
         double BuyTakeProfit = CalcBuyTakeProfit(Symbol(),TakeProfit,OpenPrice);
         if(BuyTakeProfit > 0)
           {  
             BuyTakeProfit = AdjustAboveStopLevel(Symbol(),BuyTakeProfit,5);
           }
           
      // Add stop loss and take profit
      AddStopProfit(BuyTicket,BuyStopLoss,BuyTakeProfit);
    }
  }   
 
REH:


Code for calling a buy order...

It seems your OpenBuyOrder() isn't call at all, so to understand you need to check to code before this call. Don't you have some conditions (if statement) to check if you want to send a buy order ?
 
angevoyageur:
It seems your OpenBuyOrder() isn't call at all, so to understand you need to check to code before this call. Don't you have some conditions (if statement) to check if you want to send a buy order ?


This would be the code from the beginning of the Start function with the If() conditions for a buy trade...

int start()
  {
    // Execute on bar Open
    if(CheckOncePerBar == true)
      {
        int BarShift =1;
        if(CurrentTimeStamp != Time[0])
          {
            CurrentTimeStamp = Time[0];
            bool NewBar = true;
          }
        else NewBar = false;
       }
      else
       {
         NewBar = true;
         BarShift = 0;
       }
         
    
    // Moving averages
    
    double YellowOp = iMA(NULL,0,1,0,0,1,0);  // 7th position was  BarShift in original
    double AquaOp = iMA(NULL,0,2,0,0,1,0);    // 7th position was  BarShift in original
    double BlueCh = iMA(NULL,0,2,0,0,4,0);    // 7th position was  BarShift in original
    
    double LastYellowOp = iMA(NULL,0,1,0,0,1,0);   // 7th position was  BarShift in original
    double LastAquaOp = iMA(NULL,0,2,0,0,1,0);     // 7th position was  BarShift in original//
    double LastBlueCh = iMA(NULL,0,2,0,0,4,0);      // 7th position was  BarShift in original
    
    // Calculate lot size
    double LotSize = CalcLotSize(DynamicLotSize,EquityPercent,StopLoss,FixedLotSize);
    LotSize = VerifyLotSize(LotSize);
     
   
    // Buy Order Conditions 
       
    by = BlueCh - YellowOp;  // variables by and ba are declared as doubles above
    ba = BlueCh - AquaOp;
    
     if(MathAbs(by)>MathAbs(ba) && by > 0 && BuyMarketCount(Symbol(),MagicNumber) == 0)
     if(MathAbs(ba)>MathAbs(by) && ba > 0 && BuyMarketCount(Symbol(),MagicNumber) == 0)
        
    {
       //Close Sell Orders
         if(SellMarketCount(Symbol(),MagicNumber) > 0)
           {
             CloseAllSellOrders(Symbol(),MagicNumber,Slippage);
           }
     
     // Open buy Order
     BuyTicket = OpenBuyOrder(Symbol(),LotSize,UseSlippage,MagicNumber);
     
     // Order Modification
     if(BuyTicket> 0 && (StopLoss > 0 || TakeProfit > 0))
       {
         OrderSelect(BuyTicket,SELECT_BY_TICKET);
         double OpenPrice = OrderOpenPrice();
         
         //Calculate and verify stop loss and take profit
         double BuyStopLoss = CalcBuyStopLoss(Symbol(),StopLoss,OpenPrice);
         if(BuyStopLoss > 0)
           {
             BuyStopLoss = AdjustBelowStopLevel(Symbol(),BuyStopLoss,5);
           }
           
         double BuyTakeProfit = CalcBuyTakeProfit(Symbol(),TakeProfit,OpenPrice);
         if(BuyTakeProfit > 0)
           {  
             BuyTakeProfit = AdjustAboveStopLevel(Symbol(),BuyTakeProfit,5);
           }
           
      // Add stop loss and take profit
      AddStopProfit(BuyTicket,BuyStopLoss,BuyTakeProfit);
    }
  }   
              
 

Nothing to do with your problem, but you do realise that you give NewBar and BarShift values, but then do nothing with them?

    // Execute on bar Open
    if(CheckOncePerBar == true)
      {
        int BarShift =1;
        if(CurrentTimeStamp != Time[0])
          {
            CurrentTimeStamp = Time[0];
            bool NewBar = true;
          }
        else NewBar = false;
       }
      else
       {
         NewBar = true;
         BarShift = 0;
       }
 

Please don't post code like this, use enumerations such as MODE_SMA etc

double YellowOp = iMA(NULL,0,1,0,0,1,0);

What is the point of an MA with period of 1?

Just use Open[0]

     if(MathAbs(by)>MathAbs(ba) && by > 0 && BuyMarketCount(Symbol(),MagicNumber) == 0)
     if(MathAbs(ba)>MathAbs(by) && ba > 0 && BuyMarketCount(Symbol(),MagicNumber) == 0)

Where is the function BuyMarketCount?

You don't show it.

Incidently, the 2nd line is conditional on the first if being true. You have already checked BuyMarketCount(Symbol(),MagicNumber) == 0, so no need to check again

 

I've just realised

     if(MathAbs(by)>MathAbs(ba) )
     if(MathAbs(ba)>MathAbs(by) )

// Is the same as
 
if(x > y && y > x )  //Impossible