Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 949

 
Also incorrectly displays all bar calculations that have appeared since initialisation....
 

Good day everyone!

Here is part of the script code for Metatrader5:

#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//---- показывать входные параметры
#property script_show_inputs
//---
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
CTrade         m_trade;                      // trading object
CSymbolInfo    m_symbol;                     // symbol info object
//+------------------------------------------------------------------+
//| Enum Stop or Limit                                               |
//+------------------------------------------------------------------+
enum ENUM_STOP_OR_LIMIT
  {
   stop=0,     // Buy stop and Sell stop
   limit=1     // Buy limit and Sell limit
  };
//--- input parameters
input ushort               InpUpGap          = 15;    // Gap for pending orders UP from the current price (in points)
input ushort               InpUpStep         = 30;    // Step between orders UP (in points)

input ushort               InpDownGap        = 15;    // Gap for pending orders DOWN from the current price (in points)
input ushort               InpDownStep       = 30;    // Step between orders DOWN (in points)

input ENUM_STOP_OR_LIMIT   InpPending        = stop;  // Type of pending orders

input uchar                InpUpQuantity     = 1;     // UP quantity orders
input uchar                InpDownQuantity   = 1;     // DOWN quantity orders

input double               InpLots           = 0.01;  // Lots
input ushort               InpStopLoss       = 50;    // Stop Loss (in points)
input ushort               InpTakeProfit     = 50;    // Take Profit (in points)
//---
ulong                      m_slippage=30;             // slippage

double                     ExtUpGap=0.0;
double                     ExtUpStep=0.0;

double                     ExtDownGap=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);

//---
   ExtUpGap = m_symbol.Point() * InpUpGap;
   ExtUpStep = m_symbol.Point() * InpUpStep;

   ExtDownGap = m_symbol.Point() * InpDownGap;
   ExtDownStep = m_symbol.Point() * InpDownStep;

   ExtStopLoss = m_symbol.Point() * InpStopLoss;
   ExtTakeProfit = m_symbol.Point() * InpTakeProfit;

//--- start work
   double start_price_ask=m_symbol.Ask()-ExtUpGap;
   double start_price_bid=m_symbol.Bid()+ExtDownGap;

//--- set pending orders
   for(int i=0; i<InpUpQuantity; i++)
     {
      double price_ask = start_price_ask+i*ExtUpStep;
      double price_bid = start_price_bid+i*ExtUpStep;
      if(InpPending==stop)
        {
         double sl = (ExtStopLoss==0.0)   ? 0.0 : price_ask - ExtStopLoss;
         double tp = (ExtTakeProfit==0.0) ? 0.0 : price_ask + ExtTakeProfit;
         m_trade.BuyStop(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.SellLimit(InpLots,m_symbol.NormalizePrice(price_bid),m_symbol.Name(),
         m_symbol.NormalizePrice(sl),
         m_symbol.NormalizePrice(tp));
        }
     }

   for(int i=0; i<InpDownQuantity; i++)
     {
      double price_ask = start_price_ask-i*ExtDownStep;
      double price_bid = start_price_bid-i*ExtDownStep;
      if(InpPending==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));
        }
     }
  }

The script is supposed to set either pending limit orders at a certain distance from ask and bid, or stop orders. The limitpending orders are set without problems but the stop ones are not. Please do not know why the Sell Stop and Buy Stop pending orders are not set.

Yours sincerely, Vladimir.

 
Hi guys. Made writing a lot next to an open order.
        for(int no1=0; no1<OrdersTotal(); no1++){
     if(OrderSelect(no1,SELECT_BY_POS,MODE_TRADES)){
     if(OrderSymbol()==Symbol() && OrderType()== OP_BUY){
     ObjectCreate("LOTB"+OrderTicket(),OBJ_TEXT,0,TimeCurrent(),OrderOpenPrice());
    ObjectSetText("LOTB"+OrderTicket(),OrderLots()*100,20,"Arial",clrWheat);   
    ObjectSetInteger(0,"LOTB"+OrderTicket(),OBJPROP_ANCHOR,ANCHOR_RIGHT_UPPER);  }}} 
Can you tell me how to take the last text and this list?
 
Rustam Bikbulatov:
Hi guys. Made writing a lot next to an open order. Can you tell me how to take the last text and this list?
 
Yevhenii Levchenko:

first you have to find all the texts and use this function to calculate from it?

 
Rustam Bikbulatov:

first you have to find all the texts and use this function to calculate from it?

I don't know this thoroughly, as I'm learning mql4 language recently myself. You can find everything in the help. Do you need the whole text from the object or a chunk?
 
Yevhenii Levchenko:
I don't know this thoroughly, as I'm a recent mql4 language learner myself. You can find everything in the help. Do you need the whole text from the object or a piece of it?

I need what was written last time

 
Hi guys. Made writing a lot next to an open order.
        for(int no1=0; no1<OrdersTotal(); no1++){
     if(OrderSelect(no1,SELECT_BY_POS,MODE_TRADES)){
     if(OrderSymbol()==Symbol() && OrderType()== OP_BUY){
     ObjectCreate("LOTB"+OrderTicket(),OBJ_TEXT,0,TimeCurrent(),OrderOpenPrice());
    ObjectSetText("LOTB"+OrderTicket(),OrderLots()*100,20,"Arial",clrWheat);   
    ObjectSetInteger(0,"LOTB"+OrderTicket(),OBJPROP_ANCHOR,ANCHOR_RIGHT_UPPER);  }}} 
Can you tell me how to take the last text and this list?
 
Rustam Bikbulatov:
Hi guys. Made writing a lot next to an open order. Can you tell me how to take the last text and this list?

From which list?

And please use the styler in the editor (Ctrl+<):

for(int no1=0; no1<OrdersTotal(); no1++)
  {
   if(OrderSelect(no1,SELECT_BY_POS,MODE_TRADES))
     {
      if(OrderSymbol()==Symbol() && OrderType()== OP_BUY)
        {
         ObjectCreate("LOTB"+OrderTicket(),OBJ_TEXT,0,TimeCurrent(),OrderOpenPrice());
         ObjectSetText("LOTB"+OrderTicket(),OrderLots()*100,20,"Arial",clrWheat);
         ObjectSetInteger(0,"LOTB"+OrderTicket(),OBJPROP_ANCHOR,ANCHOR_RIGHT_UPPER);
        }
     }
  } 
//+------------------------------------------------------------------+

What should be taken from where?

 
Artyom Trishkin:

From which list?

And please use the styler in the editor (Ctrl+<):

Where do I get it from?

This function writes a number on each order or more precisely lot*100.

We now need an inverse function which shows what was the last number

Reason: