You are on page 1of 2

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

//| CandleForce3.mq5 |
//| Copyright 2020, Phillipe S. Scofield |
//| https://mlatstudent.blogspot.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, Phillipe S. Scofield"
#property link "https://mlatstudent.blogspot.com/"
#property version "1.00"
#property description "Candle BEARxBULL Resultant Force 2"

#include <MovingAverages.mqh>

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 2
//+--------------------------------------------+
//| Volume Indicator drawing parameters |
//+--------------------------------------------+
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_color1 Red
#property indicator_width1 3
#property indicator_label1 "Force"
#property indicator_type2 DRAW_LINE
#property indicator_color2 Blue
#property indicator_width2 3
#property indicator_label2 "Force"

//+----------------------------------------------+
//| Indicator input parameters |
//+----------------------------------------------+
input double tailWeight=0.5; //Peso da sombra(0-1)
input double bodyWeight=0.75; //Peso do corpo(0-1)
input bool useVolume=false; //Considerar volume?
input int meanPeriod = 10; //Período da média

double forceBuffer[];
double resultantForceBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator config
IndicatorSetInteger(INDICATOR_DIGITS,2);

SetIndexBuffer(0,forceBuffer,INDICATOR_DATA);
SetIndexBuffer(1,resultantForceBuffer,INDICATOR_DATA);
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,4);
//----
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, // number of bars in history at the
current tick
const int prev_calculated,// number of bars calculated at previous
call
const datetime &time[],
const double &open[],
const double &high[], // price array of maximums of price for
the indicator calculation
const double &low[], // price array of minimums of price for
the indicator calculation
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
int limit;
if(prev_calculated==0)
limit=0;
else limit=prev_calculated-1;

if(IsStopped()) return(0); //Checking for stop flag

//--- the main loop of calculations


for(int i=limit+3;i<rates_total && !IsStopped();i++)
{

double Open=open[i-2];
double Close=close[i];
double High=MathMax(high[i-2],high[i]);
double Low=MathMin(low[i-2],low[i]);

double highTail= 0;
double lowTail = 0;
double volumeGrad = (double)MathSqrt(volume[i]);
if(Close>Open)
{
highTail= High-Close;
lowTail = Open-Low;
}
else
{
highTail= High-Open;
lowTail = Close-Low;
}
double body=Close-Open;
if(useVolume)
{
forceBuffer[i] = (bodyWeight*body + tailWeight*(lowTail-
highTail))*volumeGrad;
}
else
{
forceBuffer[i] = bodyWeight*body + tailWeight*(lowTail-highTail);
}

ExponentialMAOnBuffer(rates_total,prev_calculated,0,meanPeriod,forceBuffer,resultan
tForceBuffer);
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+

You might also like