MQL help required, how to generate key - mql4

I am struggling with one code line. It is a Key generation Line for a Expert Adviser. Can someone help me figure out how I can generate key by using this line:
int key=3*(StringToInteger(StringSubstr(IntegerToString(AccountNumber()), 0, 3)))+333333;

And what is the problem?
int accountNumber = AccountNumber();
string accountNumberString = IntegerToString(accountNumber);
string accountNumberStringFirst3Digits=
StringSubstr(accountNumberString,0,3);
int accountNumberFirstThreeDigits = StringToInteger(accountNumberStringFirst3Digits);
int accountNumberFirstThreeDigitsMultiplied = 3 * accountNumberFirstThreeDigits;
int key = accountNumberFirstThreeDigitsMultiplied + 333333;

Can someone help me figure out how to generate key by this line?
Welcome, certainly, let's look on that :
int key = 3*(StringToInteger(StringSubstr(IntegerToString(AccountNumber()), 0, 3)))+333333;
Your code actually means this:
// +------------------------------------------------------------------------------- type declaration
// | +--------------------------------------------------------------------------- variable name definition
// | | +------------------------------------------------------------------------- assignment operator
// | | | +----------------------------------------------------------------------- compile-time integer constant
// | | | | +--------------------------------------------------------------------- multiply operator
// | | | | | +-------------------------------------------------- MT4 system function: StringToInteger( aString )
// | | | | | | +------------------------------------ MT4 system function: StringSubstr( aString, aPosToStartSubstrFrom, aSubstrLength )
// | | | | | | | +------------------- MT4 system function: IntegerToString( aIntNum ) | |
// | | | | | | | | +---- MT4 system function: AccountNumber() | |
// | | | | | | | | | | |
// | | | | | | | | | +------------------------------------------------------------------+ |
// | | | | | | | | | | +------------------------------------------------------------------------------+
// | | | | | | | | | | |
int key = 3 * ( StringToInteger( StringSubstr( IntegerToString( AccountNumber() ), 0, 3 ) ) )
+ 333333;
// | ||
// +------||----------------------------------------------------------------- add operator
// +|----------------------------------------------------------------- compile-time integer constant
// +----------------------------------------------------------------- literal MQL4-language syntax-terminator
The code above both defines and generates a fair integer value, so wherever your Expert Advisor code refers to a value of key, this calculated value will be used ( see also the documentation about the New-MQL4 scope-of-validity, inside which this variable remains visible ).

Related

Symfony 3 & Doctrine - Complex form with OnetoMany and ManyToMany relation

I want to manage the rates of a product in multi-currency and keep historic of currency rates.
So onetomany relation:
A Rates can have many CurrencyRate.
A manyto many relation:
Many currencyRate have many currencies.
RATES :
+-----------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| rate | double | YES | | NULL | |
| timeStamp | datetime | NO | | NULL | |
| currencyRate_id | int(11) | YES | MUL | NULL | |
+-----------------+----------+------+-----+---------+----------------+
CURRENCY RATES
+-----------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| rate | double | NO | | NULL | |
| timeStamp | datetime | NO | | NULL | |
+-----------+----------+------+-----+---------+----------------+
currencyrateshascurrencies (manytomany join table)
+-----------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+---------+------+-----+---------+-------+
| currency_id | int(11) | NO | PRI | NULL | |
| currencyRate_id | int(11) | NO | PRI | NULL | |
+-----------------+---------+------+-----+---------+-------+
currencies
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | UNI | NULL | |
| abreviation | varchar(5) | NO | UNI | NULL | |
+-------------+--------------+------+-----+---------+----------------+
I want to generate a form from all of this.
The html form would get all available currencies with a text field to indicate the CurrencyRate.
Ex :
USD <input type="text">
EUR <input type="text">
CNY <input type="text">
...
I saw the documentation on Symfony about manytomany form. But mine is more complex with an additional onetomany relation and text field. I am totaly lost.
Thanks if you can put me on the right direction.
Best regards,
Pierre
I found the response :
First I needed to correct my Schema which didn't need a ManytoMany relation :
Rates :
+-----------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| rate | double | YES | | NULL | |
| timeStamp | datetime | NO | | NULL | |
+-----------+----------+------+-----+---------+----------------+
CURRENCY RATES
+-------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| ratio | double | NO | | NULL | |
| currency_id | int(11) | YES | MUL | NULL | |
| Rate_id | int(11) | YES | MUL | NULL | |
+-------------+---------+------+-----+---------+----------------+
Currencies
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | UNI | NULL | |
| abreviation | varchar(5) | NO | UNI | NULL | |
+-------------+--------------+------+-----+---------+----------------+
Then One Form Type
class CurrencyRateType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('currency',EntityType::class, array(
'class'=>'AppBundle:Currencies',
'choice_label' => 'abreviation',
'disabled' => true,
))
->add('ratio', TextType::class);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => CurrencyRates::class,
));
}
}
which is embedded in the final form type :
class RateType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder ->add('rate')
->add('CurrencyRate', CollectionType::class, array(
'entry_type' => CurrencyRateType::class,
'entry_options' => array('label' => false))
)
->add('save', SubmitType::class, array('label' => 'create'));
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => Rates::class,
));
}
}

Querying in Rails

How can I get the first name and last name from the table User through table Friend which is referenced by the user_id with the condition of user_id 5 and status is pending and place it in a each loop but i also need the contents of friend controller in rails. Thank a lot for the help
Controller
#add = Friend.where(user_id: 5, status: 'Pending')
User Database
+-----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
| first_name | text | YES | | NULL | |
| last_name | text | YES | | NULL | |
| email | text | YES | | NULL | |
| contact_number | varchar | YES | | NULL | |
| birth_date | date | YES | | NULL | |
| created_at | datetime | NO | | NULL | |
| updated_at | datetime | NO | | NULL | |
Friend
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
| request_date | date | YES | | NULL | |
| reason | text | YES | | NULL | |
| status | varchar(255) | YES | | NULL | |
| userid | int | YES | MUL | NULL | |
How about this:
#add = Friend.joins(:user).select("users.first_name, users.last_name").where(user_id: 5, status: 'Pending')
Seems like youre already fetching the id of the user, stored in the user_id field. In order to get the associated user, i would do
#user = User.find(#add.id)
This retrieves the user based on the id you pass, and from there you can do stuff like
#user.first_name
to get the values
All you need to do in Friend model belongs_to user and then
#add =Friend.where("user_id = ? AND status = ?", 5,"Pending")
and
<#add.each do |s|>
<%s.user.first_name%>
<%=<%s.user.last_name%>
// and so on..
<%end%>

"Extract" intervals from series in Google Sheets

If I in Google Sheets have a series defined as
[29060, 29062, 29331, 29332, 29333, 29334, 29335, 29336, 29337, 29338, 29339, 29340, 29341,
29342, 29372, 29373].
How do I make them line up in intervals like this?
|To |From |
|29060 |29062 |
|29331 |29342 |
|29372 |29373 |
I can't find any good answers for this anywhere. Please, help!
Data/Formulas
A1:
29060, 29062, 29331, 29332, 29333, 29334, 29335, 29336, 29337, 29338, 29339, 29340, 29341,
29342, 29372, 29373
B1: =transpose(split(A1,",")). Converts the input text is an a vertical array.
C1: =FILTER(B1:B16,mod(ROW(B1:B16),2)<>0). Returns values in odd rows.
D1: =FILTER(B1:B16,mod(ROW(B1:B16),2)=0). Returns values in even rows.
E1: =ArrayFormula(FILTER(C1:C8,{TRUE();C2:C8<>D1:D7+1})). Returns values that start a range.
F1: =ArrayFormula(FILTER(D1:D8,{D1:D7+2<>D2:D8;TRUE()})). Returns values that end a range.
Result
Note: A1 values are not shown for readability.
+----+---+-------+-------+-------+-------+-------+
| | A | B | C | D | E | F |
+----+---+-------+-------+-------+-------+-------+
| 1 | | 29060 | 29060 | 29062 | 29060 | 29062 |
| 2 | | 29062 | 29331 | 29332 | 29331 | 29342 |
| 3 | | 29331 | 29333 | 29334 | 29372 | 29373 |
| 4 | | 29332 | 29335 | 29336 | | |
| 5 | | 29333 | 29337 | 29338 | | |
| 6 | | 29334 | 29339 | 29340 | | |
| 7 | | 29335 | 29341 | 29342 | | |
| 8 | | 29336 | 29372 | 29373 | | |
| 9 | | 29337 | | | | |
| 10 | | 29338 | | | | |
| 11 | | 29339 | | | | |
| 12 | | 29340 | | | | |
| 13 | | 29341 | | | | |
| 14 | | 29342 | | | | |
| 15 | | 29372 | | | | |
| 16 | | 29373 | | | | |
+----+---+-------+-------+-------+-------+-------+

list of dates associated with name

What would be a good approach to report of all the dates a name occurs in a list? Can this be done with a single array formula?
Example (column A and B are input, columns C through G are to be auto-generated):
| A | B | C | D | E | F | G |
+---------+--------+--------+---------+---------+---------+---------+
| Episode | Stars | Name | Date | Date | Date | Date |
+---------+--------+--------+---------+---------+---------+---------+
| 7/24/15 | Bart | Bart | 7/24/15 | 7/18/15 | 8/15/15 | 3/29/15 |
| 8/09/15 | Maggie | Homer | 1/10/15 | | | |
| 7/24/15 | Marge | Lisa | 7/20/15 | 6/04/15 | | |
| 7/18/15 | Bart | Maggie | 8/09/15 | | | |
| 1/10/15 | Homer | Marge | 7/24/15 | | | |
| 8/15/15 | Bart | | | | | |
| 7/20/15 | Lisa | | | | | |
| 6/04/15 | Lisa | | | | | |
| 3/29/15 | Bart | | | | | |
|^^^^^^|
| |
| |
| (o)(o)
# _)
| ,___| - Thanks Dude!
| /
/___\
/ \
I don't think this is easily possible in a single arrayformula. However, as an alternative you could try this formula in cell C2:
=SORT(UNIQUE(QUERY(FILTER(B$2:B,LEN(B$2:B)))),1,1)
Then try this formula in cell D2 and drag down:
=TRANSPOSE(QUERY(A$2:B,"select A where B='"&C2&"'"))
See this example sheet to see it working: https://goo.gl/0u41u5

Stretch Image with multi region

I want to set a background image to uiview with multi region like picture below?
How can i do that?
(constant)
<----->
+------------------+ ^
| | | | | (constant)
| A | | B | |
|-----+ - - +------| v
| | | | ^
| | | | |
| C | | D | | (stretched region)
| | | | |
| | | | |
+------------------+ v
<—————> <——————>
(stretched region)
Update: This is my image http://i.imgur.com/mEk75Sc.png
Use multiple images for each region.. this will be easier.

Resources