ScalpExp03All_ver2

Download script
Profit factor:
0.00

This script is an automated trading system designed for "Scalping"—a strategy where the goal is to capture many small price movements quickly. It manages trade entries, exits, and risk parameters based on real-time market behavior and price levels.

Core Market Analysis

The logic begins by identifying a specific price range over a set period of historical data (the "channel"). It automatically calculates:

  • High and Low Boundaries: The highest and lowest prices reached during the specified timeframe.
  • Midline: The exact halfway point between the High and Low boundaries.
  • Volatility: It calculates the width of this channel to determine how much room the market has to move.

Trade Entry Logic (Signals)

The script looks for specific conditions to open trades, primarily focusing on whether the price is "stretched" relative to its recent range:

  • Sell Signals: These are triggered when the price is significantly above the Midline and shows downward momentum. It identifies a "selling" opportunity when the price has moved too far up and is expected to pull back.
  • Buy Signals: These are triggered when the price is significantly below the Midline and shows upward momentum. It identifies a "buying" opportunity when the price has dropped too far and is expected to bounce.

Dynamic Trade Management

Unlike simple bots that just set a "fire and forget" order, this script includes several management layers:

  • Dynamic Profit Thresholds: The profit target for closing a trade (the "threshold") is not always fixed. It adjusts based on the size of the current price channel. If the market is moving in a tight range, it aims for smaller profits; if the range is wide, it allows for larger movements.
  • Order Filtering: The system tracks existing positions. It will avoid opening new trades if certain conditions are met (such as having too many active orders or if a price has already moved too far from a previous entry point).
  • Pending Order Cleanup: To keep the trading environment clean, the script includes logic to automatically delete "Stop" orders that have not been triggered within a specific timeframe.

Exit and Safety Features

To protect capital, the script employs three main exit strategies:

  1. Take Profit & Stop Loss: Standard limits defined by the user to lock in gains or cut losses at predetermined price points.
  2. Trailing Stop: If enabled, this feature "follows" the price as it moves in a favorable direction. It locks in profits by moving the Stop Loss closer to the current price as the trade progresses.
  3. Profit-Based Closure: The script constantly monitors open trades and will close them immediately if they hit the calculated profit threshold for that specific market channel.

Visual Feedback

The script provides real-time information to the user by:

  • Drawing horizontal lines on the chart to show the High, Low, and Midline boundaries.
  • Displaying a data dashboard (Comment) on the screen showing current prices, channel width, and signal status.
  • Placing visual arrows on the chart to indicate where Buy or Sell signals were generated.
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategy
10 Views
0 Downloads
0 Favorites
ScalpExp03All_ver2
//+------------------------------------------------------------------+
//| Òåïåðü îí íà 100% èäåíòè÷åí SkalpExp03All.mql.                   |
//|Äà, è ñîîòâåòñòâåííî, ïîäòÿãèâàíèå îðäåðîâ ÿ çàêîììåíòàðèë.       |                                                   Scalp-M30.mq4 |
//|                                                           Vovan. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#include <stdlib.mqh>

extern double TakeProfit = 15;
extern double StopLoss = 100;
extern double Lots = 1.0;
extern double TrailingStop = 0;
extern int per=14;
extern int mgod=2006;
extern int ttime=60;
extern int m1=0;
extern int zap=15;
extern int msec=45;
extern int Pause=450;//??
extern double mlot=1.0;
double canal,ob,os,dl,dh,lb,b,s,oppr,porog,hod,MidLine,MaxH,MinL,MaxPr,ls;
   double lbsig,ssig,bsig,lssig,pb=200,ps;
   datetime ctm1;
string MaxHi="lime";
string MinLow="ww",MidLin="ee";
int korl,korh,blok,i,reg=1,j,MinPr,blokd,Prec=4,k;
//+------------------------------------------------------------------+
int start()
{
   int cnt,i,ticket;
   string arrup,arrdown;
   datetime ctm;
   if(mgod!=Year()) return(0);
   if(m1==Minute() && msec<=Seconds() && j==0) j=j+1;
//---------------------------------------Ïîäñ÷åò îòêðûòûõ ïîçèöèé----------------
   b=0;s=0;ob=0;os=0;ls=0;lb=0;
   for (cnt=0;cnt<OrdersTotal();cnt++) 
   {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()==OP_SELL && OrderSymbol()==Symbol()) {b=b+1;oppr=OrderOpenPrice();}
      if(OrderType()==OP_BUY && OrderSymbol()==Symbol()) {s=s+1;oppr=OrderOpenPrice();}
      if(OrderType()==OP_SELLSTOP && OrderSymbol()==Symbol()) {os=os+1;oppr=OrderOpenPrice();}
      if(OrderType()==OP_BUYSTOP && OrderSymbol()==Symbol()) {ob=ob+1;oppr=OrderOpenPrice();}
      if(OrderType()==OP_SELLLIMIT && OrderSymbol()==Symbol()) {ls=ls+1;oppr=OrderOpenPrice();}
      if(OrderType()==OP_BUYLIMIT && OrderSymbol()==Symbol()) {lb=lb+1;oppr=OrderOpenPrice();}
   }
   if((os+ob)>0) {blok=1;blokd=1;}
//-----------------------------------------------MiniMax Setting------------------------------------------------

   MaxH=High[per];MinL=Low[per];
   for (cnt=0;cnt<per;cnt++)
   {
      if (MaxH<High[cnt]) MaxH=High[cnt];
      if (MinL>Low[cnt]) MinL=Low[cnt];
   }
   MidLine=NormalizeDouble((MaxH+MinL)/2,Prec);
   ObjectMove("MaxHi",OBJ_HLINE,CurTime(),MaxH);
   ObjectMove("MinLow",OBJ_HLINE,CurTime(),MinL);
   ObjectMove("MidLine",OBJ_HLINE,CurTime(),MidLine);
   canal=MathRound((MaxH-MinL)/Point); 
   ObjectCreate(MaxHi, OBJ_HLINE, 0, Time[0],MaxH);ObjectsRedraw();
   ObjectCreate(MinLow, OBJ_HLINE, 0, Time[0],MinL);ObjectsRedraw();
   ObjectCreate(MidLin, OBJ_HLINE, 0, Time[0],MidLine);ObjectsRedraw();
   ObjectSet(MaxHi, OBJPROP_PRICE1,MaxH);ObjectsRedraw();
   ObjectSet(MinLow, OBJPROP_PRICE1,MinL);ObjectsRedraw();
   ObjectSet(MidLin, OBJPROP_PRICE1,MidLine);ObjectsRedraw();
   //Comment("ps - ",ps," pb - ",pb,"\nos - ",os," ob - ",ob);
   if(os==1 && ((oppr-MidLine)/Point)>=5) reg=0;
   if(ob==1 && ((oppr-MidLine)/Point)<=-5) reg=0;
   if((os+ob)==0 && (s+b)==0 && canal<30) return(0);
   if(MidLine<oppr && ssig==1) reg=0; 
   if(MidLine<oppr && bsig==1) reg=1; 
   if(MidLine>oppr && ssig==1) reg=1; 
   if(MidLine>oppr && bsig==1) reg=0; 
   if(mlot==0.1)
   {
      if(reg==0) porog=canal/10; else porog=5;
      if(canal<50) porog=canal/10;
      porog=MathRound(porog);
   }
   if (mlot==1.0)
   {
      if (reg==0) porog=canal; else porog=5;
      if (canal<50) porog=canal;
   }
//------------------------------------Îïðåäåëåíèå õîäîâûõ ïàðàìåòðîâ ïàðû---------------------------------
   hod=(Open[3]-Close[3]+Open[2]-Close[2]+Open[1]-Close[1]+Open[0]-Close[0])/Point;  

   if ((MidLine-Close[0])/Point<-5) korh=1; else korh=0;
   if ((MidLine-Close[0])/Point>5) korl=1;else korl=0;

//---------------------------------------------Ñíÿòèå ñëèâîê----------------------------------------------
//!!if((CurTime()-OrderCloseTime())<15) return(0);
   if ((s+b+os+ob+ls+lb)>0) {MaxPr=0; MinPr=0;}
   if(( b+s)>0 && TrailingStop==0)  
   {
      for (cnt=0;cnt<OrdersTotal();cnt++) 
      {//Comment("HistoryTotal - ",HistoryTotal());
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if(OrderSymbol()==Symbol())
         {
            if (OrderProfit()>MaxPr) MaxPr=OrderProfit();
            if (OrderProfit()<MinPr) MinPr=OrderProfit();
            if(OrderType()==OP_SELL && OrderSymbol()==Symbol()) 
            {
               if (OrderProfit()>0)
               {
                  if (OrderProfit()>porog)
                  {
                     OrderClose(OrderTicket(),OrderLots(),Ask,5,Violet); // close position
                     return(0);
                  }
               }
            }
            if(OrderType()==OP_BUY && OrderSymbol()==Symbol()) 
            {
               if (OrderProfit()>0)
               {
                  if (OrderProfit()>porog)
                  {
                     OrderClose(OrderTicket(),OrderLots(),Bid,5,Violet); // close position
                     return(0);
                  }
               }
            }    
         }
      } 
   }    

   if ((ob+os)==0 && (b+s)==0 && (ls+lb)==0 && Hour()!=0){blok=0; oppr=0; blokd=0;}
   if ((os+ob)>0) {blok=1;blokd=1;}
   if (((MathAbs(oppr-Close[0]))/Point)>=15) blokd=0;
   if (j>0) { blokd=0;j=0;} else blokd=1;

   if (blokd==0) 
   {
      for (cnt=OrdersTotal();cnt==0;cnt--) 
      {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if (OrderType()==OP_BUYSTOP && OrderSymbol()==Symbol()) OrderDelete(cnt);
         if (OrderType()==OP_SELLSTOP && OrderSymbol()==Symbol()) OrderDelete(cnt);
      }
   }

//-----------------------------------------------Indicators Setting--------------------------------------------

   ssig=0;bsig=0; 
   if ((s+b+os+ob+ls+lb)>0){korh=0;korl=0;}

   if (korh==1 && hod>0) {ssig=1;SetIndexArrow(0,242);}
   if ((MaxH-Close[0])>10*Point) 
   {
      if (korh==1 && hod<=-5) {bsig=1;SetIndexArrow(0,241);}
   }else{
      if (korh==1 && hod<=-5) {ssig=1;SetIndexArrow(0,242);}
   }
   if (korl==1 && hod<0) {bsig=1;SetIndexArrow(0,241);}
   if ((Close[0]-MinL)>10*Point)
   { 
      if (korl==1 && hod>=5){ssig=1;SetIndexArrow(0,242);}
   }else{
      if (korh==1 && hod>=5) {bsig=1;SetIndexArrow(0,241);}
   }

   Comment("Data: ",Year(),".",Month(),".",Day(),"  Time ",Hour(),":",Minute(),"   MidLine=",(MaxH+MinL)/2,"  MaxPr: ",MaxPr,
           "  MinPr=",MinPr,"  Blok=",blok,"  TInd=",j,"  Reg=",reg,"\n","StoProfit=",porog,"  Canal=",canal,
           "  Profit=",MathRound(OrderProfit()),"  Hod=",hod,"  KorL=",korl,"  KorH=",korh,"  DBlok=",blokd,"  OrdPrice=",oppr);
  
//-------------------------------------------------Open Positions---------------------------------------------
   if ((ob+os+lb+ls)==0) blok=0;

   if (blok==0) 
   {
      if ((CurTime()-OrderCloseTime())<ttime) return(0); //?????
      if (ssig==1 && s==0 && os==0) 
      {     
         arrdown=CharToStr(Time[0]);
         ObjectCreate(arrdown, OBJ_ARROW, 0,Time[0],High[0]+10*Point);
         ObjectSet(arrdown,OBJPROP_ARROWCODE,242);
         ObjectSet(arrdown,OBJPROP_COLOR,Yellow);
         ticket=OrderSend(Symbol(),OP_SELLSTOP,mlot,Bid-zap*Point,5,Bid+StopLoss*Point-zap*Point,Bid-TakeProfit*Point-zap*Point,"Sculp_Sell",1,0,GreenYellow);
         ps=Bid;//new
         return(0);
      } 
      if (bsig==1 && b==0 && ob==0 && (Bid+5*Point)>Ask)
      {
         arrup=CharToStr(Time[0]);
         ObjectCreate(arrup, OBJ_ARROW, 0,Time[0],Low[0]-10*Point);
         ObjectSet(arrup,OBJPROP_ARROWCODE,241);
         ObjectSet(arrup,OBJPROP_COLOR,Blue);
         ticket=OrderSend(Symbol(),OP_BUYSTOP,mlot,Ask+zap*Point,5,Ask-StopLoss*Point+zap*Point,Ask+TakeProfit*Point+zap*Point,"Sculp_Buy",2,0,Violet);
         pb=Ask;//new
         return(0);
      }
   }
 
//----------------------------TrailingStop--------------------------
   if ((b+s)>0 && TrailingStop>0)
   {
      for (cnt=0;cnt<OrdersTotal();cnt++) 
      {
         os=0;ob=0;
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if(OrderType()==OP_BUY && OrderSymbol()==Symbol())  // check for symbol
         {
            if ((Bid-OrderOpenPrice())>TrailingStop*Point)
            {
               if(OrderStopLoss()<Bid-Point*TrailingStop)
               {
                  OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                  return(0);
               }
            }
         }
         if(OrderType()==OP_SELL && OrderSymbol()==Symbol())  // check for symbol
         {  
            if((OrderOpenPrice()-Ask)>Point*TrailingStop)
            {
               if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
               {
                  OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                  return(0);
               }
            }
         }
      }
   } 
//---------------------------Çäåñü êîí÷àåòñÿ ñòàíäàðòíûé SkalpExp03All -----------------
/*
//-------------------------Ïîäòÿíåì îòëîæåííûå îðäåðà--------------------  
if((ob+os)>0)
   {
   for (cnt=0;cnt<OrdersTotal();cnt++) 
      {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()==OP_SELLSTOP && OrderSymbol()==Symbol())
         {
         //Comment("Hello");  
         if (ps< Bid)
            {
            arrdown=CharToStr(Time[0]);
            ObjectCreate(arrdown, OBJ_ARROW, 0,Time[0],High[0]+10*Point);
            ObjectSet(arrdown,OBJPROP_ARROWCODE,242);
            ObjectSet(arrdown,OBJPROP_COLOR,Yellow);
      	   ps=Bid; 
            OrderModify(OrderTicket(),Bid-zap*Point,0,0,0,Green);
            OrderModify(OrderTicket(),Bid-zap*Point,Bid+StopLoss*Point-zap*Point,Bid-Point*TakeProfit-zap*Point,0,Green);
            return(0);
      	   } 
      	}

      if(OrderType()==OP_BUYSTOP && OrderSymbol()==Symbol())
         {  

         if (pb>Ask)
            {
            arrup=CharToStr(Time[0]);
            ObjectCreate(arrup, OBJ_ARROW, 0,Time[0],Low[0]-10*Point);
            ObjectSet(arrup,OBJPROP_ARROWCODE,241);
            ObjectSet(arrup,OBJPROP_COLOR,Blue);
	         pb=Ask;
            OrderModify(OrderTicket(),Ask+zap*Point,0,0,0,Violet);
            OrderModify(OrderTicket(),Ask+zap*Point,Ask+zap*Point-StopLoss*Point,Ask+zap*Point+TakeProfit*Point,0,Violet);
            return(0);
            }
         }
    } 
}
*/
}

Profitability Reports

PERFORMANCE BY SYMBOL

Expected payoff

Average expected payoff across the available backtests for each symbol.

Positive Negative
4 reports
AUD/USD Oct 2024 - Jan 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%

Comments