I don't believe that no one knows how to do it.
Poorly readable code? Or maybe I didn't explain clearly?
I'm trying to calculate how many pips the price has to go from the breakeven price (several orders in the same direction) to get the specified profit in currency.
It's just that I don't understand how to use MODE_TICKVALUE and MODE_TICKSIZE correctly.
Example: several buy orders are open. I want to close them when their total profit reaches $100.
I think using OrderProfit() and OrderClose() is not efficient. It would be more correct to set take profits of orders in the place where their total profit will be $100.
This is what I am doing: trying to calculate the price at which take profits should be located
These are all the same equation written in different ways ...
[Volume] = [Money Value] * [Tick Size] / ( [Tick Value] * [Stop Size] ) [Stop Size] = [Money Value] * [Tick Size] / ( [Tick Value] * [Volume] ) [Money Value] = [Volume] * [Stop Size] * [Tick Value] / [Tick Size] [Volume] in lots [Stop Size] in quote price change [Money Value] in account currency
Your method seems to give the same result, but requires less computation. I will use it, thanks.
#property strict input double inpTakeProfitInCurrency = 100.0; void OnStart() { if(!OrderSelect(0, SELECT_BY_POS)) return; double first = firstMethod(inpTakeProfitInCurrency, OrderOpenPrice(), OrderLots()); double second = secondMethod(inpTakeProfitInCurrency, OrderOpenPrice(), OrderLots()); Alert(StringFormat("Profit %.2f: first method %s, second method %s, results match %i", inpTakeProfitInCurrency, prcToStr(first), prcToStr(second), first == second)); } double firstMethod(double money, double avgPrice, double volume) { double pointValue = _Point * MarketInfo(_Symbol, MODE_TICKVALUE) / MarketInfo(_Symbol, MODE_TICKSIZE); double takeProfitInPoints = money / (volume * pointValue) * _Point; return(avgPrice + takeProfitInPoints); } double secondMethod(double money, double avgPrice, double volume) { return(avgPrice + money * MarketInfo(_Symbol, MODE_TICKSIZE) / (MarketInfo(_Symbol, MODE_TICKVALUE) * volume)); } string prcToStr(double price) { return(DoubleToString(price, _Digits)); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I want to set take profit in currency for several orders (in same direction) in the settings.
Please help me to correctly calculate the price of take profit.
I think something like this (but most likely it is not correct):
Full code: