NDuet
Download scriptThis tool is designed to act as a visual trading assistant by identifying specific momentum shifts and price actions on a chart. It functions by analyzing the relationship between multiple moving averages, current price trends, and a commodity channel index to highlight potential "Buy" and "Sell" opportunities directly on your screen.
Core Logic Overview
The script monitors the market using four primary layers of data to ensure that signals are only generated when specific conditions align:
- Moving Average Dynamics: The tool tracks two different types of moving averages (short-term and long-term). It doesn't just look at where these lines are currently positioned, but also compares their current values against their previous positions. This helps identify "crosses" or significant shifts in price velocity.
- Trend Analysis: It calculates the net movement of the price over a specific period. By measuring how much the price has moved relative to its starting point in that window, the tool can determine if the immediate momentum is tilting upward or downward.
- Momentum Filtering (CCI): To prevent false signals during sideways markets, it utilizes a Commodity Channel Index. This acts as a filter to confirm that there is sufficient strength behind a move before a signal is displayed.
- Proximity and Distance Checks: The logic includes specific "zones" for price action. It only triggers a signal if the gap between the moving averages falls within a specific range—neither too wide nor too narrow—ensuring the signals are consistent with established market behavior.
Visual Execution
When all of the above technical conditions are met simultaneously, the script performs the following actions:
- Sell Signals: If the moving averages indicate a bearish crossover, the trend is positive but slowing, and momentum is dipping, the script places an Aqua-colored arrow labeled "Sell" above the price candle.
- Buy Signals: If the moving averages indicate a bullish crossover, the trend is negative but recovering, and momentum is rising, the script places a Red-colored arrow labeled "Buy" below the price candle.
Key Features for the User
- Signal Filtering: The tool includes a "block" mechanism, which prevents it from cluttering your chart with repeated signals in the same direction back-to-back, ensuring only unique entry points are highlighted.
- Real-Time Calculation: The logic automatically scans historical data and updates in real-time as new price information becomes available.
- Customizable Sensitivity: While the underlying logic is fixed, the timeframe of the moving averages and the sensitivity of the momentum filters can be adjusted via the input settings to suit different trading styles (e.g., scalping vs. swing trading).
//+------------------------------------------------------------------+
//| NDuet.mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 LightSeaGreen
#property indicator_color2 HotPink
extern int sper=55;
extern int fper=21;
extern int nBar=300;
extern int per=14;
double mas[];
double maf[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{//1
SetIndexBuffer(0,mas);
SetIndexBuffer(1,maf);
return(0);
}//1
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{//1
ObjectsDeleteAll(0);
return(0);
}//1
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{//1
int limit=0,i=0,blokb=0,bloks=0;
double mstwo=0,mftwo=0,cci=0,trend=0;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(i=0; i<limit; i++)
{//2
cci=iCCI(NULL,0,per,PRICE_CLOSE,i);
trend=((Close[i+fper]-Close[i])/Point);
mas[i]=iMA(NULL,0,sper,0,MODE_EMA,PRICE_CLOSE,i);
mstwo =iMA(NULL,0,sper,0,MODE_EMA,PRICE_CLOSE,i+2);
maf[i]=iMA(NULL,0,fper,0,MODE_EMA,PRICE_CLOSE,i);
mftwo =iMA(NULL,0,fper,0,MODE_EMA,PRICE_CLOSE,i+2);
if((mas[i]>maf[i])&&((mas[i]-maf[i])/Point<10)&&((mas[i]-maf[i])/Point>=1)
&&(mstwo<mftwo)&&(cci<0)&&(trend>0)&&(bloks==0))
{//3
string Name1="S"+i;
double Price1=NormalizeDouble(High[i]+10*Point,Digits);
ObjectCreate(Name1,OBJ_ARROW,0,Time[i],Price1);
ObjectSet(Name1,OBJPROP_ARROWCODE,242);
ObjectSet(Name1,OBJPROP_COLOR,Aqua);
ObjectSetText(Name1,"Sell",10,"Times New Roman",Aqua);
bloks=1;
blokb=0;
}//3
if((mas[i]<maf[i])&&((maf[i]-mas[i])/Point<10)&&((maf[i]-mas[i])/Point>=1)
&&(mstwo>mftwo)&&(cci>0)&&(trend<0)&&(blokb==0))
{//3
string Name2="B"+i;
double Price2=NormalizeDouble(Low[i]-10*Point,Digits);
ObjectCreate(Name2,OBJ_ARROW,0,Time[i],Price2);
ObjectSet(Name2,OBJPROP_ARROWCODE,241);
ObjectSet(Name2,OBJPROP_COLOR,Red);
ObjectSetText(Name2,"Buy",10,"Times New Roman",Aqua);
blokb=1;
bloks=0;
}//3
}//2
return(0);
}//1
//+------------------------------------------------------------------+
/*[[
Name := NDuet
Author := Copyright © 2004, HomeSoft-Tartan Corp.
Link := spiky@transkeino.ru
Separate Window := Yes
First Color := Lime
First Draw Type := Line
First Symbol := 217
Use Second Data := Yes
Second Color := Red
Second Draw Type := Line
Second Symbol := 218
]]*/
/*
Variable : shift(0),i(0),mas(0),maf(0),mstwo(0),mftwo(0),blokb(0),bloks(0),cci(0),trend(0);
SetLoopCount(0);
// loop from first bar to current bar (with shift=0)
For shift=Bars-1 Downto 0 Begin
SetIndexValue(shift, 0);
SetIndexValue2(shift, 0);
End;
For shift=nBar+fper Downto 0 Begin
cci=iCCI(per,shift);
trend=((C[shift+fper]-C[shift])/point);
mas=iMA(sper,MODE_EMA,shift);
mstwo=iMA(sper,MODE_EMA,shift+2);
SetIndexValue(shift,mas);
maf=iMA(fper,MODE_EMA,shift);
mftwo=iMA(fper,MODE_EMA,shift+2);
SetIndexValue2(shift,maf);
if mas>maf and ((mas-maf)/point)<10 and ((mas-maf)/point)>=1 and mstwo<mftwo and cci<0 and trend>0 and bloks=0 then Begin
bloks=1;blokb=0;SetArrow(Time[shift],H[shift]+10*Point,242,Aqua);end;
if mas<maf and ((maf-mas)/point)<10 and ((maf-mas)/point)>=1 and mstwo>mftwo and cci>0 and trend<0 and blokb=0 then Begin
blokb=1;bloks=0;SetArrow(Time[shift],L[shift]-10*Point,241,Red);end;
end;
*/
Comments