Your code would send two trades every tick as the ticket id's of the first two trade would be reset to zero on the next tick. Check out static variables or use OrdersTotal() to control the placing of orders.
I normally check if ALL orders of a given type are in profit -and safe- before adding to positions. The following function checks if the stoploss has already be trailed enough to assure all trades are risk-free. Change it using OrderProfit() if you just want to know if they are in profit. Cheers.
/** * Checks if all trades of a given type are risk-free * @param int Type */ bool AreTradesRiskFree(int Type) { int l_type; for(int i = OrdersTotal()-1; i >= 0; i--) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); l_type = OrderType(); if(l_type == Type && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if(l_type == OP_BUY && Type == OP_BUY && OrderStopLoss() < OrderOpenPrice()) return(false); if(l_type == OP_SELL && Type == OP_SELL && OrderStopLoss() > OrderOpenPrice()) return(false); } } return(true); }
flaab:
I normally check if ALL orders of a given type are in profit -and safe- before adding to positions. The following function checks if the stoploss has already be trailed enough to assure all trades are risk-free. Change it using OrderProfit() if you just want to know if they are in profit. Cheers.
Thanks for response :) Currently I try to read through the forum and get more information

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
Hi together,
is there anybody who can help me regarding the mentioned "problem" below...
After open 2 market orders (1 buy & 1 sell order as hedged position) I'd like to check if one of the orders in profit and open a new position in the same direction as the order which is in profit.
Currently my code looks like this:
//external variables
extern double TP=x;
extern int slippage=x;
extern double Magicnr=682012;
extern int Lotsize=x;
//global variables
int Buytickethedge;
int Selltickethedge;
double UsePoint;
double UseSlippage;
//init function
int init()
{
UsePoint=PipPoint(Symbo());
UseSlippage=GetSlippage(Symbol(), Slippage);
}
//start program
int start()
{
//Hedge Position
if(Buytickethedge ==0 && Selltickethedge==0)
//openbuyorder
double Buyopenprice = ask;
Buytickethedge = Ordersend(Symbol(), OP_BUY, Lotsize, Buyopenprice, UseSlippage,0,0,"BuyHedge", Magicnr, 0, Green);
//opensellorder
double Opensellprice= bid;
Selltickethedge = Ordersend(Symbol(), OP_SELL, Lotsize, Sellopenprice, UseSlippage,0,0,"BuyHedge", Magicnr, 0, Red);
From now on...Is it possible to find out how to check the current status of both orders...?
shall I use this function?
for (int i=0; i<OrdersTotal(); i++)
{
if((OrderSelect(i,SELECT_BY_POS)==true)
{
double Profit= OrderProfit(); // Order profit --> "Profit" as extern double for external variables?
Many thanks for help...
regards
Marc