Forex Zone | Forex Forum

Help with Coding please

Discussion started on MT4 / MT5 EAs

  • Posts: 352
  • Points: 71
  • Likes Received: 144
  • Reputation: +11/-0
Help with Coding please in MT4 / MT5 EAs_xx
Hi
I am trying my hand at coding, and wrote a simple EA.
I am having a problem with this 1 issue.

 
 bool OneOrderAtATime=false;
  if(OrdersTotal()==0 || !inOneOrderAtATime)
      OneOrderAtATime=true;
      else OrdersTotal()=MaxOrders;
     

I give the option to have more that 1 order open, I get the "OneOrderAtATime" = True right, so it doesn't open any more orders.
But if it returns false,  When I want more than 1 open order, it opens up to 20 orders, I want to set the Max.
(If I set it to false, so the false statement is what I want,) I want to set a MaxOrders value. 
(Maxorders is in my Variables), I keep on getting this error when I compile:
'OrdersTotal' - l-value required Optimizing RS.mq4 132 12

Linkback: https://www.forex.zone/mt4-mt5-eas/7/help-with-coding-please/198/
#1 - August 26, 2018, 06:58:22 PM

  • Help with Coding please in MT4 / MT5 EAs_index
  • Posts: 3284
  • Points: 34347
  • Likes Received: 2984
  • Reputation: +168/-13
Help with Coding please in MT4 / MT5 EAs_xx
I noticed a few things wrong.

1) You cannot set a value to OrdersTotal(). OrdersTotal() is a function that returns a value, but not a variable that can have a value set to it.

2) You should not even use OrdersTotal() to begin with. OrdersTotal() gives the total number of orders open in the platform, but not from your specific EA. So orders from other EA's or even manual orders will be counted. It would be better to know how many orders this specific EA has made and manage only your EA's orders.

3) You have OneOrderAtATime set to false and the very next line has a check that sees if it is false (which it will be) and then sets it to true. I'm not sure what purpose that would serve and I do not think it is right.
#2 - August 26, 2018, 07:48:36 PM

  • Posts: 352
  • Points: 71
  • Likes Received: 144
  • Reputation: +11/-0
Help with Coding please in MT4 / MT5 EAs_xx
I thought OrdersTotal will not be right
What can I call there to set a max nr of trades?
#3 - August 26, 2018, 07:55:24 PM

  • Posts: 352
  • Points: 71
  • Likes Received: 144
  • Reputation: +11/-0
Help with Coding please in MT4 / MT5 EAs_xx
I set MaxTrades as a variable in the global scope.
The EA must check how many open orders I have, (hopefully excluding pending orders, ie, SL and TP, else it will count those as open orders too. Or that is how my mind is seeing it)

I just want it to limit the amount of open trading orders.

Sorry for all the stupid posts, maybe 1 day I will code without help, then I can be like you and CP ;)
#4 - August 26, 2018, 08:00:49 PM

  • Help with Coding please in MT4 / MT5 EAs_index
  • Posts: 3284
  • Points: 34347
  • Likes Received: 2984
  • Reputation: +168/-13
Help with Coding please in MT4 / MT5 EAs_xx
What can I call there to set a max nr of trades?
You have to write your own code to count and limit orders since there is nothing you can call to do this for you.
#5 - August 26, 2018, 08:26:15 PM

  • Help with Coding please in MT4 / MT5 EAs_index
  • Posts: 3284
  • Points: 34347
  • Likes Received: 2984
  • Reputation: +168/-13
Help with Coding please in MT4 / MT5 EAs_xx
I set MaxTrades as a variable in the global scope.
The EA must check how many open orders I have, (hopefully excluding pending orders, ie, SL and TP, else it will count those as open orders too. Or that is how my mind is seeing it)

I just want it to limit the amount of open trading orders.
MaxTrades can be global or even a user input, but it doesn't matter in this case since it cannot be assigned to OrdersTotal().

If you want to exclude pending orders then OrdersTotal() definitely is not what you need here since that will return pending orders too.

I understand already what you want to do, but you are going about the wrong way of doing it. First, you need to have your EA count how many orders it itself has made. It needs to recognize and count only it's own orders, but not orders from other EA's or even manual orders. Next, you need to simply write code to prevent orders if the MaxOrders # has already been met. There are many ways to do this. For example, you can add a check before the OrderSend() function. So if current order count >= MaxOrders then no new trade. 
#6 - August 26, 2018, 08:35:27 PM

  • Posts: 352
  • Points: 71
  • Likes Received: 144
  • Reputation: +11/-0
Help with Coding please in MT4 / MT5 EAs_xx
Thanks
Trial and error is the way to go ;)
#7 - August 26, 2018, 08:42:57 PM

  • Help with Coding please in MT4 / MT5 EAs_index
  • Posts: 3284
  • Points: 34347
  • Likes Received: 2984
  • Reputation: +168/-13
Help with Coding please in MT4 / MT5 EAs_xx
No problem. Yes, that is probably the best way to learn.
#8 - August 26, 2018, 08:47:59 PM

  • Posts: 352
  • Points: 71
  • Likes Received: 144
  • Reputation: +11/-0
Help with Coding please in MT4 / MT5 EAs_xx
One more question please
I have both MT4 and MT5,
How can I compile a MT5 EA or Indo to ex4?
Obviously what I can gather is ex5 doesn't work on ex4.
#9 - August 27, 2018, 03:26:15 PM

  • Help with Coding please in MT4 / MT5 EAs_index
  • Posts: 3284
  • Points: 34347
  • Likes Received: 2984
  • Reputation: +168/-13
Help with Coding please in MT4 / MT5 EAs_xx
How can I compile a MT5 EA or Indo to ex4?
Obviously what I can gather is ex5 doesn't work on ex4.
The two platforms work differently and the languages are also different. So you need to convert the code to from MQL5 to MQL4. After this, compile using the MT4's MetaEditor which will produce an EX4.
#10 - August 27, 2018, 03:43:53 PM

  • Posts: 352
  • Points: 71
  • Likes Received: 144
  • Reputation: +11/-0
Help with Coding please in MT4 / MT5 EAs_xx
IS there software or something I can use to do the conversion, Google gives many answers but not anything I can use
Thanks again
#11 - August 27, 2018, 04:38:13 PM

  • Help with Coding please in MT4 / MT5 EAs_index
  • Posts: 3284
  • Points: 34347
  • Likes Received: 2984
  • Reputation: +168/-13
Help with Coding please in MT4 / MT5 EAs_xx
No, there is nothing I know about, but I also haven't looked for one too. Even if there is a way to automatically convert the code, I don't think it would work for everything. In my opinion, something like this needs done by hand by a real person.
#12 - August 27, 2018, 05:04:29 PM

  • Posts: 352
  • Points: 71
  • Likes Received: 144
  • Reputation: +11/-0
Help with Coding please in MT4 / MT5 EAs_xx
Hi all,
I've been very busy lately trying to master this EA coding thing.
I am getting there slowly...
A little coding help again please.
How do I ensure the EA only opens a trade on the close of the bar.
There a.re a couple of instances when an indicator reaches a "true" level, but the bar closes false, (due to price decrease/increase)
Closing the trade obviously depends on SL and TP (or other parameters/functions)
I tried assigning an index value to the indi, but that doesn't work
Thanks
I will be able to post EA's soon/ or even help with easy EA's ;)
#13 - September 25, 2018, 12:42:35 AM
« Last Edit: September 25, 2018, 12:46:52 AM by Francoisvs »

  • Help with Coding please in MT4 / MT5 EAs_index
  • Posts: 3284
  • Points: 34347
  • Likes Received: 2984
  • Reputation: +168/-13
Help with Coding please in MT4 / MT5 EAs_xx
You have to create a simple function to check when a new bar forms. Then have the EA trade the instant the new bar opens. When a new bar opens, it can then check the previous bar's indicator values, which are now closed and confirmed for many indicators.

Here is a sample code:

Code: [Select]
bool NewBar()
 {
  if (Time[0]!=time)
   {
    time=Time[0];
    return(true);
   }
  
  return(false);
 }

You would have a global variable 'time' declared (not shown above). When the current bar's time is different than the last recorded time, the time variable is updated and the function returns true. When this happens, trading is allowed. If the function is false, trading is not allowed. Let me know if that makes sense.
#14 - September 25, 2018, 01:05:07 AM

  • Posts: 352
  • Points: 71
  • Likes Received: 144
  • Reputation: +11/-0
Help with Coding please in MT4 / MT5 EAs_xx
Awesome. 
Thank you very much
#15 - September 25, 2018, 07:45:08 AM

Members:

0 Members and 1 Guest are viewing this topic.


* Share Topic

Share via delicious Share via digg Share via facebook Share via linkedin Share via pinterest Share via reddit Share via stumble Share via tumblr Share via twitter

* Similar Topics

lamp
Free coding

Started by LazyProg on Jobs / Work

14 Replies
1399 Views
Last post August 12, 2019, 11:50:22 PM
by LazyProg
xx
NEW EA Coding needed

Started by Francoisvs on New EA Coding

21 Replies
833 Views
Last post October 18, 2018, 07:34:37 PM
by Francoisvs
clip
Need help with some coding for certain things i want to add to my EA

Started by avanong1984 on EA Modifications

0 Replies
449 Views
Last post September 01, 2019, 12:23:04 AM
by avanong1984
xx
Indi Coding

Started by Francoisvs on MT4 / MT5 Indicators

2 Replies
892 Views
Last post August 23, 2018, 04:44:17 PM
by Francoisvs