Download MetaTrader 5
To add comments, please log in or register
No time to learn MQL5? Order your application from a developer!
tim
35
tim 2015.01.21 02:44 

Greetings,

I am trying to place orders with different SL and TP levels.  However only the SL and TP closest to the market are being created.

void OnStart()
{
   bool check = OrderSend(Symbol(), OP_BUY, 0.01, Ask, 3, Bid - 100 * Point, Bid + 100 * Point);
   if ( !check ) { Print("error OrderSend " ); check = true;}
   check = OrderSend(Symbol(), OP_BUY, 0.01, Ask, 3, Bid - 150 * Point, Bid + 150 * Point);    
   if ( !check ) { Print("error OrderSend " ); check = true;}
   check = OrderSend(Symbol(), OP_BUY, 0.01, Ask, 3, Bid - 200 * Point, Bid + 200 * Point);    
   if ( !check ) { Print("error OrderSend " ); check = true;}
   check = OrderSend(Symbol(), OP_BUY, 0.01, Ask, 3, Bid - 250 * Point, Bid + 250 * Point);    
   if ( !check ) { Print("error OrderSend " ); check = true;}
}

  When this is launched the last three orders take on the SL and TP of the first order.  

Can someone please explain what is going on?

Thank You. 

Keith Watford
Moderator
7990
Keith Watford 2015.01.21 03:50  

Did you possibly copy and paste the orders from the first order and then forget to recompile after changing the SL and TP ?

Is that the actual code for the script that you are attaching?

May seem silly questions, but I have made these mistakes myself 

tim
35
tim 2015.01.21 06:43  
This code has been recompiled and tested.  The only copy and pasting I did was from metaeditor to this forum.  The code I wrote was only to illustrate the problem.  
Why?  Did it work when you ran it?  This code should make 4 market buys, each one with its own distinct SL and TP.  But that's not what is does, it makes 4 market buys 
and the first SL and TP levels are shared by all 4 orders.  
Keith Watford
Moderator
7990
Keith Watford 2015.01.21 06:58  

I put your code in an EA and ran it in the strategy tester

1 2014.05.26 00:00 buy 1 0.01 1.36234 1.36114 1.36314 0.00 10000.00

2 2014.05.26 00:00 buy 2 0.01 1.36234 1.36064 1.36364 0.00 10000.00

3 2014.05.26 00:00 buy 3 0.01 1.36234 1.36014 1.36414 0.00 10000.00

4 2014.05.26 00:00 buy 4 0.01 1.36234 1.35964 1.36464 0.00 10000.00

As you can see the SL and TP were as expected.

I have no idea why it doesn't happen for you. That's why I questioned that the script you are using is the compiled version of the code that you have posted 

A number of times in the past I have been puzzled by something and it turned out that I was compiling xxxVersion 2 but had xxxVersion 1 attached to the chart

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2015.01.21 07:11  
GumRai:

A number of times in the past I have been puzzled by something and it turned out that I was compiling xxxVersion 2 but had xxxVersion 1 attached to the chart

Same thing happens to me.
tim
35
tim 2015.01.21 16:27  

I attached this script to a chart in my demo account.  All my work so far has been in the form of a script.  Last time I tried to put a script in an EA I got the error: “program is not EA”.  I suppose I’m not understanding the difference between a script and EA.  I know an EA requires calls to functions such as OnInit(),  OnDeint() and OnTick(), but I haven’t yet figured out what should go in those functions (I guess this is my new project) and haven’t found an example that does more than print output to the experts log.  What makes it more confusing is that the mql4 documentation refers to “init()” while the EA template uses “OnInit()”, are these two functions the same?  I have used OnStart() and start() and they seem to work the same.

 

Either way I would think that the script I posted would make 4 distinct SL and 4 distinct TP when attached to a chart.

honest_knave
969
honest_knave 2015.01.21 16:40  
bluepharo:

 What makes it more confusing is that the mql4 documentation refers to “init()” while the EA template uses “OnInit()”, are these two functions the same?  I have used OnStart() and start() and they seem to work the same. 

Documentation is a weak point of MQL.

There were a lot of changes from Build 600 onwards. You'll be finding some information that was relevant pre-build 600 and other information that is relevant post build 600. See here for some starting points.

tim
35
tim 2015.01.23 02:47  

Turns out multiple SL and TP levels are prohibited by my broker so I had to switch.  Now I can put down as many SL and TP levels as I want.  Plus I figured out how to get my script to run in an EA.  Many thanks to everybody that commented!

/
To add comments, please log in or register