Coding help - page 31

 

Working on Multidimensionnal Array, I block on a so simple thing..

Hi misters,

Just trying to get a cell from an Array in a screen line ( same result message Alert), it miss something it is sure, but all the day on it and I don't understand why..

Help would be so good ... ..

this is it :

//+------------------------------------------------------------------+

//| !XTEST sur arrays.mq4 |

//| |

//| |

//+------------------------------------------------------------------+

#property copyright ""

#property link ""

#property indicator_chart_window

extern int Coin = 1 ;

extern int X_Col = 700 ;

extern int Y_Ligne = 30 ;

extern string FontCar = "Arial" ;

extern int TailCar = 14 ;

extern color Couleur = Lime ;

extern int X = 1;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

string Tab1dim[2];

string Tab2dim[2,2];

string Tab3dim[2,2,2];

string Tab4dim[2,2,2,2];

// 5eme Dimension de tableau non autorisée . int Tab5dim[20,20,20,80,2];

int init()

{

//---- indicators

string Tab1dim[2]={"tab1-c0","tab1C1"};

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

ObjectDelete("R");

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

//----

Tab1dim[2]={"tab1-c0","tab1C1"};

string affich=Tab1dim[0];

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

ObjectCreate ("A1", OBJ_LABEL, 0, 0, 0 );

ObjectSet ("A1", OBJPROP_CORNER,Coin );

ObjectSet ("A1", OBJPROP_XDISTANCE,X_Col );

ObjectSet ("A1", OBJPROP_YDISTANCE,Y_Ligne );

ObjectSetText("A1",affich,TailCar, FontCar , Couleur );

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

Alert(affich);

//----

return(0);

}

//+------------------------------------------------------------------+

Thanks in advance.

 

...

Try it like this (array initialization is done differently) :

//+------------------------------------------------------------------+

//| !XTEST sur arrays.mq4 |

//| |

//| |

//+------------------------------------------------------------------+

#property copyright ""

#property link ""

#property indicator_chart_window

extern int Coin = 1 ;

extern int X_Col = 10 ;

extern int Y_Ligne = 10 ;

extern string FontCar = "Arial" ;

extern int TailCar = 14 ;

extern color Couleur = Lime ;

extern int X = 1;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

string Tab1dim[] = {"tab1-c0","tab1C1"};

string Tab2dim[2,2];

string Tab3dim[2,2,2];

string Tab4dim[2,2,2,2];

// 5eme Dimension de tableau non autorisée . int Tab5dim[20,20,20,80,2];

int init()

{

//---- indicators

string Tab1dim[2]={"tab1-c0","tab1C1"};

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

ObjectDelete("A1");

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

//----

string affich=Tab1dim[0];

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

ObjectCreate ("A1", OBJ_LABEL, 0, 0, 0 );

ObjectSet ("A1", OBJPROP_CORNER,Coin );

ObjectSet ("A1", OBJPROP_XDISTANCE,X_Col );

ObjectSet ("A1", OBJPROP_YDISTANCE,Y_Ligne );

ObjectSetText("A1",affich,TailCar, FontCar , Couleur );

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

//----

return(0);

}

//+------------------------------------------------------------------+

Ilevna:
Hi misters,

Just trying to get a cell from an Array in a screen line ( same result message Alert), it miss something it is sure, but all the day on it and I don't understand why..

Help would be so good ... ..

this is it :

Thanks in advance.
 
mladen:
Try it like this (array initialization is done differently) :

//+------------------------------------------------------------------+

//| !XTEST sur arrays.mq4 |

//| |**************

Thanks a lot, that's run well, but I don't undrestand why it is necessary as normaly we could declare , or in global scope, or inside a function, something like as they wrote in the manual : double Tab2Dim[2*n-3]; or else

int [] values =new int[3];

values[0]=5;

values[1]=values[0]*2;

values[2]=values[1]*2;

but it is nice for my end day, thank you sir.

 

...

You can partially overcome that problem with ArrayResize() function (that way you can have dynamically sized arrays)

The problem is that ArrayResize() works just for the single dimension arrays and first dimension of an array (for example if you have array[][2], you can re-size it with ArrayResize() to something like this array[anySize][2]). Any further dimension (from second dimension f arrays up) must be of a constant size known at compile time

Ilevna:
Thanks a lot, that's run well, but I don't undrestand why it is necessary as normaly we could declare , or in global scope, or inside a function, something like as they wrote in the manual : double Tab2Dim[2*n-3]; or else

int [] values =new int[3];

values[0]=5;

values[1]=values[0]*2;

values[2]=values[1]*2;

but it is nice for my end day, thank you sir.
 

Help on my Band Indicator

Hi all,

after trying lots of Band ind , such as jband,tmaband etc.. ,finally I made a decision to write my own Band Indicator ,

the attached you will find is the my Band Indicator , but When EA call it Low Band line gives a Zero Divide , I looked my code there is no zeor divisor in there ,

If you have a either idea or experience such as this , please let me helpto solve problem.

thanks in advance....

Files:
aband.gif  20 kb
 

...

Without the source (or without the code for calling the custom indicator) it is impossible to tell anything. If your indicator works, than the error is in your EA

kemal44:
Hi all,

after trying lots of Band ind , such as jband,tmaband etc.. ,finally I made a decision to write my own Band Indicator ,

the attached you will find is the my Band Indicator , but When EA call it Low Band line gives a Zero Divide , I looked my code there is no zeor divisor in there ,

If you have a either idea or experience such as this , please let me helpto solve problem.

thanks in advance....
 

Need Help with Coding a MA crossover EA

Hello guys,

I am wondering if someone could help me to code a MA crossover ea so i can use it when the time i am away from the computer.

The idea is this.

1 minute chart - 3 EMA and 8 SMA

If 3 EMA crosses below 8 SMA, sell the currency pair with TP and SL preset on the parameters.

If 3 EMA crosses above 8 SMA, buy the currency pair with TP and SL preset on the parameters.

I don't know if it is possible to code such a simple MA ea but would appreciate alot if someone could give me a hand.

Thank you in advance!

 

...

Did you check this thread : https://www.mql5.com/en/forum/general ?

jacktrader:
Hello guys,

I am wondering if someone could help me to code a MA crossover ea so i can use it when the time i am away from the computer.

The idea is this.

1 minute chart - 3 EMA and 8 SMA

If 3 EMA crosses below 8 SMA, sell the currency pair with TP and SL preset on the parameters.

If 3 EMA crosses above 8 SMA, buy the currency pair with TP and SL preset on the parameters.

I don't know if it is possible to code such a simple MA ea but would appreciate alot if someone could give me a hand.

Thank you in advance!
 
kemal44:
Hi all,

after trying lots of Band ind , such as jband,tmaband etc.. ,finally I made a decision to write my own Band Indicator ,

the attached you will find is the my Band Indicator , but When EA call it Low Band line gives a Zero Divide , I looked my code there is no zeor divisor in there ,

If you have a either idea or experience such as this , please let me helpto solve problem.

thanks in advance....

HERE is the code for band ind.

EA call mid and up signal , but low band is the problem for me ,

//+------------------------------------------------------------------+

//| IndicatorPlan.mq4 |

//| Copyright © 2007, MetaQuotes Software Corp. |

//| MetaTrader 5 Trading Platform / MetaQuotes Software Corp. |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2007, MetaQuotes Software Corp."

#property link "http://www.metaquotes.net/"

//---- drawing the indicator in the main window

#property indicator_chart_window

//---- number of indicator buffers

#property indicator_buffers 3

//---- indicator color

#property indicator_color1 Gold

#property indicator_color2 Magenta

#property indicator_color3 BlueViolet

//---- INPUT PARAMETERS OF THE INDICATOR

extern int MBand_Period = 15;

extern int UpBand_Period = 15;

extern int DnBand_Period = 15;

extern int ABand_Timeframe =15;

extern int shift =0;

//---- indicator buffers

double Ind_Buffer0[];

double Ind_Buffer1[];

double Ind_Buffer2[];

double Ind_Buffer3[];

double Ind_Buffer4[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));

IndicatorShortName("ABand "+ABand_Timeframe);

//---- defining the graph execution style

SetIndexStyle(0, DRAW_LINE);

SetIndexLabel(0,"MBand "+MBand_Period);

SetIndexStyle(2, DRAW_LINE);

SetIndexLabel(2,"UpBand "+UpBand_Period);

SetIndexStyle(1, DRAW_LINE);

SetIndexLabel(1,"DnBand "+DnBand_Period);

//---- 3 indicator buffers are used for calculation

IndicatorBuffers(5);

SetIndexBuffer(0, Ind_Buffer0);

SetIndexBuffer(1, Ind_Buffer1);

SetIndexBuffer(2, Ind_Buffer2);

SetIndexBuffer(3, Ind_Buffer3);

SetIndexBuffer(4, Ind_Buffer4);

//---- óñòàíîâêà íîìåğà áàğà, íà÷èíàÿ ñ êîòîğîãî áóäåò îòğèñîâûâàòüñÿ èíäèêàòîğ

//---- Óñòàíîâêà ôîğìàòà òî÷íîñòè îòîáğàæåíèÿ èíäèêàòîğà

IndicatorDigits(Digits);

//---- ğàçìåğ êàíàëà â ïóíêòàõ

//---- end of initialization

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

//---- Ïğîâåğêà êîëè÷åñòâà áàğîâ íà äîñòàòî÷íîñòü äëÿ äàëüíåéøåãî ğàñ÷¸òà

if(Bars < MBand_Period + UpBand_Period + DnBand_Period)

return(0);

//---- İÌÓËßÖÈß ÈÍÄÈÊÀÒÎĞÍÛÕ ÁÓÔÅĞÎÂ

if(ArraySize(Ind_Buffer0) < Bars)

{

ArraySetAsSeries(Ind_Buffer0, false);

ArraySetAsSeries(Ind_Buffer1, false);

ArraySetAsSeries(Ind_Buffer2, false);

ArraySetAsSeries(Ind_Buffer3, false);

ArraySetAsSeries(Ind_Buffer4, false);

//----

ArrayResize(Ind_Buffer0, Bars);

ArrayResize(Ind_Buffer1, Bars);

ArrayResize(Ind_Buffer2, Bars);

ArrayResize(Ind_Buffer3, Bars);

ArrayResize(Ind_Buffer4, Bars);

//----

ArraySetAsSeries(Ind_Buffer0, true);

ArraySetAsSeries(Ind_Buffer1, true);

ArraySetAsSeries(Ind_Buffer2, true);

ArraySetAsSeries(Ind_Buffer3, true);

ArraySetAsSeries(Ind_Buffer4, true);

}

//----+ ÂÂÅÄÅÍÈÅ ÑÒÀÒÈ×ÅÑÊÎÉ ÖÅËÎÉ ÏÅĞÅÌÅÍÍÎÉ ÏÀÌßÒÈ

static int IndCounted;

//----+ Insertion of variables with a floating point

double Resalt0, Resalt1, Resalt2;

double price;

//----+ Insertion of integer variables and getting calculated bars

int limit, MaxBar,bar, counted_bars = IndicatorCounted();

int i,k;

//---- checking for possible errors

if(counted_bars < 0)

return(-1);

//---- the last calculated bar must be recalculated

if(counted_bars > 0)

counted_bars--;

//---- defining the number of the oldest bar,

// starting from which new bars will be recalculated

limit = Bars - counted_bars - 1;

//---- defining the number of the oldest bar,

// starting from which new bars will be recalculated

MaxBar = Bars - 1 - (MBand_Period + UpBand_Period + DnBand_Period);

//---- initialization of zero

if(limit > MaxBar)

{

limit = MaxBar;

for(bar = Bars - 1; bar >= MaxBar; bar--)

{

Ind_Buffer0 = 0.0;

Ind_Buffer1 = 0.0;

Ind_Buffer2 = 0.0;

Ind_Buffer3 = 0.0;

Ind_Buffer4 = 0.0;

}

}

//----+ THE FIRST CYCLE OF INDICATOR CALCULATION

i=Bars-DnBand_Period;

if(counted_bars>DnBand_Period) i=Bars-counted_bars-1;

while(i>=0)

{

i=Bars-DnBand_Period;

if(counted_bars>DnBand_Period) i=Bars-counted_bars-1;

while(i>=0)

{

double min=1000000;

k=i+DnBand_Period-1;

while(k>=i)

{

price=Resalt1[k];

if(min>price) min=price;

k--;

}

Ind_Buffer1=min;

i--;

}

}

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

{

// Here code of the variable Resalt0 calculation

// based on the values of the buffer UpBand[]

// and external variable0

Ind_Buffer3 =iMAOnArray(Ind_Buffer1,limit,DnBand_Period ,shift, ma_method,i);

}

//----+ THE SECOND CYCLE OF INDICATOR CALCULATION

{

i=Bars-UpBand_Period;

if(counted_bars>UpBand_Period) i=Bars-counted_bars-1;

while(i>=0)

{

double max=-1000000;

k=i+UpBand_Period-1;

while(k>=i)

{

price=Resalt2[k];

if(max<price) max=price;

k--;

}

Ind_Buffer2=max;

i--;

}

}

//---- signal line is simple movimg average

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

{

// Here code of the variable Resalt0 calculation

// based on the values of the buffer UpBand[]

// and external variable0

Ind_Buffer4 =iMAOnArray(Ind_Buffer2,limit,UpBand_Period,shift, ma_method,i);

}

//----+ THE MAIN CYCLE OF INDICATOR CALCULATION

//---- signal line is simple movimg average

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

{

// Here code of the variable Resalt0 calculation

// based on the values of the buffer UpBand[]

// and external variable0

Ind_Buffer0 =(Ind_Buffer2+Ind_Buffer1)/2;

}

return(0);

}

//+------------------------------------------------------------------+

 

...

Can you post how are you using the iCustom() call?

kemal44:
HERE is the code for band ind.

EA call mid and up signal , but low band is the problem for me ,

//+------------------------------------------------------------------+

//| IndicatorPlan.mq4 |

//| Copyright © 2007, MetaQuotes Software Corp. |

//| MetaTrader 5 Trading Platform / MetaQuotes Software Corp. |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2007, MetaQuotes Software Corp."

#property link "http://www.metaquotes.net/"

//---- drawing the indicator in the main window

#property indicator_chart_window

//---- number of indicator buffers

#property indicator_buffers 3

//---- indicator color

#property indicator_color1 Gold

#property indicator_color2 Magenta

#property indicator_color3 BlueViolet

//---- INPUT PARAMETERS OF THE INDICATOR

extern int MBand_Period = 15;

extern int UpBand_Period = 15;

extern int DnBand_Period = 15;

extern int ABand_Timeframe =15;

extern int shift =0;

//---- indicator buffers

double Ind_Buffer0[];

double Ind_Buffer1[];

double Ind_Buffer2[];

double Ind_Buffer3[];

double Ind_Buffer4[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));

IndicatorShortName("ABand "+ABand_Timeframe);

//---- defining the graph execution style

SetIndexStyle(0, DRAW_LINE);

SetIndexLabel(0,"MBand "+MBand_Period);

SetIndexStyle(2, DRAW_LINE);

SetIndexLabel(2,"UpBand "+UpBand_Period);

SetIndexStyle(1, DRAW_LINE);

SetIndexLabel(1,"DnBand "+DnBand_Period);

//---- 3 indicator buffers are used for calculation

IndicatorBuffers(5);

SetIndexBuffer(0, Ind_Buffer0);

SetIndexBuffer(1, Ind_Buffer1);

SetIndexBuffer(2, Ind_Buffer2);

SetIndexBuffer(3, Ind_Buffer3);

SetIndexBuffer(4, Ind_Buffer4);

//---- óñòàíîâêà íîìåğà áàğà, íà÷èíàÿ ñ êîòîğîãî áóäåò îòğèñîâûâàòüñÿ èíäèêàòîğ

//---- Óñòàíîâêà ôîğìàòà òî÷íîñòè îòîáğàæåíèÿ èíäèêàòîğà

IndicatorDigits(Digits);

//---- ğàçìåğ êàíàëà â ïóíêòàõ

//---- end of initialization

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

//---- Ïğîâåğêà êîëè÷åñòâà áàğîâ íà äîñòàòî÷íîñòü äëÿ äàëüíåéøåãî ğàñ÷¸òà

if(Bars < MBand_Period + UpBand_Period + DnBand_Period)

return(0);

//---- İÌÓËßÖÈß ÈÍÄÈÊÀÒÎĞÍÛÕ ÁÓÔÅĞÎÂ

if(ArraySize(Ind_Buffer0) < Bars)

{

ArraySetAsSeries(Ind_Buffer0, false);

ArraySetAsSeries(Ind_Buffer1, false);

ArraySetAsSeries(Ind_Buffer2, false);

ArraySetAsSeries(Ind_Buffer3, false);

ArraySetAsSeries(Ind_Buffer4, false);

//----

ArrayResize(Ind_Buffer0, Bars);

ArrayResize(Ind_Buffer1, Bars);

ArrayResize(Ind_Buffer2, Bars);

ArrayResize(Ind_Buffer3, Bars);

ArrayResize(Ind_Buffer4, Bars);

//----

ArraySetAsSeries(Ind_Buffer0, true);

ArraySetAsSeries(Ind_Buffer1, true);

ArraySetAsSeries(Ind_Buffer2, true);

ArraySetAsSeries(Ind_Buffer3, true);

ArraySetAsSeries(Ind_Buffer4, true);

}

//----+ ÂÂÅÄÅÍÈÅ ÑÒÀÒÈ×ÅÑÊÎÉ ÖÅËÎÉ ÏÅĞÅÌÅÍÍÎÉ ÏÀÌßÒÈ

static int IndCounted;

//----+ Insertion of variables with a floating point

double Resalt0, Resalt1, Resalt2;

double price;

//----+ Insertion of integer variables and getting calculated bars

int limit, MaxBar,bar, counted_bars = IndicatorCounted();

int i,k;

//---- checking for possible errors

if(counted_bars < 0)

return(-1);

//---- the last calculated bar must be recalculated

if(counted_bars > 0)

counted_bars--;

//---- defining the number of the oldest bar,

// starting from which new bars will be recalculated

limit = Bars - counted_bars - 1;

//---- defining the number of the oldest bar,

// starting from which new bars will be recalculated

MaxBar = Bars - 1 - (MBand_Period + UpBand_Period + DnBand_Period);

//---- initialization of zero

if(limit > MaxBar)

{

limit = MaxBar;

for(bar = Bars - 1; bar >= MaxBar; bar--)

{

Ind_Buffer0 = 0.0;

Ind_Buffer1 = 0.0;

Ind_Buffer2 = 0.0;

Ind_Buffer3 = 0.0;

Ind_Buffer4 = 0.0;

}

}

//----+ THE FIRST CYCLE OF INDICATOR CALCULATION

i=Bars-DnBand_Period;

if(counted_bars>DnBand_Period) i=Bars-counted_bars-1;

while(i>=0)

{

i=Bars-DnBand_Period;

if(counted_bars>DnBand_Period) i=Bars-counted_bars-1;

while(i>=0)

{

double min=1000000;

k=i+DnBand_Period-1;

while(k>=i)

{

price=Resalt1[k];

if(min>price) min=price;

k--;

}

Ind_Buffer1=min;

i--;

}

}

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

{

// Here code of the variable Resalt0 calculation

// based on the values of the buffer UpBand[]

// and external variable0

Ind_Buffer3 =iMAOnArray(Ind_Buffer1,limit,DnBand_Period ,shift, ma_method,i);

}

//----+ THE SECOND CYCLE OF INDICATOR CALCULATION

{

i=Bars-UpBand_Period;

if(counted_bars>UpBand_Period) i=Bars-counted_bars-1;

while(i>=0)

{

double max=-1000000;

k=i+UpBand_Period-1;

while(k>=i)

{

price=Resalt2[k];

if(max<price) max=price;

k--;

}

Ind_Buffer2=max;

i--;

}

}

//---- signal line is simple movimg average

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

{

// Here code of the variable Resalt0 calculation

// based on the values of the buffer UpBand[]

// and external variable0

Ind_Buffer4 =iMAOnArray(Ind_Buffer2,limit,UpBand_Period,shift, ma_method,i);

}

//----+ THE MAIN CYCLE OF INDICATOR CALCULATION

//---- signal line is simple movimg average

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

{

// Here code of the variable Resalt0 calculation

// based on the values of the buffer UpBand[]

// and external variable0

Ind_Buffer0 =(Ind_Buffer2+Ind_Buffer1)/2;

}

return(0);

}

//+------------------------------------------------------------------+
Reason: