Author: Copyright � 2012, JJ Newark
JJN-Bee

This script, known as JJN-Bee, is a specialized technical analysis tool designed for the MetaTrader 4 platform. It functions by identifying specific price action patterns to suggest potential trading directions—specifically "Buy" and "Sell" signals—while simultaneously calculating objective price levels for entries, profit targets, and risk management.

Core Logic and Behavior

The script monitors price movements in real-time by comparing the relationship between current price candles and preceding ones. It focuses on a specific type of reversal or momentum shift:

  • Buy Signals: The logic triggers a "Buy" prompt when the current candle closes higher than the opening price of the previous candle, while that previous candle itself closed lower than its own opening price. This suggests a shift from downward pressure to upward momentum.
  • Sell Signals: Conversely, a "Sell" prompt is triggered when the current candle closes lower than the opening price of the previous candle, while the previous candle closed higher than its own opening price. This suggests a shift from upward pressure to downward momentum.
  • Neutral State: If the price action does not meet these specific criteria, the script defaults to a "Wait" state, providing no active signals until the conditions are met again.

Dynamic Level Calculation

A key feature of this script is its ability to provide concrete numbers for a trade setup rather than just an abstract signal. It utilizes a technical measurement known as the Average True Range (ATR) to determine volatility:

  1. Entry Level: The script identifies the exact price point (the previous candle's opening price) where the trade logic was triggered.
  2. Take Profit (TP): It calculates a target price by adding or subtracting the ATR value from the entry point, depending on the direction of the trade.
  3. Stop Loss (SL): It calculates a safety exit point by moving in the opposite direction of the trade by the same ATR amount.

Visual Interface and User Experience

To make these calculations accessible to the user without manual math, the script provides several visual aids:

  • On-Screen Dashboard: It creates a text-based display on the chart that clearly states the current status ("Buy", "Sell", or "Wait") and identifies the specific price level to watch.
  • Visual Markers: The script places arrows on the chart to highlight historical signal points.
  • Projected Levels: When enabled, the script draws horizontal lines extending into the future. These represent your potential Entry, Take Profit, and Stop Loss zones, allowing you to see exactly where your trade boundaries lie at a glance.
  • Audio Alerts: It includes an optional sound notification to alert the trader immediately when a new signal condition is met.
Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1It plays sound alerts
11 Views
1 Downloads
0 Favorites
JJN-Bee
//+------------------------------------------------------------------+
//|                                                      JJN-Bee.mq4 |
//|                                      Copyright © 2012, JJ Newark |
//|                                            http:/jjnewark.atw.hu |
//|                                             jjnewark@freemail.hu |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, JJ Newark"
#property link      "http:/jjnewark.atw.hu"


//---- indicator settings
#property indicator_chart_window
#property  indicator_buffers      4
#property  indicator_color1       YellowGreen
#property  indicator_color2       OrangeRed
#property  indicator_color3       YellowGreen
#property  indicator_color4       OrangeRed
#property  indicator_width1       1
#property  indicator_width2       1
#property  indicator_width3       1
#property  indicator_width4       1


//---- indicator parameters
extern string     __Copyright__               = "http://jjnewark.atw.hu";
extern int        AtrPeriod                   = 8;
extern bool       Show_TP_SL                  = true;
extern bool       Show_Levels                 = true;
extern color      BuyColor                    = YellowGreen;
extern color      SellColor                   = OrangeRed;
extern color      FontColor                   = Black;
extern int        DisplayDecimals             = 4;
extern int        PosX                        = 25;
extern int        PosY                        = 25;
extern bool       SoundAlert                  = false;


//---- indicator buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];


double Atr;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   IndicatorBuffers(4);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,233);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,234);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,167);//119
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,167);//119
   SetIndexBuffer(3,ExtMapBuffer4);
  
      
   SetIndexLabel(0,"BUY");
   SetIndexLabel(1,"SELL");
   SetIndexLabel(2,"TakeProfit");
   SetIndexLabel(3,"StopLoss");
   
      
//---- 
   IndicatorShortName("JJN-Bee");
   
   
   ObjectCreate("JJNBeeIndName",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("JJNBeeIndName",OBJPROP_CORNER,0);
   ObjectSet("JJNBeeIndName",OBJPROP_XDISTANCE,PosX+20);
   ObjectSet("JJNBeeIndName",OBJPROP_YDISTANCE,PosY);
   ObjectSetText("JJNBeeIndName","JJN-Bee",8,"Lucida Sans Unicode",FontColor);
   
   ObjectCreate("JJNBeeLine0",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("JJNBeeLine0",OBJPROP_CORNER,0);
   ObjectSet("JJNBeeLine0",OBJPROP_XDISTANCE,PosX+5);
   ObjectSet("JJNBeeLine0",OBJPROP_YDISTANCE,PosY+8);
   ObjectSetText("JJNBeeLine0","------------------",8,"Tahoma",FontColor);
   
   ObjectCreate("JJNBeeLine1",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("JJNBeeLine1",OBJPROP_CORNER,0);
   ObjectSet("JJNBeeLine1",OBJPROP_XDISTANCE,PosX+5);
   ObjectSet("JJNBeeLine1",OBJPROP_YDISTANCE,PosY+10);
   ObjectSetText("JJNBeeLine1","------------------",8,"Tahoma",FontColor);
   
   ObjectCreate("JJNBeeDirection",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("JJNBeeDirection",OBJPROP_CORNER,0);
   ObjectSet("JJNBeeDirection",OBJPROP_XDISTANCE,PosX);
   ObjectSet("JJNBeeDirection",OBJPROP_YDISTANCE,PosY+12);
   ObjectSetText("JJNBeeDirection","Wait",20,"Lucida Sans Unicode",FontColor);
      
   ObjectCreate("JJNBeeLevel",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("JJNBeeLevel",OBJPROP_CORNER,0);
   ObjectSet("JJNBeeLevel",OBJPROP_XDISTANCE,PosX);
   ObjectSet("JJNBeeLevel",OBJPROP_YDISTANCE,PosY+50);
   ObjectSetText("JJNBeeLevel","",9,"Lucida Sans Unicode",FontColor);
   
   
//---- initialization done
   return(0);
  }

int deinit()
  {
//----
  
   ObjectDelete("JJNBeeLine0");
   ObjectDelete("JJNBeeLine1");
   ObjectDelete("JJNBeeIndName");
   ObjectDelete("JJNBeeDirection");
   ObjectDelete("JJNBeeLevel");   
   
   ObjectDelete("JJNBeeEntryLevel");  
   ObjectDelete("JJNBeeTPLevel");
   ObjectDelete("JJNBeeSLLevel");     
//----
   return(0);
  }

int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- 

   
   
      
   for(int i=0; i<limit; i++)
   {
   Atr=iATR(NULL,0,AtrPeriod,i);
   
   if(Close[i]>Open[i+1] && Close[i+1]<Open[i+1])
      { 
      ExtMapBuffer1[i]=Low[i];
      ExtMapBuffer2[i]=EMPTY_VALUE;
      if(Show_TP_SL) ExtMapBuffer3[i]=Open[i+1]+Atr;
      if(Show_TP_SL) ExtMapBuffer4[i]=Open[i+1]-Atr;
      }
   else if(Close[i]<Open[i+1] && Close[i+1]>Open[i+1])
      {
      ExtMapBuffer1[i]=EMPTY_VALUE;
      ExtMapBuffer2[i]=High[i];
      if(Show_TP_SL) ExtMapBuffer3[i]=Open[i+1]-Atr;
      if(Show_TP_SL) ExtMapBuffer4[i]=Open[i+1]+Atr;
      }
   else 
      {
      ExtMapBuffer1[i]=EMPTY_VALUE;
      ExtMapBuffer2[i]=EMPTY_VALUE;
      ExtMapBuffer3[i]=EMPTY_VALUE;
      ExtMapBuffer4[i]=EMPTY_VALUE;
      }
   }
  
  
   if(Close[0]>Open[1] && Close[1]<Open[1]) // BUY
      { 
      ObjectDelete("JJNBeeEntryLevel");  
      ObjectDelete("JJNBeeTPLevel");
      ObjectDelete("JJNBeeSLLevel"); 
      
      ObjectSet("JJNBeeDirection",OBJPROP_XDISTANCE,PosX+5);
      ObjectSetText("JJNBeeDirection","BUY",28,"Lucida Sans Unicode",BuyColor); 
      ObjectSetText("JJNBeeLevel","above "+DoubleToStr(Open[1],DisplayDecimals),9,"Lucida Sans Unicode",BuyColor);
      if(Show_Levels)
         {
         ObjectCreate("JJNBeeEntryLevel",OBJ_TREND,0,Time[1],Open[1],Time[0],Open[1]);
         ObjectSet("JJNBeeEntryLevel",OBJPROP_RAY,True);
         ObjectSet("JJNBeeEntryLevel",OBJPROP_BACK,True); // obj in the background
         ObjectSet("JJNBeeEntryLevel",OBJPROP_STYLE,STYLE_SOLID);
         ObjectSet("JJNBeeEntryLevel",OBJPROP_WIDTH,1);
         ObjectSet("JJNBeeEntryLevel",OBJPROP_COLOR,FontColor);
         ObjectCreate("JJNBeeTPLevel",OBJ_TREND,0,Time[1],Open[1]+Atr,Time[0],Open[1]+Atr);
         ObjectSet("JJNBeeTPLevel",OBJPROP_RAY,True);
         ObjectSet("JJNBeeTPLevel",OBJPROP_BACK,True); // obj in the background
         ObjectSet("JJNBeeTPLevel",OBJPROP_STYLE,STYLE_SOLID);
         ObjectSet("JJNBeeTPLevel",OBJPROP_WIDTH,1);
         ObjectSet("JJNBeeTPLevel",OBJPROP_COLOR,BuyColor);
         ObjectCreate("JJNBeeSLLevel",OBJ_TREND,0,Time[1],Open[1]-Atr,Time[0],Open[1]-Atr);
         ObjectSet("JJNBeeSLLevel",OBJPROP_RAY,True);
         ObjectSet("JJNBeeSLLevel",OBJPROP_BACK,True); // obj in the background
         ObjectSet("JJNBeeSLLevel",OBJPROP_STYLE,STYLE_SOLID);
         ObjectSet("JJNBeeSLLevel",OBJPROP_WIDTH,1);
         ObjectSet("JJNBeeSLLevel",OBJPROP_COLOR,SellColor);
         }
      if(SoundAlert) PlaySound("alert.wav");
      }
   else if(Close[0]<Open[1] && Close[1]>Open[1]) // SELL
      {
      ObjectSet("JJNBeeDirection",OBJPROP_XDISTANCE,PosX+2);
      ObjectSetText("JJNBeeDirection","SELL",28,"Lucida Sans Unicode",SellColor); 
      ObjectSetText("JJNBeeLevel","under "+DoubleToStr(Open[1],DisplayDecimals),9,"Lucida Sans Unicode",SellColor); 
      if(Show_Levels)
         {
         ObjectCreate("JJNBeeEntryLevel",OBJ_TREND,0,Time[1],Open[1],Time[0],Open[1]);
         ObjectSet("JJNBeeEntryLevel",OBJPROP_RAY,True);
         ObjectSet("JJNBeeEntryLevel",OBJPROP_BACK,True); // obj in the background
         ObjectSet("JJNBeeEntryLevel",OBJPROP_STYLE,STYLE_SOLID);
         ObjectSet("JJNBeeEntryLevel",OBJPROP_WIDTH,1);
         ObjectSet("JJNBeeEntryLevel",OBJPROP_COLOR,FontColor);
         ObjectCreate("JJNBeeTPLevel",OBJ_TREND,0,Time[1],Open[1]-Atr,Time[0],Open[1]-Atr);
         ObjectSet("JJNBeeTPLevel",OBJPROP_RAY,True);
         ObjectSet("JJNBeeTPLevel",OBJPROP_BACK,True); // obj in the background
         ObjectSet("JJNBeeTPLevel",OBJPROP_STYLE,STYLE_SOLID);
         ObjectSet("JJNBeeTPLevel",OBJPROP_WIDTH,1);
         ObjectSet("JJNBeeTPLevel",OBJPROP_COLOR,BuyColor);
         ObjectCreate("JJNBeeSLLevel",OBJ_TREND,0,Time[1],Open[1]+Atr,Time[0],Open[1]+Atr);
         ObjectSet("JJNBeeSLLevel",OBJPROP_RAY,True);
         ObjectSet("JJNBeeSLLevel",OBJPROP_BACK,True); // obj in the background
         ObjectSet("JJNBeeSLLevel",OBJPROP_STYLE,STYLE_SOLID);
         ObjectSet("JJNBeeSLLevel",OBJPROP_WIDTH,1);
         ObjectSet("JJNBeeSLLevel",OBJPROP_COLOR,SellColor);
         }
      if(SoundAlert) PlaySound("alert.wav");
      }
   else 
      {
      ObjectSet("JJNBeeDirection",OBJPROP_XDISTANCE,PosX+8);
      ObjectSetText("JJNBeeDirection","WAIT",20,"Lucida Sans Unicode",FontColor); 
      ObjectSetText("JJNBeeLevel","",9,"Lucida Sans Unicode",FontColor);
      ObjectDelete("JJNBeeEntryLevel");  
      ObjectDelete("JJNBeeTPLevel");
      ObjectDelete("JJNBeeSLLevel");
      }
  
   //Comment("");
   
         
    
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

Comments