Download MetaTrader 5

I NEED HELP

To add comments, please log in or register
richtrader2015
12
richtrader2015  

Hello to all,

 I have recently learnt how to code the new MQL4. and i have written and EA with open position when its attached to the chart. but i have a problem!

when I change the time frame the EA recalculate and re-initiate and open new positions. I want to know how can i stop that. I really appreciate in advance for your help.

the first part of my code is as following: (the MM include file is the money management section) 

void OnInit()

   {

      MM();

//---------------------------------------------------------------------------------------Pending position

      if (MM()==true)

       {

         int Ticketbuy = OrderSend(Symbol(),OP_BUYSTOP,Lots,bullishprice,0,0,tpbull,NULL,0,0,clrNONE);

         int Ticketsell = OrderSend(Symbol(),OP_SELLSTOP,Lots,bearishprice,0,0,tpbear,NULL,0,0,clrNONE);

whroeder1
16105
whroeder1  
richtrader2015: I want to know how can i stop that.
  1. You code it not to. learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
  2. Check if there is a open or pend order already on the chart.
  3. Use the human A) Human sets an external true, code opens, sets it to false. B) MessageBox
  4. Make it a script not an EA.



richtrader2015
12
richtrader2015  
WHRoeder:
richtrader2015: I want to know how can i stop that.
  1. You code it not to. learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
  2. Check if there is a open or pend order already on the chart.
  3. Use the human A) Human sets an external true, code opens, sets it to false. B) MessageBox
  4. Make it a script not an EA.



Hello,

1-I know how to code and already coding my EA and its work very well just wanted to know this simple part. I'm about to launch it on my website.

2-I've learnt to code so that i wouldn't pay someone else to do it for me.

3-thanks for your advice.

Regards 

Keith Watford
Moderator
10614
Keith Watford  

Use a magic number in your OrderSend

Loop through the opened orders and see if there is already one opened with the magic number. If there is, don't send the order

If you also need to check if an order is already closed, loop through Orders History and filter using time or whatever.

whroeder1
16105
whroeder1  
richtrader2015: 1-I know how to code and already coding my EA and its work very well just wanted to know this simple part.
Then where is your code that "Check if there is a open or pend order already on the chart?" If you know how to code mt4 then you should already know how to do that. You don't so GumRai elaborated.
Demos Stogios
206
Demos Stogios  

Your code is inside OnInit() and in the MQL reference you can read about the fact that OnInit() is called each and every time you change a Tmeframe or Symbol on the chart the EA is attached to. So all of what you are experiencing I may say are actually expected

best regards 

To add comments, please log in or register