Download MetaTrader 5
To add comments, please log in or register
Code Base will help you in mastering your theoretical skills. Come and learn!
amerelhozn
20
amerelhozn 2014.03.08 04:54 

any one here can help me to code ea

i need code that mean

open sell order when bar open and last bar Close[1]<Open[1]

close sell order when bar close down "Bear"

and

open buy order when bar open and last bar Close[1]>Open[1]

close buy order when bar close up "Bull"


i can't code this,

when i use newbar open code :

bool NewCandel(){

if(Bars==b)return(false);

b=Bars;

return(true);

}
to open order, that's good

but when i called newbar function again and add condtions"Bear or Bull" to close ... no thing happen

.................................

this is my code .. can any one here help me

//////////////////////////////////////////////////////////////////// void OnTick() >> start

if(!ExistPositions() && LastProfit()>=0 && NewCandel()==true){

if(Close[1]<Open[1]){

open(OP_SELL,Lot,Bid,TakeProfit,StopLoss) ;

}

else

if(Close[1]>Open[1]){

open(OP_BUY,Lot,Ask,TakeProfit,StopLoss) ;

}

}

if(NewCandel()==true){///

if(MyOrders(OP_BUY)==1 && Close[1]>Open[1]){

CloseBuyOrders();

}

else

if(MyOrders(OP_SELL)==1 && Close[1]<Open[1]){

CloseSellOrders();

}

else

if(MyOrders(OP_SELL)==1 && Close[1]>Open[1]){

CloseSellOrders();

LastClosedTrade();

NewLots=LastOrderLots * Multi_Mode ;

open(OP_BUY,NewLots,Ask,TakeProfit,StopLoss) ;

}

else

if(MyOrders(OP_BUY)==1 && Close[1]<Open[1]){

CloseBuyOrders();

LastClosedTrade();

NewLots=LastOrderLots * Multi_Mode ;

open(OP_SELL,NewLots,Bid,TakeProfit,StopLoss) ;

}

///

}

////////////////////////////////////////////////void OnTick() >>> end 
Alain Verleyen
Moderator
28701
Alain Verleyen 2014.03.08 12:07  

Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.

amerelhozn
20
amerelhozn 2014.03.08 20:59  

thank you

sorry it's first time to post

but i need help please.

qjol
3243
qjol 2014.03.09 21:57  
ExistPositions()
LastProfit()>=0

maybe ExistPosition()

or maybe LastProfit < 0

i cant see your code

B.T.W. on the first call NewCandel() can be false but on the second its gonna be always true

& it's not compiling anyway 'b' undeclared identifier

amerelhozn
20
amerelhozn 2014.03.10 14:48  
qjol:

maybe ExistPosition()

or maybe LastProfit < 0

i cant see your code

B.T.W. on the first call NewCandel() can be false but on the second its gonna be always true

& it's not compiling anyway 'b' undeclared identifier


double b =0;

but
my request in other way

how can i code next bar

i tried to put

Close[-1]

but do nothing

qjol
3243
qjol 2014.03.10 14:54  

what about

bool NewBar ()
   {
   static datetime LastTime = 0;

   if (Time[0] != LastTime) 
      {
      LastTime = Time[0];     
      return (true);
      }
   else
      return (false);
   }
whroeder1
13656
whroeder1 2014.03.10 16:17  
amerelhozn: how can i code next bar. i tried to put
Close[-1]

but do nothing

Why do you think you could possibly read the future?
whroeder1
13656
whroeder1 2014.03.10 16:28  
qjol: B.T.W. on the first call NewCandel() can be false but on the second its gonna be always true
bool NewBar(){
   static datetime LastTime = 0;
   if (Time[0] != LastTime){
      LastTime = Time[0];     
      return (true);
   }
   return (false);
}
This is why I recommend not using a function (in this case.)
void OnTick(){
   static datetime time0=0; datetime timePre = time0; time0 = Time[0];
   bool isNewBar = time0 != timePre;
   :
Both of the above, also return true, mid-bar on initial load. If that isn't wanted:
datetime time0;
int OnInit(){
   time0 = Time[0];
   :
}
void OnTick(){
   datetime timePre = time0; time0 = Time[0];
   bool isNewBar = time0 != timePre;
   :
/
To add comments, please log in or register