Moving Average Switch

 
//+------------------------------------------------------------------+
//|                                                         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=0;
extern int MA_Period= 34;
extern int MA_Shift=0;
 
 
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
 
  
  
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  
       double  MAClose;
      
      MAClose = iMA(Symbol(),0,MA_Period,MA_Shift,MODE_EMA,PRICE_CLOSE,1);
  
  
if(MyOrderType == 0)
{
 if(Bid==MAClose)
  {
    MyOrderType=2;
    Print("MyOrderType=2");
     
   }
}
 
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

For some reason when I run the backtest- "MyOrderType" never becomes "2". I don't know why. The price is obviously hitting the 34 Period Moving Average line, but the "MyOrderType =2" command isn't going through- as it is not being printed in the journal.

Could anyone tell me why?

*note* I have tried switching "Bid" to "Point", and I have tried switching the Bar shift of the MAClose to 1. Also- I am not running optimization setting on backtest.

-J
 
See 'bug in MQL4 double calculation' and change your condition by more correctly one

if(Bid==MAClose)
You will understand why Bid not equal to other double number.
 

logically both values can be equal, but you need to use NormalizeDouble

if(NormalizeDouble(Bid,Digits) == NormalizeDouble(MAClose,Digits))