Hi,
I am trying to convert a my custom indicator, perfectly working, into an EA. I have set the iCustom function as follows:
Commenting the those variables, to see their value, I get only random allocation numbers: 2147483647. Furthermore those values are constants and do not change over time (while back testing).
So it is impossible to trade! If I stop the backtesting, strange thing, in the indicator window I get and see "vwp_up" and "vwp_down" values and lines. Here is a pic:
How could I handle this?
Thanks!
2147483647 is not a random value, it's EMPTY_VALUE.
You got this as you are using a shift of 0 in iCustom, but your indicator doesn't have a value at current open bar.
How could I fix it? I have tried to set the EA only on new bars opening but I still got this issue!
Fix what ? I don't know what you want to do, but your indicator doesn't have a value on open candle so don't try to use it.
Your indicator provides values starting at shift 1 :
double vwp_up=iCustom(_Symbol,0,"VWP - Price",1,1);
Fix what ? I don't know what you want to do, but your indicator doesn't have a value on open candle so don't try to use it.
Your indicator provides values starting at shift 1 :
You're right... I have forget a part of the question, sorry! lol
I changed that, it should not be my question, I mean that changing shift from 0 to 1 results in a continuous order opening by the EA! I have already used the template in which I attached the indicator and it never behave this way
void OnTick() { //--- if(Volume[0]==1) { double vwp_down=iCustom(_Symbol,0,"VWP - Price",0,1); double vwp_up=iCustom(_Symbol,0,"VWP - Price",1,1); if(vwp_up>vwp_down) { // Open buy order gBuyTicket=OrderSend(_Symbol,OP_BUY,LOTS,Ask,slippage,0,0,"Market Buy Order due to MA_HIGH violation",MAGIC,0,clrGreen); gSellTicket=0; } // Sell Order Condition if(vwp_up<vwp_down) { // Open sell order gSellTicket=OrderSend(_Symbol,OP_SELL,LOTS,Bid,slippage,0,0,"Market Sell Order due to MA_LOW violation",MAGIC,0,clrRed); gBuyTicket=0; } // Close Sell Order if condition is violated if(gSellTicket!=0) { if(vwp_up>vwp_down) { bool select=OrderSelect(gSellTicket,SELECT_BY_TICKET); // Close Order bool closed=OrderClose(gSellTicket,OrderLots(),Ask,slippage,clrGreen); gSellTicket= 0; } } // Close Buy Order if condition is violated if(gBuyTicket!=0) { if(vwp_up<vwp_down) { bool select=OrderSelect(gBuyTicket,SELECT_BY_TICKET); // Close Order bool closed=OrderClose(gBuyTicket,OrderLots(),Bid,slippage,clrRed); gBuyTicket = 0; } } } }
You're right... I have forget a part of the question, sorry! lol
I changed that, it should not be my question, I mean that changing shift from 0 to 1 results in a continuous order opening by the EA! I have already used the template in which I attached the indicator and it never behave this way
Ok. Can you explain what you mean ? Please show the trades opened and/or the log.
I mean that instead of just control the position, EA closes and reopens new one, like this:
When VWP DOWN is still above the UP one it should not close or open anything! :|
EDIT:
I missed those two conditions: (vwp_up>vwp_down && gBuyTicket == 0 && gSellTicket == 0) .. That's ok now! :D Thanks Alain!
I mean that instead of just control the position, EA closes and reopens new one, like this:
When VWP DOWN is still above the UP one it should not close or open anything! :|
Why not ? Your code doesn't check if there is an existing position before opening a new one. On each new bar, it will open a buy or a sell, except if up=down.
Aside that please note that Volume==1 is not a reliable way to detect a new bar (on a live chart you can miss ticks and so a new bar).
you forgot
if(OrdersTotal==0) { //Do order logic } else if(OrdersTotal>0) { //Do Control positions }
Hi,leo How do you get the code in the end?
Did you make a success?
I have the same kind of issue with iCustom and your successful code will be very useful for me.
if(Volume[0]==1)For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum.) Always use time.
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
New candle - MQL4 and MetaTrader 4 - MQL4 programming forum
- 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,
I am trying to convert a my custom indicator, perfectly working, into an EA. I have set the iCustom function as follows:
Commenting the those variables, to see their value, I get only random allocation numbers: 2147483647. Furthermore those values are constants and do not change over time (while back testing).
So it is impossible to trade! If I stop the backtesting, strange thing, in the indicator window I get and see "vwp_up" and "vwp_down" values and lines. Here is a pic:
How could I handle this?
Thanks!