Problem in EA

 

i have an EA working on all currency pairs except BTCUSD pair

the file is attached

Files:
aa.PNG  26 kb
 
It says invalid S/L or T/P. May be it's too close to the marketprice.
 
Abdul Salam:

i have an EA working on all currency pairs except BTCUSD pair

the file is attached


Need more details, but it seems the SL is in stop-level.

 
Mohammad Hossein Sadeghi:

Need more details, but it seems the SL is in stop-level.



thank you Mohammad Hossein Sadeghi. you are right i increase the tp and sl to 10000 and 15000 . and now its working  . . . . .

 
Abdul Salam:


thank you Mohammad Hossein Sadeghi. you are right i increase the tp and sl to 10000 and 15000 . and now its working  . . . . .


According to the screenshot it looks like a rounding issue (look at the TP SL values after the . ) See this post https://www.mql5.com/en/forum/216065#comment_5795267

NormalizeDouble not "working"
NormalizeDouble not "working"
  • 2017.09.21
  • www.mql5.com
Hi this is my first post in this incredible forum and today I need help with something that I believe is rather simple but is turning a pain in the...
 
Enrique Dangeroux:

According to the screenshot it looks like a rounding issue (look at the TP SL values after the . ) See this post https://www.mql5.com/en/forum/216065#comment_5795267

Agree, but tick size other than a multiple of 0.00001 is rare. So I believe the case is stop level, since it is solved by increasing the stop distance as stated.
 
Mohammad Hossein Sadeghi:
Agree, but tick size other than a multiple of 0.00001 is rare. So I believe the case is stop level, since it is solved by increasing the stop distance as stated.

It's rare if you trade Forex.

It's common if you trade Metals or CFDs.

It's almost never the case if you trade Futures or Stocks.

So depending of your target, your code will work or not. It's far better to made universal code, don't you think ?

 
Alain Verleyen:

It's rare if you trade Forex.

It's common if you trade Metals or CFDs.

It's almost never the case if you trade Futures or Stocks.

So depending of your target, your code will work or not. It's far better to made universal code, don't you think ?

I agree, it's best if MQL would provide a built-in function for this purpose.
 
Mohammad Hossein Sadeghi:
I agree, it's best if MQL would provide a built-in function for this purpose.

They do! It's called Tick Size, in the same way that they also provide a function for the Lot Step and also for the Stop Level.

Forum on trading, automated trading systems and testing trading strategies

NormalizeDouble not "working"

Fernando Carreiro, 2017.09.22 23:22

This is valid for both MQL4 and MQL5:

double tickSize = SymbolInfoDouble( _Symbol, SYMBOL_TRADE_TICK_SIZE );

Forum on trading, automated trading systems and testing trading strategies

NormalizeDouble not "working"

Fernando Carreiro, 2017.09.21 22:44

In short, NormalizeDouble() does nothing useful at all, and what does solve the problem is making sure the price is a aligned to the symbol's tick size.

For example, if the tick size is 0.00025 then all prices must be multiples of that, so a price like 1.34035 would be invalid, and the only valid prices closest to that would either be 1.34050 or 1.34025, with the later being the closest/better choice (rounding).

double normalised_price = round( price / tick_size ) * tick_size;

Forum on trading, automated trading systems and testing trading strategies

NormalizeDouble not "working"

Fernando Carreiro, 2017.09.23 00:41

Just as a side note.

Initially, when I started with MQL, I would manipulate prices as "doubles". Nowadays, especially in the more complex EA's, I manipulate prices as "ints". At the very first opportunity, I convert a price into ticks:

int priceTicks = (int) round( price / tickSize );

From then on, all my calculations and manipulations are done with "ints". Not only is it more memory compact and much faster, but comparisons are much easier to handle.  Doing a "priceA == priceB" for "doubles" is quite problematic, but not for "ints" because it gives exact matches. Not to mention, that in this way prices, stop sizes, etc. are ALWAYS aligned.

Then, just before I have to place or modify an order, I then convert it back:

priceTicks * tickSize
EDIT: I do the same for volume/lots by using the broker's Lot-Step.
 
Fernando Carreiro:

They do! It's called Tick Size, in the same way that they also provide a function for the Lot Step and also for the Stop Level.

I know this, I meant something like NinjaTrader has:
double Round2TickSize (double price)
 It gets price of any value and rounds it to Symbol's tick size.
 
Mohammad Hossein Sadeghi: I know this, I meant something like NinjaTrader has: double Round2Ticksize (double price), it gets price of any value and rounds it to Symbol's tick size.

Is it that difficult to make your own function to do the same?

double Round2Ticksize( double price )
{
   double tick_size = SymbolInfoDouble( _Symbol, SYMBOL_TRADE_TICK_SIZE );
   return( round( price / tick_size ) * tick_size );
}
Reason: