problem writing expert

 

Hi everyone,


I just wrote my first expert but it doesn't work

int start()                                     
   {

  MessageBox ("Ive Started");
  
  int counter;
  double MAYellow,MAOrange,MARed,GX,MAAve,TnP,SnL;
  counter = 0;
  
  for(;;)
  {
  counter = counter+1;
  int ValueOne,ValueTwo;
  ValueOne = 0;
  ValueTwo = 0;
  
  ValueOne = iStochastic(NULL,0,25,3,3,MODE_EMA,0,0,0);
  ValueTwo = iStochastic(NULL,0,25,3,3,MODE_EMA,0,1,0);
  
  MAYellow = iMA(NULL,0,14,0,MODE_EMA,PRICE_LOW,0);
  MAOrange = iMA(NULL,0,42,0,MODE_EMA,PRICE_MEDIAN,0);
  MARed = iMA(NULL,0,63,0,MODE_EMA,PRICE_HIGH,0);
  
  MessageBox (ValueOne+" and "+ValueTwo+"   "+counter);
   if (ValueOne==ValueTwo)
   {
     MessageBox ("ValueOne and Two Are Equal");
      if (MAYellow>MAOrange)
      {
         MessageBox ("Yellow is higher than orange");
         GX=(((MARed-MAOrange)/2)/MAYellow)*100;
         MAAve = (GX*MAYellow + MAOrange + MARed)/(2+GX);
         TnP = (2*Ask)-MAAve;
         SnL = (Ask/2)+(MAAve/2);
         OrderSend(Symbol(),OP_BUY,0.05,Ask,SnL,TnP,"App. Profit "+((TnP-Ask)*1000*0.025)+"  Loss "+ ((Ask-SnL)*1000*0.025));
      }
  }
 }
       
         
 MessageBox ("Finish");
  
  
  return;

It has two problems :

1- ValueOne and ValueTwo should change every second, but they don't, why is that?

2- OrderSend function is not working !!!, why?


I modified the code a bit but still not working :

int start()
  {
  int counter,ticket;
  double MAYellow,MAOrange,MARed,GX,MAAve,TnP,SnL;
  
  counter = 0;
  
  MessageBox ("Ive Started");
  
  while (iStochastic(NULL,0,25,3,3,MODE_EMA,0,0,0)!=iStochastic(NULL,0,25,3,3,MODE_EMA,0,1,0))
  {
  counter = counter+1;
  }
  
  MAYellow = iMA(NULL,0,14,0,MODE_EMA,PRICE_LOW,0);
  MAOrange = iMA(NULL,0,42,0,MODE_EMA,PRICE_MEDIAN,0);
  MARed = iMA(NULL,0,63,0,MODE_EMA,PRICE_HIGH,0);
  
     MessageBox ("ValueOne and Two Are Equal");
      if (MAYellow>MAOrange)
      {
         MessageBox ("Yellow is higher than orange");
         GX=(((MARed-MAOrange)/2)/MAYellow)*100;
         MAAve = (GX*MAYellow + MAOrange + MARed)/(2+GX);
         TnP = (2*Ask)-MAAve;
         SnL = (Ask/2)+(MAAve/2);
         ticket=OrderSend(Symbol(),OP_BUY,0.05,Ask,SnL,TnP,"App. Profit "+((TnP-Ask)*1000*0.025)+"  Loss "+ ((Ask-SnL)*1000*0.025));
      }
       
         
 MessageBox ("Finish");
  
   return(0);
  }

I'm not much experienced with MetaEditor and Forex.

Thank you all for helping

 

On MetaTrader you EA is run in three ways (some will say more but I am keeping it simple):

1) When you load it it can run some code (for instance to check the time sclae or the symbol of the window, etc.)


2) When you quit it can run some code (for instance to close all open positions)


3) Finally, everytime the EA will receive a tick it will run a specific part of the code. It is here you want to put your logic.


Your code has a for () .. next that are not needed if you understand how MetaTrader work. I recommend you read all the documentation again and look at some examples to get familiar with this concept. Basically think as if your program was being called all the time as a tick hits your system.


Hope this helps, but everything is better explained on the MQL4 book in this same website.


Best,


Y.

 
Thank you very much for explaining
yona22:

On MetaTrader you EA is run in three ways (some will say more but I am keeping it simple):

1) When you load it it can run some code (for instance to check the time sclae or the symbol of the window, etc.)


2) When you quit it can run some code (for instance to close all open positions)


3) Finally, everytime the EA will receive a tick it will run a specific part of the code. It is here you want to put your logic.


Your code has a for () .. next that are not needed if you understand how MetaTrader work. I recommend you read all the documentation again and look at some examples to get familiar with this concept. Basically think as if your program was being called all the time as a tick hits your system.


Hope this helps, but everything is better explained on the MQL4 book in this same website.


Best,


Y.

Reason: