MT4 to AFL

#1
Hi

afl conversion help needed:
Code:
//+-------------------------------------------------------------------------------------------+
//|                                                                                           |
//|                                   SonicR PVA Candles.mq4                                  |
//|                                                      				                         |
//+-------------------------------------------------------------------------------------------+
#property copyright "Copyright @ 2013 traderathome"
#property link      "email: [email protected]"
 
/*---------------------------------------------------------------------------------------------
Overview, _v1:

This indicator creates PVA (Price Volume Analysis) color coded standard candlesticks. 

1. PVA Candles-   
   The candle bars have special colors for special situations regarding individual candle
   range, individual candle volume and average volume, and are designed to be used in 
   conjuction with the co-released SonicR PVA Volumes indicator.  PVA Candle bars emphasized 
   with special colors for special situations help you quickly associate any candle to the 
   corresponding PVA volume bar of the same color.
   A. Candle Bars for Climax Candles
      Candle bars where volume is >= "Extreme_Factor" percent of the average volume of the 
      "Climax_Period" number of the most recent previous candles, and candle bars where the 
      product of candle spread x candle volume is highest for the "Climax_Period" number of  
      the most recent previous candles.  Bull candles are green and bear candles are red.    
   B. Candle Bars for Candles With Volume Rising Above Average 
      Candle bars where volume is >= "Rising_Factor" percent of the average volume of the 
      "Climax_Period" number of the most recent previous candles.  Bull candles are blue and 
      bear are blue-violet, but both can be displayed blue.         
   C. Colors Display
      The coding of colors allows the user to alter any color.  But this must be done on 
      the "Inputs" tab, not the "Colors" tab.

2. Selecting the Width of the Candle Bars-
   MT4 has six chart zoom settings referred to as number selections 1 thru 6 as you zoom a 
   chart in, going from thinnest to thickest bars.  Use numbers 1-6 in the external input
   "Chart_Zoom_0123456" to manually control bar widths. Use "1 or 2" for zoomed out 
   charts (thinnest bars).  Use "3" for the Mt4 default chart zoom.  Use "4,5, or 6" for
   zoomed in charts (wider bars).  Use "0" to get the bar width externally, meaning from
   another indicator (i.e., the Dragon indicator).  If the setting for "Chart_Zoom_0123456" 
   is not between 0-6, it defaults to "3". 
   
   The proper sequence to follow is....
   A. First, enter the "Chart_Zoom_0123456" input you want.
   B. Second, use the MT4 icons "+/-" to zoom the chart in/out, per the input you made.
   C. Switch chart TF once to reset the chart to your "Chart_Zoom_0123456" input.
       
   Setting "Chart_Zoom_0123456" to "0" turns control of bar widths over to the SonicR
   Filled Dragon indicator, so when you want to zoom in/out on the chart you only need to
   change your zoom setting in that indicator.  The SonicR Filled Dragon indicator does not
   have to be turned on for the SonicR PVA Candles indicator to be slaved to it's zoom 
   setting.  It only has to be included in the chart list of indicators above this indicator.
   If the SonicR Filled Dragon indicator is not included in the list of chart indicators, 
   then "Chart_Zoom_0123456" should be set to the 1-6 number appropriate to how you have 
   zoomed in/out on the chart. 
      
   The SonicR Control Panel special Bid Line and Bid Dot use different hard code values
   that depend on the chart zoom setting, which this indicator provides if it is used to
   control the chart zoom setting instead of the SonicR Filled Dragon, i.e. if the 
   SonicR Filled Dragon is either not on the chart list of indicators or this PVA Candles
   indicator is not slaved to it.       

3. Chart Properties Settings-
   To see Candles displayed as intended, be sure in chart Properties on the Common tab you 
   have selected "Chart on foreground" and "Line chart", and on the Colors tab be sure the 
   color for "Line graph" is "None".
   
4. On/Off & Display Range-   
   The indicator can be turned on/off without having to remove it from the chart, thereby 
   preserving your chart settings.
   
Changes from VSA Candlesticks release 05-01-2012 to current release 05-25-2013 of this indy:
01 - Removed the automatic zoom feature. 
02 - Revised the manual zoom feature.  Bar widths can now be controlled by the SonicR
     Filled Dragon indicator if used.  Otherwise this indicator controls it's bar widths and 
     the bar widths of the SonicR PVA Volumes indicator, and also controls spacing of the
     special Bid Line and Bid Dot in the SonicR Control Panel.
02 - PVA "Rising Volume" Bull/bear candles now have Bull/bear colors.
   - Classifies "Rising Volume" candles that are >= "Extreme_Factor" percent of the average 
     volume as "Climax".
   - Shifts the averaging period for "Rising Volume" by one TF.
03 - Provides easy access to colors used.  

                                                                    - Traderathome, 05-25-2013
-----------------------------------------------------------------------------------------------
Acknowledgements:
BetterVolume.mq4 - for "climax" candle code definition (BetterVolume_v1.4). 
                                                                    
----------------------------------------------------------------------------------------------
Suggested Colors            White Chart        Black Chart        Remarks
 
indicator_color1            C'015,015,068'     Gray               Candle Wicks Up
indicator_color2            C'015,015,068'     Gray               CandleWicks Dn
indicator_color3            C'163,163,163'     C'163,163,163'     Bull STD Candle 
indicator_color4            C'100,100,100'     C'100,100,100'     Bear STD Candle
indicator_color5            C'045,081,206'     C'062,158,255'     Bull Rising
indicator_color6            C'154,038,232'     C'173,051,255'     Bear Rising                                                           
indicator_color7            C'000,151,090'     C'031,192,071'     Bull Climax                      
indicator_color8            C'222,018,080'     C'231,001,006'     Bear Climax                      
 
Note: Suggested colors coincide with the colors of the SonicR PVA Volumes indicator.                                                            
---------------------------------------------------------------------------------------------*/


//+-------------------------------------------------------------------------------------------+
//| Indicator Global Inputs                                                                   |                                                        
//+-------------------------------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 8
     
#property indicator_color1  Gray      
#property indicator_color2  Gray
#property indicator_color3  C'163,163,163'      
#property indicator_color4  C'100,100,100'
#property indicator_color5  C'062,158,255'
#property indicator_color6  C'173,051,255'
#property indicator_color7  C'031,192,071'  
#property indicator_color8  C'231,001,006'

//Global External Inputs 
extern bool   Indicator_On                    = true;
extern int    Chart_Zoom_0123456              = 0;
extern color  Bull_Wick                       = Gray;
extern color  Bear_Wick                       = Gray;   
extern color  Bull_Candle                     = C'163,163,163';
extern color  Bear_Candle                     = C'100,100,100';    
extern color  Bull_Rising                     = C'062,158,255';     
extern color  Bear_Rising                     = C'173,051,255'; 
extern color  Bull_Climax                     = C'031,192,071';  
extern color  Bear_Climax                     = C'231,001,006';   

//Global Buffers and Variables
bool   Deinitialized;    
double Bar1[],Candle1[],Bar2[],Candle2[],bodyHigh,bodyLow,	   
       RisingBull[],RisingBear[],ClimaxBull[],ClimaxBear[],
       av,Range,Value2,HiValue2,tempv2,high,low,open,close;              
int    Bar_Width,va,i,j,n,shift1,shift2,time1,counted_bars,limit,lastzoom; 
int    PVA_Color_Set_123               = 1; 
int    PVA_Climax_Period               = 10; 
int    PVA_Rising_Period               = 10;
double PVA_Rising_Factor               = 1.5;
double PVA_Extreme_Factor              = 2.0;

//Global Variable Controlling Bar Widths
string Zoom = "Zoom_Setting";
string Bar = "Bar_Setting";
  
//+-------------------------------------------------------------------------------------------+
//| Custom indicator initialization function                                                  |
//+-------------------------------------------------------------------------------------------+
int init()
  {
  Deinitialized = false;

  //Use Global or Internal instructions for bar widths
  if(Chart_Zoom_0123456 == 0)
    {
    //Get GV Bar Widths for candle bars
    Bar_Width = GlobalVariableGet(Bar); 
    }        
  else 
    {
    //Manually Adjust Width                    
    if(Chart_Zoom_0123456 < 0 || Chart_Zoom_0123456 >6) {Chart_Zoom_0123456 = 3;}    
          if(Chart_Zoom_0123456 == 1) {Bar_Width = 1;}
    else {if(Chart_Zoom_0123456 == 2) {Bar_Width = 2;}      
    else {if(Chart_Zoom_0123456 == 3) {Bar_Width = 2;}
    else {if(Chart_Zoom_0123456 == 4) {Bar_Width = 3;}
    else {if(Chart_Zoom_0123456 == 5) {Bar_Width = 6;}
    else {Bar_Width = 13;} }}}}
       
    //Set bar widths for use by PVA Volumes indicator 
    GlobalVariableSet(Bar, Bar_Width); 
    
    //Set Chart Zoom for use by Control Panel and Trade Levels indicators 
    GlobalVariableSet(Zoom, Chart_Zoom_0123456);             
    }
      
  //Indicators
  //PVA: Normal bodies and wicks         
  SetIndexBuffer(0,Bar1);
  SetIndexStyle(0,DRAW_HISTOGRAM, 0, 1, Bull_Wick);   
  SetIndexBuffer(1,Bar2);  
  SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1, Bear_Wick);   			
  SetIndexBuffer(2,Candle1);
  SetIndexStyle(2,DRAW_HISTOGRAM, 0, Bar_Width, Bull_Candle);  
  SetIndexBuffer(3,Candle2);  
  SetIndexStyle(3,DRAW_HISTOGRAM, 0, Bar_Width, Bear_Candle);    
  //PVA: Rising volume bodies
  SetIndexBuffer(4, RisingBull);
  SetIndexStyle(4, DRAW_HISTOGRAM, 0, Bar_Width, Bull_Rising);
  SetIndexBuffer(5, RisingBear);                           
  SetIndexStyle(5, DRAW_HISTOGRAM, 0, Bar_Width, Bear_Rising);       
  //PVA: Climax volume bodies    
  SetIndexBuffer(6, ClimaxBull);
  SetIndexStyle(6, DRAW_HISTOGRAM, 0, Bar_Width, Bull_Climax); 
  SetIndexBuffer(7, ClimaxBear);        
  SetIndexStyle(7, DRAW_HISTOGRAM, 0, Bar_Width, Bear_Climax);                            
                
  //Indicator ShortName   
  IndicatorShortName("SonicR PVA Candles");        
 	       	 		
  return(0);
  }
   
//+-------------------------------------------------------------------------------------------+
//| Custom indicator deinitialization function                                                |
//+-------------------------------------------------------------------------------------------+    
int deinit()
  {
  return(0);
  }
   
//+-------------------------------------------------------------------------------------------+
//| Custom indicator iteration function                                                       |
//+-------------------------------------------------------------------------------------------+
int start()
  {
  //If Indicator is "Off" deinitialize only once, not every tick 
  if (!Indicator_On) 
    {
    if (!Deinitialized) {deinit(); Deinitialized = true;}
    return(0);
    }

  //Otherwise indicator is "On" & chart TF is in display range, so proceed              
  Deinitialized = false;
  
  //Confirm range of chart bars for calculations   
  //check for possible errors
  counted_bars = IndicatorCounted();
  if(counted_bars < 0)  return(-1);     
  //last counted bar will be recounted
  if(counted_bars > 0) counted_bars--;    
  limit = Bars - counted_bars;
  
  //Begin the loop of calculations for the range of chart bars. 
  for(i = limit - 1; i >= 0; i--)       
    {              
    //First, calculate OHLC etc., to construct standard candle     
	 shift1  = iBarShift(NULL,0,Time[i]);
	 time1   = iTime    (NULL,0,shift1);
	 shift2  = iBarShift(NULL,0,time1);
	 high    = iHigh(NULL,0,shift1);
    low     = iLow(NULL,0,shift1);
	 open    = iOpen(NULL,0,shift1);
	 close   = iClose(NULL,0,shift1);
	 bodyHigh= MathMax(open,close);
	 bodyLow = MathMin(open,close);
			 
	 if(close>open)
		{
	   Bar1[shift2] = high;		Candle1[shift2] = bodyHigh;
	   Bar2[shift2] = low;		Candle2[shift2] = bodyLow;
		}
	 else if(close<open)
		{
	 	Bar1[shift2] = low;		Candle1[shift2] = bodyLow;
		Bar2[shift2] = high;		Candle2[shift2] = bodyHigh;
		}
	 else //(close==open)
	   {	
		Bar1[shift2] = low;		Candle1[shift2] = close;
		Bar2[shift2] = high;		Candle2[shift2] = open-0.000001;
      }
           
    //Compute Average Volume and Volume Rising Above Average  
    //Clear buffers
    RisingBull[i] = 0;
    RisingBear[i] = 0;
    ClimaxBull[i] = 0;
    ClimaxBear[i] = 0;
    Value2        = 0;  
    HiValue2      = 0; 
    tempv2        = 0;
    av            = 0;
    va            = 0;      
                 
    //Rising Volume   
    for (j = i+1; j < (i+PVA_Rising_Period); j++) {av = av + Volume[j];}   
    av = av / PVA_Rising_Period;
    if (Volume[i] >= av * PVA_Rising_Factor) {va= 2;} 
                                   
    //Climax Volume                      
    Range = (High[i]-Low[i]);
    Value2 = Volume[i]*Range;                 
    for (n=i+1;n<i+PVA_Climax_Period;n++)
      {
      tempv2 = Volume[n]*((High[n]-Low[n])); 
      if (tempv2 >= HiValue2) {HiValue2 = tempv2;}    
      } 
    if((Value2 >= HiValue2) || (Volume[i] >= av * PVA_Extreme_Factor)) {va= 1;}                    
             
    //Apply Correct Color to Candle
    if (va==1)
      {
      ClimaxBull[i]=iClose(0,0,i);
      ClimaxBear[i]=iOpen(0,0,i);
      if(iClose(0,0,i) == iOpen(0,0,i)) {ClimaxBear[i]=iOpen(0,0,i)+0.000001;}
      }
    else if (va==2)
      {
      RisingBull[i]=iClose(0,0,i);
      RisingBear[i]=iOpen(0,0,i);
      if(iClose(0,0,i) == iOpen(0,0,i)) {RisingBear[i]=iOpen(0,0,i)+0.000001;}  
      }
    }    
                         
  return(0);
  }

//+-------------------------------------------------------------------------------------------+
//|Custom indicator end                                                                       |
//+-------------------------------------------------------------------------------------------+
 

rvlv

Active Member
#2
hope somebody can put this in afl form
somebody who knows mt4 can do it easily.
can somebody help start the code
then other expert can push it through
-----------------------------------------------
HTML:
bullclimax =C>Ref(C,1) AND V/MA(V,10)>=2.0 ;
bullrising = C>Ref(C,-1) AND V/MA(V,10)>=1.5 ;
bearrising = C<Ref(C,-1) AND V/MA(V,10) >=1.5 ;
bearclimax = C <Ref(C,-1) AND V/MA(V,10) >=2.0 ;
//These are the basic conditions

Plot( Volume, _DEFAULT_NAME(), IIf( bullclimax, ParamColor("bull climax Color", colorAqua ), IIf( bearclimax, ParamColor("bear climax Color", colorYellow ,colorGrey50 ,ParamStyle( "Style", styleHistogram | styleThick, maskHistogram ));
bullclimax =C>Ref(C,1) AND V/MA(V,10)>=2.0 ;
bullrising = C>Ref(C,-1) AND V/MA(V,10)>=1.5 ;
bearrising = C<Ref(C,-1) AND V/MA(V,10) >=1.5 ;
bearclimax = C <Ref(C,-1) AND V/MA(V,10) >=2.0 ;
//These are the basic conditions

Plot( Volume, _DEFAULT_NAME(), IIf( bullclimax, ParamColor("bull climax Color", colorAqua ), IIf( bearclimax, ParamColor("bear climax Color", colorYellow ,colorGrey50 ,ParamStyle( "Style", styleHistogram | styleThick, maskHistogram ));

This plot line has error.
can somebody fix it please
once it is fixed you have basic skeleton afl.


HERE IS A STARTING POINT SIMPLE AFL
========================================
bullclimax =C>Ref(C,1) AND V/MA(V,10)>=2.0 ;
bullrising = C>Ref(C,-1) AND V/MA(V,10)>=1.5 ;
bearrising = C<Ref(C,-1) AND V/MA(V,10) >=1.5 ;
bearclimax = C <Ref(C,-1) AND V/MA(V,10) >=2.0 ;
//These are the basic conditions


ColorHighliter = IIf(bullclimax, colorAqua,IIf(bearclimax, colorYellow,colorGrey50));

Plot(Volume,"volume",Colorhighliter, styleHistogram | styleThick, maskHistogram );
//THIS PLOTS VOLUME HISTOGRAM
--------------------------------------------------------------------------------------------------------

//================================================================


//+-------------------------------------------------------------------------------------------+
//| |
//| SonicR PVA Volumes.mq4 |
//| |
//+-------------------------------------------------------------------------------------------+
#property copyright "Copyright © 2013 traderathome"
#property link "email: [email protected]"

/*---------------------------------------------------------------------------------------------
Overview, _v1:

This indicator creates a PVA (Price Volume Analysis) color coded volume histogram.

1. PVA Volumes-
The volume bars have special colors for special situations regarding individual candle
range, individual candle volume and average volume, and are designed to be used in
conjuction with the co-released SonicR PVA Candles indicator. Volume bars emphasized
with special colors for special situations help you quickly associate a volume bar to the
corresponding candle of the same colors.
A. Volume Bars for Climax Candles
Volume bars where volume is >= "Extreme_Factor" percent of the average volume of the
"Climax_Period" number of the most recent previous bars, and volume bars where the
product of candle spread x candle volume is highest for the "Climax_Period" number of
the most recent previous bars. Volume bars for bull candles are green and for bear
cndles are red. The volume bars qualifying as "Climax" bars can trigger an alert.
b. Volume Bars for Candles With Volume Rising Above Average
Volume bars where volume is >= "Rising_Factor" percent of the average volume of the
"Rising_Period" number of the most recent previous bars. Volume bars for bull candles
are blue and for bear candles are blue-violet.
C. Colors Display
The coding of colors allows the user to alter any color. But this must be done on
the "Inputs" tab, not the "Colors" tab.

2. Selecting the Width of the Volume Bars-
MT4 has six chart zoom settings referred to as number selections 1 thru 6 as you zoom a
chart in, going from thinnest to thickest bars. Use numbers 1-6 in the external input
"Chart_Zoom_0123456" to manually control bar widths. Use "1 or 2" for zoomed out
charts (thinnest bars). Use "3" for the Mt4 default chart zoom. Use "4,5, or 6" for
zoomed in charts (wider bars). Use "0" to get the bar width externally, meaning from
another indicator (i.e., the Filled Dragon or PVA Candles indicator). If the setting
for "Chart_Zoom_0123456" is not between 0-6, it defaults to "3".

The proper sequence to follow is....
A. First, enter the "Chart_Zoom_0123456 " input you want.
B. Second, use the MT4 icons "+/-" to zoom the chart in/out, per the input you made.
C. Switch chart TF once to reset the chart to your "Chart_Zoom_0123456" input.

Setting "Chart_Zoom_0123456" to "0" turns control of bar widths over to the
SonicR Filled Dragon indicator, so when you want to zoom in/out on the chart you only
have to change your zoom setting in that indicator. The SonicR Filled Dragon indicator
does not have to be turned on for the SonicR PVA Volumes indicator to be slaved to it's
zoom setting. however, if the SonicR Filled Dragon indicator is not in the list of chart
indicators, then the SonicR PVA Volumes indicator is automatically slaved to the
SonicR PVA Candles indicator instead, if it is on the chart list of indicators, whether
it is turned on or off. If neither the SonicR Filled Dragon nor the SonicR PVA Candles
indicators are included in the list of chart indicators then "Chart_Zoom_0123456" should
be set to the appropriate number (1-6) based to how you have zoomed in/out on the chart.

3. Setting the Volume Alert-
This indicator includes the MT4 sound with text alert that will trigger once per TF at
the first qualification of the volume bar as a PVA Climax volume bar in the PVA mode, or
as an Extreme volume bar in the SRV mode. Set the input "Volume_Alert_On" to "true" to
activate the alert. Use "Broker_Name_In_Alert" to input your broker name so it will
appear in the on-screen alert. This helps to avoid confusion if you are simultaneously
using multiple MT4 platforms from different brokers.

4. On/Off & Display Range-
The indicator can be turned on/off without having to remove it from the chart, thereby
preserving your chart settings.

Changes from VSA Histogram indy released 05-01-2012 to release 05-25-2013 of this new indy:
01 - Removed the automatic zoom feature and revised the manual zoom feature. Bar widths can
now be slaved to the SonicR Solid Dragon or SonicR PVA Candles indicators.
02 - PVA "Rising Volume" Bull/bear candles now have Bull/bear colors.
- Classifies "Rising Volume" candles that are >= "Extreme_Factor" percent of the average
volume as "Climax".
- Shifts the averaging period for "Rising Volume" by one TF.
03 - Provides easy access to colors used.
05 - Revises Alert code so it now works on all TFs (including M1) and adds an External Input
so the broker name can appear in the text alert (helpful if running multiple MT4s), and
eliminates the "sound only" alert.

- Traderathome, 05-25-2013
-----------------------------------------------------------------------------------------------
Acknowledgements:
BetterVolume.mq4 - for "climax" candle code definition (BetterVolume_v1.4).

----------------------------------------------------------------------------------------------
Suggested Colors White Chart Black Chart Remarks

indicator_color1 C'113,131,149' C'102,099,163' Normal Volume
indicator_color2 C'045,081,206' C'062,158,255' Bull Rising
indicator_color3 C'154,038,232' C'173,051,255' Bear Rising
indicator_color4 C'000,151,090' C'033,207,077' Bull Climax
indicator_color5 C'208,017,074' C'231,001,006' Bear Climax

Note: Suggested colors coincide with the colors of the SonicR Suite of Candles indicator.
---------------------------------------------------------------------------------------------*/


//+-------------------------------------------------------------------------------------------+
//| Indicator Global Inputs |
//+-------------------------------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 5

#property indicator_color1 C'113,131,149'
#property indicator_color2 C'45,81,206'
#property indicator_color3 C'154,038,232'
#property indicator_color4 C'000,151,090'
#property indicator_color5 C'208,017,074'
//----
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 2
//----
//Global External Inputs
extern bool Indicator_On = true;
extern int Chart_Zoom_0123456 = 0;
extern bool Volume_Alert_On = true;
extern string Broker_Name_In_Alert = "";
extern color Std_Volume = C'113,131,149';
extern color Bull_Rising = C'045,081,206';
extern color Bear_Rising = C'154,038,232';
extern color Bull_Climax = C'000,166,100';
extern color Bear_Climax = C'208,017,074';


//Global Buffers and Variables
bool Deinitialized;
int i,j,n,Bar_Width,counted_bars,limit,lastzoom;
double Normal[],RisingBull[],RisingBear[],ClimaxBull[],ClimaxBear[],
av,rv,Range,Value2,HiValue2,tempv2;
string ShortName,rf,ef;
int PVA_Climax_Period = 10;
int PVA_Rising_Period = 10;
double PVA_Rising_Factor = 1.5;
double PVA_Extreme_Factor = 2.0;


//Alert
bool Alert_Allowed;
double prevBid;

//Global Variable Controlling Bar Widths
string Bar = "Bar_Setting";

//+-------------------------------------------------------------------------------------------+
//| Custom indicator initialization function |
//+-------------------------------------------------------------------------------------------+
int init()
{
Deinitialized = false;

if(Volume_Alert_On == true) {Alert_Allowed = true;}
prevBid = 0;

//Use Global or Internal instructions for bar widths
if(Chart_Zoom_0123456 == 0)
{
//Get GV Bar Widths for candle bars
Bar_Width = GlobalVariableGet(Bar);
}
else
{
//Manually Adjust Width
if(Chart_Zoom_0123456 < 0 || Chart_Zoom_0123456 >6) {Chart_Zoom_0123456 = 3;}
if(Chart_Zoom_0123456 == 1) {Bar_Width = 1;}
else {if(Chart_Zoom_0123456 == 2) {Bar_Width = 2;}
else {if(Chart_Zoom_0123456 == 3) {Bar_Width = 2;}
else {if(Chart_Zoom_0123456 == 4) {Bar_Width = 3;}
else {if(Chart_Zoom_0123456 == 5) {Bar_Width = 6;}
else {Bar_Width = 13;} }}}}
}

//Indicators
//Normal Bars
SetIndexBuffer(0, Normal);
SetIndexStyle(0, DRAW_HISTOGRAM, 0, 1, Std_Volume);
//PVA: Rising volume
SetIndexBuffer(1, RisingBull);
SetIndexStyle(1, DRAW_HISTOGRAM, 0, Bar_Width, Bull_Rising);
SetIndexBuffer(2, RisingBear);
SetIndexStyle(2, DRAW_HISTOGRAM, 0, Bar_Width, Bear_Rising);

//PVA: Climax volume
SetIndexBuffer(3, ClimaxBull);
SetIndexStyle(3, DRAW_HISTOGRAM, 0, Bar_Width, Bull_Climax);
SetIndexBuffer(4, ClimaxBear);
SetIndexStyle(4, DRAW_HISTOGRAM, 0, Bar_Width, Bear_Climax);

//Indicator ShortName
ShortName= "SonicR PVA";
if(Volume_Alert_On) {ShortName= ShortName + " Alert On";}
IndicatorShortName (ShortName);

//Indicator subwindow data
SetIndexLabel(0, NULL);
SetIndexLabel(1, NULL);
SetIndexLabel(2, NULL);
SetIndexLabel(3, NULL);
SetIndexLabel(4, NULL);
SetIndexLabel(5, NULL);
SetIndexLabel(6, NULL);
SetIndexLabel(7, NULL);

return(0);
}

//+-------------------------------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+-------------------------------------------------------------------------------------------+
int deinit()
{
return(0);
}

//+-------------------------------------------------------------------------------------------+
//| Custom indicator iteration function |
//+-------------------------------------------------------------------------------------------+
int start()
{
//If Indicator is "Off" deinitialize only once, not every tick
if (!Indicator_On)
{
if (!Deinitialized) {deinit(); Deinitialized = true;}
return(0);
}

//Otherwise indicator is "On" & chart TF is in display range, so proceed.
Deinitialized = false;

//Confirm range of chart bars for calculations
//check for possible errors
counted_bars = IndicatorCounted();
if(counted_bars < 0) return(-1);
//last counted bar will be recounted
if(counted_bars > 0) counted_bars--;
limit = Bars - counted_bars;

//Begin the loop of calculations for the range of chart bars.
for(i = limit - 1; i >= 0; i--)
{
//Clear buffers
Normal = 0;
RisingBull = 0;
RisingBear = 0;
ClimaxBull = 0;
ClimaxBear = 0;
Value2 = 0;
HiValue2 = 0;
tempv2 = 0;
av = 0;

//Define Normal histogram bars
Normal = Volume;

//Rising Volume
for (j = i+1; j < (i+PVA_Rising_Period); j++) {av = av + Volume[j];}
av = av / PVA_Rising_Period;
if(Volume >= av * PVA_Rising_Factor)
{
if(Close > Open) {RisingBull = NormalizeDouble(Volume,0);}
if(Close <= Open) {RisingBear = NormalizeDouble(Volume,0);}
}

//Climax Volume
Range = (High-Low);
Value2 = Volume*Range;
for(n=i+1;n<i+PVA_Climax_Period;n++)
{
tempv2 = Volume[n]*((High[n]-Low[n]));
if (tempv2 >= HiValue2) {HiValue2 = tempv2;}
}
//Define Current and Historic "Climax" bars
if((Value2 >= HiValue2) || (Volume >= av * PVA_Extreme_Factor))
{
//Bull Candle
if(Close > Open)
{
ClimaxBull = NormalizeDouble(Volume,0);
}
//Bear Candle
else if (Close <= Open)
{
ClimaxBear = NormalizeDouble(Volume,0);
}
//Sound & Text Alert
if((Volume_Alert_On) && (Alert_Allowed == true) && (i == 0) && (prevBid >0))
{
Alert(Broker_Name_In_Alert,": ",Symbol(),"-",Period()," PVA alert!");
Alert_Allowed = false;
}//End Alert
}//End Climax Volume
}//End PVA "for i" loop
prevBid = Bid;

return(0);
}

//+-------------------------------------------------------------------------------------------+
//|Custom indicator end |
//+-------------------------------------------------------------------------------------------+
 
Last edited:

Similar threads