I have been trying to call a custom indicator into an EA using icustom, my EA will not show the indicator on the chart and will not print the signals.
I want to enter short at the open of the next bar when the indicator gives a green signal and vice versa with an option to be always in the market.
normaly a position will close when an oposit signal is triggered.
Only one trade per direction at a time.
Here is the code i have attached and the indicator. Please can someone help me with this....
Try something like this for start:
//| Tester.mq4 |
extern int dist2=6;
extern int SignalBar=2;
input double lots=3;
input double TakeProfit=320;
int OpenOrders=0, cnt=0;
int flagval1 = 0;
int flagval2 = 0;
bool uptrend= iCustom(NULL,0,"super_signals_v2_alert",1,0)!=EMPTY_VALUE;
But be advised that super trend recalculates.
Thanks for your help, I tried and I still get error 130 with no trades and the chart does not paint the signals.
I am aware it repaints and moves with the bar, however the alert is actualy sound on the open of the next bar, that is when I would like to open the trade.
Do you think I am getting error codes as MT4 is trying to open too many trades rather than a single trade on the open of the next bar after the signal is printed?
Do you have any idea why the indicator is not showing up on the chart when I load the EA?
I just cant get it to trade its driving me mad.. but thanks for helpong me out..
Error 130 means that either your broker is an ECN/STP like broker and it does not allow placing stop loss and / or take profit along with order opening, or that stop loss and / or take profit are too close to the current price.
If it is ECN/STP broker then you have to open an order with stop loss and take profit set to 0 and only then to modify the order to desired stop loss and take profit. If it is the error of too close prices then you have to set those to greater (stop loss and take profit). The EA is opening orders (see this example) :
In that code you will also get errors 134 (not enough money error) since you do not control if there is enough money to open the order or not. You have a lot of work on that EA to do in order to control all that needs to be controlled in an EA
Have you loaded the indicator , is there a way to load the indicator so you can see it via the EA and simply open a position rather than trigger an alert?
I could then try to build from there?
iCustom() calls the indicator and retrieves the values from it. It is exactly the same as if you have attached the indicator to the chart, except that you do not see the indicators values on the chart
Here is one thread with a detailed explanation and examples of what exactly iCustom() does and how it is doing it : https://www.mql5.com/en/forum/173108
The reason I ask is because when testing different variations of the code, I could see the indicator signals on the visual but no trade had opened on the open of the next bar.
Thanks for the link, ill have a good read.
Hi Guys, I can now get the EA to open positions but it tries to open a trade on every tic of the signal bar. I only want to have one trade in any one direction at a time, once a position is open, no more trade tickets. Can someone help me achieve this?
// #include why do you need this file included
extern int dist2=301;
extern int SignalBar=5;
input double sl=110;
input double tp=1232;
input double icustomsigup=1;
input double icustomsigdown=0;
input double icustomtimeup=3;
input double icustomtimedown=3;
extern int MagicNumber=45645;
int Buy_Pos = 0, Sell_Pos = 0;
//| Expert initialization function |
//| Expert deinitialization function |
void OnDeinit(const int reason)
//| Expert tick function |
for(int i = OrdersTotal() -1; i >= 0; i--)
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
if (OrderType() == OP_BUY)
if (OrderType() == OP_SELL)
if(uptrend && Buy_Pos == 0)
ticket = OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Ask + sl * Point, Ask - tp * Point,NULL, MagicNumber,0, Red);
if (ticket < 0)
Alert("Can't open Sell Order, Error code ", GetLastError());
if(downtrend && Sell_Pos == 0)
ticket = OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Bid - sl * Point, Bid + tp,NULL, MagicNumber, 0, Blue);
Alert("Can't open Buy Order, Error code ", GetLastError());
Attach the indicator that you are using in the EA too so that it can be tested