Replace
if(dLowest < Low[iLowest(0,0,MODE_LOW,iBaseLag,iBaseBar)])
to
if(dLowest < Low[iLowest(NULL,0,MODE_LOW,iBaseLag,iBaseBar)])
- Always count DOWN when closing
for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. ){
double dHighest; // if(Open[1]<ma && Close[1]>ma)|| //if (dBid > ma) //&& if(dHighest > High[iHighest(0,0,MODE_HIGH,iBaseLag,iBaseBar)])
dHighest = zero if (0 > High[x]) will never be true
Hi you all
The code liquidates well with
And also with But if I request a SELL order or BUY order to liquidate when Highest High or Lowest Low condition, the liquidation does not occur. Below is the block with the situation I have tried with andA few others as well. Presently, iBaseLag =2, IbaseBar = 1. Could someone have a look and give advise and or critic.
Thanks for all the help now and from the past.
regards Huckleberry
i think this should solve your problem
highest high= High[1] < High[2]
for lowest low= Low[1] > Low[2]
with these u will be able to close with the most recent highest high and lowest low respectively
Thank you, everyone who has responded. There is still much to learn. The code is now liquidateing and I am now experimenting with two Stops. One stop is Profit and the other is StopLoss. If I build the code with onestop and not the other, eventually the trade will stop out. But when I try to use both at the same time so as to create a stop for profit and one for a stoploss, the code does not compile. I have tried useing "||" (OR), and I have tried inserting an" OrderClose()" for each stop. I will continue to reading the documents and articles, but if anyone has advice I be glad to hear from you.
Thanks again for your past inputs.
Regards Huckleberry
Ruuning out the door and forgot the insert the code. I was also thinking I could insert one of the stops in the Ordersend()??.
ere is the code so far.
//+------------------------------------------------------------------+ //| Check for close order conditions | //+------------------------------------------------------------------+ void CheckForClose() { double ma; //---- go trading only for first tiks of new bar if(Volume[0]>1) return; //---- get Moving Average ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0); //---- int pos; for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == MAGICMA // my magic number && OrderSymbol() == Symbol() // and my pair. ) { //-------------------------------------------------------------------------------- /* 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_SELL) { double dBid = MarketInfo(Symbol(), MODE_BID); double dAsk = MarketInfo(Symbol(), MODE_ASK); double dLowest = MarketInfo(Symbol(), MODE_BID); double dHighest = MarketInfo(Symbol(),MODE_ASK); if (dAsk < ma) || (dHighest = High[iHighest(NULL,0,MODE_HIGH,iBaseLag,iBaseBar)]) OrderClose(OrderTicket(),OrderLots(),Ask,3,Blue); return; } if(OrderType()==OP_BUY) { if (dBid > ma)|| (dLowest = Low[iLowest(NULL,0,MODE_LOW,iBaseLag,iBaseBar)]) OrderClose(OrderTicket(),OrderLots(), Bid,3,Red); return; } } }Thanks for your help/
OK, to make your code compile . . . do this . . .
if (dAsk < ma) || (dHighest = High[iHighest(NULL,0,MODE_HIGH,iBaseLag,iBaseBar)]) change to . . if (dAsk < ma || dHighest == High[iHighest(NULL,0,MODE_HIGH,iBaseLag,iBaseBar)]) if (dBid > ma)|| (dLowest = Low[iLowest(NULL,0,MODE_LOW,iBaseLag,iBaseBar)]) change to . . if (dBid > ma || dLowest == Low[iLowest(NULL,0,MODE_LOW,iBaseLag,iBaseBar)])
When you use if it can only apply to one expression, so if you want to use multiple expressions they have to be enclosed within brackets to make the multiple expressions into one, e.g. a>b || c<d is two expressions, but ( a>b || c<d ) is one expression. Redundant brackets are OK to use if it makes your code more readable for you, so this is OK . . . ( (a>b) || (c<d) ), each of the expressions gets resolved to true or false . . then the final result is arrived at,
a = 4, b = 2, c = 3, d = 1
( (a>b) || (c<d) ) ---> ( (true) || (false) )
That is a great explanation. It was a complete walk through and I will work with this and get back to you. Thank you.
Cheers

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi you all
The code liquidates well with
And also withif (dAsk < ma)
But if I request a SELL order or BUY order to liquidate when Highest High or Lowest Low condition, the liquidation does not occur. Below is the block with the situation I have tried with andA few others as well. Presently, iBaseLag =2, IbaseBar = 1. Could someone have a look and give advise and or critic.
Thanks for all the help now and from the past.
regards Huckleberry