All tools

AI indicator generator (MQL5 and Pine Script)

Describe an indicator or strategy's logic in plain language and the AI generates ready-to-compile MQL5 (for MetaTrader) or Pine Script (for TradingView) code, with its explanation, parameters and install instructions. You compile and use the code under your own responsibility; always test it on Demo before going live.

How it works

  • · You describe the logic you want — 'arrows when two moving averages cross', for example.
  • · The AI generates the MQL5 or Pine Script code, with an explanation, parameters and how to install it.
  • · You copy or download it and compile it in MetaEditor or open it in TradingView. With an account you can iterate it with AI.

A real example

Example

Sample MQL5 indicator: arrows on a moving-average cross. With your account you generate it your way.

MQL5v1SMA Cross Arrows

What this indicator does

Draws a buy arrow when the fast moving average crosses above the slow one, and a sell arrow when it crosses below. It is a visual indicator: it does not open or close trades, it only marks the crosses on the chart.

Code

Checking that it compiles…

//+------------------------------------------------------------------+
//|                                          SMA_Cross_Arrows.mq5     |
//|  Buy/sell arrows on the cross of two simple moving averages.
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2

input int FastPeriod = 10;   // Fast moving average period
input int SlowPeriod = 50;   // Slow moving average period

double BuyBuffer[];
double SellBuffer[];
int    fastHandle, slowHandle;

int OnInit()
{
   SetIndexBuffer(0, BuyBuffer, INDICATOR_DATA);
   SetIndexBuffer(1, SellBuffer, INDICATOR_DATA);
   PlotIndexSetInteger(0, PLOT_ARROW, 233); // up arrow
   PlotIndexSetInteger(1, PLOT_ARROW, 234); // down arrow
   fastHandle = iMA(_Symbol, _Period, FastPeriod, 0, MODE_SMA, PRICE_CLOSE);
   slowHandle = iMA(_Symbol, _Period, SlowPeriod, 0, MODE_SMA, PRICE_CLOSE);
   return(fastHandle == INVALID_HANDLE || slowHandle == INVALID_HANDLE ? INIT_FAILED : INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total, const int prev_calculated, const int begin,
                const double &price[])
{
   double fast[], slow[];
   int toCopy = rates_total - prev_calculated + 1;
   if(CopyBuffer(fastHandle, 0, 0, toCopy, fast) <= 0) return(prev_calculated);
   if(CopyBuffer(slowHandle, 0, 0, toCopy, slow) <= 0) return(prev_calculated);

   int start = (prev_calculated > 1) ? prev_calculated - 1 : 1;
   for(int i = start; i < rates_total; i++)
   {
      BuyBuffer[i]  = EMPTY_VALUE;
      SellBuffer[i] = EMPTY_VALUE;
      if(fast[i-1] <= slow[i-1] && fast[i] > slow[i]) BuyBuffer[i]  = fast[i];
      if(fast[i-1] >= slow[i-1] && fast[i] < slow[i]) SellBuffer[i] = fast[i];
   }
   return(rates_total);
}

Configurable parameters

FastPeriod (int, default 10)

Fast moving average period.

SlowPeriod (int, default 50)

Slow moving average period.

How to install it

Save the file as .mq5, open it in MetaEditor and compile it (F7). Then drag it onto the chart from the MetaTrader 5 Navigator.

Warnings

Arrows are drawn at the close of the crossing candle; they do not repaint past candles.

Iterate on this indicator

Modifying what you generated with AI is a paid-plan feature. On the free plan you can generate, but not iterate on the result with AI.

Upgrade plan

AI-generated educational code. Review it and test it on a demo account before using it. This is not financial advice.

Ready to use it with your data?

Pine Script and MQL5 code generator with AI · SuaVar