How to code? - page 29

 

Here...

string price = (DoubleToStr(iMA(Symbol(),0,1,0,MODE_EMA,PRICE_CLOSE,0),Digits));

if (price=>1.0000 && price< 1.0050)

{

sell order here

}

 

thanks

thank you for the quick response.

 
ejoi:
Here...

string price = (DoubleToStr(iMA(Symbol(),0,1,0,MODE_EMA,PRICE_CLOSE,0),Digits));

if (price=>1.0000 && price< 1.0050)

{

sell order here

}

when i try to compile this it get diff types in comparison

 

I think ejoi made a slight mistake with the stringifying part; the code should have been like:

double price = iMA(Symbol(),0,1,0,MODE_EMA,PRICE_CLOSE,0);

if (price=>1.0000 && price< 1.0050)

{

sell order here

}
 

thanks

thanks that worked great!!!

 

it seems that i also have this problem if anyone can help. i'm trying to limit the time that trades can be opened.

total=OrdersTotal();

if (total<1)

{

if (TimeHour(CurTime())<StartHour) {return(0);}

if (TimeMinute(CurTime())<StartMinute) {return(0);}

if (TimeHour(CurTime())>EndHour) {return(0);}

if (TimeMinute(CurTime())>EndMinute) {return(0);}

}[/PHP]

it seems right that no trades are executed whenever i use it

my extern is as follows

[PHP]extern int StartHour=0;

extern int StartMinute=30;

extern int EndHour=22;

extern int EndMinute=30;
 

You might add the following function

bool isTradableTime()

{

datetime time = TimeCurrent();

int now = TimeHour( time ) * 60 + TimeMinute( time );

int begin = StartHour * 60 + StartMinute;

int end = EndHour * 60 + EndMinute;

return ( begin <= now && now < end );

}

[/PHP]

and then use it like the following in your start() function

[PHP]if ( ! isTradableTime() )

return( 0 );
 

If the trading period does not include midnight:

total=OrdersTotal();

if (total<1)

{

if(Hour()<StartHour) return(0);

if(Hour()==StartHour && Minute()<StartMinute) return(0);

if(Hour()>EndHour) return(0);

if(Hour==EndHour && Minute()>EndMinute) return(0);

}
 
Michel:
If the trading period does not include midnight:
total=OrdersTotal();

if (total<1)

{

if(Hour()<StartHour) return(0);

if(Hour()==StartHour && Minute()<StartMinute) return(0);

if(Hour()>EndHour) return(0);

if(Hour==EndHour && Minute()>EndMinute) return(0);

}

thank you both...i went with this one becuase i liked the simplicity of it and it works great....

thank you again

 

new question

does any one know how to code into an EA if a trade exsist already do not open a second one unless it's 10 pips apart?

Reason: