On a failed OrderSelect you quit the entire function. You probably should use a continue rather than a break so you check the rest of the open orders
void CheckForClose() { double psar, price; for(int i=0; i < OrdersTotal(); i++) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==false) { // TODO use a continue here rather than a break or you will just quit the function break; } if(OrderSymbol() == Symbol() && OrderMagicNumber() == MAGIC && OrderCloseTime() == 0) { psar = iSAR(NULL, 0, 0.02, 0.2, 1); price = iClose(NULL, 0, 1); if(OrderType() == OP_BUY && psar > price) { OrderClose(OrderTicket(), OrderLots(), Ask, slippage, Red); } if(OrderType() == OP_SELL && psar < price) { OrderClose(OrderTicket(), OrderLots(), Bid, slippage, Red); } } } return; }
same thing in the TradeExists function
This construction is unpleasant
tp_level = Ask + (Take_Profit / MathPow(10, Digits))
People usually multiply TakeProfit by Point (often with pip to point factors to allow for 4 or 5 digit brokers.)
I am new to coding so please bear with me if I ask a lot of questions.
...I am also looking for a way to get the Expert to trade only once per bar (within the other parameters obviously).
For somebody "new to coding" your code is looking remarkably good :-)
The once per bar thing is easy. Use a static or global datetime variable and compare it Time[0]. If not equal it is a new bar. On the new bar set the datetime variable to equal Time[0]. This forum is flooded with this code.
I just cant find out how to get it to only open a trade on the 3rd PSAR dot.
So you want the case when the current Psar dot is below the price, and the previous one, and the previous one, but not the one previous to that.
Something like ...
if( psar(1)<Low[1] && psar(2)<Low[2] && psar(3)<Low[3] && psar(4)>High[4] ){
// do stuff
}
(I apologize if your previous answer just explained exactly what I just showed you)
Well my answer was supposed to address just the 3rd psar dot issue. When I wrote psar(1) for example I was just saying "the value of the psar indicator for bar 1". Perhaps I should have written it out more fully as
psar1 = iSAR(NULL, 0, 0.02, 0.2, 1); psar2 = iSAR(NULL, 0, 0.02, 0.2, 2); psar3 = iSAR(NULL, 0, 0.02, 0.2, 3); psar4 = iSAR(NULL, 0, 0.02, 0.2, 4); if( psar1<Low[1] && psar2<Low[2] && psar3<Low[3] && psar4>High[4] ){ // do stuff }
Well my answer was supposed to address just the 3rd psar dot issue. When I wrote psar(1) for example I was just saying "the value of the psar indicator for bar 1". Perhaps I should have written it out more fully as
hello everybody
i wonder if anybody could help me modify the above strategy a bit.
i would really appreciate your help.
hello everybody
i wonder if anybody could help me modify the above strategy a bit.
i would really appreciate your help.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am new to coding so please bear with me if I ask a lot of questions.
Okay so the idea behind the EA is that
Long Entry Short Entry
PSAR < Price PSAR > Price
MACD > 0 MACD < 0
The expert will close out a trade when it has reached a user defined amount of pips OR the PSAR reverses to the opposite side. However, when it comes to opening trades, I am trying to get the system to ONLY open a buy/sell on the third SAR dot in the trend, and not any other dots. I can't seem to get it to do this. I have gotten it to wait until the third dot but it will open a trade on the 4th dot, 5th dot, etc. I am also looking for a way to get the Expert to trade only once per bar (within the other parameters obviously).
I just am looking for some direction. If anyone can help point me the right way I would be very appreciative. Thank you.