abricot91: new LONG #1 position for making a downward average.
- Guaranteed to blow your account. The market will go down more than you can afford.
OrderSend(Symbol(),OP_BUY,lot,Ask,0,0,0,"BUY",magic,0,Blue); OrderSelect(x,SELECT_BY_POS,MODE_TRADES);
What are Function return values ? How do I use them ? - MQL4 forumif( OrderOpenPrice() - Ask == 0.001) // the idea here was : if LONG #0 loose 10 points
- The == operand. - MQL4 forum
- On non JPY currencies 0.0010 is 10 pips, (10 pips is 100 points on a 5 digit broker.)
- Don't hard code numbers (10 * pips2dbl)
- When you fix #3 and open the second order, on the next tick, you will find second or, then the first order which is still below 10 pips and you will open another, and another, etc. one per tick. You must break out of the loop on the first matching order.
- No magic number makes the script incompatible with every other EA, including itself on other charts and manual trading.
Thanks WHRoeder for some precision about the return value of Orderselect() and OrderSend(), I have add condition for 5 digits, 3 Digits and 1 Digits to my code but I don't understand your "4." step ?
I don't want to use this code for a real account, in fact, I just want to create a downward average for practice some code
So, I'm still have some difficulty to open the second order, I withdraw the control structure FOR because the code just need to select one order (the first order)
Here my new code :
#property copyright "Copyright 2014, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict extern int heuredebut = 7; extern int heurefin = 17; extern double lot = 1; int a ; int digit = Digits; void OnTick() { int total = OrdersTotal(); int magic = 20; int ticket; switch(digit) { case 5: a = 10000; break; case 3: a = 100; break; case 1: a = 1; break; } if (total<1) { if( Hour() >= heuredebut && Hour()<= heurefin) { ticket =OrderSend(Symbol(),OP_BUY,lot,Ask,0,0,0,"BUY",magic,0,Blue); if (ticket >0) { if (OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)&& magic == OrderMagicNumber() && OrderType() == OP_BUY) { if ( (OrderOpenPrice() - Ask)*a >= 10 ) { OrderSend(Symbol(),OP_BUY,lot,Ask,0,0,0,"BUY",magic,0,Blue); } } } } } return; }
if (total<1) //First order will be sent { if( Hour() >= heuredebut && Hour()<= heurefin) { ticket =OrderSend(Symbol(),OP_BUY,lot,Ask,0,0,0,"BUY",magic,0,Blue); if (ticket >0) { if (OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)&& magic == OrderMagicNumber() && OrderType() == OP_BUY) { if ( (OrderOpenPrice() - Ask)*a >= 10 ) //This line will only be executed in the same tick as the OrderSend { OrderSend(Symbol(),OP_BUY,lot,Ask,0,0,0,"BUY",magic,0,Blue); } } } }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
hello,
this time I would like to create a script which Open a first LONG#0 position between 7am to 5pm. The goal is : if the LONG #0 loose 10 pips, i would like the script OPEN à new LONG #1 position for making a downward average.
I have begin a script but this one just open the LONG#0 :/ THANKS