gpt-4-0314· openai
Suzhen/CodeChat
i need to write a code in mt4 by mql4 that show me price pivot in eur/usd chart .
- User
i need to write a code in mt4 by mql4 that show me price pivot in eur/usd chart .
- Assistant
i need to write a code in mt4 by mql4 that show me price pivot in eur/usd chart .
To create a simple pivot point indicator in MT4 using MQL4, follow these steps:
//+------------------------------------------------------------------+
//| PivotPoint.mq4|
//| Copyright 2021, MetaQuotes Software Corp.|
//| https://www.mql5.com|
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 MediumBlue
double Pivot[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,Pivot);
SetIndexLabel(0,"Pivot");
IndicatorShortName("Pivot Point");
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[])
{
int i, limit;
if(prev_calculated == 0)
limit = rates_total - 1;
else
limit = rates_total - prev_calculated;
for(i = limit; i >= 0; i--)
{
double h = high[i];
double l = low[i];
double c = close[i];
Pivot[i] = (h + l + c) / 3.0;
}
return(rates_total);
}
//+------------------------------------------------------------------+
Please keep in mind that this is just a simple pivot point indicator, and there are many other ways to calculate pivot points and additional support and resistance levels. You can modify the code as needed to match your desired calculations and appearance.