JJN-Scalper
Download scriptThe JJN-Scalper is a visual trading assistant designed to help identify potential entry points, profit targets, and stop-loss levels on a price chart. Rather than just giving general signals, it looks for specific structural relationships between current price action and historical "reversal" candles.
Core Logic Overview
The script operates by scanning the recent market history to find significant price turning points. It specifically looks for "Opposite Candles"—candles that move significantly in the opposite direction of the current trend—and uses them as anchors for calculating potential trade zones.
How it Works:
1. Identification Phase The script constantly monitors the current candle's movement. Depending on which way the price is moving, it performs a backward search through history to find the most recent significant "counter-move":
- For Buy Signals: If the price is currently moving up, the script searches backward for the most recent significant downward (bearish) candle.
- For Sell Signals: If the price is currently moving down, the script searches backward for the most recent significant upward (bullish) candle.
To ensure these candles are meaningful and not just "noise," the script checks that the move was large enough to exceed a specific minimum threshold (the "Doji Difference").
2. Signal Validation A signal is only displayed if the current price crosses a specific historical level:
- Buy Signal: Triggered when the current price is rising and has climbed above the opening price of that previous significant downward candle.
- Sell Signal: Triggered when the current price is falling and has dropped below the opening price of that previous significant upward candle.
3. Visual Feedback and Trade Planning Once a valid setup is identified, the script automatically draws several visual elements on your chart to help you plan the trade:
- Direction Label: A clear text indicator showing "BUY" or "SELL" in contrasting colors.
- Entry Level: A horizontal line marking the specific price point where the signal was triggered.
- Take Profit & Stop Loss: The script uses a technical volatility measure (ATR) to automatically calculate your targets. It projects your profit target and your safety net (stop loss) at a set distance away from the entry point based on recent market volatility.
- Price Arrows: Small icons appear on the chart to pinpoint exactly where the entry, stop loss, and profit levels are located.
Summary of Behavior
If the market conditions do not meet the specific requirements for a reversal setup, the script remains in a "Wait" state, clearing all drawings from the screen. When a valid setup appears, it instantly populates the chart with a complete visual roadmap, including color-coded targets and an optional audible alert to notify you of the opportunity.
//+------------------------------------------------------------------+
//| JJN-Scalper.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
//---- indicator parameters
extern string __Copyright__ = "http://jjnewark.atw.hu";
extern int AtrPeriod = 8;
extern double DojiDiff = 0.0002;
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 Atr;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
//----
IndicatorShortName("JJN-Scalper");
ObjectCreate("JJNScalperIndName",OBJ_LABEL,0,0,0,0,0);
ObjectSet("JJNScalperIndName",OBJPROP_CORNER,0);
ObjectSet("JJNScalperIndName",OBJPROP_XDISTANCE,PosX+12);
ObjectSet("JJNScalperIndName",OBJPROP_YDISTANCE,PosY);
ObjectSetText("JJNScalperIndName","JJN-Scalper",8,"Lucida Sans Unicode",FontColor);
ObjectCreate("JJNScalperLine0",OBJ_LABEL,0,0,0,0,0);
ObjectSet("JJNScalperLine0",OBJPROP_CORNER,0);
ObjectSet("JJNScalperLine0",OBJPROP_XDISTANCE,PosX+5);
ObjectSet("JJNScalperLine0",OBJPROP_YDISTANCE,PosY+8);
ObjectSetText("JJNScalperLine0","------------------",8,"Tahoma",FontColor);
ObjectCreate("JJNScalperLine1",OBJ_LABEL,0,0,0,0,0);
ObjectSet("JJNScalperLine1",OBJPROP_CORNER,0);
ObjectSet("JJNScalperLine1",OBJPROP_XDISTANCE,PosX+5);
ObjectSet("JJNScalperLine1",OBJPROP_YDISTANCE,PosY+10);
ObjectSetText("JJNScalperLine1","------------------",8,"Tahoma",FontColor);
ObjectCreate("JJNScalperDirection",OBJ_LABEL,0,0,0,0,0);
ObjectSet("JJNScalperDirection",OBJPROP_CORNER,0);
ObjectSet("JJNScalperDirection",OBJPROP_XDISTANCE,PosX);
ObjectSet("JJNScalperDirection",OBJPROP_YDISTANCE,PosY+12);
ObjectSetText("JJNScalperDirection","Wait",20,"Lucida Sans Unicode",FontColor);
ObjectCreate("JJNScalperLevel",OBJ_LABEL,0,0,0,0,0);
ObjectSet("JJNScalperLevel",OBJPROP_CORNER,0);
ObjectSet("JJNScalperLevel",OBJPROP_XDISTANCE,PosX);
ObjectSet("JJNScalperLevel",OBJPROP_YDISTANCE,PosY+50);
ObjectSetText("JJNScalperLevel","",9,"Lucida Sans Unicode",FontColor);
//---- initialization done
return(0);
}
int deinit()
{
//----
ObjectDelete("JJNScalperLine0");
ObjectDelete("JJNScalperLine1");
ObjectDelete("JJNScalperIndName");
ObjectDelete("JJNScalperDirection");
ObjectDelete("JJNScalperLevel");
ObjectDelete("JJNScalperEntry");
ObjectDelete("JJNScalperTakeProfit");
ObjectDelete("JJNScalperStopLoss");
ObjectDelete("TPPrice");
ObjectDelete("EntryPrice");
ObjectDelete("SLPrice");
//----
return(0);
}
int start()
{
int lastbullishindex=0;
int lastbearishindex=0;
double lastbearishopen=0;
double lastbullishopen=0;
Atr=iATR(NULL,0,AtrPeriod,0);
if(Close[0]>Open[0]) // BUY
{
int found=0;
int w=0;
while(found<1) // search for the last bearish candle
{
if(Close[w]<Open[w] && Open[w]-Close[w]>DojiDiff)
{
lastbearishopen=Open[w];
lastbearishindex=w;
found++;
}
w++;
}
}
else if(Close[0]<Open[0]) // SELL
{
found=0;
w=0;
while(found<1) // search for the last bullish candle
{
if(Close[w]>Open[w] && Close[w]-Open[w]>DojiDiff)
{
lastbullishopen=Open[w];
lastbullishindex=w;
found++;
}
w++;
}
}
else // NO TRADE
{
lastbullishindex=0;
lastbearishindex=0;
lastbearishopen=0;
lastbullishopen=0;
}
ObjectDelete("JJNScalperEntry");
ObjectDelete("JJNScalperTakeProfit");
ObjectDelete("JJNScalperStopLoss");
ObjectDelete("TPPrice");
ObjectDelete("EntryPrice");
ObjectDelete("SLPrice");
if(Close[0]>Open[0] && Close[0]<lastbearishopen) // BUY
{
ObjectSet("JJNScalperDirection",OBJPROP_XDISTANCE,PosX+5);
ObjectSetText("JJNScalperDirection","BUY",28,"Lucida Sans Unicode",BuyColor);
ObjectSetText("JJNScalperLevel","above "+DoubleToStr(lastbearishopen,DisplayDecimals),9,"Lucida Sans Unicode",BuyColor);
ObjectCreate("JJNScalperEntry",OBJ_TREND,0,Time[lastbearishindex],lastbearishopen,Time[0],lastbearishopen);
ObjectSet("JJNScalperEntry",OBJPROP_RAY,False);
ObjectSet("JJNScalperEntry",OBJPROP_BACK,True); // obj in the background
ObjectSet("JJNScalperEntry",OBJPROP_STYLE,STYLE_SOLID);
ObjectSet("JJNScalperEntry",OBJPROP_WIDTH,1);
ObjectSet("JJNScalperEntry",OBJPROP_COLOR,FontColor);
ObjectCreate("JJNScalperTakeProfit",OBJ_TREND,0,Time[lastbearishindex],lastbearishopen+Atr,Time[0],lastbearishopen+Atr);
ObjectSet("JJNScalperTakeProfit",OBJPROP_RAY,False);
ObjectSet("JJNScalperTakeProfit",OBJPROP_BACK,True); // obj in the background
ObjectSet("JJNScalperTakeProfit",OBJPROP_STYLE,STYLE_SOLID);
ObjectSet("JJNScalperTakeProfit",OBJPROP_WIDTH,1);
ObjectSet("JJNScalperTakeProfit",OBJPROP_COLOR,BuyColor);
ObjectCreate("JJNScalperStopLoss",OBJ_TREND,0,Time[lastbearishindex],lastbearishopen-Atr,Time[0],lastbearishopen-Atr);
ObjectSet("JJNScalperStopLoss",OBJPROP_RAY,False);
ObjectSet("JJNScalperStopLoss",OBJPROP_BACK,True); // obj in the background
ObjectSet("JJNScalperStopLoss",OBJPROP_STYLE,STYLE_SOLID);
ObjectSet("JJNScalperStopLoss",OBJPROP_WIDTH,1);
ObjectSet("JJNScalperStopLoss",OBJPROP_COLOR,SellColor);
ObjectCreate("TPPrice", OBJ_ARROW, 0, Time[0], lastbearishopen+Atr);
ObjectSet("TPPrice", OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
ObjectSet("TPPrice", OBJPROP_COLOR, BuyColor);
ObjectCreate("EntryPrice", OBJ_ARROW, 0, Time[0], lastbearishopen);
ObjectSet("EntryPrice", OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
ObjectSet("EntryPrice", OBJPROP_COLOR, FontColor);
ObjectCreate("SLPrice", OBJ_ARROW, 0, Time[0], lastbearishopen-Atr);
ObjectSet("SLPrice", OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
ObjectSet("SLPrice", OBJPROP_COLOR, SellColor);
if(SoundAlert) PlaySound("alert.wav");
}
else if(Close[0]<Open[0] && Close[0]>lastbullishopen) // SELL
{
ObjectSet("JJNScalperDirection",OBJPROP_XDISTANCE,PosX+2);
ObjectSetText("JJNScalperDirection","SELL",28,"Lucida Sans Unicode",SellColor);
ObjectSetText("JJNScalperLevel","under "+DoubleToStr(lastbullishopen,DisplayDecimals),9,"Lucida Sans Unicode",SellColor);
ObjectCreate("JJNScalperEntry",OBJ_TREND,0,Time[lastbullishindex],lastbullishopen,Time[0],lastbullishopen);
ObjectSet("JJNScalperEntry",OBJPROP_RAY,False);
ObjectSet("JJNScalperEntry",OBJPROP_BACK,True); // obj in the background
ObjectSet("JJNScalperEntry",OBJPROP_STYLE,STYLE_SOLID);
ObjectSet("JJNScalperEntry",OBJPROP_WIDTH,1);
ObjectSet("JJNScalperEntry",OBJPROP_COLOR,FontColor);
ObjectCreate("JJNScalperTakeProfit",OBJ_TREND,0,Time[lastbullishindex],lastbullishopen-Atr,Time[0],lastbullishopen-Atr);
ObjectSet("JJNScalperTakeProfit",OBJPROP_RAY,False);
ObjectSet("JJNScalperTakeProfit",OBJPROP_BACK,True); // obj in the background
ObjectSet("JJNScalperTakeProfit",OBJPROP_STYLE,STYLE_SOLID);
ObjectSet("JJNScalperTakeProfit",OBJPROP_WIDTH,1);
ObjectSet("JJNScalperTakeProfit",OBJPROP_COLOR,BuyColor);
ObjectCreate("JJNScalperStopLoss",OBJ_TREND,0,Time[lastbullishindex],lastbullishopen+Atr,Time[0],lastbullishopen+Atr);
ObjectSet("JJNScalperStopLoss",OBJPROP_RAY,False);
ObjectSet("JJNScalperStopLoss",OBJPROP_BACK,True); // obj in the background
ObjectSet("JJNScalperStopLoss",OBJPROP_STYLE,STYLE_SOLID);
ObjectSet("JJNScalperStopLoss",OBJPROP_WIDTH,1);
ObjectSet("JJNScalperStopLoss",OBJPROP_COLOR,SellColor);
ObjectCreate("TPPrice", OBJ_ARROW, 0, Time[0], lastbullishopen-Atr);
ObjectSet("TPPrice", OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
ObjectSet("TPPrice", OBJPROP_COLOR, BuyColor);
ObjectCreate("EntryPrice", OBJ_ARROW, 0, Time[0], lastbullishopen);
ObjectSet("EntryPrice", OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
ObjectSet("EntryPrice", OBJPROP_COLOR, FontColor);
ObjectCreate("SLPrice", OBJ_ARROW, 0, Time[0], lastbullishopen+Atr);
ObjectSet("SLPrice", OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
ObjectSet("SLPrice", OBJPROP_COLOR, SellColor);
if(SoundAlert) PlaySound("alert.wav");
}
else
{
ObjectSet("JJNScalperDirection",OBJPROP_XDISTANCE,PosX+8);
ObjectSetText("JJNScalperDirection","WAIT",20,"Lucida Sans Unicode",FontColor);
ObjectSetText("JJNScalperLevel","",9,"Lucida Sans Unicode",FontColor);
ObjectDelete("JJNScalperEntry");
ObjectDelete("JJNScalperTakeProfit");
ObjectDelete("JJNScalperStopLoss");
ObjectDelete("TPPrice");
ObjectDelete("EntryPrice");
ObjectDelete("SLPrice");
}
//Comment("");
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments