Why does this code only take sell position?

 
   double redMa = iMA(_Symbol,indicatorTimeFrameRed,maPeriodRed,0,maMethodRed,appliedPriceRed,redMaShift);
   redMa= NormalizeDouble(redMa,_Digits);
   
   double blueMa = iMA(_Symbol,indicatorTimeFrameBlue,maPeriodBlue,0,maMethodBlue,appliedPriceBlue,blueMaShift);
   blueMa= NormalizeDouble(blueMa,_Digits);
   
   //double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
   //ask = NormalizeDouble(ask,_Digits);   
   //static double lastAsk = ask;
   
   double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
   bid = NormalizeDouble(bid,_Digits);
   static double lastBid = bid;
   
   //if(strategy1enabled == true ){
       Print("Strategy 1 is active");
   
       if(lastBid < redMa && bid >= redMa){
       Print("Ask is near entry");
       //if(isTradingAllowed == true){
       Print("Price touched the red Line from Below...Buying...");
       
       double sl = bid - (slPoints * _Point);
       sl = NormalizeDouble(sl,_Digits);
       double tp = bid + (tpPoints * _Point);
       tp = NormalizeDouble(tp,_Digits);
       
         if(OrderSend(_Symbol,OP_BUY,Lots,bid,maxSlippage,sl,tp)){
          Print("Buy Executed");
          //isTradingAllowed = false;
         } 
       }
     
       //} 
       
       else if(lastBid > redMa && bid <= redMa){
      // if(isTradingAllowed == true){
       Print("Price touched the red Line from Above...Selling...");
            
       double sl = bid + (slPoints * _Point);
       sl = NormalizeDouble(sl,_Digits);
       double tp = bid - (tpPoints * _Point);
       tp = NormalizeDouble(tp,_Digits);
       
         //if(OrderSend(_Symbol,OP_SELL,Lots,bid,maxSlippage,sl,tp)){
          Print("Sell Executed");
         // isTradingAllowed = false;
         //}      
       }    
    // }
  //  }
 
Check with the debugger (or Print() or Comment()) the values that should cause to open a buy. You should know this.
 
Carl Schreiber #:
Check with the debugger (or Print() or Comment()) the values that should cause to open a buy. You should know this.

Yeah Thank You so much. I am doing mql4 code so i was confused. 

(or Print() or Comment()) the values that should cause to open a buy. solved the problem.
 
  1.    double redMa = iMA(_Symbol,indicatorTimeFrameRed,maPeriodRed,0,maMethodRed,appliedPriceRed,redMaShift);
       double blueMa = iMA(_Symbol,indicatorTimeFrameBlue,maPeriodBlue,0,maMethodBlue,appliedPriceBlue,blueMaShift);

    On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)

  2.    static double lastBid = bid;

    That is not an assignment; it's initialization of a common (globally declared), or static variable(s) with a constant. They work exactly the same way in MT4/MT5/C/C++.

    1. They are initialized once on program load.

    2. They don't update unless you assign to them.

    3. In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use).

      MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:

      1. Terminal starts.
      2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
      3. OnInit is called.
      4. For indicators OnCalculate is called with any existing history.
      5. Human may have to enter password, connection to server begins.
      6. New history is received, OnCalculate called again.
      7. A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

    4. Unlike indicators, EAs are not reloaded on chart change, so you must reinitialize them, if necessary.
                external static variable - MQL4 programming forum #2 (2013)

  3.         if(OrderSend(_Symbol,OP_BUY,Lots,bid,maxSlippage,sl,tp)){
           double sl = bid + (slPoints * _Point);
           double tp = bid - (tpPoints * _Point);
             //if(OrderSend(_Symbol,OP_SELL,Lots,bid,maxSlippage,sl,tp)){
              Print("Sell Executed");

    You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)

      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
      My GBPJPY shows average spread = 26 points, average maximum spread = 134.
      My EURCHF shows average spread = 18 points, average maximum spread = 106.
      (your broker will be similar).
                Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)

Reason: