What's new

hi this indicator good

Md rawaha

New Member
//+------------------------------------------------------------------+
//| TrendArrowPro |
//| Trend-Following Arrow Indicator |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2

// Buy Arrow
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrLime
#property indicator_width1 2
#property indicator_label1 "Buy Arrow"
// Sell Arrow
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrRed
#property indicator_width2 2
#property indicator_label2 "Sell Arrow"

//--- input parameters
input int FastEMA = 20;
input int SlowEMA = 50;
input int ATR_Period = 14;
input double ATR_Multiplier = 1.2;
input bool Show_Arrows = true;
input bool Alert_On_Signal = true;

//--- indicator buffers
double BuyBuffer[];
double SellBuffer[];

//--- indicator handles
int handleFastEMA, handleSlowEMA, handleATR;

//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0, BuyBuffer);
SetIndexBuffer(1, SellBuffer);

PlotIndexSetInteger(0, PLOT_ARROW, 233); // Up arrow (wingdings)
PlotIndexSetInteger(1, PLOT_ARROW, 234); // Down arrow

ArrayInitialize(BuyBuffer, EMPTY_VALUE);
ArrayInitialize(SellBuffer, EMPTY_VALUE);

//--- create indicator handles
handleFastEMA = iMA(_Symbol, _Period, FastEMA, 0, MODE_EMA, PRICE_CLOSE);
handleSlowEMA = iMA(_Symbol, _Period, SlowEMA, 0, MODE_EMA, PRICE_CLOSE);
handleATR = iATR(_Symbol, _Period, ATR_Period);

if (handleFastEMA == INVALID_HANDLE || handleSlowEMA == INVALID_HANDLE || handleATR == INVALID_HANDLE)
{
Print("Failed to create indicator handles");
return INIT_FAILED;
}

return INIT_SUCCEEDED;
}
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
if (rates_total < MathMax(SlowEMA, ATR_Period) + 10)
return 0;

double fastEMA[], slowEMA[], atr[];
ArraySetAsSeries(fastEMA, true);
ArraySetAsSeries(slowEMA, true);
ArraySetAsSeries(atr, true);

CopyBuffer(handleFastEMA, 0, 0, rates_total, fastEMA);
CopyBuffer(handleSlowEMA, 0, 0, rates_total, slowEMA);
CopyBuffer(handleATR, 0, 0, rates_total, atr);

for (int i = rates_total - 100; i >= 0; i--)
{
BuyBuffer = EMPTY_VALUE;
SellBuffer = EMPTY_VALUE;

// Check if enough data is available
if (i + ATR_Period >= rates_total) continue;

// Calculate average ATR
double avgATR = 0.0;
for (int j = 0; j < ATR_Period; j++)
avgATR += atr[i + j];
avgATR /= ATR_Period;

bool strongVolatility = atr > avgATR * ATR_Multiplier;

// BUY condition
if (fastEMA > slowEMA && strongVolatility)
{
if (Show_Arrows)
BuyBuffer = Low - (10 * _Point);
if (Alert_On_Signal && i == 0)
Alert("BUY Signal on ", Symbol(), " at ", TimeToString(TimeCurrent(), TIME_DATE | TIME_MINUTES));
}

// SELL condition
if (fastEMA < slowEMA && strongVolatility)
{
if (Show_Arrows)
SellBuffer = High + (10 * _Point);
if (Alert_On_Signal && i == 0)
Alert("SELL Signal on ", Symbol(), " at ", TimeToString(TimeCurrent(), TIME_DATE | TIME_MINUTES));
}
}

return rates_total;
}
//+------------------------------------------------------------------+
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Members Online

No members online now.

Similar threads

Replies
1
Views
381

Users Who Are Viewing This Thread (Total: 1, Members: 0, Guests: 1)

Top