i want the distance between (open price-EMA)*2 for take profit - mql4

in my expert i want the distance between (open price-EMA)*2 for take profit?how can i do this in mql4?
i use this formula for buy position but it does not work
Ask+((Bid-EMA)*2)

Your question references Open Price, but you are using Bid, this is incorrect. You should be using something like the following
int ema_period=20;
double EMA=iMA(NULL,0,ema_period,0,MODE_EMA,PRICE_CLOSE,0);
double take_profit=Ask+MathAbs(iOpen(NULL,0,0)-EMA)*2;
You should also check that your take profit is far enough away from the current price to be accepted by the trade server (using MarketInfo(NULL, MODE_STOPLEVEL)).

Related

MQL4 how can I check if the order hit SL?

I am coding an algorithmic trading robot and how can I check if the order hit SL on MQL4?
The most robust method is to record then track the trade using its OrderTicket(). Track this until the trade is closed (using OrderCloseTime() to determine when closed). You can then retrieve the OrderClosePrice() and check it against the OrderStopLoss().
For MQL5
If trade hit stoploss or target then it will close automatically
You just need to check position of that symbol.
if(!PositionSelect(_Symbol))
{
// trade is closed, now you can take new entry of that symbol.
}

The Here API returns distance, what unit of measurement is the numeric in?

here API... "distance"... is it meters? Is it miles? Feet?
Using the API here.com I am able to get lots of great info, one item is the distance somewhere is from the supplied location in their search api. The documentation shows the distance as a text example output, but I can't find anywhere that explains what the unit of measurement is. Maybe all sites use meters and this is just a dumb question? Maybe I am just not that good at searching through the documentation and it wasn't as hard to find as it seems? Maybe you have worked with the Here API and just know the answer?
Any help would be appreciated!
-dan
As mentioned in their documents, they use meters
information about each route segment (interconnection) in between two consecutive waypoints including the distance between them in meters and the estimated time in seconds
check it out here press ( cmd + F for mac or ctrl + F for windows ) and paste the above sentence you should be able to see it.
UPDATE: Check also here they mention its meters
It is meters. Please use our documentation page to get information on all the request and response fields for any API - developer.here.com/documentation/versions

MQL4 (Metatrader 4 prog language) OrderSend() , take profit and stop loss variables

if (Ask > highest_price) {
double takeprofit=NormalizeDouble(Bid+15*Point,Digits);
double stoploss=NormalizeDouble(Bid-5*Point,Digits);
int ticket=OrderSend(Symbol(),OP_BUY,0.1, Ask,0,stoploss,takeprofit,"My order",0,0,clrGreen); }
Currently this is my code. I want to use custom stop loss and take profit for 5 pips and 15 pips respectively. But i get an error code 130 which is related to that. It only allows me to use the MarketInfo() (eg. the minimum required distance from the price which is actually 0 for EURUSD) to specify take profit and stop loss levels which it does not work with my strategy at all.
I will appreciate your opinion on that.
First of all, 15 Point does not necessary mean 15 pips. If your broker has 5-digit quotes, 15*Point will mean 1.5 pips and that might be too short to the current price.
Next, it is always easier to print the values before asking us. So try to see all values (Bid, Ask, stop loss, take profit) and it might be easy to see the problem.
Last suggestion is that your broker is a ECN broker or behaves like the one. In such a case, try to int ticket=OrderSend(_Symbol,OP_BUY,0.1,Ask,10/*slippage in Point*/,0,0,NULL) and if ok then modify it by placing stoploss and take profit

How to read an actual price of another currency pair, not available directly in a [ Strategy Tester ] - for a Multi-Currency Strategy?

In the Internet, across many boards one can read that it is impossible to make use of MarketInfo() function in the Strategy Tester. It's the limitation of the platform.
I haven't found on the web any workaround for this. However, since the need is the mother of invention, and my need was to make USDJPY market decisions with EA that depends on the state of EURUSD market I've found the workaround ( which is good enough for me ). I use iMA() with a period of one, and M1 resolution.
iMA( "EURUSD", PERIOD_M1, 1, 0, MODE_SMA, PRICE_MEDIAN, i )
The question is: since MetaTrader is able to calculate Moving Average for another currency ( which is surely based on the actual price of the pair! ),Q1: why can't one has access to the current value : directly?
And a follow-up question:Q2: Is there any other ( more accurate ) workaround for this limitation?
REASON: The reason to that question is because of "Tick". Because a "tick" in one currency happens independently from the "tick" of another currency, it is not possible to accurately determine the Price of another currency basing on the current "Tick" of one currency. The iMA is calculated using the OHLC of the M1 candle, and not the actual "Tick" (which is not the same as "Tick" data).
Rephrase: Let's say we are on USDJPY, and this "tick" happens at 12:00:00.210 (12mid-night at the 210th millisecond). When that "tick" happens, the start() event gets triggered. In that function, we look for Bid of EURUSD. However, there is no "Tick" for EURUSD as of that time (the USDJPY and EURUSD do not "tick" at the same time), thus it is not possible to determine the exact price of EURUSD at-that-point-in-time.
There is no workaround because it is impossible to determine the price on the "Tick" level because MQL4's datetime variable is an integer and accurate only to the seconds, and the HistoryCenter>Export are OHLC only.
Your iMA() is as good as it gets.
Q1: was well served by #JosephLee + there is one more option (ref. below)
Q2: deserves a word:
Yes, there is a workaround.
While MetaTrader Terminal 4 has many weaknesses, not worth one's time to spend time here, there are also nice things one can do with it.
Some five years ago, there was a project-need to integrate a distributed-processing for MT4, so as to circumvent it's given weaknesses.
That happened. This way you can benefit from a distributed-processing framework and can have down to a few nanoseconds ( latency-wise ) exact prices of all instruments at will ( based on a remote QUOTE-stream processing ) independently of your localhost MT4.graph _Symbol
Do not hesitate to ask more
&
welcome to the
Worlds of MQL4
New-MQL4.56789 has an iClose() functionality for multi-currency
Returns Close price value for the bar of specified symbol with timeframe and shift.
double iClose( string symbol, // symbol
int timeframe, // timeframe
int shift // shift
);
Parameterssymbol[in] Symbol name. NULL means the current symbol.timeframe[in] Timeframe. It can be any of ENUM_TIMEFRAMES enumeration values. 0 means the current chart timeframe.shift[in] Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).Returned valueClose price value for the bar of specified symbol with timeframe and shift. If local history is empty (not loaded), function returns 0. To check errors, one has to call the GetLastError() function.
Be cautious on it's use in StrategyTester with a due care taken on error-handling the cases the history data is not in local database and a need to provide a remedy-handling procedures for remote-retrieval from server appears.
Print( "A first date in the history for the EURUSD on the [MT4SERVER] = ",
(datetime) SeriesInfoInteger( "EURUSD", 0, SERIES_SERVER_FIRSTDATE )
);
Similarly need to provide some measures for cases the above indicated need ERR_HISTORY_WILL_UPDATED appears while the remote-server is not online / market is closed ERR_MARKET_CLOSED / the requested date is already before the SERIES_SERVER_FIRSTDATE etc.
In a corner-case, there is always a possibility to create a special-setup with step-wise updating both local CCY_PAIR and a REMOTE_CCY_PAIR totally independent of a Broker-side equipment status.
All these are important aspects of this new MQL4 feature.

How do I calculate the nearest country on a given heading?

I'd like to calculate the closest country (as viewed on a world map) in a given direction (provided in degrees) from a user's current location.
I realize one way of doing this is to use the formula provided here to step in, for example, 5-mile increments from point to point until I finally reach a country that is not the user's starting country. However, that seems horribly inefficient with regard to use of geocoding resources.
Do any of you know of a better algorithm I could use for this?
Thanks in advance.
One way to reduce the amount of reverse geocoding operations is to treat this problem as a search for the border. If you use a binary search algorithm, and reverse geocode each point, you find where the country changes from your current country to the adjacent country with a minimum number of reverse geocode operations.
In the binary search, your heading is constant, and you have a minimum range (5 miles) and a maximum range (12,000 miles), you are searching for the range at which the border lies. Then you reverse geocode a position just beyond the border to find out what country is there. One problem is that just beyond the border might be ocean.
I would use MKReverseGeocoding. Check this SO question for code examples.

Resources