plot own array values onto the chart

 

Hi

This mql5 code failed to plote the values of myArray unto the chart, could someone please help find why?

Thank you


#property indicator_buffers 1
#property indicator_plots   1 
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDodgerBlue
double    myArray[];

int OnInit() {
  SetIndexBuffer(0, myArray, INDICATOR_DATA);
  //... other stuff
  return(INIT_SUCCEEDED);
}

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) {
  if(id==CHARTEVENT_CLICK) {

    myClassInst.fillArray(myArray); //populates the array, but it does not plot the line as I expected. how to fix it?
 
samjesse:

This mql5 code failed to plote the values of myArray unto the chart, could someone please help find why?

First, you need this line at the top, to indicate where you want the plot to appear:

#property indicator_chart_window

Next, you need this line to set the array's index to begin from the latest bar (default is from the earliest bar):

  ArraySetAsSeries(myArray,true);

Finally, you need this line (after you fill your array) to get your chart to redraw, especially during the weekend when there is no tick coming in:

    ChartRedraw();
 

Seng. Thanks but the modified code after your suggestions did not fix the problem. Any suggestions? Thanks


#property indicator_chart_window 
#property indicator_buffers 1
#property indicator_plots   1 
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDodgerBlue
double    myArray[];

int OnInit() {
  SetIndexBuffer(0, myArray, INDICATOR_DATA); //switching places of this line with the next did not fix the problem either
  ArraySetAsSeries(myArray, true);
}

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) {
  if(id==CHARTEVENT_CLICK) {

    myClassInst.fillmyArray(myArray);
    ChartRedraw();
 }
}



    void fillLevelBuffer(double &arr[]){
      Print("will fill the array");		//shows the size ok
      int size = ArraySize(arrWithData);
      ArrayResize(arr, size);
      for(int i = 0; i < size; i++){
        arr[i] = arrWithData[i] - (158*_Point);
        Print(arr[i]);				//prints the value ok
      }
    }
 

MQL5: Create Your Own Indicator. Already sent you there

The first thing we see

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//---- plot TSI
#property indicator_label1  "TSI"
#property indicator_type1   DRAW_LINE
#property indicator_color1  Blue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
 
Konstantin Nikitin:

MQL5: Create Your Own Indicator. Already sent you there

The first thing we see

Thanks Konstantin, I followed your link and tried to deduce what I need from the code to fix my problem for no avail, even with the suggestions you posted, I am still getting no plot. Any other suggestions? Thanks :)

 
samjesse:

Seng. Thanks but the modified code after your suggestions did not fix the problem. Any suggestions? Thanks

Here's my test code:

#property indicator_chart_window

#property indicator_buffers 1
#property indicator_plots   1 
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDodgerBlue
double    myArray[];

int OnInit() {
  SetIndexBuffer(0, myArray, INDICATOR_DATA);
  //IndicatorSetString(INDICATOR_SHORTNAME,"myArray");
  ArraySetAsSeries(myArray,true);
  //... other stuff
  return(INIT_SUCCEEDED);
}

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) {
  if(id==CHARTEVENT_CLICK) {
    Print ("ChartEvent!");

    //myClassInst.fillArray(myArray); //populates the array, but it does not plot the line as I expected. how to fix it?
    for (int i=0; i<10; i++)
       myArray[i] = iClose(_Symbol,_Period,i);
    ChartRedraw();
  }
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   return (rates_total);
}

What I've done is to fix the "structural" issues for it to be able to display something, so that you can learn from there. As for it to work the way you wanted, you'll have to define what you mean by myClassInst and arrWithData. These are things I wouldn't be able to fix for you.

What you can do is to add things one step at a time, each time making sure it is still able to display something, then proceed.

 
Open project "New_Indicators"
Files:
Reason: