Hello. I'm writing a strategy . When I put close trade before entry signal, it skips alot of trades. This should trade one time each bar, and go from buy to sell trades only. This I made conditional. When I had entry before close, I get one trade a bar. Changing that skips about 7 days after trading a full day, every bar. When I place entry before close trade it seems to work right, every bar.
Do you see something wrong. Or should entry come before close in the program. There lots of extra lines in the program. I'm editing a program & will take them out after it works.
When you place and close orders is down to how your strategy works. Perhaps i don't understand your question . . .
This looks OK to me . . . not sure why you are seeing a problem with parenthesis ?
bool IsNewBar() { datetime curbar =Time[0];//Open time of current Bar if(lastbar!=curbar) { lastbar=curbar; return(true); } // end of if return(false); } // end of IsNewBar
for(cnt=0;cnt<total;cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
total = OrdersTotal(); if(total < 1)
You must count down when closing trades in the pretense of multiple open orders (multiple charts). No magic number makes the EA incompatible with every other including itself on multiple charts. Always test return codes.int count=0; 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. if(OrderType()==OP_BUY) // long position is opened { // should it be closed? if (Low[0]<Close[1]-Close[1]/10000 && curnum==True ) { if (OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet)) // close position continue; //////////////////////return(0); // exit Alert("OrderClose failed: ", GetLastError()); } count++;
When you close an order you are returning, so nothing else happens until the next bar AND the direction changes again.- Put the newbar test up at the beginning of start, BEFORE you test for crossings.
- EA's must adjust for 4/5 digit brokers, TP, SL, AND slippage. On ECN brokers you must open first and THEN set stops
//++++ These are adjusted for 5 digit brokers. int pips2points; // slippage 3 pips 3=points 30=points double pips2dbl; // Stoploss 15 pips 0.0015 0.00150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init(){ if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
-
You must count down when closing trades in the pretense of multiple open orders (multiple charts). No magic number makes the EA incompatible with every other including itself on multiple charts. Always test return codes.
When you close an order you are returning, so nothing else happens until the next bar AND the direction changes again.
- Put the newbar test up at the beginning of start, BEFORE you test for crossings.
- EA's must adjust for 4/5 digit brokers, TP, SL, AND slippage. On ECN brokers you must open first and THEN set stops
I want to thank-You both very much for your time and input. I'll get to work on all the changes.
- 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. I'm writing a strategy . When I put close trade before entry signal, it skips alot of trades. This should trade one time each bar, and go from buy to sell trades only. This I made conditional. When I had entry before close, I get one trade a bar. Changing that skips about 7 days after trading a full day, every bar. When I place entry before close trade it seems to work right, every bar.
Do you see something wrong. Or should entry come before close in the program. There lots of extra lines in the program. I'm editing a program & will take them out after it works. Also for IsNewBar athe endif I change parenthesis to look more accurate I get function definition unexpected for IsNewBar. And curbar variable not defined. Please help and Thank-You very much.