Download MetaTrader 5

Comfortable Scalping

13 June 2008, 07:02
Eryomin Sergey
7
3 117

Introduction

This article describes an algorithm of trade opening that allows to make scalping more comfortable. However, this algorithm can also be applied in other trading approaches. Actually, the article offers a method of helping a trader at such a fast trading.

Generally scalping is considered a very nervous type of trading. Very important here is the necessity to indicate lot, TakeProfit and StopLoss levels each time, thus being distracted from a chart.

This article is the continuation of "Betting Modeling as Means of Developing "Market Intuition"". I recommend reading it before starting to study the present article.

I'd like to remind you of what scalping is. Scalping is a method of quick trading. Usually in such a trading profit is fixed at 1-10 pips (points). Scalping is known for its complexity, nervousness and higher attentiveness required. Someone thinks it not serious, someone considers it a perfect mastery. As for me, I am not going to estimate this type of trading - it is widely discussed and everyone has one's own opinion.


Concept

Probably every trader ever tried to use a scalping strategy. For some traders scalping is the most convenient type of trading, for others - on the contrary. Some consider scalping the most interesting trading, others - a mere waste of time. However everyone can note about the necessity of a higher attention to market and opened trades in this type of trading.

Many traders decline using scalping just because it requires much effort and nerves. However, there is a method to help a scalper.

Suppose a trader is going to use scalping with a fixed lot and take profit at each trade. Obviously, it is reasonable to eliminate the necessity of indicating these parameters every time for each trade. Because it takes extra time and draws a trader's attention from a chart.

It means we need a tool that will open a trade with a fixed lot and TP/SL levels on a trader's command. The tool's operation should be maximally simple; besides it should minimally distract a trader from a chart.

Such a tool can be easily implemented using MQL4 means.


Implementation

As the basis we will take a game described in the article "Betting Modeling as Means of developing "Market Intuition"". We will create a tool, which will help to play this game and trade at the same time.

Short description of the game. Two arrows are drawn on the chart - up and down. A trader deletes an unnecessary arrow, thus making a choice denoting his opinion - whether a security will rise or fall. At the beginning of a new candlestick the EA checks whether a trader's forecast is right or wrong. The correctness of forecasting influences the game score. Moreover, a trader can make his choice within a limited period of time, which can be changed (a trader decides whether to set it or not).

For the implementation we will draw two more arrows one bar back than the current one. The current bar will be still used for the betting. Deletion of an arrow on the previous bar will be a signal for the EA to open a trade in the necessary direction. Besides, limitation of time period for choosing a trade direction will be disabled for trading. There will be the following changeable parameters: TakeProfit and StopLoss levels, lot, acceptable slippage and the magic number. Besides, trading can be disabled using the extern bool variable, thus the EA will be used only for betting.

Besides, at trade opening an arrow named 'buy' or 'sell' will be drawn on a chart, depending on a trade open at the time. This will be done to prevent the EA from opening new trades on this candlestick. This arrow will be drawn 300 points away from a bar opening price, so a user won't probably even notice it.

The EA itself will be divided into two blocks - the game and trade opening. Thus a reader can see what is added to the code.

So, we have the following program code:

//+------------------------------------------------------------------+
//|                                                       trener.mq4 |
//|                                       Copyright © 2008, FXRaider |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, FXRaider"
extern int gap=2;
extern bool Trading=true;
extern int TP=2;
extern int SL=20;
extern double Lots=0.02;
extern int slippage=1;
extern int MagicNumber=777;
extern int time_limit=30;
int start()
  {
//----
//#################################################################################
//####################################### GAME ####################################
//------------------------------
string solution="none"; 
int point, 
    point_neg, 
    point_pos;
//------------------------------    
//+---------------------------------------------------------------+
//|                      "up" choice searching                    | 
 if(
    ObjectGet("up", OBJPROP_PRICE1)==Open[1]+gap*Point
    &&iBarShift(NULL,0,ObjectGet("up",OBJPROP_TIME1))==1
    &&ObjectFind("down") != 0
    &&ObjectFind("up") == 0
    )
    {
     solution="up";
    }
//|                      "up" choice searching                    |  
//+---------------------------------------------------------------+
  
//+---------------------------------------------------------------+
//|                      "down" choice searching                  |     
 if(
    ObjectGet("down", OBJPROP_PRICE1)==Open[1]-gap*Point
    &&iBarShift(NULL,0,ObjectGet("down",OBJPROP_TIME1))==1    
    &&ObjectFind("up") != 0
    &&ObjectFind("down") == 0
    )
    {
     solution="down";
    }
//|                      "down" choice searching                  |       
//+---------------------------------------------------------------+    
 
//+---------------------------------------------------------------+
//|             counting points at a positive answer              |
    if((solution=="up"&&Open[1]<Close[1])
      ||(solution=="down"&&Open[1]>Close[1]))
    {
     point=1;
     point_pos=1;
     point_neg=0;     
    }  
//|             counting points at a positive answer              |   
//+---------------------------------------------------------------+
 
//+---------------------------------------------------------------+
//|             counting points at a negative answer              |    
    if((solution=="up"&&Open[1]>Close[1])
      ||(solution=="down"&&Open[1]<Close[1]))
    {
     point=-1;
     point_pos=0;
     point_neg=1;     
    } 
//|             counting points at a negative answer              |
//+---------------------------------------------------------------+
 
//+----------------------------------------------------------------------------------+
//|                              working with an external file                       |       
      int handle; 
      double points,     //total score
             points_pos, //score of positive answers
             points_neg; //score of negative answers 
       handle=FileOpen("trener_"+Symbol()+"_"+Period()+".csv",
                       FILE_CSV|FILE_WRITE|FILE_READ,";");
       if(handle>0) //if there is a file, read it
       { 
        points=NormalizeDouble(StrToDouble(FileReadString(handle)),Digits); 
        points_pos=NormalizeDouble(StrToDouble(FileReadString(handle)),Digits); 
        points_neg=NormalizeDouble(StrToDouble(FileReadString(handle)),Digits);       
        FileClose(handle);
       } 
       
    if(solution!="none") //if a choice has been made made 
    {        
      handle=FileOpen("trener_"+Symbol()+"_"+Period()+".csv",
                      FILE_CSV|FILE_WRITE|FILE_READ,";");
      FileWrite(handle ,points+point);         //write the total score
      FileWrite(handle ,points_pos+point_pos); //write the score of positive answers
      FileWrite(handle ,points_neg+point_neg); //write the score of negative answers                    
      FileClose(handle); 
    } 
//|                              working with an external file                       | 
//+----------------------------------------------------------------------------------+    
 
//+------------------------------------------------------------------------------------+
//|                                 working with objects                               |   
  if(iBarShift(NULL,0,ObjectGet("down",OBJPROP_TIME1))>0
     ||ObjectGet("down",OBJPROP_PRICE1)!=Open[0]-gap*Point) 
    {
     ObjectDelete("down"); 
    }  
 if(iBarShift(NULL,0,ObjectGet("up",OBJPROP_TIME1))>0
    ||ObjectGet("up",OBJPROP_PRICE1)!=Open[0]+gap*Point)            
    { 
     ObjectDelete("up"); 
    } 
   
  int sec_lim;  
  if(!time_limit)
  {
   sec_lim=0; 
  }
  else
  {
   sec_lim=TimeCurrent()-time_limit;
  }
  if(sec_lim>ObjectGet("up",OBJPROP_TIME1)
     &&sec_lim>ObjectGet("down",OBJPROP_TIME1) 
     &&ObjectFind("down") == 0&&ObjectFind("up") == 0
     &&iBarShift(NULL,0,ObjectGet("down",OBJPROP_TIME1))==0
     &&iBarShift(NULL,0,ObjectGet("up",OBJPROP_TIME1))==0)            
    { 
     ObjectDelete("up"); 
     ObjectDelete("down");      
    } 
  
   if((ObjectFind("down") != 0&&ObjectFind("up") != 0) //if no object
      &&sec_lim<Time[0])
   {
     ObjectCreate("down", OBJ_ARROW, 0, Time[0], Open[0]-gap*Point); //draw a down arrow
     ObjectSet("down", OBJPROP_STYLE, STYLE_DOT);
     ObjectSet("down", OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
     ObjectSet("down", OBJPROP_COLOR, Red);
 
     ObjectCreate("up", OBJ_ARROW, 0, Time[0], Open[0]+gap*Point); //draw an up arrow
     ObjectSet("up", OBJPROP_STYLE, STYLE_DOT);
     ObjectSet("up", OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
     ObjectSet("up", OBJPROP_COLOR, Blue);
    }      
//|                                 working with objects                               |   
//+------------------------------------------------------------------------------------+
//####################################### GAME ####################################
//#################################################################################
 
 
//#################################################################################
//#################################### TRADING ####################################
//+------------------------------------------------------------------------------------+  
//|                                working with objects I                              | 
  if(iBarShift(NULL,0,ObjectGet("down_1",OBJPROP_TIME1))>1
  ||ObjectGet("down_1",OBJPROP_PRICE1)!=Open[0]-gap*Point
  ||!Trading)  
  {
   ObjectDelete("down_1"); 
  }  
  
  if(iBarShift(NULL,0,ObjectGet("up_1",OBJPROP_TIME1))>1
  ||ObjectGet("up_1",OBJPROP_PRICE1)!=Open[0]+gap*Point
  ||!Trading)  
  { 
   ObjectDelete("up_1"); 
  } 
  
  if(iBarShift(NULL,0,ObjectGet("sell",OBJPROP_TIME1))>0
  ||ObjectGet("sell",OBJPROP_PRICE1)!=Open[0]-300*Point
  ||!Trading) 
  {
   ObjectDelete("sell"); 
  }
  if(iBarShift(NULL,0,ObjectGet("buy",OBJPROP_TIME1))>0
  ||ObjectGet("buy",OBJPROP_PRICE1)!=Open[0]+300*Point 
  ||!Trading)
  
  {
   ObjectDelete("buy"); 
  } 
  
   if(ObjectFind("down_1") != 0&&ObjectFind("up_1") != 0 && Trading)
   {
     ObjectCreate("down_1", OBJ_ARROW, 0, Time[1], Open[0]-gap*Point);
     ObjectSet("down_1", OBJPROP_STYLE, STYLE_DOT);
     ObjectSet("down_1", OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
     ObjectSet("down_1", OBJPROP_COLOR, Red);
 
     ObjectCreate("up_1", OBJ_ARROW, 0, Time[1], Open[0]+gap*Point);
     ObjectSet("up_1", OBJPROP_STYLE, STYLE_DOT);
     ObjectSet("up_1", OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
     ObjectSet("up_1", OBJPROP_COLOR, Blue);
    }  
//|                                working with objects I                              |    
//+------------------------------------------------------------------------------------+     
 if(Trading)
 {
//+----------------------------------------------------------------------------------------------+
//|                              searching open orders for a security                            |
    int pos_sell=0, bar_op_buy, bar_op_sell;
  for (int i_op_sell=OrdersTotal()-1; i_op_sell>=0; i_op_sell--) 
  { 
   if (!OrderSelect(i_op_sell,SELECT_BY_POS,MODE_TRADES)) break; 
   if (Symbol()==OrderSymbol()
   &&(OrderType()==OP_SELLSTOP||OrderType()==OP_SELL)
   &&(OrderMagicNumber()==MagicNumber)
   &&iBarShift(NULL,0,OrderOpenTime())==0)
   {
    pos_sell=1; break;   
   } 
  }
    
    int pos_buy=0;
  for (int i_op_buy=OrdersTotal()-1; i_op_buy>=0; i_op_buy--) 
  { 
   if (!OrderSelect(i_op_buy,SELECT_BY_POS,MODE_TRADES)) break; 
   if (Symbol()==OrderSymbol()
   &&(OrderType()==OP_BUYSTOP||OrderType()==OP_BUY)
   &&(OrderMagicNumber()==MagicNumber)
   &&iBarShift(NULL,0,OrderOpenTime())==0)
   {
    pos_buy=1; break;   
   } 
  }    
//|                              searching open orders for a security                            |
//+----------------------------------------------------------------------------------------------+ 
 
//+------------------------------------------------------------------------------------+  
//|                                working with objects II                             |   
 if(pos_buy==1)
 {   
      ObjectCreate("buy", OBJ_ARROW, 0, Time[0], Open[0]+300*Point);
      ObjectSet("buy", OBJPROP_STYLE, STYLE_DOT);
      ObjectSet("buy", OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
      ObjectSet("buy", OBJPROP_COLOR, Red);
 }
 
 if(pos_sell==1)
 {
      ObjectCreate("sell", OBJ_ARROW, 0, Time[0], Open[0]-300*Point);
      ObjectSet("sell", OBJPROP_STYLE, STYLE_DOT);
      ObjectSet("sell", OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
      ObjectSet("sell", OBJPROP_COLOR, Red);    
 }
//|                                working with objects II                             |   
//+------------------------------------------------------------------------------------+ 
  
//+------------------------------------------------------------------------------------+ 
//|                                   opening trades                                   |
double sl_buy, sl_sell;
 if(!SL)
 { 
  sl_buy=0;
  sl_sell=0;
 }
 else
 {
  sl_buy=Ask-SL*Point;
  sl_sell=Bid+SL*Point;
 }
  if(
     ObjectGet("up_1", OBJPROP_PRICE1)==Open[0]+gap*Point
     &&iBarShift(NULL,0,ObjectGet("up_1",OBJPROP_TIME1))==1
     &&ObjectFind("down_1") != 0
     &&ObjectFind("up_1") == 0
     &&!pos_buy
     &&ObjectFind("buy") != 0    
     )
     {
      OrderSend(Symbol(),OP_BUY, Lots,Ask,slippage,sl_buy,Ask+TP*Point,"trener",MagicNumber,0,Blue);            
     }
  if(
     ObjectGet("down_1", OBJPROP_PRICE1)==Open[0]-gap*Point
     &&iBarShift(NULL,0,ObjectGet("down_1",OBJPROP_TIME1))==1
     &&ObjectFind("up_1") != 0
     &&ObjectFind("down_1") == 0
     &&!pos_sell
     &&ObjectFind("sell") != 0
     )
     {
      OrderSend(Symbol(),OP_SELL, Lots,Bid,slippage,sl_sell,Bid-TP*Point,"trener",MagicNumber,0,Red);  
     }
//|                                   opening trades                                   |  
//+------------------------------------------------------------------------------------+   
 }
//#################################### TRADING ####################################
//#################################################################################
 
Comment("Score: ", points," (",points_pos,"/",points_neg,   //displaying score
        ") | Time: ", Hour(),":", Minute(),":", Seconds()); //displaying time (for convenience)
     
   return(0);
  }
//+------------------------------------------------------------------+

The code includes all the necessary comments.

After the Expert Advisor is attached to a chart, we will get the following:

Here the last two arrows are intended for the game, the two arrows before them are used to open orders.

The deletion of an arrow on the previous candlestick will cause the execution of the OrderSend() function and a corresponding order will be opened:

Here is the tab of changing input parameters:

The "gap" variable is responsible for the number of points equal to the distance between an arrow and the open price of a candlestick. The variable "Trading" denotes the trading function, "TP" - TakeProfit in points, "SL" - StopLoss in points. The "Lots" variable is responsible for the volume of opened positions; "slippage" denotes the admissible slippage in points that we are ready to accept. "MagicNumber" indicates the magic number which is assigned by the EA to opened positions (necessary for the EA to be able to track its "own" orders). The "time_limit" limit variable sets the number of seconds within which a user must make his choice. If "0" is indicated, time is not limited, i.e. choice can be made during all the period of candlestick formation.


Conclusion

As a result we have a security for a comfortable trading using orders with standard parameters (TP, SL, Slippage, lot). This tool can be useful in any trading. However, it is the most efficiently used when a large number of trades is opened within a short period of time. For example, in scalping.

Using this program, a trader does not have to set parameters of an opened order each time. Thus the maximum of his attention is concentrated in a chart. Undoubtedly, this may help to increase the effectiveness of trading.

Translated from Russian by MetaQuotes Software Corp.
Original article: https://www.mql5.com/ru/articles/1509

Attached files |
trener.mq4 (11.66 KB)
Last comments | Go to discussion (7)
alex dahmen
alex dahmen | 29 Jul 2008 at 23:06

you rock !!!!!!! .. can you contact me at skype : ctzulu


i just want to discuss two of my trading strategies and what you think of it


thx alex

eduardo fiuza
eduardo fiuza | 18 Oct 2008 at 01:36

Hi,



Can you add a feature to close the trades using only the mouse at chart window?



Thanks

MQL4 Comments
MQL4 Comments | 26 Jan 2009 at 14:32

Hi


I have put this trener.mq4 in experts folder, comiled and attached it to my chart (smiley face appeared), but when I remove one of the candles on the 2nd last bar no trade is placed.... I have got Allow Live Trading checked and also have set the Trading value to true in the EA settings.....


any ideas how to get this to work

MQL4 Comments
MQL4 Comments | 9 Aug 2010 at 18:07
gbolla:

Stop level must be more then 5pips to open price!!! TP=2 pips don't work --> error: invalid stop

Bolla


In some pair, not only 5 pips minimum at stop level to make an order, but also you have to set 10 pips at minimum. I want to remove TP from OrderSend() and move it to OrderClose() instead. I hope it worked.
ROGERIO BORGES
ROGERIO BORGES | 3 Jun 2016 at 18:53
Hello
This EA works with the latest version of MT4?

I tested only the arrow appears in the graph but does not open orders.


Thank you.

ROgério

Step on New Rails: Custom Indicators in MQL5 Step on New Rails: Custom Indicators in MQL5

I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.

Here Comes the New MetaTrader 5 and MQL5 Here Comes the New MetaTrader 5 and MQL5

This is just a brief review of MetaTrader 5. I can't describe all the system's new features for such a short time period - the testing started on 2009.09.09. This is a symbolical date, and I am sure it will be a lucky number. A few days have passed since I got the beta version of the MetaTrader 5 terminal and MQL5. I haven't managed to try all its features, but I am already impressed.

How to create an indicator of non-standard charts for MetaTrader Market How to create an indicator of non-standard charts for MetaTrader Market

Through offline charts, programming in MQL4, and reasonable willingness, you can get a variety of chart types: "Point & Figure", "Renko", "Kagi", "Range bars", equivolume charts, etc. In this article, we will show how this can be achieved without using DLL, and therefore such "two-for-one" indicators can be published and purchased from the Market.

Evaluating the effectiveness of trading systems by analyzing their components Evaluating the effectiveness of trading systems by analyzing their components

This article explores the effectiveness of complex trading systems by analyzing the efficiency of its individual components. Any analysis, whether it is graphic, based on indicators, or any other, is one of the key components of successful trading in financial markets. This article is to some extent a research of few simple and independent trading systems for analyzing their effectiveness and usefulness of the joint application.