Help with first indicator, having trouble getting line to plot

 

Hello, I have what I know is a very basic problem, but I can't seem to figure out how to use the object draw function to create a line.

As you can see below, I'm using an if statement to determine if the current price is close to the 5 minute moving average. If it is, the count variable is assigned a value of 1. I then want a separate window below the price to plot a line at either 0 or 1 to show at what points the price is close to the moving average.

When creating the new indicator, the parameters I had to enter had me choose the line type and color as well as the fact that I want the window to be separate from the chart. Unfortunately I can't seem to figure out how to actually plot it from here.

Reading the documentation I'm having trouble figuring out how to use the object draw function to do so. At first I thought just assigning the value to the TestIndicatorBuffer[0] would plot it at the current bar, but I see now that I have to use the objectdraw function. Though since I already defined the line type, color, and style at the top of the code, would it be redundant to declare those values again in the objectdraw function? If someone could give me an example of how to plot it from here I would be very appreciative.

Also, is there any suggested documentation for how to learn this? I am an amateur programmer with a little experience with C# and C++, but all of the tutorials I can find for MQL4 assume I know everything and they basically just copy and paste code and explain vaguely what each block of code does. I tried also reading the reference which shows the definition of each function but not how to put it all together.


#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_minimum 1
#property indicator_maximum 100
#property indicator_buffers 1
#property indicator_plots   1
//--- plot TestIndicator
#property indicator_label1  "TestIndicator"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrPurple
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      marginPercent;

//--- indicator buffers
double         TestIndicatorBuffer[];

int      marginMultiplier;
int      count;
double      indicator1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,TestIndicatorBuffer);



marginMultiplier = 100 / marginPercent + 1;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---
      indicator1 = iMA(_Symbol, PERIOD_M1, 5, 0, 0, 0, 0);
      if (Close[0] > indicator1 && close[0] < indicator1 * marginMultiplier)
      {
      count = 1;
      }
      
      TestIndicatorBuffer[0] = count;
      
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
You are setting count to one. Once set, it will always be that — thus a straight line at the bottom.
 
I know, that's just so I can test that it's working. Once I can get a line plotted on a chart I'm going to add the rest of the code. I've never used MQL4 before so I'm trying to understand how buffering works and how to plot values onto charts.
 
I figured it out, didn't realize I had to put the buffer inside of a for loop.
Reason: