What's wrong with these codes?

 
Hello,

This code's purpose is to check if there's any active order opened by this EA. If none, it will open 2 orders, buy and sell. I haven't test it on real market because it's sunday now, but from backtester, there's no trade appear. What's wrong with these codes?

    int ordtotal=0;
    for(int ft=OrdersTotal()-1;ft>=0;ft--)
     {
       OrderSelect(ft,SELECT_BY_POS,MODE_TRADES);
       if(OrderSymbol()==Symbol() && OrderComment()==comment && OrderMagicNumber()==magic)
        {
          if(OrderType()<=OP_SELL) ordtotal++;
        } 
     }
 
    int Pips=30;
    //- first trade
    if(ordtotal<0)
     {
       while(b<0)
        {
          buyticket=OrderSend(Symbol(),OP_BUY,Lots(),Ask,Slippage,0,Ask+Pips*Point,0,magic,0,Blue);
          if(buyticket>0) b=1;
        }
       while(s<0)
        { 
          sellticket=OrderSend(Symbol(),OP_SELL,Lots(),Bid,Slippage,0,Bid-Pips*Point,0,magic,0,Red);
          if(sellticket>0) s=1;
        }
     }
Thank you
 

One thing you may want to change is

if ( ordtotal < 0 )

from the chunk of code you posted you could see that the ordtotal will never get below 0, therefore the lines inside the if block will never get executed...

Also take a look at this line please:

while ( b < 0 )

it will never get executed unless b<0, however I dont see anywhere in the code you initialize b with a value less then 0, so the lines inside the loop will never get executed i.e. a trade wont be opened...the same is true for the sell order. ..

 
Automated:

One thing you may want to change is

if ( ordtotal < 0 )

from the chunk of code you posted you could see that the ordtotal will never get below 0, therefore the lines inside the if block will never get executed...

Also take a look at this line please:

while ( b < 0 )

it will never get executed unless b<0, however I dont see anywhere in the code you initialize b with a value less then 0, so the lines inside the loop will never get executed i.e. a trade wont be opened...the same is true for the sell order. ..

Damn you're right, how can I be so stupid? Too much love maybe, lolololol..
Thanks a lot
 

you are welcome :)

you could always contact me at automatedfx@gmail.com if you would like to discuss it further...


thank you

Automated

 
Thanks automated for your offer, but it's already solved now :)

Thank you
 

I have started coding my EA. I am by no means a decent coder for MQL b/c I've never seen C++/C.

My settings are as follows: There are two indicators: IND1 [indicator] and IND2. IND1 has 1 line, IND2 has 2 lines. Lines = lines on a chart. For instance, Bollinger bands indicator has 3 lines, but isn't used in this example. Both INDs have their 0.0 level shown on the chart; although, only IND1's is used.

My logic is as follows: when IND1 crosses its 0 level the first time and goes into negative, send the SELL order. Wait for the IND2 to have its line1 cross line2 and send the BUY order, automatically closing the SELL submitted by IND1. If there's a 2nd/3rd/etc 0 level crossing by IND1 into either positive or negative before the BUY, disregard that crossing, do nothing and proceed w/ that first SELL order[otherwise there will be a 2nd/3rd/etc SELL order w/ no corresponding BUY order]. When the BUY order is executed by the IND2 [IND2's line1 has crossed line2], wait for the following crossing of 0 [into the negative] by IND1 and send the SELL order, automatically closing the BUY order submitted by IND2.
I'm going to include my coding. Please take a look at it, b/c it isn't graphing anything and isn't working. Does everything make sense?

Here's the code itself:

#property copyright "Copyright © 2008 BDHT"
#define MAGIC 689
//do not take into consideration
//the names of the indicators
//they're fabricated
extern double lots = 0.1; // Lots
extern double TP = 140; // Take Profit
extern double SL = 30; // Stop Loss
static int prevtime = 0;
static int res = 0;
double IND2_line1, IND2_line2, IND1, IND1_prev, IND2_line1_prev;
int init() { 
IND2_line1 = iIND2_line1(NULL,0,0,MODE_MAIN,0);
IND2_line2 = iIND2_line2(NULL,0,0,MODE_SIGNAL,0);
IND1= iCustom(NULL, 0, "IND1", 0, 0, 0);
IND1_prev= iCustom(NULL,0, "IND1", 0, 0, 1);
IND2_line1_prev = iCustom(NULL, 0, "IND2", 0, 0, 1);
return(0);
}
int deinit() {
return(0);
}
int start() {
//Make sure there are no open orders; if yes - stop
if (OrdersTotal() > 0) 
return (0);
 
if (IND1< 0 && IND1 < IND1_prev && IND1_prev > 70 && IND2_line1 < 0 && IND2_line2 < 0) { 
// 70 may be 10; simply means that the IND1_prev was greater than 0
res=OrderSend(Symbol(),OP_SELL,lots,Bid,3,Bid+SL*Point,Ask+TP*Point,"My EA",MAGIC,0,Blue);
return(0);
}
if (IND2_line1 > IND2_line2 && IND2_line1_prev < IND2_line1) {
res=OrderSend(Symbol(),OP_BUY,lots,Ask,3,Ask+SL*Point,Bid+TP*Point,"My EA",MAGIC,0,Blue);
return(0);
}
It doesn't graph anything either... I know there has to be something wrong, but what is it?
 

There are many problems with your code.

 
Okay. That's understood, what are the problems? Could you point out some?
 

One problem, code within init() is only executed one time.

 
Does this mean that there should be a loop? Doesn't the int start() execute every time there is a new bar? Is this what you meant?
 

Code withing start() executes every tick

Code within init() executes once per intitialization/start/restart of the EA

Reason: