I realize that this is not the correct site for MQII questions, but, I wasn't sure
where else to go to get support.
I'm trying to create an expert which both closes part of an order and then moves
it's SL to B/E at nearby levels. But, I'm running into the 10-second limitation.
Is there any known workaround to this in MQII?
Thanks.
stockwet
- Stochastic Oscillator - Oscillators - Technical Indicators - Price Charts, Technical and Fundamental Analysis
- MQL5 Wizard: Development of trading robots for MetaTrader 5
- Relative Vigor Index - Oscillators - Technical Indicators - Price Charts, Technical and Fundamental Analysis
You can use flags, see example (WasClosedNow flag)
/*[[ Name := MA20 cross Author := Copyright й 2003, Metaquotes Software Corp Link := https://www.metaquotes.net// Lots := 1.00 Stop Loss := 0 Take Profit := 0 Trailing Stop := 0 ]]*/ Variables: PrevTime(0); Variables: MaCurrent(0),MaPrevious(0); Variable: cnt(0), WasClosedNow(False); If Not WasClosedNow And PrevTime=Time Then exit; PrevTime=Time; MaCurrent=iMA(20,MODE_SMA,1); MaPrevious=iMA(20,MODE_SMA,2); If Close[2]>MaPrevious And Close[1]<MaCurrent And WasClosedNow=False Then Begin print("Close crosses down MA20"); SetOrder(OP_SELL,1,Bid,3,0,0,RED); Exit; End; If (Close[2]<MaPrevious And Close[1]>MaCurrent) Or WasClosedNow Then Begin If (Close[2]<MaPrevious And Close[1]>MaCurrent) then print("Close crosses up MA20") Else print("Some trades is to be closed"); For cnt=1 to TotalTrades Begin If OrderValue(cnt,VAL_SYMBOL)=Symbol And OrderValue(cnt,VAL_TYPE)==OP_SELL Then Begin CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Bid,3,Violet); WasClosedNow=True; Exit; // close only 1 order at same time! and exit End; End; WasClosedNow=False; // open position at next time SetOrder(OP_BUY,Lots,Ask,3,0,0,GREEN); End;
I'm doing something similar. The problem I'm running into is that after the CloseOrder
block, I set my flag. But, the flag gets set whether or not the order actually
goes through or not. So, I can see in my journal that the order was requested (close
#5479138 1.00 lots at 236.0700 [slippage 3]), but, the order didn't actually close.
So, I don't want the flag set unless the operation actually goes through.
I did try this:
if ModifyOrder(OrderValue(i,VAL_TICKET),OrderValue(i,VAL_OPENPRICE), OrderValue(i,
VAL_OPENPRICE)+(Point*s),OrderValue(i,VAL_TAKEPROFIT),Red)
then
{
setFlag = True;
Print(setFlag);
}
But, that didn't seem to have any effect at setting the flag at all, even though
it compiled.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register