Can you draw inclined levels from the other side?
i.e. draw support and resistance lines not from below when ascending, but on the contrary from above?
Can you draw inclined levels from the other side?
i.e. draw support and resistance lines not from the bottom when ascending, but on the contrary from the top?
yes of course, it is not as difficult as it seems.
Literate guys, please tell me how to find the maximum high and low for the set number of bars in MQL5
For example, in mql4 it's easy to do it there.
_High = NormalizeDouble(iHigh(Symb,PERIOD_CURRENT,iHighest(Symb,PERIOD_CURRENT,MODE_HIGH,CanalBar,0)), Digits); // calculate the highest high price for the last CanalBar _Low = NormalizeDouble(iLow (Symb,PERIOD_CURRENT,iLowest (Symb,PERIOD_CURRENT,MODE_LOW, CanalBar,0)), Digits); // calculate the lowest low price for the last CanalBar
Here we just take what we have found and draw a line on the chart.
But how to find the high and low for the number of bars in mql5 is a puzzle. iHighest and iLowest
as I understand it, there is no simple understanding here.
I will be grateful if you can help me, and if there is an example code it would be great in general.
thanks.
Literate guys, please tell me how to find the maximum high and low for the set number of bars in MQL5
For example, in mql4 it's easy to do it there.
Here we just take what we have found and draw a line on the chart.
But how to find the high and low for the number of bars in mql5 is a puzzle. iHighest and iLowest
as I understand it, there is no simple understanding here.
I will be grateful if you can help me, and if there is a code example, it would be great in general.
_High = NormalizeDouble(high[ArrayMaximum(high, 0, CanalBar)], Digits); // calculate the highest high price for the last CanalBar
where high is an array of high bar prices
if it is an indicator, it comes to you in OnCalculation,
if it is in the Expert Advisor, request it via CopyHigh.
don't forget ArraySetAsSeries true
thanks.
SPS
Literate guys, please tell me how to find the maximum high and low for the set number of bars in MQL5
For example, in mql4 it's easy to do it there.
Here we just take what we have found and draw a line on the chart.
But how to find the high and low for the number of bars in mql5 is a puzzle. iHighest and iLowest
as I understand it, there is no simple understanding here.
I will be grateful if you can help me, and if there is an example code it would be great in general.
Thank you.
you confuse the commands of the general request to all data with the commands of the request to the current data, which in this case is unnecessary.
//for current data (access to current data from any EA or indicator) will be _High=NormalizeDouble(High[iHighest(Symb,_Period,MODE_HIGH,CanalBar)],_Digits); //for general data (access from any EA or indicator to any data in the database) will be _High=NormalizeDouble(iHigh(Symb,PERIOD_CURRENT,iHighest(Symb,PERIOD_CURRENT,MODE_HIGH,CanalBar)),MarketInfo(Symb,MODE_DIGITS));
and now on the code in mt5.
double high[]; ArrayResize(high,CanalBar); CopyHigh(Symb,PERIOD_CURRENT,0,CanalBar,high); _High=NormalizeDouble(high[ArrayMaximum(high)],SymbolInfoInteger(Symb,SYMBOL_DIGITS)); ArrayFree(high);
in this case, the access to any data in the database for any symbol from any indicator or EA is given.
there is no need to be wise about the direction of indexing, as we need only the maximum, no matter where it is located.
ArrayMaximum() command (according to the help) returns the necessary value taking into account the direction of array indexing.
c/u.
P.S. I would not normalise the price, it is unnecessary, unless of course you are building a pipsmith that catches 1 Point from a trade.
Firstly, on your code. I would make it simpler, based on the fact that you request the maximum on the current chart, I will give you an example for tops, for troughs everything is almost the same.
you confuse commands of general request to all data with commands of request to current data, which in this case is unnecessary.
and now on the code in mt5.
in this case, the access to any data in the database for any symbol from any indicator or EA is given.
there is no need to be wise about the direction of indexing, as we need only the maximum, no matter where it is located.
ArrayMaximum() command (according to the help) returns the necessary value taking into account the direction of array indexing.
c/u.
P.S. I wouldn't normalise the price, it's unnecessary, unless of course you are building a pipsmith that catches 1 Point from a trade.
Great, that's all sorted out
Now here's another question
The implementation is as follows
input int CanalBar = 200; // Number of bars to calculate //+------------------------------------------------------------------+ //| Expert tick function| //+------------------------------------------------------------------+ void OnTick() { double high[]; ArrayResize(high,CanalBar); CopyHigh(_Symbol,PERIOD_CURRENT,0,CanalBar,high); double _High=NormalizeDouble(high[ArrayMaximum(high)],SymbolInfoInteger(_Symbol,SYMBOL_DIGITS)); ArrayFree(high); HLineCreate(0,"HIGH",0,_High,"",clrBlue,1,1); // Draw a line on the graph. } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Creates a horizontal line| //+------------------------------------------------------------------+ //| Based on:| //| MQL5 Reference Guide / Standard constants, enums and structures| //| / Object constants / Object types / OBJ_HLINE | //+------------------------------------------------------------------+ bool HLineCreate(const long chart_ID=0, // chart ID const string name="HLine", // line name const int sub_window=0, // subwindow number double price=0, // line price const string toolTip="\n", // tooltip text const color clr=clrRed, // line colour const ENUM_LINE_STYLE style=STYLE_SOLID, // line style const int line_width=1, // line thickness const bool back=false, // in the background const bool selection=true, // select to move const bool hidden=true, // hidden in the list of objects const long z_order=0, // mouse click priority const int timeFrames=OBJ_ALL_PERIODS)//display the object at different periods { //--- reset the error value ResetLastError(); //--- create a horizontal line if(!ObjectCreate(chart_ID,name,OBJ_HLINE,sub_window,0,price)) { Print(LINE_NUMBER,__FUNCTION__, ": failed to create a horizontal line! Error code = ",GetLastError()); return(false); } //--- set the tooltip text ObSetString(chart_ID,name,OBJPROP_TOOLTIP,toolTip); //--- set the line colour ObSetIntegerColor(chart_ID,name,OBJPROP_COLOR,clr); //--- set the line display style ObSetIntegerLineStyle(chart_ID,name,style); //--- set the line thickness ObSetIntegerInt(chart_ID,name,OBJPROP_WIDTH,line_width); //--- display in foreground (false) or background (true) ObSetIntegerBool(chart_ID,name,OBJPROP_BACK,back); //--- enable (true) or disable (false) the mouse line movement mode //--- when creating a graphical object with the ObjectCreate function, by default the object //--- cannot be selected and moved. Inside this method, the selection parameter //--- defaults to true, which allows you to select and move this object ObSetIntegerBool(chart_ID,name,OBJPROP_SELECTABLE,selection); ObSetIntegerBool(chart_ID,name,OBJPROP_SELECTED,selection); //--- hide (true) or display (false) the name of the graphical object in the list of objects ObSetIntegerBool(chart_ID,name,OBJPROP_HIDDEN,hidden); //--- set the priority to receive the mouse click event on the chart ObSetIntegerLong(chart_ID,name,OBJPROP_ZORDER,z_order); //--- setting object visibility on different timeframes ObSetIntegerInt(chart_ID,name,OBJPROP_TIMEFRAMES,timeFrames); //--- successful execution return(true); }
When starting visual testing, the line on the chart is drawn, but stands still, the line does not change its values in the course of testing, in mql5 it is necessary to give calculations an additional kick in the arse in some way ?
All right, that's all taken care of.
Now here's another question
The implementation is as follows
When you start visual testing, the line on the chart is drawn, but stands still, its values line does not change during the testing, in mql5 that you need to additionally somehow give the calculations a kick in the arse ?
Try this:
void HLineCreate(const long chart_ID=0, // chart ID const string name="HLine", // line name const int sub_window=0, // subwindow number double price=0, // line price const string toolTip="\n", // tooltip text const color clr=clrRed, // line colour const ENUM_LINE_STYLE style=STYLE_SOLID, // line style const int line_width=1, // line thickness const bool back=false, // in the background const bool selection=true, // select to move const bool hidden=true, // hidden in the list of objects const long z_order=0, // mouse click priority const int timeFrames=OBJ_ALL_PERIODS)//display the object at different periods { if(ObjectFind(chart_ID, name)<0) { //--- create a horizontal line ObjectCreate(chart_ID,name,OBJ_HLINE,sub_window,0,price); //--- set the tooltip text ObjectSetString(chart_ID,name,OBJPROP_TOOLTIP,toolTip); //--- set the line colour ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); //--- set the line display style ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); //--- set the line thickness ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,line_width); //--- display in foreground (false) or background (true) ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); //--- enable (true) or disable (false) the mouse line movement mode //--- when creating a graphical object with the ObjectCreate function, by default the object //--- cannot be selected and moved. Inside this method, the selection parameter //--- defaults to true, which allows you to select and move this object ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); //--- hide (true) or display (false) the name of the graphical object in the list of objects ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); //--- set the priority to receive the mouse click event on the chart ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); //--- setting object visibility on different timeframes ObjectSetInteger(chart_ID,name,OBJPROP_TIMEFRAMES,timeFrames); } //--- set the binding method ObjectSetDouble(chart_ID,name,OBJPROP_PRICE,price); }
All right, that's all taken care of.
Now here's another question
The implementation is as follows
When you start visual testing, the line on the chart is drawn, but stands still, its values line does not change during the testing, in mql5 that need to additionally somehow give calculations a kick in the arse ?
if(!ObjectCreate(chart_ID,name,OBJ_HLINE,sub_window,0,price))if there is already an object with this name is not implemented, as a consequence, your price on the existing line will not change.
as you were rightly told, it should be done by command.
ObjectSetDouble(chart_ID,name,OBJPROP_PRICE,price);and one more remark, try not to get into classes and other wisdom, if there is a possibility to write simpler, using commands of direct access.
apply only those commands which are necessary, it is not necessary to go through all parameters of the line at each access, after all you need to change only the price of the line.
with respect.
Thanks guys, it's all sorted now.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
New article An example of an indicator drawing Support and Resistance lines has been published:
The article provides an example of how to implement an indicator for drawing support and resistance lines based on formalized conditions. In addition to having a ready-to-use indicator, you will see how simple the indicator creation process is. You will also learn how to formulate conditions for drawing any desired line by changing the indicator code.
Pay attention to indicators based on moving averages. They first of all include Moving Averages, as well as Bollinger Bands and Envelopes from the standard terminal package. These indicators are very effective tools for showing support and resistance levels on the chart. Open the indicator properties -> the "Levels" tab, and add there two levels with a minus sign and with a plus sign. We obtain an image like this:
Author: Andrey Kisselyov