
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
Hi,
I tried to change your code from this page:
https://www.mql5.com/en/forum/177583
because I want to change the TenkanSen Indicator in that way, that it is on the german dax only calculating from 9-17:30.
But I think I made something wrong because this is the same tankensen and the same calculation only without the time between 9-17:30 is missing.
Can you see my error
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 PaleVioletRed
#property indicator_width1 2
#property indicator_level1 0
#property indicator_levelcolor DarkGray
extern double SmaPeriod = 1;
extern int Price = PRICE_CLOSE;
extern string StartFrom = "09:00";
extern string EndAt = "17:30";
double TenkanSen[];
double TenkanSen_TimeLimited[];
int init()
{
IndicatorBuffers(2);
SetIndexBuffer(0,TenkanSen_TimeLimited);
SetIndexBuffer(1,TenkanSen);
return(0);
}
int deinit() { return(0); }
int start()
{
int c,k,count,counted_bars=IndicatorCounted();
if(counted_bars < 0) return(-1);
if(counted_bars>0) counted_bars--;
int limit = MathMin(Bars-counted_bars,Bars-1);
for(int i = limit; i>=0; i--)
{
string today = TimeToStr(Time,TIME_DATE);
datetime tfrom = StrToTime(today+" "+StartFrom);
datetime tto = StrToTime(today+" "+EndAt);
if (Time>=tfrom && Time<tto)
TenkanSen = iIchimoku(NULL,0, 9, 26, 52, MODE_TENKANSEN, i);
else { TenkanSen = EMPTY_VALUE; TenkanSen_TimeLimited = TenkanSen_TimeLimited; continue; }
//
TenkanSen_TimeLimited = 0; for (c=0,k=0; c<SmaPeriod && (i+k)<Bars; k++) if ( TenkanSen!=EMPTY_VALUE) { TenkanSen_TimeLimited += TenkanSen; c++; }
TenkanSen_TimeLimited /= (1.0*SmaPeriod);
}
return(0);sunshineh
It is doing exactly what it is told to do : it takes the values from TenkanSen which is within the given time limit or inherits the previous value if the time is outside the bounds.
If you wish to ignore the data that is outside the given time limits you would have to rewrite the ichimoku completely or you can use a period converter of some sort and make it generate offline charts that would contain data only for given time period
Some MQL4 training videos from Youtube, maybe useful for the newbies like me.
How can I write in an EA " If last losing trade was buy......", buy....., else ....
Thanks for help.
Jo
How can I write in an EA " If last losing trade was buy......", buy....., else ....
Thanks for help.
JoTry something like this :
{
datetime lastTime = 0;
int lastType = -1;
for (int i=OrdersHistoryTotal()-1; i >= 0; i--)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
if ((OrderType() == OP_BUY || OrderType() == OP_SELL) && OrderProfit() = lastTime)
{
lastTime = OrderCloseTime();
lastType = OrderType();
}
}
return (lastType);
}
If it does not find a loosing trade it will return -1
Has anyone managed to use the resource code to copy image files into an ex4 so that the ex4 can be transferred into another platform without having to transfer the images as well. I have tried just about every option for the resource path I can think of and the files do not transfer with the ex4 file. Below is the MQL4 help descriptionIncluding resources to executable files during compilation of mql4 programsAn mql4 program may need a lot of different
downloadable resources in the form of image and sound files. In order to
eliminate the need to transfer all these files when moving an executable file in
MQL4, the compiler's directive #resource should be used:[/TD]
[/TR]
[/TABLE]The #resource command tells the compiler that
the resource at the specified path path_to_resource_file should be included
into the executable EX5 file. Thus all the necessary images and sounds can be
located directly in an EX4 file, so that there is no need to transfer
separately the files used in it, if you want to run the program on a different
terminal. Any EX4 file can contain resources, and any EX4 program can use
resources from another EX4 program.
The files in format BMP and WAV are
automatically compressed before including them to an EX4 file. This denotes that
in addition to the creation of complete programs in MQL4, using resources also
allows to reduce the total size of necessary files when using graphics and
sounds, as compared to the usual way of MQL4 program writing.
The resource file size must not exceed 16Mb.Search for specified resources by a compilerA resource is inserted using the command
#resource ""The length of the constant string
must not exceed 63 characters.
The compiler searches for a resource at the
specified path in the following order:
·if the backslash "\" separator (written as "\\") is placed at the
beginning of the path, it searches for the resource relative to the directory
terminal_data_directory\MQL4\,
·if there is no backslash, it searches for the resource relative to
the location of the source file, in which the resource is written.
The resource path cannot contain the
substrings "..\\" and ":\\".
Examples of resource inclusion:[TR]
[TD]//--- correct specification of resources
#resource "\\Images\\euro.bmp" // euro.bmp is located in terminal_data_directory\MQL4\Images\
#resource "picture.bmp" // picture.bmp is located in the same directory as the source file
#resource "Resource\\map.bmp" // the resource is located in source_file_directory\Resource\map.bmp
//--- incorrect specification of resources
#resource ":picture_2.bmp" // must not contain ":"
#resource "..\\picture_3.bmp" // must not contain ".."
#resource "\\Files\\Images\\Folder_First\\My_panel\\Labels\\too_long_path.bmp" //more than 63 symbols
[/TABLE]however theicon codefor changing the EA icon works no problem and transfers to the new platform and it uses a similar path to the resource examples above. An example of the #resource path could be helpful as it could be very likely that I am doing something wrong.Or is this perhaps just another glich with the new MT4?
Has anyone managed to use the resource code to copy image files into an ex4 so that the ex4 can be transferred into another platform without having to transfer the images as well. I have tried just about every option for the resource path I can think of and the files do not transfer with the ex4 file. Below is the MQL4 help descriptionIncluding resources to executable files during compilation of mql4 programsAn mql4 program may need a lot of different
downloadable resources in the form of image and sound files. In order to
eliminate the need to transfer all these files when moving an executable file in
MQL4, the compiler's directive #resource should be used:[/TR]
[/TABLE]The #resource command tells the compiler that
the resource at the specified path path_to_resource_file should be included
into the executable EX5 file. Thus all the necessary images and sounds can be
located directly in an EX4 file, so that there is no need to transfer
separately the files used in it, if you want to run the program on a different
terminal. Any EX4 file can contain resources, and any EX4 program can use
resources from another EX4 program.
The files in format BMP and WAV are
automatically compressed before including them to an EX4 file. This denotes that
in addition to the creation of complete programs in MQL4, using resources also
allows to reduce the total size of necessary files when using graphics and
sounds, as compared to the usual way of MQL4 program writing.
The resource file size must not exceed 16Mb.
Search for specified resources by a compilerA resource is inserted using the command #resource ""The length of the constant string
must not exceed 63 characters.
The compiler searches for a resource at the
specified path in the following order:
·if the backslash "\" separator (written as "\\") is placed at the
beginning of the path, it searches for the resource relative to the directory
terminal_data_directory\MQL4\,
·if there is no backslash, it searches for the resource relative to
the location of the source file, in which the resource is written.
The resource path cannot contain the
substrings "..\\" and ":\\".
Examples of resource inclusion:[TR]
[TD]//--- correct specification of resources
#resource "\\Images\\euro.bmp" // euro.bmp is located in terminal_data_directory\MQL4\Images\
#resource "picture.bmp" // picture.bmp is located in the same directory as the source file
#resource "Resource\\map.bmp" // the resource is located in source_file_directory\Resource\map.bmp
//--- incorrect specification of resources
#resource ":picture_2.bmp" // must not contain ":"
#resource "..\\picture_3.bmp" // must not contain ".."
#resource "\\Files\\Images\\Folder_First\\My_panel\\Labels\\too_long_path.bmp" //more than 63 symbols [/TABLE]Are you using "/portable" switch?
If not, that might be a problem (due to the path where the resource actually has to reside). Doing a guessing game now, but if it needs to know the path relative to the data path it either can be that a compiler is looking for resources at a wrong place or that the feature is simply not working in the new metatrader 4 yet (as so much features that still can not be used)
Hi mladen,
I suspect it maybe yet another MT4 issue and I say that because the Help file instructs me to use the icon code the same way as the resource code and the icon code using a path to the file in the same image folder works so if one path works there should be no reason why another bit of code using the same path would fail? We are talking MT4 though so I guess anything is possible.
Hi mladen, I suspect it maybe yet another MT4 issue and I say that because the Help file instructs me to use the icon code the same way as the resource code and the icon code using a path to the file in the same image folder works so if one path works there should be no reason why another bit of code using the same path would fail? We are talking MT4 though so I guess anything is possible.
That sentence (the "We are talking MT4 though so I guess anything is possible.") might be the one that describes all. We can not count on any stability or certainty in this new metatrader 4
That sentence (the "We are talking MT4 though so I guess anything is possible.") might be the one that describes all. We can not count on any stability or certainty in this new metatrader 4
What do you think : when are they going to solve all those errors? A lot of people does not know what to do now
The best way to learn how to programm robots with MQL4 or 5 is to check some open source robots to see how they operate. Only then you can learn how the code works and improve your learning with the book or manuals.