Libraries: Symbol - page 6

 
class CURRENCY_CHECK
{
public:
  CURRENCY_CHECK( void )
  {
    const string CurrencyProfit = ::SymbolInfoString(_Symbol, SYMBOL_CURRENCY_PROFIT);
    const string AccountCurrency = ::AccountInfoString(ACCOUNT_CURRENCY);
    const bool Res = !::MQLInfoInteger(MQL_TESTER) || (CurrencyProfit == AccountCurrency);
    
    if (!Res && !::MQLInfoInteger(MQL_OPTIMIZATION))
    {
      ::Print(CurrencyProfit + " = SYMBOL_CURRENCY_PROFIT != ACCOUNT_CURRENCY = " + AccountCurrency);
      
      ::TesterStop();
    }
  }
};

CURRENCY_CHECK CurrencyCheck; // Does not allow slow variants to be tested

2018.07.01 00:00:00   TER = SYMBOL_CURRENCY_PROFIT != ACCOUNT_CURRENCY = USD
TesterStop() called on 0% of testing interval
 
// The script sets the commission for all positions with non-zero profit.
#property script_show_inputs

input double inCommission = 0.004; // Commission in percentage per round (0.004 - 20 units per side per million)
input bool inAdd = false;          // true - added to the current value, false - set value

#include <Symbol.mqh>

string CommissionToString( const double TickValue )
{
  const double Commission = 1 - TickValue;
  
  return("Commission = " + DoubleToString(Commission * 100, 5) + "% per round (" + DoubleToString(Commission * 1000000 / 2, 1) + " per million (one side))");
}

void OnStart()
{
  const SYMBOL Symb;
  
  if (Symb.IsCustom())
  {
    const double TickValue = Symb.GetProperty(SYMBOL_TRADE_TICK_VALUE);
    const double NewTickValue = inAdd ? TickValue * (1 - inCommission / 100) : 1 - inCommission / 100;
    
    if ((MessageBox(Symb.Name + "\nBefore: " + CommissionToString(TickValue) +
                   "\nAfter: " + CommissionToString(NewTickValue) + "\n\n Do you agree?", "Commission Change", MB_YESNO) == IDYES) &&
        Symb.SetProperty(SYMBOL_TRADE_TICK_VALUE, NewTickValue))
      MessageBox(Symb.Name + ": current " + CommissionToString(Symb.GetProperty(SYMBOL_TRADE_TICK_VALUE)));
  }
}


It' s not working yet.

 

If it is not too much trouble, I would like an example of how to use the Symbol library correctly to generate a custom symbol - let it be 1/EURUSD = USDEUR.

I would like to know how to correctly copy the available tick history and how to generate each tick on a new chart, so that everything would be correct in the "Market Watch" window, i.e. so that the USDEUR chart would be as close as possible to regular charts both for online work and for testing in the tester.

thank you in advance

 
Igor Makanu:

If it's not too much trouble, I would like an example of how to use the Symbol library correctly to generate a custom symbol - let it be 1/EURUSD = USDEUR

I would like to know how to correctly copy the available tick history and how to generate each tick on a new chart, so that everything would be correct in the "Market Watch" window, i.e. so that the USDEUR chart would be as close as possible to the usual charts both for online work and for testing in the tester.

thank you in advance

// Example of creating an inverted symbol

#include <fxsaber\ThirdPartyTicks\CustomSymbol.mqh> // https://www.mql5.com/en/code/20225

CUSTOMSYMBOL CustomSymb(StringSubstr(_Symbol, 3, 3) + StringSubstr(_Symbol, 0, 3) + StringSubstr(_Symbol, 6)); // Created a symbol

double ReversePrice( const double Price )
{
  return(Price ? NormalizeDouble(1 / Price, _Digits) : 0);
}

void ReverseTick( MqlTick &Tick )
{
  Tick.bid = ReversePrice(Tick.bid);
  Tick.ask = ReversePrice(Tick.ask);
  Tick.last = ReversePrice(Tick.last);
}

bool ReverseTicks( MqlTick &Ticks[] )
{
  for (int i = ArraySize(Ticks) - 1; i >= 0; i--)
    ReverseTick(Ticks[i]);
    
  return(true);
}

bool GetTicks( MqlTick &Ticks[] )
{
  return(CopyTicks(_Symbol, Ticks) > 0);
}

void OnInit()
{
  MqlTick Ticks[];
  
  if (CustomSymb.IsCustom() && GetTicks(Ticks) && ReverseTicks(Ticks) &&
      (CustomSymb.AddTicks(Ticks) > 0) && (CustomSymb.DataToSymbol() > 0) && CustomSymb.On())
    ChartOpen(CustomSymb.Name, PERIOD_CURRENT); // Opened the chart
}

void OnTick()
{  
  MqlTick Tick[1];
  
  if (CustomSymb.IsCustom() && SymbolInfoTick(_Symbol, Tick[0]) && ReverseTicks(Tick))
    CustomTicksAdd(CustomSymb.Name, Tick);
}
 
fxsaber:

Thank you!

I'll look into it tonight, I have a different problem, but I need a simple example to understand what your library can do.

----------------------------------


ran the example // Example of creating an inverted symbol

everything is clear, it's fantastic that in a couple of lines you can get a real live custom character programmatically, very cool stuff!

SUS: in build 1158 a warning appeared during compilation:

expression not boolean Symbol.mqh 192 17

in Symbol.mqh file method bool IsCustom( void ) const
 
Igor Makanu:

SZY: in build 1158 a warning appeared at compilation:

expression not boolean Symbol.mqh 192 17

in Symbol.mqh file method bool IsCustom( void ) const

I forget to update, I already have a lot of code of my own in KB, what to say about the wilds of my MQL folder...

Updated.

 
fxsaber:

Updated.

updated:

0 error(s), 0 warning(s), compile time: 1220 msec

all OK, thanks!
 

Hello!

Is it possible to copy futures by list into a custom symbol with time information offset? Time information will have to be shifted due to the need to have low-liquidity tails from futures, which can affect the calculation of indicators during the transition to a new futures.

I just want to glue the futures one after another, as it is in fact - their entire history, and in the Expert Advisor just make points on the dates of periods where trading is not carried out.
 
Aleksey Vyazmikin:

Hello!

Is it possible to copy futures by list into a custom symbol with time information offset? Time information will have to be shifted due to the need to have low-liquidity tails from futures, which can affect the calculation of indicators during the transition to a new futures.

I just want to glue the futures one after another, as it is in fact - their entire history, and in the Expert Advisor just make points on the dates of periods where trading is not carried out.

If there is source data and a gluing algorithm, then, of course, there is such a possibility. You just need to write the formation of tick archive of a new symbol. The formation of a custom symbol with this history will be done in the same way as in the examples of this branch.


The only thing is that you need to decide on the price of bar formation and at what prices market orders will be executed. I would exclude last-price, but everyone is free to decide for himself what he needs.

 
fxsaber:

If there is source data and gluing algorithm, then, of course, such a possibility is available. You just need to write the formation of tick archive of a new symbol. Formation of a custom symbol with this history will be done in the same way as in the examples of this branch.


The only thing is that you need to decide on the price of bar formation and at what prices market orders will be executed. I would exclude last-price, but everyone is free to decide for himself what he needs.

Of course, the initial data is in the terminal - futures of previous years. What does it mean to form a tick archive? In general, I would like to test OHLC on M1, without extra ticks, so to speak.

Why do not like last prices? I don't understand about the bar formation price again - minute bars are fine, at the original prices. In general, I need the same thing as on a separate futures, and the fact that it will not coincide with the real at any settings, so it is clear - according to my observations it is necessary to put 5 points in the minus on average, if testing on all ticks.

Can you help me with such a script?