Scripts: Pending orders DOWN - page 3

 
Михаил Рымарь:

Hello, the script is really great and the only one on MQ5, but I would like to have in my arsenal the same, but with a lot, say 1 or 0.5.

Thank you for your labours and happy holidays.

In this series was originally the idea to use the minimum lot. Therefore, for now only so far.

 
Hello Sir. Can you help me a little bit. How can i adjust the code to my desired lot Size. I have try several time by changing the inplots: 5 but still the lots value when i execute it become 0.01, I am newbie, hopefull there is a way for me to change it. Thank You
//+------------------------------------------------------------------+
//|                                          Pending orders DOWN.mq5 |
//|                              Copyright © 2017, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2017, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.002"
#property description "The script sets the pending orders down from the price"
#property script_show_inputs
//---
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>  
CTrade         m_trade;                      // trading object
CSymbolInfo    m_symbol;                     // symbol info object
//+------------------------------------------------------------------+
//| Enum pending orders DOWN                                         |
//+------------------------------------------------------------------+
enum ENUM_PENDING_ORDERS_DOWN
  {
   buy_limit         =0,   // Buy Limit
   sell_stop         =3    // Sell Stop
  };
//--- input parameters
input ushort                     InpDownGep        = 10;             // Gap for pending orders DOWN from the current price (in pips)
input ushort                     InpDownStep       = 3;             // Step between orders DOWN (in pips)
input ENUM_PENDING_ORDERS_DOWN   InpDownOrders     = buy_limit;      // Type of pending orders DOWN
input uchar                      InpDownQuantity   = 33;              // DOWN quantity
input double                     InpLots           = 5;            // Lots
input ushort                     InpStopLoss       = 100;             // Stop Loss (in pips)
input ushort                     InpTakeProfit     = 100;             // Take Profit (in pips)
//---
ulong                            m_slippage=1;                      // slippage
double                           m_adjusted_point;                   // point value adjusted for 3 or 5 points
double                           ExtDownGep=0.0;
double                           ExtDownStep=0.0;
double                           ExtStopLoss=0.0;
double                           ExtTakeProfit=0.0;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   if(InpLots<=0.0)
     {
      Print("The \"Lots\" can't be smaller or equal to zero");
      return;
     }
//---
   if(!m_symbol.Name(Symbol())) // sets symbol name
      return;
   if(!RefreshRates())
      return;

   string err_text="";
   if(!CheckVolumeValue(InpLots,err_text))
     {
      Print(err_text);
      return;
     }
//---
   if(IsFillingTypeAllowed(SYMBOL_FILLING_FOK))
      m_trade.SetTypeFilling(ORDER_FILLING_FOK);
   else if(IsFillingTypeAllowed(SYMBOL_FILLING_IOC))
      m_trade.SetTypeFilling(ORDER_FILLING_IOC);
   else
      m_trade.SetTypeFilling(ORDER_FILLING_RETURN);
//---
   m_trade.SetDeviationInPoints(m_slippage);
   m_trade.SetAsyncMode(true);
//--- tuning for 3 or 5 digits
   int digits_adjust=1;
   if(m_symbol.Digits()==3 || m_symbol.Digits()==5)
      digits_adjust=10;
   m_adjusted_point=m_symbol.Point()*digits_adjust;

   ExtDownGep     = m_adjusted_point * InpDownGep;
   ExtDownStep    = m_adjusted_point * InpDownStep;
   ExtStopLoss    = m_adjusted_point * InpStopLoss;
   ExtTakeProfit  = m_adjusted_point * InpTakeProfit;
//--- start work
   double start_price_ask=m_symbol.Ask()-ExtDownGep;
   double start_price_bid=m_symbol.Bid()-ExtDownGep;
//--- pending orders DOWN
   for(int i=0;i<InpDownQuantity;i++)
     {
      double price_ask     = start_price_ask-i*ExtDownStep;
      double price_bid     = start_price_bid-i*ExtDownStep;
      if(InpDownOrders==buy_limit)
        {
         double sl         = (ExtStopLoss==0.0)   ? 0.0 : price_ask - ExtStopLoss;
         double tp         = (ExtTakeProfit==0.0) ? 0.0 : price_ask + ExtTakeProfit;
         m_trade.BuyLimit(m_symbol.LotsMax(),m_symbol.NormalizePrice(price_ask),m_symbol.Name(),
                          m_symbol.NormalizePrice(sl),
                          m_symbol.NormalizePrice(tp));
        }
      else
        {
         double sl         = (ExtStopLoss==0.0)   ? 0.0 : price_bid + ExtStopLoss;
         double tp         = (ExtTakeProfit==0.0) ? 0.0 : price_bid - ExtTakeProfit;
         m_trade.SellStop(m_symbol.LotsMax(),m_symbol.NormalizePrice(price_bid),m_symbol.Name(),
                          m_symbol.NormalizePrice(sl),
                          m_symbol.NormalizePrice(tp));
        }
     }
  }
//+------------------------------------------------------------------+
//| Refreshes the symbol quotes data                                 |
//+------------------------------------------------------------------+
bool RefreshRates()
  {
//--- refresh rates
   if(!m_symbol.RefreshRates())
      return(false);
//--- protection against the return value of "zero"
   if(m_symbol.Ask()==0 || m_symbol.Bid()==0)
      return(false);
//---
   return(true);
  }
//+------------------------------------------------------------------+
//| Check the correctness of the order volume                        |
//+------------------------------------------------------------------+
bool CheckVolumeValue(double volume,string &error_description)
  {
//--- minimal allowed volume for trade operations
   double min_volume=m_symbol.LotsMin();
   if(volume<min_volume)
     {
      error_description=StringFormat("Volume is less than the minimal allowed SYMBOL_VOLUME_MIN=%.2f",min_volume);
      return(false);
     }

//--- maximal allowed volume of trade operations
   double max_volume=m_symbol.LotsMax();
   if(volume>max_volume)
     {
      error_description=StringFormat("Volume is greater than the maximal allowed SYMBOL_VOLUME_MAX=%.2f",max_volume);
      return(false);
     }

//--- get minimal step of volume changing
   double volume_step=m_symbol.LotsStep();

   int ratio=(int)MathRound(volume/volume_step);
   if(MathAbs(ratio*volume_step-volume)>0.0000001)
     {
      error_description=StringFormat("Volume is not a multiple of the minimal step SYMBOL_VOLUME_STEP=%.2f, the closest correct volume is %.2f",
                                     volume_step,ratio*volume_step);
      return(false);
     }
   error_description="Correct volume value";
   return(true);
  }
//+------------------------------------------------------------------+ 
//| Checks if the specified filling mode is allowed                  | 
//+------------------------------------------------------------------+ 
bool IsFillingTypeAllowed(int fill_type)
  {
//--- Obtain the value of the property that describes allowed filling modes 
   int filling=m_symbol.TradeFillFlags();
//--- Return true, if mode fill_type is allowed 
   return((filling & fill_type)==fill_type);
  }
//+------------------------------------------------------------------+

 
Mjame116 :
Hello Sir. Can you help me a little bit. How can i adjust the code to my desired lot Size. I have try several time by changing the inplots: 5 but still the lots value when i execute it become 0.01, I am newbie, hopefull there is a way for me to change it. Thank You

It is necessary instead of the minimum lot to put the input parameter Lots

//--- pending orders DOWN
   for(int i=0;i<InpDownQuantity;i++)
     {
      double price_ask     = start_price_ask-i*ExtDownStep;
      double price_bid     = start_price_bid-i*ExtDownStep;
      if(InpDownOrders==buy_limit)
        {
         double sl         = (ExtStopLoss==0.0)   ? 0.0 : price_ask - ExtStopLoss;
         double tp         = (ExtTakeProfit==0.0) ? 0.0 : price_ask + ExtTakeProfit;
         m_trade.BuyLimit(m_symbol.LotsMin(),m_symbol.NormalizePrice(price_ask),m_symbol.Name(),
                          m_symbol.NormalizePrice(sl),
                          m_symbol.NormalizePrice(tp));
        }
      else
        {
         double sl         = (ExtStopLoss==0.0)   ? 0.0 : price_bid + ExtStopLoss;
         double tp         = (ExtTakeProfit==0.0) ? 0.0 : price_bid - ExtTakeProfit;
         m_trade.SellStop(m_symbol.LotsMin(),m_symbol.NormalizePrice(price_bid),m_symbol.Name(),
                          m_symbol.NormalizePrice(sl),
                          m_symbol.NormalizePrice(tp));
        }
     }
  }

need to do this:

//--- pending orders DOWN
   for(int i=0;i<InpDownQuantity;i++)
     {
      double price_ask     = start_price_ask-i*ExtDownStep;
      double price_bid     = start_price_bid-i*ExtDownStep;
      if(InpDownOrders==buy_limit)
        {
         double sl         = (ExtStopLoss==0.0)   ? 0.0 : price_ask - ExtStopLoss;
         double tp         = (ExtTakeProfit==0.0) ? 0.0 : price_ask + ExtTakeProfit;
         m_trade.BuyLimit(InpLots,m_symbol.NormalizePrice(price_ask),m_symbol.Name(),
                          m_symbol.NormalizePrice(sl),
                          m_symbol.NormalizePrice(tp));
        }
      else
        {
         double sl         = (ExtStopLoss==0.0)   ? 0.0 : price_bid + ExtStopLoss;
         double tp         = (ExtTakeProfit==0.0) ? 0.0 : price_bid - ExtTakeProfit;
         m_trade.SellStop(InpLots,m_symbol.NormalizePrice(price_bid),m_symbol.Name(),
                          m_symbol.NormalizePrice(sl),
                          m_symbol.NormalizePrice(tp));
        }
     }
  }
 
Vladimir Karputov:

It is necessary instead of the minimum lot to put the input parameter Lots

need to do this:

Thank You so much Sir, i really appreciate it
 

Hello, the script is great and works perfectly.

I am using the same one to set the net up, and I would like to ask you: can you combine them into one? I mean a script that would place both up and down order nets at the same time, with the same parameters for both long and short nets.

 
mason_one:

Hello, the script is great and works fine.

I am using the same one to set the net up, and I would like to ask you: can you combine them into one? I mean a script that would place both up and down order nets at the same time, with the same parameters for both long and short nets.

Thank you for your interest. I am publishing a script (not an Expert Advisor) that sets a grid of pending orders both up and down - Pending orders UP DOWN.

 
Hello Vladimir, very interesting your script. works very well but I hope you can help me by telling me how to change the lotaje from 0.01 to 0.03. I remain attentive and in advance thank you very much my friend.
 
Carlos Devia :
Hello Vladimir, very interesting your script. works very well but I hope you can help me by telling me how to change the lotaje from 0.01 to 0.03. I remain attentive and thank you very much in advance my friend.

In this code, instead of"m_symbol.LotsMin()" put"InpLots":

//--- pending orders DOWN
   for(int i=0;i<InpDownQuantity;i++)
     {
      double price_ask     = start_price_ask-i*ExtDownStep;
      double price_bid     = start_price_bid-i*ExtDownStep;
      if(InpDownOrders==buy_limit)
        {
         double sl         = (ExtStopLoss==0.0)   ? 0.0 : price_ask - ExtStopLoss;
         double tp         = (ExtTakeProfit==0.0) ? 0.0 : price_ask + ExtTakeProfit;
         m_trade.BuyLimit(m_symbol.LotsMin(),m_symbol.NormalizePrice(price_ask),m_symbol.Name(),
                          m_symbol.NormalizePrice(sl),
                          m_symbol.NormalizePrice(tp));
        }
      else
        {
         double sl         = (ExtStopLoss==0.0)   ? 0.0 : price_bid + ExtStopLoss;
         double tp         = (ExtTakeProfit==0.0) ? 0.0 : price_bid - ExtTakeProfit;
         m_trade.SellStop(m_symbol.LotsMin(),m_symbol.NormalizePrice(price_bid),m_symbol.Name(),
                          m_symbol.NormalizePrice(sl),
                          m_symbol.NormalizePrice(tp));
        }
     }
 

Dear Vladimir, at this moment you are like a god to me. You don't know how much I have been looking for this, I really appreciate that you have taken the time to answer me. I am a person passionate about trading and the little I know I have learned from people like you.

I want to ask you the last question if it is possible. I programmed a hotkey on my keyboard

I programmed a hotkey on my keyboard to activate my sell stop order, but before activating it, a window opens, which I would like not to open, but simply to execute my order immediately.

I am attaching a picture of the window that opens.

I would appreciate your kind help Vladimir so that this window does not appear, because when it opens I have to"accept" the parameters and I lose time in this process.

Files:
 
Carlos Devia :

Dear Vladimir, at this moment you are like a god to me. You don't know how much I have been looking for this, I really appreciate that you have taken the time to answer me. I am a person passionate about trading and the little I know I have learned from people like you.

I want to ask you the last question if possible. I programmed a hotkey on my keyboard.

I programmed a hotkey on my keyboard to activate my sell stop order, but before it is activated a window opens, which I would like not to open, but simply to execute my order immediately.

I attach a picture of the window that opens.

I would appreciate your kind help Vladimir so that this window does not appear, because when it opens I have to "accept" the parameters and I lose time in this process.

A hotkey is not an option: at startup anyway, the input parameters will be visible.

I would suggest another way:

  • write an advisor - a panel, in the panel everything has a "Start" button.
  • when you start the advisor, once you set the input parameters
  • after the launch, a small panel is hung on the chart: when you click the "Start" button on this panel, the pending orders will be placed (all parameters will be taken from the input parameters.

Example panel:



You can search for such a panel in Market or order it in the Freelance service.