Signals_Enter
Download scriptThis script is designed as a visual trading tool for the MetaTrader platform, specifically created to help traders identify potential entry points by analyzing the relationship between two different moving averages.
Core Logic and Functionality
The primary objective of this tool is to detect "cross-overs"—moments when a short-term trend line intersects with a long-term trend line. It uses two distinct periods to calculate these averages:
- Short-Term Period (HPeriod): Set at 10, which reacts quickly to recent price changes.
- Long-Term Period (LPeriod): Set at 40, which represents the broader, smoother trend of the market.
How the Signals are Generated
The script constantly scans the historical price data to find specific "cross" events. When these conditions occur, it places visual markers on the chart for the trader to see:
- Sell Signals: The script looks for a moment where the short-term average moves from above the long-term average to below it. This downward crossover suggests that downward momentum is gaining strength. When this happens, the tool places an orange marker slightly below the current price candle.
- Buy Signals: Conversely, the script looks for a moment where the short-term average moves from below the long-term average to above it. This upward crossover suggests that upward momentum is taking over. When this happens, the tool places a red marker slightly above the current price candle.
User Experience
Instead of requiring the trader to manually watch the moving averages constantly, this script automates the detection process. It acts as an alert system that highlights these pivotal shifts in trend direction directly on the main chart window, providing clear visual cues for potential buying and selling opportunities based on traditional momentum-based analysis.
#include <stdlib.mqh>
//+------------------------------------------------------------------+
//| Signals_Enter.mq4 |
//| |
//| |
//| Converted by Mql2Mq4 v2.0 |
//| http://yousky.free.fr |
//| Copyright (c) 2006, Yousky Soft |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
#property indicator_chart_window
#property indicator_color1 Blue
#property indicator_buffers 1
//+------------------------------------------------------------------+
//| Common External variables |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| External variables |
//+------------------------------------------------------------------+
extern double HPeriod = 10;
extern double LPeriod = 40;
//+------------------------------------------------------------------+
//| Special Convertion Functions |
//+------------------------------------------------------------------+
int LastTradeTime;
double ExtHistoBuffer[];
double ExtHistoBuffer2[];
void SetLoopCount(int loops)
{
}
void SetIndexValue(int shift, double value)
{
ExtHistoBuffer[shift] = value;
}
void SetIndexValue2(int shift, double value)
{
ExtHistoBuffer2[shift] = value;
}
//+------------------------------------------------------------------+
//| End |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Initialization |
//+------------------------------------------------------------------+
int init()
{
SetIndexBuffer(0, ExtHistoBuffer);
SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID);
SetIndexBuffer(1, ExtHistoBuffer2);
return(0);
}
int start()
{
//+------------------------------------------------------------------+
//| Local variables |
//+------------------------------------------------------------------+
int Shift = 0;
double Value = 0;
double Price = 0;
/*[[
Name := Signals_Enter
Separate Window := No
First Color := Orange
First Draw Type := Symbol
First Symbol := 241
Use Second Data := Yes
Second Color := Red
Second Draw Type := Symbol
Second Symbol := 242
]]*/
SetLoopCount(10);
for(Shift =0;Shift <=Bars - 1;Shift ++){
Value = 0;
Price = Low[Shift] - 15 * Point;
if( iMA(NULL, 0, HPeriod, 0, 1, PRICE_CLOSE, Shift) < iMA(NULL, 0, LPeriod, 0, 1, PRICE_CLOSE, Shift) && iMA(NULL, 0, HPeriod, 0, 1, PRICE_CLOSE, Shift - 1) > iMA(NULL, 0, LPeriod, 0, 1, PRICE_CLOSE, Shift - 1)
) Value = Price;
SetIndexValue(Shift,Value);
Value = 0;
Price = High[Shift] + 15 * Point;
if( iMA(NULL, 0, HPeriod, 0, 1, PRICE_CLOSE, Shift) > iMA(NULL, 0, LPeriod, 0, 1, PRICE_CLOSE, Shift) && iMA(NULL, 0, HPeriod, 0, 1, PRICE_CLOSE, Shift - 1) < iMA(NULL, 0, LPeriod, 0, 1, PRICE_CLOSE, Shift - 1)
) Value = Price;
SetIndexValue2(Shift,Value);
}
return(0);
}
Comments