ScalpRandom

Author: Mokara
Orders Execution
It automatically opens orders when conditions are reached
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
ScalpRandom
#property copyright           "Mokara"
#property link                "https://www.mql5.com/en/users/mokara"
#property description         "Scalp Random"
#property version             "1.0"
#property script_show_inputs  true
#define MAGIC 999

input double rTP = 5;      //Take Profit Ratio
input double rSL = 10;     //Stop Loss Ratio
input double vol = 0.1;    //Volume
input int spread = 100;   //Maximum Spread

enum TRADE
{
   BUY = 0,
   SELL = 1
};

void OnStart()
{
   MqlTradeRequest tReq = {0};
   MqlTradeResult tRes = {0};
   int t = -1, i = 0, d, s;
   double p;
   string n;
   
   MathSrand(GetTickCount());
   i = MathRand()%SymbolsTotal(true);
   
   while(i < SymbolsTotal(true))
   {      
      n = SymbolName(i, true);
      s = SymbolInfoInteger(n, SYMBOL_SPREAD);      
      if(s > spread)
      {
         i++;
         continue;
      }
      else
      {
         break;
      }
   }
   
   if(s > spread)
   {
      Alert("ERROR: high spread. try again." );
      return;
   }
   
    
   p = SymbolInfoDouble(n, SYMBOL_POINT);
   d = SymbolInfoInteger(n, SYMBOL_DIGITS);
   
   ZeroMemory(tReq);
   ZeroMemory(tRes);
   tReq.symbol = n;
   tReq.volume = vol;
   tReq.action = TRADE_ACTION_DEAL;
   tReq.deviation = 5;
   tReq.magic = MAGIC;
   
   MathSrand(GetTickCount());
   Sleep(MathRand()%50);
   t = int(MathRand() % 2);
   switch(t)
   {
      case BUY: 
         tReq.type = ORDER_TYPE_BUY; 
         tReq.price = SymbolInfoDouble(n, SYMBOL_ASK); 
         tReq.tp = tReq.price + NormalizeDouble(s * p * rTP, d);
         tReq.sl = tReq.price - NormalizeDouble(s* p * rSL, d);
         break;
      case SELL: 
         tReq.type = ORDER_TYPE_SELL; 
         tReq.price = SymbolInfoDouble(n, SYMBOL_BID); 
         tReq.tp = tReq.price - NormalizeDouble(s * p * rTP, d);
         tReq.sl = tReq.price + NormalizeDouble(s* p * rSL, d);
         break;
   }
   
   if(!OrderSend(tReq, tRes))
   {
      Print("ERROR: order send. Error Code: " + GetLastError());         
      return;     
   }
}

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---