Referencing a Currency's price in the Expert Adviser (MQL 4)

 

Hi I would like to incorporate a trading rule that when price is below a certain price for instance USD JPY 148.37 then it will allow a sell based on other parameters. The EA would run on the time frame and currency.

I have all the coding for the mechanics of the sell etc. I just can't find how to reference the currency properly, I created something like the below:

extern string note24 = "UsePriceZone";
extern bool UsePriceZone = true;
extern double JPYPrice = 148.37;

I am pretty sure this is not the way to do it.


I would then code the criteria elsewhere in the EA:


bool IsPriceZoneUp(int i) {
if (!UsePriceZone) return(true);
double p1 = iClose(NULL,0,i);
return (p1 > JPYPrice );

}

bool IsPriceZoneDown(int i) {
if (!UsePriceZone) return(true);
double p1 = iClose(NULL,0,i);
return (p1 < JPYPrice );

}


I might make this just a 'SELL' EA and when price is below 148.37 it should return true. I think my issue is that I am not incorporating the price of JPY (or any other currency) into this bool properly.

Any help appreciated.

 
Your topic has been moved to the section: MQL4 and MetaTrader 4
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 

Hi

I don’t see any problem with your code here – the function return proper values when price is above/below chosen value.

If you want to use different symbols or timeframes use them as parameters (like you used “I” for choosing the bar from which price is obtained). So instead of :\

double p1 = iClose(NULL,0,i);

use

string symbol = “USDJPY”;

ENUM_TIMEFRAMES timeframe = PERIOD_CURRENT;
double p1 = iClose(symbol,timeframe,i);

Have a nice day👍📊

 
Marzena Maria Szmit #:

Hi

I don’t see any problem with your code here – the function return proper values when price is above/below chosen value.

If you want to use different symbols or timeframes use them as parameters (like you used “I” for choosing the bar from which price is obtained). So instead of :\

Have a nice day👍📊

Hey thanks for the reply. The problem I have is that I want the actual price. So when USDJPY is below some price such as 148.37 then it would do something else.

But I can't reference the actual currency rate. The second part of my code is ok it's just trying to reference the actual currency.

Basically when price moves below or above a price, I can't get it.

 

Hi

I’m afraid I don’t understand this. You can get current price by using this: 

double p1 = iClose(NULL,0,i);

this is the current price on current chart. You can try also using Ask/Bid variables those are also current prices (but for Ask/Bid respectively)

If you want to find the good trading price Zone that’s another story, you would simply find an algorithm which would detect proper prices, but here you need to define the rules for the algo and code it properly. 

Have a nice day👍📊