Metatrader 5 coding questions / issues - page 23

 
mladen:
QuantF

Replace these lines of code :

plus=MainBuffer-MainBuffer;

minus=MainBuffer-MainBuffer;[/PHP]

with these

[PHP] plus=MainBuffer-MainBuffer;

minus=MainBuffer-MainBuffer;
In metatrader 5, if not explicitly specified (by using the ArraySetAsSerries()) , buffer indexes are not the same as in metatrader 4. Ie : index i+1 in metatrader 5 does not mean previous value but the next value (it s the same as i-1 in metatrader 4)

Thank you!

All okay.

Your advice helped me.

 

Multiple DRAW_FILLING type buffers - only one displaying

I am trying to get my indicator, to, among other things, display the next likely support and resistance levels as a coloured band. The buffers placed above the DRAW_FILL declarations behave as expected, and the support levels display, but not the resistance levels. The values are correctly set in the buffers as seen in the data window. Can anyone see what is wrong? Extracts from the top of the code and OnInit() are below.

#property indicator_buffers 16

#property indicator_plots 6

//SPs

#property indicator_color1 clrYellow,clrViolet

#property indicator_type1 DRAW_COLOR_ARROW

#property indicator_color2 clrYellow,clrViolet

#property indicator_type2 DRAW_COLOR_ARROW

//TrendBase

#property indicator_color3 clrGray

#property indicator_type3 DRAW_LINE

//Trend Limit

#property indicator_color4 clrAliceBlue

#property indicator_type4 DRAW_LINE

//resistance band

#property indicator_color5 clrRed

#property indicator_type5 DRAW_FILLING

//support band

#property indicator_color6 clrGreen

#property indicator_type6 DRAW_FILLING

#property indicator_label1 "SH_Points"

#property indicator_label2 "SL_Points"

#property indicator_label3 "TrendBase"

#property indicator_label4 "TrendLimit"

#property indicator_label5 "Next_Resistance_Span"

#property indicator_label6 "Next_Support_Span"

#property indicator_width1 4

#property indicator_width2 4

#property indicator_width3 1

#property indicator_width4 1

#property indicator_width5 1

#property indicator_width6 1

OnInit()

{

// swing points indicated by a small square

SetIndexBuffer(0,SH_Points,INDICATO R_DATA);

PlotIndexSetInteger(0,PLOT_ARROW,250);

PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);

SetIndexBuffer(1,SH_Points_color,INDICATOR_COLOR_INDEX);

PlotIndexSetInteger(1,PLOT_ARROW,250);

SetIndexBuffer(2,SL_Points,INDICATOR_DATA);

PlotIndexSetInteger(2,PLOT_ARROW,250);

PlotIndexSetInteger(2,PLOT_COLOR_INDEXES,2);

SetIndexBuffer(3,SL_Points_color,INDICATOR_COLOR_INDEX);

PlotIndexSetInteger(3,PLOT_ARROW,250);

SetIndexBuffer(4,TrendBase,INDICATOR_DATA);

SetIndexBuffer(5,TrendLimit,INDICATOR_DATA);

SetIndexBuffer(6,Next_Resistance_Span,INDICATOR_DATA);

SetIndexBuffer(7,Next_Resistance,INDICATOR_DATA);

SetIndexBuffer(8,Next_Support_Span, INDICATOR_DATA);

SetIndexBuffer(9,Next_Support,INDICATOR_DATA);

// buffers for data storage only

SetIndexBuffer(10,SH_Levels,INDICATOR_CALCULATIONS);

SetIndexBuffer(11,SL_Levels,INDICATOR_CALCULATIONS);

SetIndexBuffer(12,RoundedO,INDICATOR_CALCULATIONS);

SetIndexBuffer(13,RoundedH,INDICATOR_CALCULATIONS);

SetIndexBuffer(14,RoundedL,INDICATOR_CALCULATIONS);

SetIndexBuffer(15,RoundedC,INDICATOR_CALCULATIONS);

PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(5,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(6,PLOT_EMPTY_VA UE,0);

PlotIndexSetDouble(7,PLOT_EMPTY_VALUE,0);

PlotIndexSetDouble(8,PLOT_EMPTY_VALUE,0);

PlotIndexSetDouble(9,PLOT_EMPTY_VALUE,0);

PlotIndexSetDouble(10,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(11,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(12,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(13,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(14,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(15,PLOT_EMPTY_VALUE,EMPTY_VALUE);

}
 
whitebloodcell:
I am trying to get my indicator, to, among other things, display the next likely support and resistance levels as a coloured band. The buffers placed above the DRAW_FILL declarations behave as expected, and the support levels display, but not the resistance levels. The values are correctly set in the buffers as seen in the data window. Can anyone see what is wrong? Extracts from the top of the code and OnInit() are below.
#property indicator_buffers 16

#property indicator_plots 6

//SPs

#property indicator_color1 clrYellow,clrViolet

#property indicator_type1 DRAW_COLOR_ARROW

#property indicator_color2 clrYellow,clrViolet

#property indicator_type2 DRAW_COLOR_ARROW

//TrendBase

#property indicator_color3 clrGray

#property indicator_type3 DRAW_LINE

//Trend Limit

#property indicator_color4 clrAliceBlue

#property indicator_type4 DRAW_LINE

//resistance band

#property indicator_color5 clrRed

#property indicator_type5 DRAW_FILLING

//support band

#property indicator_color6 clrGreen

#property indicator_type6 DRAW_FILLING

#property indicator_label1 "SH_Points"

#property indicator_label2 "SL_Points"

#property indicator_label3 "TrendBase"

#property indicator_label4 "TrendLimit"

#property indicator_label5 "Next_Resistance_Span"

#property indicator_label6 "Next_Support_Span"

#property indicator_width1 4

#property indicator_width2 4

#property indicator_width3 1

#property indicator_width4 1

#property indicator_width5 1

#property indicator_width6 1

OnInit()

{

// swing points indicated by a small square

SetIndexBuffer(0,SH_Points,INDICATO R_DATA);

PlotIndexSetInteger(0,PLOT_ARROW,250);

PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);

SetIndexBuffer(1,SH_Points_color,INDICATOR_COLOR_INDEX);

PlotIndexSetInteger(1,PLOT_ARROW,250);

SetIndexBuffer(2,SL_Points,INDICATOR_DATA);

PlotIndexSetInteger(2,PLOT_ARROW,250);

PlotIndexSetInteger(2,PLOT_COLOR_INDEXES,2);

SetIndexBuffer(3,SL_Points_color,INDICATOR_COLOR_INDEX);

PlotIndexSetInteger(3,PLOT_ARROW,250);

SetIndexBuffer(4,TrendBase,INDICATOR_DATA);

SetIndexBuffer(5,TrendLimit,INDICATOR_DATA);

SetIndexBuffer(6,Next_Resistance_Span,INDICATOR_DATA);

SetIndexBuffer(7,Next_Resistance,INDICATOR_DATA);

SetIndexBuffer(8,Next_Support_Span, INDICATOR_DATA);

SetIndexBuffer(9,Next_Support,INDICATOR_DATA);

// buffers for data storage only

SetIndexBuffer(10,SH_Levels,INDICATOR_CALCULATIONS);

SetIndexBuffer(11,SL_Levels,INDICATOR_CALCULATIONS);

SetIndexBuffer(12,RoundedO,INDICATOR_CALCULATIONS);

SetIndexBuffer(13,RoundedH,INDICATOR_CALCULATIONS);

SetIndexBuffer(14,RoundedL,INDICATOR_CALCULATIONS);

SetIndexBuffer(15,RoundedC,INDICATOR_CALCULATIONS);

PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(5,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(6,PLOT_EMPTY_VA UE,0);

PlotIndexSetDouble(7,PLOT_EMPTY_VALUE,0);

PlotIndexSetDouble(8,PLOT_EMPTY_VALUE,0);

PlotIndexSetDouble(9,PLOT_EMPTY_VALUE,0);

PlotIndexSetDouble(10,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(11,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(12,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(13,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(14,PLOT_EMPTY_VALUE,EMPTY_VALUE);

PlotIndexSetDouble(15,PLOT_EMPTY_VALUE,EMPTY_VALUE);

}

whitebloodcell

that type of an error is frequent with metatrader 5

Try placing the fill buffers as first buffers - metatrader 5 sometimes messes up when color buffers and different type of buffers are declared before the fill buffers

 
mladen:
whitebloodcell

that type of an error is frequent with metatrader 5

Try placing the fill buffers as first buffers - metatrader 5 sometimes messes up when color buffers and different type of buffers are declared before the fill buffers

You can never know the exact order of buffers in metatrader 5. It is as clumsy as it gets

 
nbtrading:
You can never know the exact order of buffers in metatrader 5. It is as clumsy as it gets

It is odd sometimes how they treat the buffers - better to "push" the buffers that expect pairs of buffers in front

 

Hi Mladen,

some months ago you created for me this indicator CARBON for mt5 wich display the distance in % from sma 15.

Now,please, can create the same indicator but displayng distance in pips?

thank's in advance

Files:
carbon.mq5  7 kb
 
carbonmimetic:
Hi Mladen,

some months ago you created for me this indicator CARBON for mt5 wich display the distance in % from sma 15.

Now,please, can create the same indicator but displayng distance in pips?

thank's in advance

carbonmimetic

Here is a version that calculates pips : carbon_2.mq5

Files:
carbon_2.mq5  7 kb
 

thank you very much....a lot of pips for you!

 

Sorry Mladen,

can you adjust Carbon 2 to Carbon?

In Carbon I see distance percent from low to sma 15 when price is under sma 15 and distance percent from high to sma 15 when price is above sma 15.

I would like that in Carbon 2 I can see difference in pips from low to sma 15 when price is under sma 15 and difference in pips from high to sma 15 when price is above sma 15.

Is there possibility to create a little window on the screen in wich appears that difference in pips?

thank's in advance

 
carbonmimetic:
Sorry Mladen,

can you adjust Carbon 2 to Carbon?

In Carbon I see distance percent from low to sma 15 when price is under sma 15 and distance percent from high to sma 15 when price is above sma 15.

I would like that in Carbon 2 I can see difference in pips from low to sma 15 when price is under sma 15 and difference in pips from high to sma 15 when price is above sma 15.

Is there possibility to create a little window on the screen in wich appears that difference in pips?

thank's in advance

carbonmimetic

Try out this version (it shows the distances the same way as it was in the "carbon" version only in pips - calculation done the way you described it) : carbon_2_1.mq5

Files:
Reason: