can u plz explain idea more of strategy?
add more comments, what is tp and why if tp==-1.0?
how to replicate error?
thx and gl
can u plz explain idea more of strategy?
add more comments, what is tp and why if tp==-1.0?
how to replicate error?
thx and gl
sure thing.
sadly, since i didnt code it - i have no idea what is tp==-1.0.
error is pretty easy to spot - after the EA has been reset, trades closed, we start up the EA anew, but for some reason an extra buy order is closed, just like it would have had hit a TP.
when the "flush" was implemented, we had a similar issue, which we fixed by issuing new magic numbers (which, as we see doesnt work if "hedger" is on, for some reason).
so far, as ive managed to find out - supposedly i need to improve the code for restarting :
if(FLUSH){ if(AccountEquity()>=(accountbalance/100*FLUSH_Percent)+accountbalance){ Sleep((SleepXMinutes*60)*1000); first=true; nAll=nBuy=nSell=0; LastBuy=LastSell=0.0; close=CloseOrders(); accountbalance=AccountBalance(); MagicNumber=MagicNumber+1; }}
{
first=false;
if (hedge){
int type = Check_tp();
// if (type>=0) OpenOrder(type,-1.0,0); // why opening extra order of same type here???
if (type>=0) {};
}else{
if(nBuy==0) OpenOrder(OP_BUY,-1.0,0);
if(nSell==0) OpenOrder(OP_SELL,-1.0,0);
}
if(nBuy>0 && (LastBuy-Ask)>=ReOpenDist*_Point*mult) OpenOrder(OP_BUY,LastBuy,0);
if(nSell>0 &&( Bid-LastSell)>=ReOpenDist*_Point*mult) OpenOrder(OP_SELL,LastSell,0);
}
// call the display function.
display();
if(nAll>0) { first=false; if (hedge){ int type = Check_tp(); if (type>=0) OpenOrder(type,-1.0,0); }else{ if(nBuy==0) OpenOrder(OP_BUY,-1.0,0); if(nSell==0) OpenOrder(OP_SELL,-1.0,0); } if(nBuy>0 && (LastBuy-Ask)>=ReOpenDist*_Point*mult) OpenOrder(OP_BUY,LastBuy,0); if(nSell>0 &&( Bid-LastSell)>=ReOpenDist*_Point*mult) OpenOrder(OP_SELL,LastSell,0); }because if tp triggered we have to open "hedge" trade in opposite direction as i remember right
because if tp triggered we have to open "hedge" trade in opposite direction as i remember right
hey there,
you're almost correct - we had to open a trade in the same direction, but the lot size was calculated using the difference of positions in both direction.
if(nAll>0)
{
first=false;
if (hedge){
int type = Check_tp();
// if (type>=0) OpenOrder(type,-1.0,0); // why opening extra order of same type here???
if (type>=0) {};
}else{
if(nBuy==0) OpenOrder(OP_BUY,-1.0,0);
if(nSell==0) OpenOrder(OP_SELL,-1.0,0);
}
if(nBuy>0 && (LastBuy-Ask)>=ReOpenDist*_Point*mult) OpenOrder(OP_BUY,LastBuy,0);
if(nSell>0 &&( Bid-LastSell)>=ReOpenDist*_Point*mult) OpenOrder(OP_SELL,LastSell,0);
}
// call the display function.
display();
its what goverkms said - on TP's it opens an increased lotsize trade in the same direction.
so, if that line is disabled - when TP is met, no action is initiated.
may i ask a question?
why did you re-arrange the code?
out of habit, or does it has a different purpose?
excuse me for such a silly question.
re arranged code so ontick is at top, which is your main program, then the place order function because problem was extra order so seemed next most likely culprit.
check_tp seems to return the type of the last closed winning trade. assuming there is no problem with check_tp function, then you need to say new extra order only when there is only one open trade (because one closed as a winner) not more than zero open trades (two is more than zero so places your unwanted extra trade). ???
if ((type>=0) && (nAll==1)) OpenOrder(type,-1.0,0);
but even that seems redundant, since you then check nBuy and nSell
if(nAll>0)
{
first=false;
if (hedge)
{
if(nBuy==0) OpenOrder(OP_BUY,-1.0,0);
if(nSell==0) OpenOrder(OP_SELL,-1.0,0);
}
if(nBuy>0 && (LastBuy-Ask)>=ReOpenDist*_Point*mult) OpenOrder(OP_BUY,LastBuy,0);
if(nSell>0 &&( Bid-LastSell)>=ReOpenDist*_Point*mult) OpenOrder(OP_SELL,LastSell,0);
}
or maybe this is better...
if(nAll==1)
{
first=false;
if (hedge)
{
if(nBuy==0) OpenOrder(OP_BUY,-1.0,0);
if(nSell==0) OpenOrder(OP_SELL,-1.0,0);
}
else
{
if(nBuy>0 && (LastBuy-Ask)>=ReOpenDist*_Point*mult) OpenOrder(OP_BUY,LastBuy,0);
if(nSell>0 &&( Bid-LastSell)>=ReOpenDist*_Point*mult) OpenOrder(OP_SELL,LastSell,0);
}
}
re arranged code so ontick is at top, which is your main program, then the place order function because problem was extra order so seemed next most likely culprit.
check_tp seems to return the type of the last closed winning trade. assuming there is no problem with check_tp function, then you need to say new extra order only when there is only one open trade (because one closed as a winner) not more than zero open trades (two is more than zero so places your unwanted extra trade). ???
if ((type>=0) && (nAll==1)) OpenOrder(type,-1.0,0);
it wasnt as much as an unwanted place, it was more of a trade placed in the wrong place, at the wrong time.
im not entirely sure what does who check where, but i do know that the extra trade was mainly only a buy, since i never saw any sells.
i couldnt get this one :
if ((type>=0) && (nAll==1)) OpenOrder(type,-1.0,0);
to work, but the middle solution seems to be working, however, ill check it thoroughly.
we kinda fixed this error with the "hedger" input off, what it previously did, was after the "flush", it continued trading the previous (increased) lot sizes.
fixed that with issuing a new magic number.

- 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 there!
so, as the subject mentions - theres a bug in this code - annoying me, quite a bit - might anyone experienced point out where the issue is?
the issue is - when the "flush", or the restart of the EA is activated - for some reason it opens the two initial trades, but with one extra trade - and thus - bias'ing the whole idea.
might work differently for other people, but as far as ive seen - it opens an extra "buy" order right off the bat.
the issue only occurs if "hedger" is on.
any one kind enough to lend a hand?
p.s.
feel free to point out any mistakes, errors and so on..
for the greater good.
cheerios.