why pending orders doesn't adjusted in mql4? error: the price doesnt declared. here is the mql4 code - mql4

/here i saved my last order's open price at op parameter./
double op = OrderOpenPrice();
int ticket = SendOrder(_symbol,OP_SELLSTOP,0.02,op -0.0020,100, 0,0);

If you are trying to change existing orders you should be using OrderSelect() and OrderModify().

Related

Rails sum all prices inside a record

I have a model Products that belongs_to model Kit
Kit has_many Products
¿How can I sum all of the prices of each product that belongs to a kit?
I tried with no luck:
#kitprice = Kit.products.price.sum
Try this:
#kitprice = kit.products.sum(:price)
In my case i have wallet with many operations
wallet = Wallet.first
amount = wallet.operations.sum(:amount)
Question is slightly ambiguous. Assuming you have an instance of Kit named as kit, and a kit has many product objects; following would get you the desired result.
sum = 0
kit_id = <enter kit id here>
kit = Kit.find_by_id(kit_id)
# iterate through every product object and compound price here
kit.products.each{|product| sum = sum + product.price}
puts sum
Basically you need to iterate through every product object and compute the sum, since it's a has many relationship.
This will give you every kit with the sum of it's products, i assume there is a column named name in your kit model
#kit_products_price = Kit.includes(:products).group(:name).sum('products.price')
If you want the sum of all the kit products :
#kit_price = Kit.includes(:products).sum('products.price')
The following should work I believe:
Active Record collection
#total = kit.products.sum("price")
Ruby array
#total = kit.products.sum(&:price)

How to add a column to mnesia table

I am trying to add new column to an existing mnesia table. For that, I use following code.
test()->
Transformer =
fun(X)->
#users{name = X#user.name,
age = X#user.age,
email = X#user.email,
year = 1990}
end,
{atomic, ok} = mnesia:transform_table(user, Transformer,record_info(fields, users),users).
Two records I have
-record(user,{name,age,email}).
-record(users,{name,age,email,year}).
My problem is when I get values from my user table it comes as
{atomic,[{users,sachith,28,sachith#so,1990}]}
Why do I get users record name when I retrieve data from user table?
The table name and the record name are not necessarily the same. You started out with a table called user holding user records, and then you transformed all the user records into users records. So when you read from the table, it will return users records, since that's what the table now contains.
If you look at the internal representation of record,
-record(Name, {Field1,...,FieldN}). is represented by {Name,Value1,...,ValueN}.
So, basically you are converting {user,name,age,email} to {users,name,age,email,year} in your table.
But there is better approach for such migration which will come in handy as you update your records later,
Looking at this production codebase a better snippet for the transformer function,
%%-record(user,{name,age,email}). // old
%%-record(user,{name,age,email,year}). // new
Transformer =
fun(X)->
#user{name = element(2,X),
age = element(3,X),
email = element(4,X),
year = 1990}
end,

How are MQL4 Orders ordered by default?

When using OrderSelect() in mql4, are the orders ordered according to the ticket number by default? My intention is to use OrderModify() on orders starting from the first that was opened to the most recent.
Never assume anything in MQL unless it's explicitly specified in the documentation. That said, you'll need to sort your ticket numbers before iterating them in order.
CArrayInt tickets;
for(int i=0; OrderSelect(i, SELECT_BY_POS); i++)
tickets.Add(OrderTicket());
tickets.Sort();
for(int i=0; i<tickets.Total(); i++)
if(OrderSelect(tickets[i], SELECT_BY_TICKET))
...
`enter code here`
int Magic = 12345;
// This reads the orders LIFO (last in...)
// the index is an integer and is incremented from 0
// as the orders are placed. It is NOT
// the ticket number. No sorting necessary.
for(int i=OrdersTotal()-1;i>=0;i--)
if(_Symbol=OrderSymbol() && Magic = OrderMagicNumber())
if(OrderSelect(i, SELECT_BY_POS) {
Print("Order Index: ",i,", Ticket: ",OrderTicket());
You cannot call OrderSelect() function without parameters. You must specify id and the way the orders are selected. If you know an ID of the order, as it is seen it MT4 terminal window, you can call OrderSelect( order_id, SELECT_BY_TICKET), if you dont know or in case you loop over history trades you have to apply OrderSelect(i,SELECT_BY_POS) or OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) where i is integer between 0 and OrdersTotal() or OrdersHistoryTotal() respectfully.
If you loop over the array of trades with i as an integer, you are strongly advised to loop from the maximum value to zero (and not vice versa), and you can obtain ticket id by calling OrderTicket() function after OrderSelect(*,*[,MODE_HISTORY]) is successful.

GroupBy in F# and Average to values for each group

I am a brand new to F#, and I am having trouble with a simple first query. I have a data set, and I want to group the dollar amount based on the codes (which repeat in the data). Then, for each group I want the average (and eventually standard deviation) of the dollar amounts for each group. Also, I only want to look at ONE providerID, hence the 'where' clause. From my research, I have gotten this far:
let dc = new TypedDataContext()
let query2 = query { for x in dc.MyData do
groupBy x.Code into g
where (x.ProviderId = "some number of type string")
let average = query { for n in g do
averageBy n.DollarAmt }
select (g.Key, average) }
System.Console.WriteLine(query2)
With this I get a compiling error that says, "The namespace or module 'x' is not defined."
I do not understand this because when I ran the query that only collected the data with the specified providerID, it did not complain about this 'x', and I followed the same format with this 'x' for this larger query.
Any ideas? Thank you in advance.
From #kvb's comment: After the groupBy you can only access the group g, not the individual items x. Try putting the where before the groupBy.

Rails method to monitor status of a variable for a set period of time

Trying to setup a method that will give customers a discount if a certain sales volume is met in a set period of time.
I have 6 variables
1- units_sold - total number of items sold
2- sales_volume - sales volume required to get a certain benefit
3- sales_time - the amount of time available to meet the required sales volume
4- price - regular price of item
5- discount - discount granted if sales_volume met within sales_time
6- final_price - price customer pays
and i tried to create the method like this...
def speed_discount ( unit_sales, product)
while product.sales_time != 0
if unit_sales(product)==product.volume
final_price = price+discount
else final_price = price
end
end
end
The method should monitor sales_time and units_sold and if the required sales_volume is met before sales_time expires it updates the price to reflect the additional discount. i've tried the following but i think something is wrong with the While stmt and i dont know how to have sales_time start counting down.
This question is answered elsewhere on the site. see the link below
see question at for answer
Comparing datetime variables in Rails

Resources