help!!! No error, but cannot trade

 

When I run my EA, there was no error, but cannot trade. Please check for me. thanks so much

extern double Lots=0.1;
extern double Stoploss=20;
extern double Takeprofit=40;
extern double Factor=4;

//----
   
//----
  
//+------------------------------------------------------------------+
//| Calculate open position                                          |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   double price1, price2;
   int res; 
   price1=Bid;
   if(RefreshRates()==true)
      {
       price2=Bid;
       if(price1>price2 && price1-price2==Factor*Point)
           {   
            res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+Stoploss*Point,Bid-Takeprofit*Point,"",0,0,Red);
            return;
           }
       if(price1<price2 && price2-price1==Factor*Point)
           {
            res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-Stoploss*Point,Ask+Takeprofit*Point,"",0,0,Blue);
            return;
           }
       else
           {
            return;
           }
      }
   else
       {
       return;
       }
  } 

int start()
  {
   CheckForOpen();
   Alert (GetLastError());
   return;
  } 










































Files:
 

 

Its got allot of problems. However, It's not reaching the OrderSend for one reason or another. At a glance, this logic will probably never pass this line.

if(price1>price2 && price1-price2==Factor*Point)

Price1 may never be > than Price2 because they are both Bid.

Why the RefreshRates()? You didn't Sleep() or anything. Bid is Not gonna change that fast.

Equality and In-Equality performed on Doubles is a bad idea. Use > < if you can help it.

I recommend using allot of Print() Statements to Debug your codes.

 
ubzen:

Its got allot of problems. However, It's not reaching the OrderSend for one reason or another. At a glance, this logic will probably never pass this line.

Price1 may never be > than Price2 because they are both Bid.

Why the RefreshRates()? You didn't Sleep() or anything. Bid is Not gonna change that fast.

Equality and In-Equality performed on Doubles is a bad idea. Use > < if you can help it.

I recommend using allot of Print() Statements to Debug your codes.


"Equality and In-Equality performed on Doubles is a bad idea. Use > < if you can help it." what does it really mean?
 
That means don't ask double if they're Equal (==) or not-equal (!=). Here read this Article.
Reason: