I've racked my brain around this stuff. Looked at the book, watched videos and dove into forums with no luck.
the code is in mql4.
I'm trying to use iCustom with quite a few hiccups.
Global variables and function calls are done once - when the EA is loaded. That's why all your iCustoms are not updated.
You should put your iCustom statements within your OnTick() so that it's called again, to retrieve updated values every Tick.
Is there a way to store them in some type of memory so I'm not calling several indicators at once, which would eat up CPU?
I haven't seen any such way... moreover, such calls are necessary.
However, if your strategy only requires you to look at the indicator results of fully formed bars, you can make iCustom calls with 1 and 2 as the last parameter, and only make the calls when a bar has been formed (i.e. skip all ticks within the latest bar). This will lighten up the CPU drastically.
I haven't seen any such way... moreover, such calls are necessary.
However, if your strategy only requires you to look at the indicator results of fully formed bars, you can make iCustom calls with 1 and 2 as the last parameter, and only make the calls when a bar has been formed (i.e. skip all ticks within the latest bar). This will lighten up the CPU drastically.
Finally found the damn reply button...
That's another issue I'm running into, in several cases. Is there a way to take a non array to a buffer for a later call of the EA, ie. the lot calculator doesn't have an array but it being part of lots in an OP_ORDER, which then takes from ATR TP/SL.
Underworldbros: the code is in mql4.
I do hope the get mql5 up to and more intuitive than mql4's standards.
Is there a way to take a non array to a buffer for a later call of the EA,
-
Why did you post your MT4 question in the
Root /
MT5 EA section
instead of the MQL4 section,
(bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. - Global and static variables work exactly the same way in MT4/MT5/C/C++.
- They are initialized once on program load.
- They don't update unless you assign to them.
- In C/C++ you can only initialize them with constants, and they default to zero.
- In MTx you should only initialize them with constants. There is no default. The MT4/MT5 actually compiles with non-constants. The order that they are initialized is unspecified. Don't try to use any price or server related
functions in OnInit (or on load,) as there may be no connection/chart
yet:
- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
-
Unlike indicators, EAs are not reloaded on chart change so you must
reinitialize them, if necessary.
external static variable - Inflation - MQL4 and MetaTrader 4 - MQL4 programming forum
- Only indicators can have buffers.
- Why would you want an indicator to compute lots? Only the EA (or script,) can trade. Have it compute your risk. Never risk more than a small percentage of your account, certainly less than 2%
per trade.
-
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.
Finally found the damn reply button...
That's another issue I'm running into, in several cases. Is there a way to take a non array to a buffer for a later call of the EA, ie. the lot calculator doesn't have an array but it being part of lots in an OP_ORDER, which then takes from ATR TP/SL.
Looking at the codes for the lot calculator, it'll serve its purpose well by becoming just a function within your expert. As for the other indicators, I just moved their iCustom statements into OnTick(). If you want to reduce number of calls, try limiting the call to just the start of bars, but that also means you should only call iCustom with bar index 1, not 0.
Attached is a version that runs, without the discrepancies you mentioned in your first post.
- 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've racked my brain around this stuff. Looked at the book, watched videos and dove into forums with no luck.
the code is in mql4.
I'm trying to use iCustom with quite a few hiccups.
I'm still new to coding in mql4 but i can't seem to find answers to my issues anywhere.
The red boxes have mismatching numbers. They are cole but still mis matching.
The blue arrows are an ATR multiplier set (in the EA) for the previous candle. The indicator is set for current candle. The code in the EA will not advance to the next candle. It just sticks on the initialized candle.
I use iCustom for most of my call functions. None of the indicators are mine, they are all free and I do not plan to sell my EA.
It's still in it's beginning stages and there are other indicators I would like to add for testing. I just need to get past these hiccups first.
Attached are pictures of my issues and the indies I'm using thus far. My code for my EA is also below.
Any help would be appreciated.
Most of the videos are either non-native english speaking, which makes their accent hard to understand.
The others are convoluted, run off on tangents a lot, and constantly repeat themselves un-necessarily. (Jim Dandy)
Any materials I've read are cryptic and I have a hard time understanding them.
Forum posts have little to nothing to do with my issues.
I do hope the get mql5 up to and more intuitive than mql4's standards.
Thanx in advance.