Price Data Components
Series array that contains the lowest prices of each bar
0 Views
0 Downloads
0 Favorites
ScriptBuy
//+------------------------------------------------------------------+
//|                                                    ScriptBuy.mq5 |
//|                                                         B Gabela |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property strict
#property script_show_inputs

#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\AccountInfo.mqh>

#include "TradeHelper.mqh"

input double   FIXED_DEAL_AMOUNT = 10000.00; //FIXED_DEAL_AMOUNT: Fixed amount to use per trade
input bool     USE_SL_ON_BUY = true; //USE_SL_ON_BUY: Use stop loss on Long position

//--- Global Variables
/*
_Symbol+_MAX_SPREAD              //Max spread for given symbol
*/

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   init();

   int spread = SymbolInfoInteger(_Symbol,SYMBOL_SPREAD);
   printHelper(LOG_INFO, StringFormat("Script: About to execute buy on %s with spread %d ", _Symbol, spread));

//Check spread
   int maxSpread = GlobalVariableGet(_Symbol+"_MAX_SPREAD");
   if((maxSpread > 0) && (spread > maxSpread))
     {
      printHelper(LOG_INFO, StringFormat("Script: Can't execute buy on %s as spread is above %d ", _Symbol, maxSpread));
      return;
     }

   int barIndex = findLastRedBar(20);
   double sl = iLow(NULL,0,barIndex) - (getAdjustedPoint()*0.60);
   if(!USE_SL_ON_BUY)
     {
      sl = 0.00;
     }

     placeBuyOrder(m_trade, sl, 0.00, FIXED_DEAL_AMOUNT, "[M] ");
  }

//+------------------------------------------------------------------+
//| Initialisation of script                                                                 |
//+------------------------------------------------------------------+
void init()
  {
   m_trade.SetExpertMagicNumber(getMagicWithTimeframe());
   m_trade.SetMarginMode();
   m_trade.SetTypeFillingBySymbol(_Symbol);
   m_trade.SetDeviationInPoints(m_slippage);
  }

//+------------------------------------------------------------------+

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 ---