Programming Question from a Newbie

 

I recently tried to write small programs with some success. But, at time I get stumpted like as in this example. I am trying to better understand the iMA() function.

1- Why is it I can add + or - 10 without any errors when I comple it but they won't get displayed on the chart? ===> ExtMapBuffer2[i] = (iMA(NULL,0,ExtParam1,0,MODE_EMA,PRICE_CLOSE,i)+10);
ExtMapBuffer3[i] = (iMA(NULL,0,ExtParam1,0,MODE_EMA,PRICE_CLOSE,i)-10);

2. But, Delta which is not an ARRAY() can take on the values of an ARRAY() then later assigns its parameter to an ARRAY[] and gets displayed ?

Thanks for you help, Tigger

/+------------------------------------------------------------------+
//| Mov_Ave_Delta-200_Day.mq4 |
//| Tigger |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Tigger"
#property link "https://www.metaquotes.net/"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 Lime
#property indicator_color3 Magenta
//---- input parameters
extern int ExtParam1=200;
extern int ExtParam2= 10;
extern int ExtParam3 = 10;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,ExtMapBuffer3);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
double Delta;

int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars-1;

int i;

for( i = 0; i <= limit; i++)
{

Delta = iMA(NULL,0,ExtParam1,0,MODE_EMA,PRICE_CLOSE,i);


ExtMapBuffer1[i] = Delta;
ExtMapBuffer2[i] = (iMA(NULL,0,ExtParam1,0,MODE_EMA,PRICE_CLOSE,i)+10);
ExtMapBuffer3[i] = (iMA(NULL,0,ExtParam1,0,MODE_EMA,PRICE_CLOSE,i)-10);


}
return(0);
}
//+------------------------------------------------------------

 
tigger:

I recently tried to write small programs with some success. But, at time I get stumpted like as in this example. I am trying to better understand the iMA() function.

1- Why is it I can add + or - 10 without any errors when I comple it but they won't get displayed on the chart? ===> ExtMapBuffer2[i] = (iMA(NULL,0,ExtParam1,0,MODE_EMA,PRICE_CLOSE,i)+10);
ExtMapBuffer3[i] = (iMA(NULL,0,ExtParam1,0,MODE_EMA,PRICE_CLOSE,i)-10);

2. But, Delta which is not an ARRAY() can take on the values of an ARRAY() then later assigns its parameter to an ARRAY[] and gets displayed ?

Thanks for you help, Tigger


Hi tigger


Your code works fine ;-)

You are adding or subtracting 10 to the moving average of a close price. If the prices are around 1.5000, for example, adding 10 gives 11.5000 and sbutracting give -8.5000. Thus your +10 & -10 make indicator lines too far above and below the prices to see. I suspect you mean to + or - 10 points. If so, add or subtract 10*Point . For example:

ExtMapBuffer2[i] = (iMA(NULL,0,ExtParam1,0,MODE_EMA,PRICE_CLOSE,i)+10*Point);
ExtMapBuffer3[i] = (iMA(NULL,0,ExtParam1,0,MODE_EMA,PRICE_CLOSE,i)-10*Point);

Cheers

Jellybean

 
Jellybean wrote >>

Hi tigger

Your code works fine ;-)

You are adding or subtracting 10 to the moving average of a close price. If the prices are around 1.5000, for example, adding 10 gives 11.5000 and sbutracting give -8.5000. Thus your +10 & -10 make indicator lines too far above and below the prices to see. I suspect you mean to + or - 10 points. If so, add or subtract 10*Point . For example:

Cheers

Jellybean

That explains it, thank you.

 
Jellybean wrote >>

Hi tigger

Your code works fine ;-)

You are adding or subtracting 10 to the moving average of a close price. If the prices are around 1.5000, for example, adding 10 gives 11.5000 and sbutracting give -8.5000. Thus your +10 & -10 make indicator lines too far above and below the prices to see. I suspect you mean to + or - 10 points. If so, add or subtract 10*Point . For example:

Cheers

Jellybean

Hi Jellybean

I am a newbie at programming mql. I did some programming on COBOL a long while back so really the brain and some concepts are okay but the language is foreign. I have been decompiling indicators and placing new alerts / checks - but I do not know how to restrict the alerts to once per candle, only at the end, or start of the next candle.

I saw a prior post where you placed some code on what some candle code should look like but can I have a real life example please. Because I don't know if fields mentioned in the post such as new.bar are set/calculated, which are system defined variables I cannot use your sample. Do you or anyone have an indicator / or have sample mql code from any sort of simple indicator that only writes an alert at end of code. That way I can look at it, pull it apart and work out what variables are needed/set and natural flow of events. I learn best this way.

Thanks again.

Clancy