1)try to get iCustom datas on every new bar instead of every tick
2)also get its datas from candle 1 instead of candle 0
-----------------------------------
use same magic number to close previous order and open a new one
Hi.
i'm trying to wrote a simple expert based on indicator buffers. but when indicator send a Sell or Buy signal , my expert make many buy or Sell Orders! while i want to Run the order just once , not dozens of times. also i want to close the past order when a new order runs. can anybody help me with that? thanks in advance if someone help me and edit the code. here is the code :
Looking at it another way, WHY is your code generating multiple orders?
Your start() function, which I think should be OnTick(), generates the code every tick, so there is nothing to stop orders being placed on every tick?
It's unlikely you want orders placed on every tick, so, as others have suggested, create a function to identify if an order already exists for chart symbol. You might do this by looping through existing orders and seeing if the OrderSymbol() matches the chart symbol.
This function handily returns the ticket# in case you want to close the order. If it returns -1 there is no existing order and you can carry on.
int ticket(){ for (int i=0;i<OrdersTotal();i++){ if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol())return OrderTicket(); } return -1; }
So, that should prevent multiple orders and the next step would be to run the code not every tick, but every x bars....if you do a search for "mql4 identifying new bar" that will get you going.....(50,000 hits on google!)
- www.metatrader5.com
- 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'm trying to wrote a simple expert based on indicator buffers. but when indicator send a Sell or Buy signal , my expert make many buy or Sell Orders! while i want to Run the order just once , not dozens of times. also i want to close the past order when a new order runs. can anybody help me with that? thanks in advance if someone help me and edit the code. here is the code :