if(Digits == 3 || Digits == 2) isYenPair = true; // Adjust for YenPair
If you change symbol, your EA goes through a deinit/init cycle, but your variable will be wrong.isYenPair = Digits == 3 || Digits == 2;
if (isSizingOn == true)
You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.- Never risk more than a small percentage of your account, certainly less than 2%
per trade, 6% total.
-
In code (MT4): Risk depends on your initial stop loss, lot size, and the
value of the pair.
- You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
- AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the spread, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
-
Do NOT use TickValue by itself - DeltaPerLot and
verify that MODE_TICKVALUE is returning a value in your deposit currency,
as promised by the documentation, or whether it is returning a value in the
instrument's base currency.
MODE_TICKVALUE is not reliable on non-fx instruments with many brokers. - You must normalize lots properly and check against min and max.
- You must also check FreeMargin to avoid stop out
-
In code (MT4): Risk depends on your initial stop loss, lot size, and the
value of the pair.
- If you change symbol, your EA goes through a deinit/init cycle, but your variable will be wrong.
- You should be able to read your code out loud and have it make sense. You would
never write if( (2+2 == 4) == true) would you?
if(2+2 == 4) is sufficient. So don't write
if(bool == true), just use if(bool) or
if(!bool). Code becomes self documenting when you use meaningful
variable names, like bool isLongEnabled where as Long_Entry
sounds like a trigger price or a ticket number and "if long entry" is an
incomplete sentence.
- Never risk more than a small percentage of your account, certainly less than 2%
per trade, 6% total.
-
In code (MT4): Risk depends on your initial stop loss, lot size, and the
value of the pair.
- You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
- AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the spread, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
-
Do NOT use TickValue by itself - DeltaPerLot and
verify that MODE_TICKVALUE is returning a value in your deposit currency,
as promised by the documentation, or whether it is returning a value in the
instrument's base currency.
MODE_TICKVALUE is not reliable on non-fx instruments with many brokers. - You must normalize lots properly and check against min and max.
- You must also check FreeMargin to avoid stop out
-
In code (MT4): Risk depends on your initial stop loss, lot size, and the
value of the pair.
Try this little modification.
if (isYenPair == true ) Lots = Lots * 100.0 ; // Adjust for Yen Pairs
Never multiply a Double value with an Int value because the result could be an Int (depending on the language).
Never in any language that I know of. They all will up cast - D•I always becomes D•double(I). All you save is a cast that the optimizer should do at compile time.
Only an int÷int is a problem if you expect a fraction.
- If you change symbol, your EA goes through a deinit/init cycle, but your variable will be wrong.
- You should be able to read your code out loud and have it make sense. You would
never write if( (2+2 == 4) == true) would you?
if(2+2 == 4) is sufficient. So don't write
if(bool == true), just use if(bool) or
if(!bool). Code becomes self documenting when you use meaningful
variable names, like bool isLongEnabled where as Long_Entry
sounds like a trigger price or a ticket number and "if long entry" is an
incomplete sentence.
- Never risk more than a small percentage of your account, certainly less than 2%
per trade, 6% total.
-
In code (MT4): Risk depends on your initial stop loss, lot size, and the
value of the pair.
- You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
- AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the spread, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
-
Do NOT use TickValue by itself - DeltaPerLot and
verify that MODE_TICKVALUE is returning a value in your deposit currency,
as promised by the documentation, or whether it is returning a value in the
instrument's base currency.
MODE_TICKVALUE is not reliable on non-fx instruments with many brokers. - You must normalize lots properly and check against min and max.
- You must also check FreeMargin to avoid stop out
-
In code (MT4): Risk depends on your initial stop loss, lot size, and the
value of the pair.
You good Sir, have solved my problem!
Sorry it took me so long to get back to my EA's issue, and since tomorrow is a holiday, I had time now to really sit down and go through your comment properly.
Your comment on if (bool) and if (!bool) made me take a good look at the code in detail. And I realized I have forgotten to add in the !bool portion. With that last bit of code, everything is in order. Auto sizing can now be selected; and it is working.
if (isSizingOn) { Lots = Entry_Amount; Lots = Risk * 0.01 * AccountBalance() / (MarketInfo(Symbol(),MODE_LOTSIZE) * Stop_Loss * P * Point); // Sizing Algo based on account size if(isYenPair == true) Lots = Lots * 100.0; // Adjust for Yen Pairs } if (!isSizingOn) { Lots = Entry_Amount; }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi guys,
I'm currently in a bind with my EA. Everything was fine and dandy until i tried adding an auto lot sizing function or money mangement
The following are the codes I've added in and got me the error.
All variables are declared, no errors, not warnings.
Is my calculation wrong? Or am I doing it entirely wrong?