Libraries: Symbol - page 9

 
Stanislav Korotky:

And an interesting question arose - the same problem is not observed with the stack - so that in the stack prices differ from the chart?

A user complains to me about the unsynchronisation of the BookEvent-based inducer and the chart.

The stack should correspond to the Market Watch. Accordingly, it may differ from the chart.

 
fxsaber:

Consequently, in the Tester you will not be able to recreate on the original symbol what you see in the Terminal.

And here is what you see in the Terminal.

Deals are made "in the air". Indicators go to the forest. Only the demarcation of tick history.

 

I don't understand what's wrong, probably the new build 2515 is doing something wrong.

Here's the script:

#property copyright "IgorM"
#property link      "https://www.mql5.com/en/users/igorm"
#property version   "1.00"
#property script_show_inputs

input int      History        = 1 e5;
input double   Weierstrass_A  = 0.33;
input double   Weierstrass_B  = 1.5;
input int      Weierstrass_N  = 10;
input double   Weierstrass_Koeff = 0.45;

#include <fxsaber\Symbol.mqh> // https://www.mql5.com/en/code/18855
//+------------------------------------------------------------------+
//| Script programme start function|
//+------------------------------------------------------------------+
void OnStart()
{
   const SYMBOL SymbDB("W" + _Symbol);
   datetime dt_end = TimeCurrent();
   if(!SymbDB.IsExist()) // If the symbol is not created, exit
   {
      Alert("Error create Weierstrass func, symbol = ", "W" + _Symbol);
      return;
   }
   SymbDB.Off();
   SymbDB.CloneProperties(); // Copied the properties
   if(CustomRatesDelete(SymbDB.Name, 0, dt_end) == -1)
   {
      Alert("Error CustomRatesDelete , GetLastError = ", GetLastError());
      return;
   }
// find coefficients for normalisation
   int fw_MAX = INT_MIN, fw_MIN = INT_MAX;
   for(int i = 4 * History; i >= 0; i--)
   {
      int wtmp = FuncWeierstrass(Weierstrass_A, Weierstrass_B, Weierstrass_N, i);
      if(wtmp > fw_MAX) fw_MAX = wtmp;
      if(wtmp < fw_MIN) fw_MIN = wtmp;
   }
   const int fw_knorm = fw_MAX - fw_MIN;

// create a chart by recording ticks
   MqlTick ticks[];
   ArrayResize(ticks, History * 4);
   for(int i = 4 * History - 1; i >= 0; i--)
   {
      int wtmp = FuncWeierstrass(Weierstrass_A, Weierstrass_B, Weierstrass_N, i);
      ticks[i].last = ticks[i].bid = ticks[i].ask = NormalizeDouble(1.0 + Weierstrass_Koeff * (2.0 * (wtmp - fw_MIN) / fw_knorm - 1), _Digits);
      ticks[i].bid -= _Point;
      ticks[i].time_msc = ticks[i].time = dt_end--;
      ticks[i].time_msc *= 1000;
      ticks[i].volume = 1;
      ticks[i].volume_real = 1.0;
      ticks[i].flags = TICK_FLAG_ASK | TICK_FLAG_BID;
   }
   CustomTicksAdd(SymbDB.Name, ticks);
   if(SymbDB.On()) // Included in the Market Watch
      ChartOpen(SymbDB.Name, PERIOD_M1); // Opened a new symbol chart
}
//+------------------------------------------------------------------+
int FuncWeierstrass(const double Wa, const double Wb, const int WN, const int cnt)
{
   int result = 0;
   for(int i = 0; i <= WN; i++)
   {
      result += (int)(MathPow(Wb, i) * MathCos(MathPow(Wa, i) * M_PI * cnt));
   }
   return(result);
}
//+------------------------------------------------------------------+


everything works, but it works only once.

when restarting it will be a black screen "Waiting for update", cured by deleting custom symbol by hand


what is not working correctly? the library or a new build of the terminal?

 
Igor Makanu:

what is not working correctly? library or new build of the terminal?

I don't know. I don't use TicksAdd.

 
fxsaber:

I don't know. I don't use TicksAdd.

I think I figured it out, so I replaced it in my code

CustomTicksAdd(SymbDB.Name, ticks);

with

CustomTicksReplace(SymbDB.Name,0,TimeCurrent()*1000,ticks);

It seems to work now when the script is restarted, the only thing is that there are no Ask/Bid symbol values in the market overview window, but it is not critical.



UPD:

the help should be read carefully, everything works, but CustomTicksAdd works correctly when the symbol is added to the market overview, i.e. it should be used like this

if(SymbDB.On()) // Included in the Market Watch
   {
      CustomTicksAdd(SymbDB.Name, ticks);
      ChartOpen(SymbDB.Name, PERIOD_M1); // Opened a new symbol chart
   }
 

I came across an unpleasant bug in MT - for some reason it does not set SYMBOL_TRADE_TICK_SIZE. Debugging shows that the correct value is written to the property (for example, 0.00001 for EURUSD), but after creating a symbol, it contains 0.

Has anyone fixed this? Is it an MT bug or a specificity in the Symbol library?

 
Stanislav Korotky:

I came across an unpleasant bug in MT - for some reason it does not set SYMBOL_TRADE_TICK_SIZE. Debugging shows that the correct value is written to the property (for example, 0.00001 for EURUSD), but after creating the symbol, it contains 0.

Has anyone fixed this? Is it an MT bug or a specificity in the Symbol library?

Do you just see the '0' or do you get the '0' after polling the property?

 
Stanislav Korotky:

I came across an unpleasant bug in MT - for some reason it does not set SYMBOL_TRADE_TICK_SIZE. Debugging shows that the correct value is written to the property (for example, 0.00001 for EURUSD), but after creating the symbol, it contains 0.

Has anyone fixed this? Is it an MT bug or a specificity in the Symbol library?

Probably, it depends on the sequence of setting fields. I have it like this.

    this.SetProperty(SYMBOL_DIGITS, this.Ticks.GetDigits());

    this.SetProperty(SYMBOL_TRADE_CONTRACT_SIZE, 1 e5); // https://www.mql5.com/ru/forum/330333#comment_14608694
    this.SetProperty(SYMBOL_TRADE_TICK_VALUE, 1);

    this.SetProperty(SYMBOL_TRADE_TICK_SIZE, this.GetProperty(SYMBOL_POINT));
 
fxsaber:

Probably depends on the sequence of field assignment. I have it like this.

I use the CloneProperties call, and it has these lines (in the current publicly available version):

...
    CLONE(SYMBOL_TRADE_CONTRACT_SIZE) &&
    CLONE(SYMBOL_TRADE_FACE_VALUE) &&
    CLONE(SYMBOL_TRADE_LIQUIDITY_RATE) &&
    CLONE(SYMBOL_TRADE_TICK_SIZE) &&
    CLONE(SYMBOL_TRADE_TICK_VALUE) &&
...

Here the sequence is slightly different, but the correct values are transferred to the contract and other properties, the only problem is with the tick size.

 

After calling CloneProperties, I wrote this nonsense:

    Symb.CloneProperties(_Symbol);
    if(SymbolInfoDouble(_SymbolName, SYMBOL_TRADE_TICK_SIZE) == 0)
    {
      CustomSymbolSetDouble(_SymbolName, SYMBOL_TRADE_TICK_SIZE, SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE));
    }

This is how it is applied normally. But this is some kind of crutch.