0% ont trouvé ce document utile (0 vote)
37 vues2 pages

TrendColorreview2 mq5

Code HTML pour créer un indicateur

Transféré par

Orlane LOKO
Copyright
© © All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats TXT, PDF, TXT ou lisez en ligne sur Scribd
0% ont trouvé ce document utile (0 vote)
37 vues2 pages

TrendColorreview2 mq5

Code HTML pour créer un indicateur

Transféré par

Orlane LOKO
Copyright
© © All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats TXT, PDF, TXT ou lisez en ligne sur Scribd

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

//| TrendColor.mq5|
//| Copyright 2024, MetaQuotes Software Corp. |
//| [Link] |
//+------------------------------------------------------------------+
#property strict

// Define input parameters


input int FastMA = 12;
input int SlowMA = 26;

// Declare global variables


int FastMAHandle;
int SlowMAHandle;

//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Create moving averages
FastMAHandle = iMA(_Symbol, _Period, FastMA, 0, MODE_SMA, PRICE_CLOSE);
SlowMAHandle = iMA(_Symbol, _Period, SlowMA, 0, MODE_SMA, PRICE_CLOSE);

if (FastMAHandle == INVALID_HANDLE || SlowMAHandle == INVALID_HANDLE)


{
Print("Error creating Moving Averages");
return(INIT_FAILED);
}

return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// Release moving averages
if (FastMAHandle != INVALID_HANDLE)
IndicatorRelease(FastMAHandle);
if (SlowMAHandle != INVALID_HANDLE)
IndicatorRelease(SlowMAHandle);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double FastMAValue[], SlowMAValue[];

// Get the last values of the moving averages


if (CopyBuffer(FastMAHandle, 0, 0, 1, FastMAValue) <= 0 ||
CopyBuffer(SlowMAHandle, 0, 0, 1, SlowMAValue) <= 0)
{
Print("Error retrieving Moving Average values");
return;
}

// Determine the market tendency


if (FastMAValue[0] > SlowMAValue[0])
{
// Uptrend
ColorBackground(clrGreen);
}
else if (FastMAValue[0] < SlowMAValue[0])
{
// Downtrend
ColorBackground(clrRed);
}
else
{
// Sideways
ColorBackground(clrYellow);
}
}
//+------------------------------------------------------------------+
//| Color the background |
//+------------------------------------------------------------------+
void ColorBackground(color clr)
{
ChartSetInteger(0, CHART_COLOR_BACKGROUND, clr);
}

Vous aimerez peut-être aussi