Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 176
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Reading, but would never have guessed to open the file before the loop )
Maybe I didn't read it carefully )There is an Expert Advisor, which is guided by the Pinbar when trading. The robot works correctly on currencies and is totally unpredictable on CFDs.
Can you please tell me how this can happen?
I have written a robot which is based on Pinbar when trading. The robot works correctly on currencies and completely unpredictable on CFDs.
Can you please tell me how this can happen?
Here is the Pinbar definition function
When I insert it into the Expert Advisor, the function works fine (i.e. the Expert Advisor sets deals on the next bar after the bar corresponding to the conditions of the function) for currency pairs. However, trades on CFD are opened everywhere.
What is the difference between CFDs and currency pairs for this function?
Here is the Pinbar definition function
When I insert it into the Expert Advisor, the function works fine (i.e. the Expert Advisor sets deals on the next bar after the bar corresponding to the conditions of the function) for currency pairs. However, trades on CFD are opened everywhere.
What is the difference between CFDs and currency pairs for this function?
First of all replace all && with {} so that each of conditions was in its own block - then you can in each block unwind tested result - see in log what values you get.
Thanks, I followed the advice and understood where I was going wrong. Because my EA was moving in 5 digits and CFD is only 2 digits and I expected the EA to react to 50 pips minimum and got the reaction from 5 pips. I messed up.
Please help me with this aspect.
There is such a part in the code:
MathAbs(Close1-Open1)/(High1-Low1)
Sometimes it happens that High1=Low1. The tester then generates the critical error saying that it cannot divide by zero.
How to work around it?
Thanks, I followed the advice and understood where I was going wrong. Because my EA was moving in 5 digits and CFD is only 2 digits and I expected the EA to react to 50 pips minimum and got the reaction from 5 pips. I messed up.
Please help me with this aspect.
There is such a part in the code:
Sometimes it happens that High1=Low1. The tester then generates the critical error saying that it cannot divide by zero.
How to work around it?
You can do it without thinking:
Hello, encountered a problem during compilation:
void OnTick()
{
double minprice=999999, mp, maxprice=-999999;
for(int i=0; i<10; i++)
{
mp = iLow(Simbol(), PERIOD_CURRENT, i);
if (mp < minprice)
minprice = mp;
}
for(int i=0; i<10; i++)
{
mp = iHigh(Simbol(), PERIOD_CURRENT, i);
if (mp > maxprice)
maxprice = mp;
}
Comment("Minprice: " + DoubleToString(minprice, 5) + "\n "+
"Maxprice: " + DoubleToString(maxprice, 5));
}
The source code contains functions the compiler swears by iLow and iHigh and variable Simbol() there in string mode, but it solves another problem in the example. What do I need to fix in the code above. I'm stuck and can't compile the loop to check it.
FROM THE TEXTBOOK
If you want to get the value corresponding to the current incomplete bar, then
you can use the first form of the call specifying start_pos=0 and count=1.
Example:
#property copyright "2009, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property description "Example output of High[i] and Low[i] values"
#property description "for randomly chosen bars"
double High[],Low[];
//+------------------------------------------------------------------+
//| Get Low for a given bar number |
//+------------------------------------------------------------------+
double iLow(string symbol,ENUM_TIMEFRAMES timeframe,int index)
{
double low=0;
ArraySetAsSeries(low,true);
int copied=CopyLow(symbol,timeframe,0,Bars(symbol,timeframe),Low);
if(copied>0 && index<copied) low=Low[index];
return(low);
}
//+------------------------------------------------------------------+
//| Get High for the given bar number |
//+------------------------------------------------------------------+
double iHigh(string symbol,ENUM_TIMEFRAMES timeframe,int index)
{
double high=0;
ArraySetAsSeries(high,true);
int copied=CopyHigh(symbol,timeframe,0,Bars(symbol,timeframe),High);
if(copied>0 && index<copied) high=High[index];
return(high);
}
//+------------------------------------------------------------------+
Hello, encountered a problem during compilation:
void OnTick()
{
double minprice=999999, mp, maxprice=-999999;
for(int i=0; i<10; i++)
{
mp = iLow(Simbol(), PERIOD_CURRENT, i);
if (mp < minprice)
minprice = mp;
}
for(int i=0; i<10; i++)
{
mp = iHigh(Simbol(), PERIOD_CURRENT, i);
if (mp > maxprice)
maxprice = mp;
}
Comment("Minprice: " + DoubleToString(minprice, 5) + "\n "+
"Maxprice: " + DoubleToString(maxprice, 5));
}
The source code contains functions the compiler swears by iLow and iHigh b variable Simbol() is in string mode there, but it solves another problem in the example. What do I need to fix in the code above. I'm stuck and can't compile the loop to check it.
FROM THE TEXTBOOK
If you need to get the value corresponding to the current incomplete bar, then
you can use the first form of the call, specifying start_pos=0 and count=1.
Example:
#property copyright "2009, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property description "Example output of High[i] and Low[i] values"
#property description "for randomly chosen bars"
double High[],Low[];
//+------------------------------------------------------------------+
//| Get Low for a given bar number |
//+------------------------------------------------------------------+
double iLow(string symbol,ENUM_TIMEFRAMES timeframe,int index)
{
double low=0;
ArraySetAsSeries(low,true);
int copied=CopyLow(symbol,timeframe,0,Bars(symbol,timeframe),Low);
if(copied>0 && index<copied) low=Low[index];
return(low);
}
//+------------------------------------------------------------------+
//| Get High for the given bar number |
//+------------------------------------------------------------------+
double iHigh(string symbol,ENUM_TIMEFRAMES timeframe,int index)
{
double high=0;
ArraySetAsSeries(high,true);
int copied=CopyHigh(symbol,timeframe,0,Bars(symbol,timeframe),High);
if(copied>0 && index<copied) high=High[index];
return(high);
}
//+------------------------------------------------------------------+
there's a mistake in this wordSimbol() you should write Symbol() or _Symbol
You have an error in this wordSimbol() - Symbol() or _Symbol should be written
Thank you, the error on Simbol has been corrected by spelling Symbol correctly. I have something wrong with iLow and iHigh functions.
Thedifference in % between MQL4 and MQL5 ? otherwise I will have to scratch my head every time I go through MQL4 video tutorials.