int L = iLowest(NULL,0,MODE_LOW,3,1); double Lowest = iLow(NULL,0,L);
Lowest is the low of bars 1,2 and 3
if(B1== 1 && B2 == 1 && B0 == 0 && Close[1] < Lowest)
It is not possible that the close of bar[1] will be lower than the low of bars 1,2 and 3
Lowest is the low of bars 1,2 and 3
It is not possible that the close of bar[1] will be lower than the low of bars 1,2 and 3
Thank you for correcting me..
But After I altered it, Bid < Lowest, that means if bid price is lower than last 3 bars lowest low, sell.
Now it takes only 2 trades. One buy trade after it got closed, one sell trade, then later no trade.
Why is that?
cashcube: One buy trade after it got closed, one sell trade, then later no trade. Why is that?
if(OrderSelect(x,SELECT_BY_POS) && OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol()) { if(OrderType()==OP_BUY) can_buy=false; if(OrderType()==OP_SELL) can_sell=false; } | It open a buy, set can_buy to false; it will never open another buy. It opens a sell, sets can_sell to false; it will never trade again. If you had printed your if variables you would have found out why. |
cashcube: One buy trade after it got closed, one sell trade, then later no trade. Why is that? | It open a buy, set can_buy to false; it will never open another buy. It opens a sell, sets can_sell to false; it will never trade again. If you had printed your if variables you would have found out why. |
Thank you WHReoder,
I was also thinking about it...I copied this code from somewhere else.
Actually as I mentioned, EA should take only one trade at a time. When current trade is online, it shouldn't take another trade until it got closed. Then how to do that? With OrdersTotal()?
I was also thinking about it...I copied this code from somewhere else.
The code is an example that I gave you in your previous thread.
bool can_buy=true; bool can_sell=true; for(int x=OrdersTotal()-1;x>=0;x--) { if(OrderSelect(x,SELECT_BY_POS) && OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol()) { if(OrderType()==OP_BUY) can_buy=false; if(OrderType()==OP_SELL) can_sell=false; } } if(can_buy) { //Check whether to place order } if(can_sell) { //Check whether to place order }
Note, can_buy and can_sell are locally declared variables
It can easily be modified to only allow 1 trade open at a time
bool can_trade=true; for(int x=OrdersTotal()-1;x>=0;x--) { if(OrderSelect(x,SELECT_BY_POS) && OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol()) { can_trade=false } }
Then check conditions to trade. If by some strange chance it is possible that both buy and sell conditions can be satisfied, you would need to take that into account
The code is an example that I gave you in your previous thread.
Note, can_buy and can_sell are locally declared variables
It can easily be modified to only allow 1 trade open at a time
Then check conditions to trade. If by some strange chance it is possible that both buy and sell conditions can be satisfied, you would need to take that into account
Yes you have shared the code with me. But misunderstood the local part. Now I declared them inside start() function & it works perfectly.
Thank you again..
- 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,
I made this EA which will take only one trade at time if the buy/sell condition satisfies. It will not take any new trade if current trade is online. Once current trade got closed it will check for buy/sell conditions again.
But currently its not taking any trades. I tested the code, part by part. I observed that if statement is not getting satisfied when I compare Close[1] < Lowest or Close[1] > Highest
Here is the code.
Any Suggestion?
Thank you.