HLCrossSig for WPR

Download script
HLCrossSig for WPR

This script is a technical trading indicator designed to identify specific entry points and manage risk levels on a financial chart. Instead of relying on a single price movement, it uses a multi-layered logic system that combines trend filters, momentum analysis, and volatility measurements to generate visual signals for potential "Buy" and "Sell" actions.

Core Logic Overview

The script functions by constantly scanning historical and current price data to determine if the market is showing enough strength in a specific direction to warrant an entry. It achieves this by balancing three main components:

  • Trend and Momentum Filtering: It uses the Weighted Price Range (WPR) and Heiken Ashi-style variables to ensure that trades are only suggested when there is established momentum. This prevents "false signals" during choppy or sideways markets.
  • Price Action Breakouts: The logic looks for specific price breaks—specifically, whether the current price has exceeded recent highs or lows over a set period.
  • Volatility Adjustment: By incorporating an Average True Range (ATR) calculation, the script adjusts its targets and safety levels based on how much the market is currently swinging, ensuring that signals remain relevant whether the market is calm or volatile.

How it Identifies Signals

The script uses a "State Switch" (Flag) system to prevent repetitive signals. It looks for two primary conditions:

1. Buy Signals (Bullish): To trigger a buy signal, the market must meet several criteria simultaneously:

  • The price must be breaking above recent highs.
  • The closing price must be trending higher than the average median and specific moving averages.
  • The momentum filter (WPR) must be in a positive zone. Once these conditions are met, the script calculates an entry point and a corresponding safety level (Stop Loss).

2. Sell Signals (Bearish): Conversely, to trigger a sell signal:

  • The price must be breaking below recent lows.
  • The closing price must be trending lower than the average median and specific moving averages.
  • The momentum filter must be in a negative zone. Once triggered, it identifies a sell entry and calculates a protective exit point based on the prevailing market volatility.

Risk and Target Management

Beyond just showing arrows on the chart, the script performs automated math to help with trade management:

  • Dynamic Stop Levels: It automatically calculates "safety zones" (Stop Losses) based on the distance between recent price extremes and current volatility.
  • Take Profit Calculations: Based on a user-defined ratio ($Q$), the script calculates a target exit point relative to the size of the risk taken. For example, if you are risking a certain amount of movement, it will project a mathematically proportional goal for your profit.
  • Risk Caps: It includes a safety mechanism that allows users to set a maximum "Risk" value. If the calculated stop loss is too wide (too risky), the script will automatically pull that level closer to the current price to protect the account.
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Indicators Used
Moving average indicatorLarry William percent range indicatorIndicator of the average true range
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
HLCrossSig for WPR
//+------------------------------------------------------------------+
//|                                      HL Cross Signal for WPR.mq4 |
//|                                 Copyright © 2008, Bigeev Rustem. |
//|                                             http://www.parch.ru/ |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 6

//---- input parameters
extern int CountBars=1500;   // Êîëè÷åñòâî áàðîâ äëÿ ðàñ÷åòà èíäèêàòîðà
extern int P=6;              // Ïàðàìåòð ïðîáèâàåìîãî äèàïàçîíà, ÷åì áîëüøå çíà÷åíèå, òåì áîëåå ïîçäíèå ñèãíàëû è ðåæå.
extern int PMA=21;           // Ïàðàìåòð äëÿ "Heiken Ashi variable" - ñëóæèò â êà÷åñòâå äîï. ôèëüòðà.
extern int Risk=0;           // Ìàêñèìàëüíûé ðèñê â ïèïñàõ äëÿ ðàñ÷åòà óðîâíÿ âõîäà èñõîäÿ èç óðîâíÿ áëèæàéøåãî MAX/MIN
extern int ATR_P=120;        // Ïàðàìåòð äëÿ ÀÒR ñëóæèò äëÿ ðàñ÷åòà óðîâíÿ âîëàòèëüíîñòè.
extern double Q=0.7;         // Ïàðàìåòð äëÿ ïîñòàíîâêè Òåéêà. - Äîëÿ îò ðàçìåðà Ñòîïà. åñëè =1, Òåéê = Ñòîïó.
extern int Period_WPR=12;    // Ïàðàìåòðû äëÿ "WPR" - ñëóæèò â êà÷åñòâå äîï. ôèëüòðà.
extern int HLine=-38;        // Âåðõíÿÿ ñèãíàëüíàÿ ëèíèÿ äëÿ WPR
extern int LLine=-62;        // Íèæíÿÿ ñèãíàëüíàÿ ëèíèÿ äëÿ WPR

//---- buffers
double val1[];
double val2[];
double val3[];
double val4[];
double val5[];
double val6[];
double HAClose, HAOpen, HAClose1, HAOpen1;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   IndicatorBuffers(6);
   SetIndexBuffer(0,val1);
   SetIndexBuffer(1,val2);
   SetIndexBuffer(2,val3);
   SetIndexBuffer(3,val4);
   SetIndexBuffer(4,val5);
   SetIndexBuffer(5,val6);
   
   SetIndexStyle(0,DRAW_ARROW,EMPTY,1,Red);
   SetIndexArrow(0,234);
   SetIndexStyle(1,DRAW_ARROW,EMPTY,1,Blue);
   SetIndexArrow(1,233); 
   SetIndexStyle(2,DRAW_ARROW,EMPTY,1,DarkOrange);
   SetIndexArrow(2,251); 
   SetIndexStyle(3,DRAW_ARROW,EMPTY,1,Yellow);
   SetIndexArrow(3,158); 
   SetIndexStyle(4,DRAW_ARROW,EMPTY,1,Magenta);
   SetIndexArrow(4,4); 
   SetIndexStyle(5,DRAW_ARROW,EMPTY,1,Magenta);
   SetIndexArrow(5,4); 

   SetIndexDrawBegin(0,Bars-CountBars);
   SetIndexDrawBegin(1,Bars-CountBars);
   SetIndexDrawBegin(2,Bars-CountBars);
   SetIndexDrawBegin(3,Bars-CountBars);
   SetIndexDrawBegin(4,Bars-CountBars);
   SetIndexDrawBegin(5,Bars-CountBars);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| HA Cross Signal
//+------------------------------------------------------------------+
int start()
  {      
   if (CountBars>=Bars) CountBars=Bars;

   int i,shift,counted_bars=IndicatorCounted();
   static int Flag=1;
   double LHigh,LLow,ATR,WPR_Filter,Median;
      //---- check for possible errors
   if(counted_bars<0) return(-1);

   //---- initial zero
   if(counted_bars<1)
     {
      for(i=1;i<=CountBars;i++) val1[CountBars-i]=0.0;
      for(i=1;i<=CountBars;i++) val2[CountBars-i]=0.0;
      for(i=1;i<=CountBars;i++) val3[CountBars-i]=0.0;
      for(i=1;i<=CountBars;i++) val4[CountBars-i]=0.0;
     } 
 for (shift = CountBars; shift>=0; shift--) 
 { 
	HAOpen=iMA(NULL,0,PMA,0,MODE_SMA,PRICE_MEDIAN,shift);
   Median=iMA(NULL,0,1,0,MODE_SMA,PRICE_MEDIAN,shift);
   LHigh=iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,P,shift+1));
   LLow=iLow(NULL,0,iLowest(NULL,0,MODE_LOW,P,shift+1));
   WPR_Filter=iWPR(NULL,0,Period_WPR,shift);
   ATR=iATR(NULL,0,ATR_P,shift);

	// Óñëîâèå ñèãíàëà íà ïîêóïêó
	if ((High[shift] >= LHigh && Close[shift] > Median && Close[shift] > HAOpen && High[shift] > HAOpen  && WPR_Filter >=HLine && Flag<0)|| 
	    (Close[shift] >= val3[shift+1] && High[shift] > LHigh && Flag<0))  
	    //|| (Median > HAClose && Median > (HAClose-HAOpen)/2 && HAClose < HAOpen && WPR_Filter >= -50 && Flag <0)) //||
	
   {
     val2[shift]= MathMin(Close[shift],(LLow+2*ATR));
     if (Risk != 0 && val2[shift]-LLow > Risk*Point) val2[shift]=LLow+Risk*10*Point; //Q=Q/2;
	  if (Close[shift] < LLow + Risk*10*Point) val2[shift]= Close[shift];
	  Flag=1;
   }    
   if (Flag>0) {val3[shift]=LLow-(Ask-Bid)*2; val4[shift]=LHigh+(Ask-Bid)*3;}  // Óðîâåíü ïîñòàíîâêè Òðåéëèíã Ñòîïà
      val5[shift]=val2[shift]+(val2[shift]-val3[shift])*Q;               


   // Óñëîâèå ñèãíàëà íà ïðîäàæó
   if ((Low[shift] <= LLow && Close[shift] < Median && Close[shift] < HAOpen && Low[shift] < HAOpen  && WPR_Filter <=LLine && Flag>0) || 
       (Close[shift] <= val3[shift+1] && Low[shift] < LLow && Flag>0)) 
       // ||(Median < HAClose && Median > (HAOpen-HAClose)/2 && HAClose > HAOpen && WPR_Filter <= -50 && Flag >0)) // || 

   {
     val1[shift]= MathMax(Close[shift],(LHigh-2*ATR));
     if (Risk != 0 && LHigh-val1[shift] > Risk*Point) val1[shift]=LHigh-Risk*10*Point; //Q=Q/2;
     if (Close[shift] > LHigh - Risk*10*Point) val1[shift]= Close[shift];
	  Flag=-1;
	}
   if (Flag<0) {val3[shift]=LHigh+(Ask-Bid)*3; val4[shift]=LLow-(Ask-Bid)*2;} // Óðîâåíü ïîñòàíîâêè Òðåéëèíã Ñòîïà
       val6[shift]=val1[shift]-(val3[shift]-val1[shift])*Q+(Ask-Bid);               
 }  
 
 return(0);
}
//+------------------------------------------------------------------+

Comments