You code it exactly the same. When you open a new trade, remember the current candle's time. If they are the same, don't open a new one.
Show us your attempt (using the CODE button) and state the nature of your problem.
No free help (2017.04.21)
You code it exactly the same. When you open a new trade, remember the current candle's time. If they are the same, don't open a new one.
Show us your attempt (using the CODE button) and state the nature of your problem.
No free help (2017.04.21)
Code:
//+------------------------------------------------------------------+ //| Tradeallowed | //+------------------------------------------------------------------+ bool Tradeallowed() { bool hastraded; for(int a =PositionsTotal()-1; a>=0; a--) { string symbol1 = PositionGetSymbol(a); if(Symbol() == symbol1) { ulong pticket1 = PositionGetTicket(a); double csl1 = PositionGetDouble(POSITION_SL); int posT = PositionGetInteger(POSITION_TYPE); if(NewBar() == true) { if(posT == POSITION_TYPE_BUY) { hastraded = true; } if(posT == POSITION_TYPE_SELL) { hastraded = true; } } } } return false; }
-
Please edit your post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum (2019.05.06)
Messages Editor -
Your code has no checks for #2
Code:
Code:
Even if this is your approach the function should return proper value
return(hastraded);
and also select the position by index before you start working with them
bool Tradeallowed(){ bool hastraded = false; for(int a =PositionsTotal()-1;a>=0;a--){ string symbol1 = PositionGetSymbol(a); if(Symbol() == symbol1){ ulong pticket1 = PositionGetTicket(a); double csl1 = PositionGetDouble(POSITION_SL); int posT = PositionGetInteger(POSITION_TYPE); if(posT == POSITION_TYPE_BUY){ hastraded = true; } if(posT == POSITION_TYPE_SELL){ hastraded = true; } } } return hastraded; }
Please insert the code correctly: when editing a message, press the button and paste your code into the pop-up window. (The first time I corrected your message)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use