This tool is designed as a visual trading assistant for the MetaTrader platform, providing real-time signals to help identify potential market entries and exits. It operates by analyzing price movements through three different moving averages, which act as "smoothed" representations of the market's momentum.
Core Operational Logic
The script monitors the relationship between three specific timeframes: a Short Period (for immediate trends), a Big Period (for the broader trend), and an Exit Period (to manage active positions).
1. Entry Signals (Buy and Sell)
The primary logic for entering a trade is based on a "crossover" system between the Short and Big periods:
- Buy Signal: When the short-term momentum crosses above the long-term trend, the script identifies a potential upward movement. It marks this on your chart with a specific arrow.
- Sell Signal: Conversely, when the short-term momentum drops below the long-term trend, the script signals a potential downward move and places an arrow accordingly.
To ensure these signals are actionable, the tool includes automated notifications. Depending on your settings, it can trigger an audible alert and display a detailed text comment on your screen including the current price (Ask/Bid), the exact date and time, and the specific currency pair being traded.
2. Exit Strategy Logic
Beyond just telling you when to enter, the script includes logic to help identify when it might be time to close an open position. This is determined by comparing the short-term momentum against the "Exit Period" average, while simultaneously checking the price relative to the broader trend:
- Closing a Short Position: If the short-term momentum crosses below the exit average while the price is currently trading below the long-term trend, an exit signal is triggered.
- Closing a Long Position: If the short-term momentum crosses above the exit average while the price is trading above the long-term trend, a corresponding exit signal appears.
Visual Summary
The script populates your chart with four types of visual indicators:
- Up Signals: Arrows pointing toward an entry point for a "Buy" position.
- Down Signals: Arrows pointing toward an entry point for a "Sell" position.
- Exit Long: Markers indicating a potential point to close out a purchase.
- Exit Short: Markers indicating a potential point to close out a sale.
//+------------------------------------------------------------------+
//|
//| Kalenzo |
//| simone@konto.pl |
//+------------------------------------------------------------------+
#property copyright "Kalenzo"
#property link "simone@konto.pl"
#property indicator_chart_window
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Black
#property indicator_color4 Black
extern bool UseSound = True;
extern bool TypeChart = True;
extern string NameFileSound = "alert.wav";
extern int ShortPeriod = 3;
extern int BigPeriod = 11;
extern int ExitPeriod = 20;
#property indicator_buffers 4
//---- input parameters
//---- buffers
double UpBuffer[];
double DnBuffer[];
double ExitLong[];
double ExitShort[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
// IndicatorBuffers(2);
SetIndexStyle(0,DRAW_ARROW,EMPTY,1);
SetIndexStyle(1,DRAW_ARROW,EMPTY,1);
SetIndexStyle(2,DRAW_ARROW,EMPTY,1);
SetIndexStyle(3,DRAW_ARROW,EMPTY,1);
SetIndexBuffer(0,UpBuffer);
SetIndexBuffer(1,DnBuffer);
SetIndexBuffer(2,ExitLong);
SetIndexBuffer(3,ExitShort);
SetIndexArrow(0,108);
SetIndexArrow(1,108);
SetIndexArrow(2,251);
SetIndexArrow(3,251);
SetIndexLabel(0,"Up Signal");
SetIndexLabel(1,"Down Signal");
SetIndexLabel(2,"Exit Long");
SetIndexLabel(3,"Exit Short");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) counted_bars=0;
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int i = 0 ;i < limit ;i++)
{
double pwma5 = iMA(Symbol(),0,ShortPeriod,0,MODE_LWMA,PRICE_CLOSE,i+1);
double cwma5 = iMA(Symbol(),0,ShortPeriod,0,MODE_LWMA,PRICE_CLOSE,i);
double pwma50 = iMA(Symbol(),0,BigPeriod,0,MODE_LWMA,PRICE_CLOSE,i+1);
double cwma50 = iMA(Symbol(),0,BigPeriod,0,MODE_LWMA,PRICE_CLOSE,i);
double pwma20 = iMA(Symbol(),0,ExitPeriod,0,MODE_LWMA,PRICE_CLOSE,i+1);
double cwma20 = iMA(Symbol(),0,ExitPeriod,0,MODE_LWMA,PRICE_CLOSE,i);
if( cwma5 > cwma50 && pwma5 <= pwma50)
{
UpBuffer[i] = iLow(Symbol(),0,i)-(3*Point);
DnBuffer[i] = EMPTY_VALUE;
if (UseSound==1) PlaySound(NameFileSound);
if (TypeChart==1) Comment ("Buy signal at Ask=",Ask,", Bid=",Bid,", Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime())," Symbol=",Symbol()," Period=",Period());
}
else if( pwma5 >= pwma50 && cwma5 < cwma50)
{
UpBuffer[i] = EMPTY_VALUE;
DnBuffer[i] = iHigh(Symbol(),0,i)+(3*Point);
if (UseSound==1) PlaySound(NameFileSound);
if (TypeChart==1) Comment ("Sell signal at Ask=",Ask,", Bid=",Bid,", Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime())," Symbol=",Symbol()," Period=",Period());
}
else
{
DnBuffer[i] = EMPTY_VALUE;
UpBuffer[i] = EMPTY_VALUE;
}
if( cwma5 > cwma20 && pwma5 <= pwma20 && iClose(Symbol(),0,i) < cwma50)
{
ExitShort[i] = iHigh(Symbol(),0,i)+(3*Point);
ExitLong[i] = EMPTY_VALUE;
}
else if( pwma5 >= pwma20 && cwma5 < cwma20 && iClose(Symbol(),0,i) > cwma50)
{
ExitShort[i] = EMPTY_VALUE;
ExitLong[i] = iLow(Symbol(),0,i)-(3*Point);
}
else
{
ExitShort[i] = EMPTY_VALUE;
ExitLong[i] = EMPTY_VALUE;
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments