Indian Scalp(euro)
Download scriptThis automated trading script is designed to manage trades based on momentum indicators and specific time filters. It focuses on "scalping," which involves capturing small price movements quickly. Below is a professional breakdown of its operational logic:
Core Trading Mechanics
The script primary utilizes a technical indicator (Relative Strength Index) to determine when a market trend is overextended or beginning to shift. It looks for specific thresholds—essentially "overbought" and "oversold" levels—to trigger actions.
- Entry Logic: The system monitors the price data to identify moments where the market momentum reaches an extreme point. When it detects these conditions, it opens either a Buy or Sell position depending on which direction the momentum is signaling.
- Exit Logic: The script doesn't just wait for a fixed target; it constantly evaluates active trades. If the momentum indicator reverses (signaling that the previous move might be exhausting), the script can proactively close an open position to protect profits or minimize losses.
Risk Management Tools
To ensure capital protection, the script includes several automated safety features:
- Fixed Targets: Users can define a specific "Stop Loss" (to limit how much can be lost on a single trade) and a "Take Profit" (to automatically lock in gains).
- Trailing Stop: This is a dynamic risk management feature. As a trade moves into profit, the script can "trail" the exit price behind it. If the price moves favorably, the stop loss follows; if the price reverses against the trade by a specific amount, the position is closed automatically. This helps in securing profits during volatile trends.
Operational Constraints
The script includes intelligent filters to ensure it operates only under optimal conditions:
- Time Filtering: It can be configured to only trade during specific global market sessions (such as the London, USA, or Asian sessions). This prevents the bot from trading during low-liquidity periods or "sideways" markets where signals are often less reliable.
- Order Management: The script tracks its own active trades. It ensures that it does not over-leverage by checking how many positions are currently open before initiating a new trade.
- Market Readiness: It includes basic checks to ensure the trading platform has enough historical data and that "Auto-Trading" is enabled before attempting to execute any orders.
Summary of Workflow
- Scan: Every heartbeat, the bot checks if there are active trades and monitors the current time.
- Analyze: It calculates momentum levels to see if the market is overextended.
- Execute: If no trades are open and conditions are met (within the allowed time windows), it opens a position.
- Monitor: While a trade is active, it constantly checks for "reversal" signals to close the trade early or adjusts the trailing stop to lock in current progress.
//+------------------------------------------------------------------+
//| StochScalp^^2^^.mq4 |
//| Nicholishen |
//| |
//+------------------------------------------------------------------+
#property copyright "Nicholishen @ Apex Group Investments,LLC"
#property link "www.forex-tsd.com"
#include <stdlib.mqh>
#include <WinUser32.mqh>
extern string ________Inputs_________;
extern int Confirm=3000;
extern int K=3;
//extern int D=2;
//extern int SL=1;
extern double lots=1;
extern int TakeProfit=9;
extern int StopLoss=25;
extern int ob=99;
extern int os=1;
extern string _______TradeTime________;
extern bool UseTimeFilter=false;
extern int USA_Session=1100;
extern int USA_End=1500;
extern int Asian_Session=2300;
extern int Asian_End=300;
extern int London_Session=600;
extern int London_End=1000;
extern string ______TrailingStop_______;
extern bool UseTrail = true;
extern double TrailingAct = 6;
extern double TrailingStep = 6;
//extern int BeginHour=8;
//extern int EndHour=18;
int bar;
int TestStart;
int k;
int mm,dd,yy,hh,min,ss,tf;
string comment;
string syym;
string qwerty;
int OrderID;
double TrailPrice;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int TimeFilter(){
if (((Hour()>=USA_Session && Hour() < USA_End) || (Hour()>=Asian_Session && Hour() < Asian_End) || (Hour()>=London_Session && Hour()< London_End)) ) {
return(1);
}
return(0);
}
//+------------------------------------------------------------------+
// Calculates Current Orders on TF,Pair,EA
//+------------------------------------------------------------------+
int CalculateCurrentOrders(){
int orders=0;
for(int i=0;i<OrdersTotal();i++){
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
if(OrderSymbol()==Symbol() && OrderMagicNumber()==OrderID ){
orders++;
}
}
}
return(orders);
}
int TradeSignal(int functyp){
bool Rev=false;
int x = Confirm;
double sto1=iRSI(NULL,0,K,0,x);
// double sto2=iStochastic(NULL,0,15,2,1,MODE_SMA,0,MODE_SIGNAL,1);
// double stdev=iStdDev(NULL,0,10,MODE_SMA,0,0,0);
//double sto3=iStochastic(NULL,1440,15,2,1,MODE_SMA,0,MODE_MAIN,0);
// double sto4=iStochastic(NULL,1440,15,2,1,MODE_SMA,0,MODE_SIGNAL,0);
if(functyp==1){
if(sto1 >ob ){
if(Rev){
return(1);
}else{
return(2);
}
}
if(sto1 < os ){
if(Rev){
return(2);
} else{
return(1);
}
}
}
if(functyp==2){
if(sto1 >ob){
if(Rev){
return(1);
}else{
return(2);
}
}
if(sto1 < os){
if(Rev){
return(2);
} else{
return(1);
}
}
}
return(0);
}
//+------------------------------------------------------------------+
//| Open Conditions |
//+------------------------------------------------------------------+
void CheckForOpen(){
double sl,tp; int res,error;
if(TradeSignal(1)==2){
if (StopLoss==0) {sl=0;} else sl=Bid+Point*StopLoss;
if (TakeProfit==0) {tp=0;} else tp=Bid-Point*TakeProfit;
bar=Bars;
res = OrderSend(Symbol(),OP_SELL,lots,Bid,3,sl,tp,"Indian Scalp",OrderID,0,Blue); // def
if(res<0){
error=GetLastError();
Print("Error = ",ErrorDescription(error));
}
}
if(TradeSignal(1)==1){
if (StopLoss==0) {sl=0;} else sl=Ask-Point*StopLoss;
if (TakeProfit==0) {tp=0;} else tp=Ask+Point*TakeProfit;
bar=Bars;
res = OrderSend(Symbol(),OP_BUY,lots,Ask,3,sl,tp,"Indian Scalp",OrderID,0,Red); // def
if(res<0){
error=GetLastError();
Print("Error = ",ErrorDescription(error));
}
}
}
//+------------------------------------------------------------------+
//| Close conditions |
//+------------------------------------------------------------------+
void CheckForClose(){
for(int i=0;i<OrdersTotal();i++){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderType()==OP_BUY && OrderMagicNumber()==OrderID && Symbol()==OrderSymbol()){
if (TradeSignal(2)==2) { // MA SELL signals
int res = OrderClose(OrderTicket(),OrderLots(),Bid,3,White); // close
TrailPrice=0;
if(res<0){
int error=GetLastError();
Print("Error = ",ErrorDescription(error));
}
}
}
if (OrderType()==OP_SELL && OrderMagicNumber()==OrderID && Symbol()==OrderSymbol() ){
if (TradeSignal(2)==1) { // MA BUY signals
res = OrderClose(OrderTicket(),OrderLots(),Ask,3,White); // close
TrailPrice=0;
if(res<0){
error=GetLastError();
Print("Error = ",ErrorDescription(error));
}
}
}
}
}
void TrailingPositions() {
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderMagicNumber()==OrderID ) {
if (OrderType()==OP_BUY) {
if (Bid-OrderOpenPrice()>TrailingAct*Point && TrailPrice ==0) {
TrailPrice=Bid-TrailingStep*Point;
Print("TRAIL PRICE MODIFIED: ",TrailPrice);
}
if (TrailPrice>0 && TrailPrice < Bid-TrailingStep*Point){
TrailPrice=Bid-TrailingStep*Point;
Print("TRAIL PRICE MODIFIED: ",TrailPrice);
}
if (TrailPrice >0 && TrailPrice >= Bid-TrailingStep*Point){
CloseOrder(1);
}
}
if (OrderType()==OP_SELL) {
if (OrderOpenPrice()-Ask > TrailingAct*Point && TrailPrice ==0) {
TrailPrice=Ask+TrailingStep*Point;
Print("TRAIL PRICE MODIFIED: ",TrailPrice);
}
if (TrailPrice>0 && TrailPrice > Ask+TrailingStep*Point){
TrailPrice=Ask+TrailingStep*Point;
Print("TRAIL PRICE MODIFIED: ",TrailPrice);
}
if (TrailPrice >0 && TrailPrice <= Ask+TrailingStep*Point){
CloseOrder(2);
}
}
}
}
}}
void CloseOrder(int ord){
for(int i=0;i<OrdersTotal();i++){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderType()==OP_BUY && OrderMagicNumber()==OrderID){
if (ord==1){
int res = OrderClose(OrderTicket(),OrderLots(),Bid,3,White); // close
TrailPrice=0;
if(res<0){
int error=GetLastError();
Print("Error = ",ErrorDescription(error));
}
}}
if (OrderType()==OP_SELL && OrderMagicNumber()==OrderID ){
if (ord==2) { // MA BUY signals
res = OrderClose(OrderTicket(),OrderLots(),Ask,3,White); // close
TrailPrice=0;
if(res<0){
error=GetLastError();
Print("Error = ",ErrorDescription(error));
}
}
}
}
}
int start(){
if(Bars<100 || IsTradeAllowed()==false) return;
if(CalculateCurrentOrders()==0) {
TrailPrice=0;
if(UseTimeFilter && TimeFilter()==1)return;
CheckForOpen();
}else{
CheckForClose();
}
if(UseTrail){TrailingPositions();}
// if(UseEmailAlerts){MailAlert();}
return(0);
}
//------------------------------------------------------------+
Profitability Reports
Expected payoff
Average expected payoff across the available backtests for each symbol.
Comments