OpenAtMarket=OrderSend

 

After i changed and shnipt around a few EA's i like to try a very simple EA on my own step by step and see what happen thru the prosses.

I start with something like a candle trader. Past Candle is long open long.

I have the feeling o missing somewhere around my readings, like braces and start-end functions.

in the book one line documentation is not enough to understand would like to see more simple exemple.

But any how, i know i get nice help here like always. 

Thats what i have so far of course with errors. 

Thanks

Piero 

extern bool TradeCandle=true;
bool buysig;

int start()
{

int CheckForSingnal()
{
      buysig=false;

      double LClose = iClose(NULL, 0,1);
      double LOpen  = iOpen (NULL, 0,1);
             if (TradeCandle)
           {
             if (LClose>LOpen) buysig=true;
}
int OpenAtMarket()
  if(buysig)
    {
     OpenAtMarket=OrderSend(Symbol(),OP_BUY,0.01,Ask,3,Ask-50*Point,Ask+100*Point,Green);
     
     return(0);
   }
 
pieronetto:

After i changed and shnipt around a few EA's i like to try a very simple EA on my own step by step and see what happen thru the prosses.

I start with something like a candle trader. Past Candle is long open long.

I have the feeling o missing somewhere around my readings, like braces and start-end functions.

in the book one line documentation is not enough to understand would like to see more simple exemple.

But any how, i know i get nice help here like always. 

Thats what i have so far of course with errors. 

If you want to create your own functions you need to declare them outside of any other function,  for example:

extern bool TradeCandle=true;
bool buysig;

int start()
   { 
   //  call your functions here . . .
    
   return(0);
   }

int CheckForSingnal()
   {
   buysig=false;

   double LClose = iClose(NULL, 0,1);
   double LOpen  = iOpen (NULL, 0,1);
   if (TradeCandle)
      {
      if (LClose>LOpen) buysig=true;
      }
   return;
   }

int OpenAtMarket()
   {

   if(buysig)
      {
      OpenAtMarket=OrderSend(Symbol(),OP_BUY,0.01,Ask,3,Ask-50*Point,Ask+100*Point,Green);
      }
   
   return(0);
   }
 
RaptorUK:

If you want to create your own functions you need to declare them outside of any other function,  for example:

 

Hi everyone!

with my pur coding skills i do get it to work just fine with a normal Function.

What im trying to do and dont know if it is possible is to put the singnal in one function and the return to specefyt function.

Let say CheckForSingnal() is the one calculate the open creteria and the result is beeing send to the OpenOrder() function.

Is this possible? I try alot and was reading here  https://book.mql4.com/basics/functions   

 Any hint is great or iwas reading in the wrong place.

As normal function it works and as two seperate function how i pass the signal?

that what i have so far and of course want work.

Thanks

Piero 

 

//NORMAL FUNCTION WORKING
bool buysig;
int start()
{
int CheckForSingnal;
{
      buysig=false;
      double CA= iClose(NULL, 0,1);
      double CB = iOpen(NULL, 0,1);
      if(CA>CB)
      buysig=true;
}     
int OpenOrder;
{
    if (buysig)
     OpenOrder=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-100*Point,Ask+100*Point,"My order #2",16384,0,Green);
     if(OpenOrder<0)
       {
        Print("OrderSend failed with error #",GetLastError());
        return(0);
       }
}
   return(0); 
}
//TWO FUNCTION NOT WORKING //HOW TO PASS THE SIGNAL?
bool buysig;
int start()
{
int CheckForSingnal()
{
      buysig=false;
      double CA= iClose(NULL, 0,1);
      double CB = iOpen(NULL, 0,1);
      if(CA>CB)
      buysig=true;
}     
int OpenOrder()
{
    if (buysig)
     OpenOrder=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-100*Point,Ask+100*Point,"My order #2",16384,0,Green);
     if(OpenOrder<0)
       {
        Print("OrderSend failed with error #",GetLastError());
        return(0);
       }
}
   return(0); 
}
 
RaptorUK:

If you want to create your own functions you need to declare them outside of any other function,  for example:

Did you read what I wrote ? I guess not . . .   you CANNOT define a function inside another function.

You cannot do this . . .

//NORMAL FUNCTION WORKING
bool buysig;
int start()
{
int CheckForSingnal;      //  function definition inside the start()  function ! ! 
{
      buysig=false;
      double CA= iClose(NULL, 0,1);
      double CB = iOpen(NULL, 0,1);
      if(CA>CB)
      buysig=true;
}     
int OpenOrder;

  . . .  do this . . .

//NORMAL FUNCTION WORKING
bool buysig;

int start()
   {
   CheckForSingnal();

   return(0);
   }


void CheckForSingnal() 
   {
   buysig=false;
   double CA= iClose(NULL, 0,1);
   double CB = iOpen(NULL, 0,1);
   if(CA>CB)
      buysig=true;
   }     

 

If you want help read what is written to help you . . . 

 
RaptorUK:

Did you read what I wrote ? I guess not . . .   you CANNOT define a function inside another function.

You cannot do this . . .

  . . .  do this . . .

 

If you want help read what is written to help you . . . 

Thanks alot i got it now. I was writting the buy condition everything went well until i was adding the sell condition the EA want make any sells.

No errors compiling. 

Please be pagent with my learning prosses and thanks again for you gread help.

sorry about my english.

extern int TakeProfit=100;
extern int StopLoss  =100;
bool buysig,sellsig;
int start()
{
   Signal();
   OpenConditon();
}
void Signal()
{     
      sellsig=false;
      buysig=false;
      double CC= iClose(NULL, 0,1);
      double CO = iOpen(NULL, 0,1);
      if(CC>CO)buysig =true;
      if(CC<CO)sellsig=true;
}
void OpenConditon(){
{    
     int res;
     if(buysig)
     {
     res = OpenOrder(OP_BUY);
     }
return;    
}
     if(sellsig)
     {
     res = OpenOrder(OP_SELL);
     }
return;
}

int OpenOrder(int mode)
{     
     int res,col;
     double openprice,sl,tp;
     if (mode==OP_BUY)
     {
     openprice=Ask;
     sl=openprice-StopLoss*Point;
     tp=openprice+TakeProfit*Point;
     col=Lime;
     }
     else
     {
     openprice=Bid;
     sl=openprice+StopLoss*Point;
     tp=openprice-TakeProfit*Point;
     col=Red;
     }
     res=OrderSend(Symbol(),mode,0.01,openprice,3,sl,tp,"My",11111,0,col);
     if(res<0)
       {
        Print("OrderSend failed with error #",GetLastError());
        return(0);
       }

   return(0); 
}
 
pieronetto:

Thanks alot i got it now. I was writting the buy condition everything went well until i was adding the sell condition the EA want make any sells.

No errors compiling. 

Please be pagent with my learning prosses and thanks again for you gread help.

sorry about my english.

 

Stupid me. got it working now, thanks anyway for your help.
extern int TakeProfit=100;
extern int StopLoss  =100;
bool buysig,sellsig;
int start()
{
   Signal();
   OpenConditon();
}
void Signal()
{     
      sellsig=false;
      buysig=false;
      double CC= iClose(NULL, 0,1);
      double CO = iOpen(NULL, 0,1);
      if(CC>CO)buysig =true;
      if(CC<CO)sellsig=true;
}
void OpenConditon()
{    
     int res;
     if(buysig)
     {
     res = OpenOrder(OP_BUY);
     }

     if(sellsig)
     {
     res = OpenOrder(OP_SELL);
     }
return;
}
int OpenOrder(int mode)
{     
     int res,col;
     double openprice,sl,tp;
     if (mode==OP_BUY)
     {
     openprice=Ask;
     sl=openprice-StopLoss*Point;
     tp=openprice+TakeProfit*Point;
     col=Lime;
     }
     else
     {
     openprice=Bid;
     sl=openprice+StopLoss*Point;
     tp=openprice-TakeProfit*Point;
     col=Red;
     }
     res=OrderSend(Symbol(),mode,0.01,openprice,3,sl,tp,"My",11111,0,col);
     if(res<0)
       {
        Print("OrderSend failed with error #",GetLastError());
        return(0);
       }

   return(0); 
}
Reason: