if (OrderSelect(TakeProfitBuy,SELECT_BY_POS)==true)
The first parameter of OrderSelect() is an index number into the list of orders. In this case, 50. Is that what you want?
Thank you for the reply.
50 is the amount of pips above the open BUY order, is what I am looking for. Basically, a hard stop profit.
else, the open order will close with the ma0 < ma1..blah, blah.
Hope that explains better.
Thanks again
Phy,
Here is another attempt. But not with desired result.
if (OrderSelect(i,SELECT_BY_POS)==true) if ((iOpen(NULL,0,0)< Close [0]) >= 50) OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);Just another way to explain
Sorry Phy
Does not compute. My last post (code) was way off the mark . The code below is how I understand you in your post.
void CheckForClose() { double ma0; ma0=iMA(NULL,0,8,0,MODE_SMA,PRICE_CLOSE,0); double ma1; ma1=iMA(NULL,0,10,0,MODE_SMA,PRICE_CLOSE,0); double LowerBB; LowerBB=iBands(NULL,0,30,1,0,PRICE_WEIGHTED,MODE_LOWER,0); double UpperBB; UpperBB=iBands(NULL,0,30,1,0,PRICE_WEIGHTED,MODE_UPPER,0); double TakeProfitBuy = OrderProfit (); TakeProfitBuy = 50; double TakeProfitSell = OrderProfit(); TakeProfitSell = 50; for(int i=0; i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue; //---- check order type if(OrderType()==OP_BUY) { if (OrderSelect(50,SELECT_BY_POS)==true) // This is where the 50 should be inserted? If so, the code does buy // one position. But never closes? if (ma0 < ma1 && Close [0] < LowerBB && ma1 > LowerBB) OrderClose(OrderTicket(),OrderLots(), Bid,3,Red); else if (OrderOpenPrice() > Close [0] >= TakeProfitBuy) OrderClose(OrderTicket(),OrderLots(), Bid,3,Red); break; } if(OrderType()==OP_SELL) { if (ma0 > ma1 && Close [0] > UpperBB && ma1 < UpperBB) OrderClose(OrderTicket(),OrderLots(),Ask,3,Blue); else if (OrderOpenPrice() < Close [0] >= TakeProfitSell) OrderClose(OrderTicket(),OrderLots(),Ask,3,Blue); break;
Thanks again for the help. Eventually this will all soak in.
Regards
By the way, if I take the 50 out
if (OrderSelect(50,SELECT_BY_POS)==true)and reinsert the .. i ..
if (OrderSelect(i,SELECT_BY_POS)==true)The code will compute, but the
else if (OrderOpenPrice() > Close [0] >= TakeProfitBuy)
is not acknowledged as part of the complete code.
Hi
I have not had a hard look at your source but it seems you define TakeProfitBuy as OrderProfit() prior to selecting an order.
Try selecting an order first and then define TakeProfitBuy.
Hello ssn
Thank you for the input. This is how I understand you.
//+------------------------------------------------------------------+ //| Checking for Close order conditions | //+------------------------------------------------------------------+ void CheckForClose() { static double dHighest1, dHighest2, dLowest1, dLowest2; dHighest1 = High [iHighest (0,0, MODE_HIGH, iBaseLag1, iBaseBar)]; dHighest2 = High [iHighest (0,0, MODE_HIGH, iBaseLag2, iBaseBar)]; dLowest1 = Low [iLowest (0,0, MODE_LOW , iBaseLag1, iBaseBar)]; dLowest2 = Low [iLowest (0,0, MODE_LOW , iBaseLag2, iBaseBar)]; double ma0; ma0=iMA(NULL,0,8,0,MODE_SMA,PRICE_CLOSE,0); double ma1; ma1=iMA(NULL,0,10,0,MODE_SMA,PRICE_CLOSE,0); double LowerBB; LowerBB=iBands(NULL,0,30,1,0,PRICE_WEIGHTED,MODE_LOWER,0); double UpperBB; UpperBB=iBands(NULL,0,30,1,0,PRICE_WEIGHTED,MODE_UPPER,0); /*double TakeProfitBuy = OrderProfit (); TakeProfitBuy = 50; double TakeProfitSell = OrderProfit(); TakeProfitSell = 50;*/ int cnt; for(int i=0; i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue; //---- check order type if(OrderType()==OP_BUY) { /* if (OrderSelect(cnt,SELECT_BY_POS)==true) if (ma0 < ma1 && Close [0] < LowerBB && ma1 > LowerBB) OrderClose(OrderTicket(),OrderLots(), Bid,3,Red); else */ if (OrderSelect(50,SELECT_BY_POS)==true) // 1). This is what you are suggesting? OrderSelect here? double TakeProfitBuy = OrderProfit (); // defined TakeProfitBuy = 50; if (OrderOpenPrice() > Close [0] >= TakeProfitBuy) OrderClose(OrderTicket(),OrderLots(), Bid,3,Red); break; } if(OrderType()==OP_SELL) { /* if (OrderSelect(cnt,SELECT_BY_POS)==true) if (ma0 > ma1 && Close [0] > UpperBB && ma1 < UpperBB) OrderClose(OrderTicket(),OrderLots(),Ask,3,Blue); else */ if (OrderSelect(50,SELECT_BY_POS)==true)// 2). And add insert OrderSelect here also? double TakeProfitSell = OrderProfit(); //defined TakeProfitSell = 50; if (OrderOpenPrice() < Close [0] >= TakeProfitSell) OrderClose(OrderTicket(),OrderLots(),Ask,3,Blue); break; } } //---- }
The code does not close out existing position. Any other suggestions are welcomed. I will continue with reseach.
Thanks again
u need to understand something this line means
if (OrderSelect(50,SELECT_BY_POS)==true)
that u selecting position no. 50
another thing u have extra lines that u don't need
double ma0; ma0=iMA(NULL,0,8,0,MODE_SMA,PRICE_CLOSE,0); double ma1; ma1=iMA(NULL,0,10,0,MODE_SMA,PRICE_CLOSE,0); double LowerBB; LowerBB=iBands(NULL,0,30,1,0,PRICE_WEIGHTED,MODE_LOWER,0); double UpperBB; UpperBB=iBands(NULL,0,30,1,0,PRICE_WEIGHTED,MODE_UPPER,0);
why not use it like this
double ma0=iMA(NULL,0,8,0,MODE_SMA,PRICE_CLOSE,0); double ma1=iMA(NULL,0,10,0,MODE_SMA,PRICE_CLOSE,0); double LowerBB=iBands(NULL,0,30,1,0,PRICE_WEIGHTED,MODE_LOWER,0); double UpperBB=iBands(NULL,0,30,1,0,PRICE_WEIGHTED,MODE_UPPER,0);
and this lines doesn't make sence
double TakeProfitBuy = OrderProfit (); // defined TakeProfitBuy = 50; double TakeProfitBuy = OrderProfit (); // defined TakeProfitBuy = 50;
double TakeProfitBuy = OrderProfit() or 50 ?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello to everyone,
The complete code was working. Compiled with buys/sells. Not that it was profitable. Just adding more steps.
When I attempted to add on TakeProfitBuy = 50; the Buy trade will now not close.
Could I have some input please.
Thank you