MQL4 - automated forex trading   /  

Forum

help!!! No error, but cannot trade

Back to topics list To post a new topic, please log in or register

avatar
22
Pain 2011.06.05 07:51 

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;
  } 










































Attached files:
  JEFFsLEUNGa1.0.mq4 (2.13 KB)
Recipes for Neuronets

Recipes for Neuronets

The article is intended for beginners in baking "multi-layered" cakes.


avatar
1971
ubzen 2011.06.05 07:57 


avatar
1971
ubzen 2011.06.05 09:49 

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.


avatar
22
Pain 2011.06.05 11:35 
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?

avatar
1971
ubzen 2011.06.05 12:53 
That means don't ask double if they're Equal (==) or not-equal (!=). Here read this Article.
Back to topics list  

To add comments, please log in or register