Can someone help me before I loose my mind......agagghhhhhhh

To add comments, please log in or register
Mccallum28
354
Mccallum28  

Hi all,

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....

Mladen Rakic
153805
Mladen Rakic  
rg83:
Hi all,

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 |

//| |

//+------------------------------------------------------------------+

#include

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;

int start()

{

bool uptrend= iCustom(NULL,0,"super_signals_v2_alert",1,0)!=EMPTY_VALUE;

bool downtrend=iCustom(NULL,0,"super_signals_v2_alert",0,0)!=EMPTY_VALUE;

Comment(uptrend," ",downtrend);

if(downtrend)

{

bool ticket=OrderSend(Symbol(),OP_SELL,lots,Bid,3,Bid-60*Point,Bid+TakeProfit*Point,NULL,0,0,clrRed);

}

else if(uptrend)

{

ticket=OrderSend(Symbol(),OP_BUY,lots,Ask,3,Ask-60*Point,Ask+TakeProfit*Point,NULL,0,0,clrGreen);

}

return(0);

}

But be advised that super trend recalculates.

Mccallum28
354
Mccallum28  

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..

Mladen Rakic
153805
Mladen Rakic  
rg83:
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

Files:
tester.gif 70 kb
Mccallum28
354
Mccallum28  

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?

Mladen Rakic
153805
Mladen Rakic  
rg83:
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?

rg83

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

Mccallum28
354
Mccallum28  

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.

Mccallum28
354
Mccallum28  

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?

//+------------------------------------------------------------------+

//| Tester.mq4 |

//| |

//+------------------------------------------------------------------+

#property strict

// #include why do you need this file included

extern int dist2=301;

extern int SignalBar=5;

input double lots=3;

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;

int ticket;

bool IsNewBar=false;

//+------------------------------------------------------------------+

//| Expert initialization function |

//+------------------------------------------------------------------+

int OnInit()

{

//---

//---

return(INIT_SUCCEEDED);

}

//+------------------------------------------------------------------+

//| Expert deinitialization function |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

{

//---

//---

}

//+------------------------------------------------------------------+

//| Expert tick function |

//+------------------------------------------------------------------+

void OnTick()

{

for(int i = OrdersTotal() -1; i >= 0; i--)

{

if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)

{

if (OrderType() == OP_BUY)

{

Buy_Pos++;

}

if (OrderType() == OP_SELL)

{

Sell_Pos++;

}

}

}

bool uptrend=iCustom(NULL,0,"super_signals_v2_alert",icustomsigup,icustomtimeup)!=EMPTY_VALUE;

bool downtrend=iCustom(NULL,0,"super_signals_v2_alert",icustomsigdown,icustomtimedown)!=EMPTY_VALUE;

if(uptrend && Buy_Pos == 0)

if (IsNewBar=true)

{

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)

if (IsNewBar=true)

{

ticket = OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Bid - sl * Point, Bid + tp,NULL, MagicNumber, 0, Blue);

if (ticket < 0)

Alert("Can't open Buy Order, Error code ", GetLastError());

}

//---

}

Files:
tester.mq4 3 kb
Mladen Rakic
153805
Mladen Rakic  
rg83:
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?

//+------------------------------------------------------------------+

//| Tester.mq4 |

//| |

//+------------------------------------------------------------------+

#property strict

// #include why do you need this file included

extern int dist2=301;

extern int SignalBar=5;

input double lots=3;

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;

int ticket;

bool IsNewBar=false;

//+------------------------------------------------------------------+

//| Expert initialization function |

//+------------------------------------------------------------------+

int OnInit()

{

//---

//---

return(INIT_SUCCEEDED);

}

//+------------------------------------------------------------------+

//| Expert deinitialization function |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

{

//---

//---

}

//+------------------------------------------------------------------+

//| Expert tick function |

//+------------------------------------------------------------------+

void OnTick()

{

for(int i = OrdersTotal() -1; i >= 0; i--)

{

if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)

{

if (OrderType() == OP_BUY)

{

Buy_Pos++;

}

if (OrderType() == OP_SELL)

{

Sell_Pos++;

}

}

}

bool uptrend=iCustom(NULL,0,"super_signals_v2_alert",icustomsigup,icustomtimeup)!=EMPTY_VALUE;

bool downtrend=iCustom(NULL,0,"super_signals_v2_alert",icustomsigdown,icustomtimedown)!=EMPTY_VALUE;

if(uptrend && Buy_Pos == 0)

if (IsNewBar=true)

{

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)

if (IsNewBar=true)

{

ticket = OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Bid - sl * Point, Bid + tp,NULL, MagicNumber, 0, Blue);

if (ticket < 0)

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

To add comments, please log in or register