A Problem with Bid ==

 
//+------------------------------------------------------------------+
//|                                                         Test.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "https://www.metaquotes.net/"
 
double MyOrderType= 6;
string Text="";
extern double Decimal_Points=4;
extern double Lots=1;
extern double MA_Period=34;
extern double MA_Shift=0;
 
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
 
  
  
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  
   double  MAHigh, MAClose, MALow, Profit;
      
   MAHigh = iMA(Symbol(),0,MA_Period,MA_Shift,MODE_EMA,PRICE_HIGH,0);
   MAClose = iMA(Symbol(),0,MA_Period,MA_Shift,MODE_EMA,PRICE_CLOSE,0);
   MALow = iMA(Symbol(),0,MA_Period,MA_Shift,MODE_EMA,PRICE_LOW,0);
  
   double Fibo_0L, Fibo_100L, Fibo_N_percentL, MethodL, ApplicationL,
   SellLimit, ApplicationLM, Fibo_N_percentLM, SellLevel, SellStop;
 
   if(MyOrderType == 6)
    
    {
         ObjectCreate("FibLow", OBJ_FIBO, 0, 0, MALow,0, MAClose);
         Fibo_0L=ObjectGet("FibLow",OBJPROP_PRICE1);
         Fibo_100L=ObjectGet("FibLow",OBJPROP_PRICE2);
         MethodL=Fibo_100L - Fibo_0L;
         ApplicationL=MethodL*2.618;
         Fibo_N_percentL=Fibo_100L-ApplicationL;
         SellLimit=NormalizeDouble(Fibo_N_percentL, Decimal_Points);
         Print(DoubleToStr(SellLimit,6));
         SellStop=NormalizeDouble(MAClose,Decimal_Points);
         Print(DoubleToStr(SellStop,6));
         
         ApplicationLM=MethodL*1.618;
         Fibo_N_percentLM=Fibo_100L-ApplicationLM;
         SellLevel=NormalizeDouble(Fibo_N_percentLM, Decimal_Points);
         Print(DoubleToStr(SellLevel,6));
         
         
         MyOrderType= 7;       
         Print("MyOrderType=7");
         
         
      
    }
    
//-----Initiating Sell Order
 
   if(MyOrderType == 7)     
    {
     if(OrdersTotal() < 4 && Bid== SellLevel)
      {
         OrderSend(Symbol(), OP_SELL, Lots, Bid, 0, SellStop, SellLimit, 
         "Moving Order2", 00002, 0, Red);
         MyOrderType = 8;
         Print("MyOrderType=8");
      
      
        if(OrdersTotal() < 0)
         {
          Print("OrderSend failed with error #",GetLastError());
            
            
              
        }
       }
      }   
 
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
The code above is relatively simple, but for some reason it's not working.

I know that the specific problem is the line "Bid = SellLevel"

I'm sure that it Normalized to the right decimal point. When I removed that simple command- The order goes through. When I add it, the order doesn't get iniated (with no errors).

So I am kind of stuck.

Could someone tell me if "Bid = SellLevel" is correct?

*Note- if you run it in the backtest, you can see the price for "SellLevel, SellStop, and SellLimit". They look compeletly right. I have tried switching Bid with both Point and Ask.

-J
 
MQL4 often has trouble with comparing doubles with ==, I once had that I did this:

double a = b
if(b!=a) Print("Bug");

And it printed Bug!

Anyway - work around it with MathAbs(Bid-SellLevel)<0.0001 or something like that.
 
Use function from Stdlib.mq4

//+------------------------------------------------------------------+
//| right comparison of 2 doubles                                    |
//+------------------------------------------------------------------+
bool CompareDoubles(double number1,double number2)
  {
   if(NormalizeDouble(number1-number2,8)==0) return(true);
   else return(false);
  }
 
ThomasB:
MQL4 often has trouble with comparing doubles with ==, I once had that I did this:

double a = b
if(b!=a) Print("Bug");

And it printed Bug!

Anyway - work around it with MathAbs(Bid-SellLevel)<0.0001 or something like that.

This is not only problem of MQL4. in all programming languages you should round your double numbers before comparing. I remember this problem from ages of using turbo pascal upto now.
 
If you wont to compare the Bid price which is given by the terminal and are a number from the typ double, with another double number it is often better when you compare like this : if SellLevel is between High[0] and Low[0] because the Bid price can always do not reach and jump and than a queries will not match.