- using tick value by itself is wrong
- Your StopLoss is NOT in pips but your multiplying tick_value to be pip_value.
- using Normalize double is wrong, that will only work if minlot and lotstep are both exactly 0.1. Fails for any other multiple
double NormalizeLots(double lots, string pair=""){ if (pair == "") pair = Symbol(); double lotStep = MarketInfo(pair, MODE_LOTSTEP), minLot = MarketInfo(pair, MODE_MINLOT); lots = MathRound(lots/ls) * ls; if (lots < minLot) lots = 0; // or minLot return(lots); }
Print all the variables and then you will know what is causing your problem.
multiplier is intially initialized to 10. in the init function it gets modified
if((MarketInfo(Symbol(),MODE_DIGITS) == 5)||(MarketInfo(Symbol(),MODE_DIGITS) == 3))multiplier = MathPow(multiplier,MarketInfo(Symbol(),MODE_DIGITS)-1); else multiplier = MathPow(multiplier,MarketInfo(Symbol(),MODE_DIGITS));
it works perfect when the percents are set to 1% but somehow the number is modified when I set the percents to be 22% of equity
multiplier is intially initialized to 10. in the init function it gets modified
it works perfect when the percents are set to 1% but somehow the number is modified when I set the percents to be 22% of equity
- using tick value by itself is wrong
- Your StopLoss is NOT in pips but your multiplying tick_value to be pip_value.
- using Normalize double is wrong, that will only work if minlot and lotstep are both exactly 0.1. Fails for any other multiple
Is "ls" defined as lotStep?
Probably just a fluke that 1% works . . . your multiplier is clearly wrong . . . find out why.
I am probably doing something silly, but it works for all my other code and I cant see where the error is.
the number I want the multiplier to be is 10000.
I use the multiplier so if I want to find the difference between to prices in pips, I just multiply the price by my multiplier and take the difference excluding the 5th digit after decimal if it exists.
That is what this code is for
if((MarketInfo(Symbol(),MODE_DIGITS) == 5)||(MarketInfo(Symbol(),MODE_DIGITS) == 3)) { multiplier = MathPow(multiplier,MarketInfo(Symbol(),MODE_DIGITS)-1); }
So the -1 makes multplier 10000 what I need instead of 100000.
If it is standard 4 digits after decimal then this part of code is executed
else multiplier = MathPow(multiplier,MarketInfo(Symbol(),MODE_DIGITS));
Either way I get my condition for multiplier to be 10000. Now the atr24 is four digits after the decimal so
StopLoss = multiplier*atr24 is supposed to give me the pips I am using to calculate my stop so I can calculate the lots I want to open.
This code is slightly modified from the one presented earlier and it still does not work.
- 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 am trying to use the method of opening lots based of the percentage of equity I want to risk.
If I initialize the external double variables EquityPercent1 and EquityPercent2 to 1, it means I want to risk 1 percent. The code executes fine. But if I set them to 22 to risk 22% on lot1 and 22% on lot2
It assigns a value of 0 to both lots and the order fails due to invalid lotsize.
I am using MBtrading.
I used print statements and verified that MarketInfo(Symbol(),MODE_LOTSTEP) == 0.1
MarketInfo(Symbol(),MODE_MAXLOT) == 1000
MarketInfo(Symbol(),MODE_MINLOT) == 0.1
ALL the variables used to calculate LotSize1 and 2 are of type double as well as LotSize1 and 2 themselves. What could the problem be?