How do I capture the price at which my order was place?

 

For example, if my EA placed an order for a "buy" how can I move that price value into a variable?



Opening price

 
 
phy:
See OrderOpenPrice()

Doesn't seem to be working. Here's my code:

while (execute_trade ==5)

{if ( OrdersTotal() <= buy_trade1 )

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point);

double price = OrderOpenPrice();

Comment ("My 1st trade order " + price);

execute_trade=0;


 

Before you can "work with a ticket", you must "select" it.

See OrderSelect()

 
Or you could try something like:
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point);

if (ticket>0)

Comment ("My 1st trade order " + Ask);

 
blogzr3:
Or you could try something like:


Well, if I tried that the comment would change with each new "Ask" price change, right?


I'm a total newbie here but the ultamate goal that I'm trying to reach is to have it do the following:

  1. Place a buy order with T/P of 60
  2. If price drops -60 pips from the 1st order then place a 2nd "buy" order
  3. If the price of the 2nd order drops another -60 pips then place a 3rd order and so on in a loop until the tickets close out on their own.
  4. If the 1st order is fine...then +30 pips from the 1st order place a 2nd order with t/p of 60 pips
  5. If 2nd order is fine...then +30 pips from the 2nd order...place a 3rd and last trade with t/p of 60 pips.
  6. Also, if any of the "good" trades drop -60 pips have the EA place another buy order...same as before.
This is a biggie of a challenge for me, being as this is my first EA and because I dont know any programming. I'll accept any help :)

 
rortiz77:

Well, if I tried that the comment would change with each new "Ask" price change, right?

No, only after you placed an OrderSend and that OrderSend succeeded.

 
blogzr3:

No, only after you placed an OrderSend and that OrderSend succeeded.


Ok yeah that worked. But how can I move it into a variable so I can compare it in an "if" or "while" loop?

 
rortiz77:

Ok yeah that worked. But how can I move it into a variable so I can compare it in an "if" or "while" loop?

double myVariable = Ask;


(Please have a look at the docs.)


CB

 

I can make it now put in the 1st trade fine...but the second trade it puts in 76 trades all at once. How can I control it to only add in 1?


while (execute_trade ==5)

{if ( OrdersTotal() == buy_trade1 ) //this stops it after 1 order have been placed.

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point);

execute_trade=0;

if(OrderSelect(1, SELECT_BY_TICKET)==true) //selecting order 1

{

buy1 = OrderOpenPrice(); //taking the 1st order's price and pushing it into this variable

// Comment("order #1 open price is ", OrderOpenPrice() + " " + buy1 + " less than " + (buy1-0.0030));

if (buy1 >= (buy1-0.0030))

{

//if ( OrdersTotal() <= buy_trade1 ) //this stops it after 1 order have been placed.

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point);

execute_trade=0;

}

}

else

Print("OrderSelect returned the error of ",GetLastError());

}

Reason: