EA won't place a trade - page 2

 

made errors in last comment so i deleted it and submitting a new one if you saw last one. Start function isn't supported in EA's by your version of MT4.

Try this:

void OnTick() {
   double BSL     = NormalizeDouble((Bid - 40*Point),Digits);
   double BTP     = NormalizeDouble((Bid + 40*Point),Digits);
   double SSL     = NormalizeDouble((Ask + 40*Point),Digits);
   double STP     = NormalizeDouble((Ask - 40*Point),Digits);
   int    MinStop = MarketInfo(Symbol(), MODE_STOPLEVEL);
   
   if(MinStop > 40) {
      Alert("Minimum stop distance allowed is: ",MinStop);
   }
   
   if (iMA(NULL, 0, 3, 0, MODE_EMA, 0, 1) > iMA(NULL, 0, 10, 0, MODE_EMA, 0, 1)) {
      int order = OrderSend(Symbol(), OP_BUY,1,Ask,10,BSL,BTP);
      if(order < 0) {
         Alert("trade not placed");
      }
   }
   Alert(GetLastError());
   
   if (iMA(NULL, 0, 3, 0, MODE_EMA, 0, 1) < iMA(NULL, 0, 10, 0, MODE_EMA, 0, 1)) {
      int order = OrderSend(Symbol(), OP_SELL,1,Bid,10,SSL,STP);
      if(order < 0) {
         Alert("trade not placed");
      }
   }
}
 
fantomfx:

made errors in last comment so i deleted it and submitting a new one if you saw last one. Start function isn't supported in EA's by your version of MT4.

Try this:

The code from my previous comment works i tested myself, but it opened multiple orders make sure you code in that it only opens one
 
Cerberus:


Well I've made all these changes, and run it. Still no trading, no alerts or anything. If it makes any difference I'm running it on a demo account with Axitrader. Testing this on the 1 min EUR/USD


Then you cannot be running this EA. Make sure that the EA attached to the chart has exactly the same name as this EA. The Alerts are not dependant on any condition, so you should be getting alerts.

Please show your modified code

Note: You need to do something in your code so that it doesn't keep opening orders every tick while conditions are satisfied

 
GumRai:


Then you cannot be running this EA. Make sure that the EA attached to the chart has exactly the same name as this EA. The Alerts are not dependant on any condition, so you should be getting alerts.

Please show your modified code

Note: You need to do something in your code so that it doesn't keep opening orders every tick while conditions are satisfied


it's been answered, the start function is outdated, he must use onTick
 
fantomfx:

made errors in last comment so i deleted it and submitting a new one if you saw last one. Start function isn't supported in EA's by your version of MT4.

Try this:



Awesome! This works thanks!! But isn't OnTick() an MQL5 function?? Does this mean I am forced to use MQL5 with this build??

Thanks for the advice about the code keeping on opening orders. Will get there, for now just wanted to see this little bit of code work

 
yes mql4 is merged with mql5
 
fantomfx:

it's been answered, the start function is outdated, he must use onTick


Are you sure? Maybe I have missed an update. MT4 is 625 and Editor 914.

I didn't realise that the start function no longer worked and so one has to use onTick.

 
I am using start function and it is working like it should (latest build).
 
GumRai:


Are you sure? Maybe I have missed an update. MT4 is 625 and Editor 914.

I didn't realise that the start function no longer worked and so one has to use onTick.

You don't have to use OnTick, it's not mandatory to use the new features. start() is running just fine.

Current build is 646 and ME 934.

 
deysmacro:
I am using start function and it is working like it should (latest build).

angevoyageur:

You don't have to use OnTick, it's not mandatory to use the new features. start() is running just fine.

Current build is 646 and ME 934.



Thank you,

I thought that fantomfx was wrong, but many people seem to have been updated to a later build, so I couldn't be sure.

So that brings me back to what I posted before.

GumRai:


Then you cannot be running this EA. Make sure that the EA attached to the chart has exactly the same name as this EA. The Alerts are not dependant on any condition, so you should be getting alerts.

Please show your modified code

Note: You need to do something in your code so that it doesn't keep opening orders every tick while conditions are satisfied

Reason: