Bunnygirl Cross and Daily Open 10_v1

Download script
Author: Copyright � 2005, David W. Thomas
Bunnygirl Cross and Daily Open 10_v1

This script is a technical analysis tool designed to identify specific price movements and trend changes on a trading chart. It focuses on "crosses" and "bounces" between two different moving averages, while also providing visual data regarding the daily opening price and specific trade entry filters.

Here is a breakdown of how the logic works in plain English:

Core Tracking Mechanisms

The script performs several background tasks to organize the data you see on your screen:

  • Daily Open Tracking: It automatically identifies and plots the opening price for each day. This provides a visual baseline so you can see how far the current price has moved relative to where the day started.
  • Moving Average Analysis: The script monitors the relationship between two moving averages (a faster one and a slower one). It calculates the "distance" or difference between these two lines to detect momentum.

Signal Logic (The "Cross" and "Bounce")

The primary goal of this tool is to signal when the trend is shifting. It looks for three specific scenarios:

  1. Simple Cross: When the faster moving average moves from below to above the slower one (Bullish/Buy) or vice versa (Bearish/Sell).
  2. Exact Cross: Identifying the precise moment a cross occurs on a single candle.
  3. The "Bounce": This is a more nuanced logic where the script detects if the price has dipped toward the moving average but then "bounced" back. It uses a user-defined "PipsForBounce" setting to decide how close the price needs to get before it qualifies as a valid bounce rather than a trend reversal.

Trading Filters and Visual Cues

To help refine these signals, the script applies several layers of filtering:

  • Time Window Filtering: You can choose to only display certain buy/sell signals during specific hours of the day (e.g., during the London or New York sessions). This helps filter out "noise" during low-activity periods.
  • Dynamic Price Filters: The script calculates a specific price level for potential entries based on the cross amount, a set buffer (filter), and the current market spread (Ask/Bid).
  • Visual Indicators: Instead of just lines, the script places visual arrows on the chart to highlight "Cross Up" and "Cross Down" symbols, making it easier to see exactly where the script detected a valid move.

Multi-Timeframe Compatibility

The logic is designed to be smart about the timeframe you are viewing:

  • If you are looking at a 30-minute chart, it performs all calculations directly on that data.
  • If you are viewing smaller timeframes (like 5-minute or 15-minute charts), it automatically pulls the necessary 30-minute data into your current view so that the signals remain consistent regardless of your zoom level.

On-Screen Summary

Finally, the script provides a real-time text summary in the corner of your chart. This summary tells you:

  • The current daily opening price.
  • The time and direction (Bullish or Bearish) of the most recent moving average cross or bounce.
  • The exact price level where that cross/bounce occurred.
Price Data Components
Series array that contains open time of each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
Bunnygirl Cross and Daily Open 10_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                               Bunnygirl Cross and Daily Open.mq4 |
//|                                Copyright © 2005, David W. Thomas |
//|                                           mailto:davidwt@usa.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, David W. Thomas"
#property link      "mailto:davidwt@usa.net"

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 DarkViolet
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Gray
#property indicator_color5 Blue
#property indicator_color6 Red

//---- input parameters
extern int PipsForBounce=3;
extern int TimeZoneOfData=2;
extern int ma_method=MODE_LWMA;

//---- buffers
double DailyOpenBuffer[];
double BuyFilterBuffer[];
double SellFilterBuffer[];
double CrossBounceBuffer[];
double BuySymbolBuffer[];
double SellSymbolBuffer[];

//---- variables
int indexbegin = 0;
string mastrtype = "";
double dailyopen = 0,
		crossamount,
		filter = 0;
datetime crosstime = 0;
bool crossdir = true;
bool FilterTradingTime = true;
int beginfiltertime = 0;
int endfiltertime = 24;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
	SetIndexStyle(0, DRAW_LINE);
	SetIndexBuffer(0, DailyOpenBuffer);
	SetIndexLabel(0, "Daily Open");
	SetIndexEmptyValue(0, 0.0);
	SetIndexStyle(1, DRAW_LINE);
	SetIndexBuffer(1, BuyFilterBuffer);
	SetIndexLabel(1, "Buy Filter");
	SetIndexEmptyValue(1, 0.0);
	SetIndexStyle(2, DRAW_LINE);
	SetIndexBuffer(2, SellFilterBuffer);
	SetIndexLabel(2, "Sell Filter");
	SetIndexEmptyValue(2, 0.0);
	SetIndexStyle(3, DRAW_LINE, STYLE_DOT);
	SetIndexBuffer(3, CrossBounceBuffer);
	SetIndexLabel(3, "Cross/Bounce");
	SetIndexEmptyValue(3, 0.0);
	SetIndexStyle(4, DRAW_ARROW);
	SetIndexArrow(4, 233);
	SetIndexBuffer(4, BuySymbolBuffer);
	SetIndexLabel(4, "Cross Up Symbol");
	SetIndexEmptyValue(4, 0.0);
	SetIndexStyle(5, DRAW_ARROW);
	SetIndexArrow(5, 234);
	SetIndexBuffer(5, SellSymbolBuffer);
	SetIndexLabel(5, "Cross Down Symbol");
	SetIndexEmptyValue(5, 0.0);
//----
	indexbegin = Bars - 10;
	if (indexbegin < 0)
		indexbegin = 0;
	if (Symbol() == "EURUSD")
		filter = 10 * Point;
	else
		filter = 15 * Point;
	if (ma_method == MODE_EMA)
		mastrtype = "EMA";
	else
		mastrtype = "WMA";
	Print(" Cross of ", mastrtype, " with a filter of ", filter/Point, " pips.");
	if (FilterTradingTime)
	{
		beginfiltertime = 6 + TimeZoneOfData;
		endfiltertime = 17 + TimeZoneOfData;
      Print(" Only shows buy/sell filters from ", beginfiltertime, " to ", endfiltertime, " hours (chart time).");
	}
	else
	{
		beginfiltertime = 0;
		endfiltertime = 24;
		Print(" Show buy/sell filters at all times.");
	}

	return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
	
//----
	return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int i;
	int counted_bars = IndicatorCounted();
	string crossdirstr = "";
	
	//---- check for possible errors
	if (counted_bars < 0) counted_bars = 0;
	//---- last counted bar will be recounted
	if (counted_bars > 0) counted_bars--;
	if (counted_bars > indexbegin) counted_bars = indexbegin;

	if (Period() == 30)
	{
		double ma20c, ma20p1, ma20p2,
				 diff0, diff1, diff2;

		for (i = indexbegin-counted_bars; i >= 0; i--)
		{
			if ((TimeMinute(Time[i]) == 0) && (TimeHour(Time[i]) - TimeZoneOfData == 0))
				dailyopen = Open[i];
			DailyOpenBuffer[i] = dailyopen;

			ma20c = iMA(NULL, PERIOD_M30, 20, 0, ma_method, PRICE_CLOSE, i);
			ma20p1 = iMA(NULL, PERIOD_M30, 20, 0, ma_method, PRICE_CLOSE, i+1);
			ma20p2 = iMA(NULL, PERIOD_M30, 20, 0, ma_method, PRICE_CLOSE, i+2);
			diff0 = iMA(NULL, PERIOD_M30, 5, 0, ma_method, PRICE_CLOSE, i) - ma20c;
			diff1 = iMA(NULL, PERIOD_M30, 5, 0, ma_method, PRICE_CLOSE, i+1) - ma20p1;
			diff2 = iMA(NULL, PERIOD_M30, 5, 0, ma_method, PRICE_CLOSE, i+2) - ma20p2;

			// bull signals:
			if (diff0 > 0)
			{
				if (diff1 < 0) // simple bull cross.
				{
					crossdir = true;
					// determine which bar is closer to the cross:
					if (MathAbs(diff0) < MathAbs(diff1))
					{
						crosstime = Time[i];
						crossamount = ma20c;
					}
					else
					{
						crosstime = Time[i+1];
						crossamount = ma20p1;
					}
				}
				else
				if (diff1 == 0 && diff2 < 0) // exact cross on last bar.
				{
					crossdir = true;
					crosstime = Time[i+1];
					crossamount = ma20p1;
				}
				else
				if (diff1 > 0 && diff2 > diff1 && diff0 >= diff1 && diff1 <= PipsForBounce*Point) // a bounce.
				{
					crossdir = true;
					crosstime = Time[i+1];
					crossamount = ma20p1;
				}
			}
			else
			// bear signals:
			if (diff0 < 0)
			{
				if (diff1 > 0) // simple bear cross.
				{
					crossdir = false;
					// determine which bar is closer to the cross:
					if (MathAbs(diff0) < MathAbs(diff1))
					{
						crosstime = Time[i];
						crossamount = ma20c;
					}
					else
						crosstime = Time[i+1];
						crossamount = ma20p1;
					{
					}
				}
				else
				if (diff1 == 0 && diff2 > 0) // exact cross on last bar.
				{
					crossdir = false;
					crosstime = Time[i+1];
					crossamount = ma20p1;
				}
				else
				if (diff1 < 0 && diff2 < diff1 && diff0 <= diff1 && MathAbs(diff1) <= PipsForBounce*Point) // a bounce.
				{
					crossdir = false;
					crosstime = Time[i+1];
					crossamount = ma20p1;
				}
			}
			CrossBounceBuffer[i] = crossamount;
			if (TimeHour(Time[i]) >= beginfiltertime && TimeHour(Time[i]) <= endfiltertime)
			{
				if (crossdir)
				{
					BuyFilterBuffer[i] = crossamount + filter + Ask - Bid;
					SellFilterBuffer[i] = 0;
					if (i > 0 && BuyFilterBuffer[i] != BuyFilterBuffer[i+1])//crosstime == Time[i])
						BuySymbolBuffer[i] = BuyFilterBuffer[i] + 5*Point;
				}
				else
				{
					SellFilterBuffer[i] = crossamount - filter;
					BuyFilterBuffer[i] = 0;
					if (i > 0 && SellFilterBuffer[i] != SellFilterBuffer[i+1])//crosstime == Time[i])
						SellSymbolBuffer[i] = SellFilterBuffer[i] - 5*Point;
				}
			}
			if (crosstime == Time[i+1] && TimeHour(Time[i+1]) >= beginfiltertime && TimeHour(Time[i+1]) <= endfiltertime)
			{
				CrossBounceBuffer[i+1] = crossamount;
				if (crossdir)
				{
					BuyFilterBuffer[i+1] = crossamount + filter + Ask - Bid;
					BuySymbolBuffer[i+1] = BuyFilterBuffer[i+1] + 5*Point;
					BuySymbolBuffer[i] = 0.0;
				}
				else
				{
					SellFilterBuffer[i+1] = crossamount - filter;
					SellSymbolBuffer[i+1] = SellFilterBuffer[i+1] - 5*Point;
					SellSymbolBuffer[i] = 0.0;
				}
			}
		}
	}
	else
	if (Period() < 30)
	{
      // diff formula from aircom@strategybuilderfx.com.
		int diff = (TimeMinute(Time[0]) - TimeMinute(iTime(NULL, PERIOD_M30, 0))) / Period() + 1;
		int per30 = 30 / Period();
		int j;
		for (i = indexbegin-counted_bars; i >= 0; i--)
		{
			j = (i + per30 - diff)/per30;
			dailyopen = iCustom(NULL, PERIOD_M30, "Bunnygirl Cross and Daily Open",
									PipsForBounce, TimeZoneOfData, ma_method, 0, j);
			DailyOpenBuffer[i] = dailyopen;
			crossamount = iCustom(NULL, PERIOD_M30, "Bunnygirl Cross and Daily Open",
									PipsForBounce, TimeZoneOfData, ma_method, 3, j);
			CrossBounceBuffer[i] = crossamount;
			if (CrossBounceBuffer[i+1] != crossamount)
				crosstime = Time[i];
			BuyFilterBuffer[i] = iCustom(NULL, PERIOD_M30, "Bunnygirl Cross and Daily Open",
									PipsForBounce, TimeZoneOfData, ma_method, 1, j);
			SellFilterBuffer[i] = iCustom(NULL, PERIOD_M30, "Bunnygirl Cross and Daily Open",
									PipsForBounce, TimeZoneOfData, ma_method, 2, j);
			if (i > 0 && BuyFilterBuffer[i] > 0.0 && BuyFilterBuffer[i+1] == 0.0)
				BuySymbolBuffer[i] = BuyFilterBuffer[i] + 5*Point;
			else if (i > 0 && SellFilterBuffer[i] > 0.0 && SellFilterBuffer[i+1] == 0.0)
				SellSymbolBuffer[i] = SellFilterBuffer[i] - 5*Point;
		}
		crossdir = BuyFilterBuffer[0] != 0.0;
	}
	else
	{
		dailyopen = iCustom(NULL, PERIOD_M30, "Bunnygirl Cross and Daily Open",
									PipsForBounce, TimeZoneOfData, ma_method, 0, 0);
		crossamount = iCustom(NULL, PERIOD_M30, "Bunnygirl Cross and Daily Open",
								PipsForBounce, TimeZoneOfData, ma_method, 3, 0);
		BuyFilterBuffer[0] = iCustom(NULL, PERIOD_M30, "Bunnygirl Cross and Daily Open",
								PipsForBounce, TimeZoneOfData, ma_method, 1, 0);
		SellFilterBuffer[0] = iCustom(NULL, PERIOD_M30, "Bunnygirl Cross and Daily Open",
								PipsForBounce, TimeZoneOfData, ma_method, 2, 0);
		crossdir = BuyFilterBuffer[0] != 0.0;
	}

	if (crossdir)
		crossdirstr = "bull";
	else
		crossdirstr = "bear";

	if (crosstime != 0)  // use of Digits suggested by aircom@strategybuilderfx.com.
		Comment("Current daily open = ", DoubleToStr(dailyopen,Digits), "\nLast ", mastrtype, " cross/bounce: ", TimeToStr(crosstime), ", ", crossdirstr, " at ", DoubleToStr(crossamount,Digits));
	else
		Comment("Current daily open = ", DoubleToStr(dailyopen,Digits), "\nLast ", mastrtype, " cross/bounce: ", crossdirstr, " at ", DoubleToStr(crossamount,Digits));
	
	return(0);
}
//+------------------------------------------------------------------+

Comments