# Help with make a very simple Ea - page 2

2019

RaptorUK:

Do you realise that Close[0] = Bid ? it changes as Bar 0 is forming . . . bar 0 never has a fixed Close price, when it is actually closed it becomes Bar 1 . . .

Yes I now, but the problem is, that my EA opens only one trade per Bar. I want to make new buy order when Close[0]>Open[0] and Close it when Close[0]<Open[0] and vise versa for sell.

here is the code.please tell me why it does not make new orders by Bid movement relating to Open[0] !?

```//+------------------------------------------------------------------+
//|                                                Hamirta OC EA.mq4 |
//|                                                                  |
//+------------------------------------------------------------------+

//---- input parameters
extern int        TP = 0;
extern int      risk = 10;
double  LOT;

#define Magic 7777777
#define Slippage 3

int bartime = 0;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
LOT = LOT(risk,1);
//----

int tiket;

if(OrdersTotal()<1 && bartime != Time[0])
{
if(Close[0]>Open[0])
{
if(tiket>0) bartime = Time[0];
}
if(Close[0]<Open[0])
{
tiket = OrderSend(Symbol(),OP_SELL,LOT,Bid,Slippage,0,Bid-TP*Point,"",Magic,0,Red);
if(tiket>0) bartime = Time[0];
}
return(0);
}

for (int y=OrdersTotal()-1;y>=0;y--)
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
{
if(Close[0]<Open[0]) OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,CLR_NONE);
}

if(OrderType()==OP_SELL)
{
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
double LOT(int risk,int ord)
{
double MINLOT = MarketInfo(Symbol(),MODE_MINLOT);
LOT = AccountFreeMargin()*risk/100/MarketInfo(Symbol(),MODE_MARGINREQUIRED)/ord;
if (LOT>MarketInfo(Symbol(),MODE_MAXLOT)) LOT = MarketInfo(Symbol(),MODE_MAXLOT);
if (LOT<MINLOT) LOT = MINLOT;
if (MINLOT<0.1) LOT = NormalizeDouble(LOT,2); else LOT = NormalizeDouble(LOT,1);
return(LOT);
}
//--------------------------------------------------------------------```
17304

RaptorUK:

You need to make use of the variable you have created for the return value from OrderSend . . res, check it to see if the OrderSend worked, if it didn't print the error and you will be in a better position to fix your own issues.

Your Orders do not take into account spread . . Buy at Ask, but a Buy is closed with a Sell and a Sell is executed at Bid.

You need to do this . . .
17304

hmrt135:

Yes I now, but the problem is, that my EA opens only one trade per Bar.

After the first trade is placed bartime = Time[0]; so you cannot place more than 1 trade per bar . . your code does not allow it.

`if(OrdersTotal()<1 &&    bartime != Time[0]  )`
23455

I want to make new buy order when Close[0]>Open[0]

and on the first tick of the bar Close[0] == Open[0]

so your 2 criteria are mutually incompatible.

2019

WHRoeder:

and on the first tick of the bar Close[0] == Open[0]

so your 2 criteria are mutually incompatible.

yes you are right, then i do not used Close[0] >= Open[0] or Close[0] <= Open[0]...

exactly when the current close 1 tick more or less than current Open is, we make new reversal trade and close the other one, but i do not know how to do this.

2019

RaptorUK:

After the first trade is placed bartime = Time[0]; so you cannot place more than 1 trade per bar . . your code does not allow it.

yes you are right, but how can i repair it?

i do not know how to make reversal code for several position on 1 bar?

17304

hmrt135:

i do not know how to make reversal code for several position on 1 bar?

Well what have you tried ? I'm not writing your code for you . . .
2019

Unfortunatly i am not a coder, i used other Ea codes and assembeld it. I know about mql codes. I want to know what should i change in the above code in order to permiting several trade in 1 bar?
17304

hmrt135:
Unfortunatly i am not a coder, i used other Ea codes and assembeld it. I know about mql codes. I want to know what should i change in the above code in order to permiting several trade in 1 bar?
Time to start learning: Book & Documentation