Bunnygirl Cross and Daily Open_v1

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

This technical tool is designed to assist traders by identifying specific price movements and trend shifts based on the interaction between moving averages and daily price levels. It focuses on detecting "crosses" and "bounces" to help determine potential entry points while filtering for specific trading windows.

Core Trading Logic

1. Trend Detection (Moving Average Crosses & Bounces) The primary logic relies on the relationship between two different moving averages: a faster one and a slower one.

  • Crossovers: The tool monitors when the faster average moves from below the slower average to above it (a bullish signal) or vice versa (a bearish signal).
  • Bounces: Beyond simple crossovers, the logic identifies "bounces." This occurs when price momentum slows down near a moving average and then rebounds. The script includes a specific "pips" parameter to define how close to the moving average the price must be to qualify as a bounce rather than a standard trend continuation.

2. Signal Filtering by Time The script does not provide signals at all times of the day. It includes a built-in time filter that limits active signals to a specific window (which can be adjusted based on your local time zone). This ensures that the tool only highlights movements during high-liquidity sessions or preferred trading hours, ignoring volatile "noise" outside of these periods.

3. Dynamic Buy and Sell Thresholds Once a bullish or bearish cross/bounce is detected within the active timeframe, the script calculates specific "Filter" levels:

  • For Bullish signals: It identifies a price threshold slightly above the moving average.
  • For Bearish signals: It identifies a price threshold slightly below the moving average. These levels act as visual guides, helping the trader see the target zones where the trend shift is most confirmed.

4. Multi-Timeframe Synchronization The logic is designed to work seamlessly across different charts. If you are viewing a timeframe larger than 30 minutes, the script automatically performs "multi-timeframe analysis." It calculates all its data based on the 30-minute chart and projects that information onto your current view. This ensures that whether you are looking at 1-minute, 5-minute, or 1-hour charts, the trend signals remain consistent and synchronized with the primary 30-minute analysis.

5. On-Screen Information Display To keep the trader informed without cluttering the chart, the tool provides a text summary in the corner of the screen. This live update shows:

  • The current price at which the market opened today.
  • The exact time and direction (Bullish/Bearish) of the most recent moving average cross or bounce.
  • The specific price level where that crossover occurred.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
Bunnygirl Cross and Daily Open_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 4
#property indicator_color1 DarkViolet
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Gray

//---- 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[];

//---- variables
int indexbegin = 0;
string mastrtype = "";
double dailyopen = 0,
		crossamount,
		filter = 0;
int 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);
//----
	indexbegin = Bars - 20;
	if (indexbegin < 0)
		indexbegin = 0;
	if (Symbol() == "EURUSD")
		filter = 20 * Point + Bid;
	else
		filter = 25 * Point + Bid;
	if (ma_method == MODE_EMA)
		mastrtype = "EMA";
	else
		mastrtype = "WMA";
	if (FilterTradingTime)
	{
		beginfiltertime = 6 + TimeZoneOfData;
		endfiltertime = 17 + TimeZoneOfData;
	}
	else
	{
		beginfiltertime = 0;
		endfiltertime = 24;
	}

	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;
				}
				else
				{
					SellFilterBuffer[i] = crossamount - filter;
					BuyFilterBuffer[i] = 0;
				}
			}
			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;
				else
					SellFilterBuffer[i+1] = crossamount - filter;
			}
		}
	}
	else
	if (Period() < 30)
	{
		int per30 = 30 / Period();
		int j;
		for (i = indexbegin-counted_bars; i >= 0; i--)
		{
			j = (i + per30 - 1)/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);
		}
		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)
		Comment("Current daily open = ", dailyopen, "\nLast ", mastrtype, " cross/bounce: ", TimeToStr(crosstime), ", ", crossdirstr, " at ", crossamount);
	else
		Comment("Current daily open = ", dailyopen, "\nLast ", mastrtype, " cross/bounce: ", crossdirstr, " at ", crossamount);
	
	return(0);
}
//+------------------------------------------------------------------+

Comments