res=OrderSend(Symbol(), OP_SELL, LotsOptimized(), Bid, 3, Bid+StopLoss*DigitPoint(), Bid-TakeProfit*DigitPoint(), "", MAGICMA, 0, Red);
You're adjusting TP and SL for 5 digit brokers, but you must ALSO adjust slippage//++++ These are adjusted for 5 digit brokers. int pips2points; // slippage 3 pips 3=points 30=points double pips2dbl; // Stoploss 15 pips 0.0015 0.00150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init(){ if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
- On ECN brokers you must open and THEN set stops.
- Always check return codes so you know WHY
res=OpenOrder(...); if (res<0) Alert("OpenOrder failed: ", GetLastError());
if(LotStep==1) LotDigit=0; if(LotStep==0.1) LotDigit=1; if(LotStep==0.01) LotDigit=2; ////////////////////////////////////////// Lot=NormalizeDouble(LotSize,LotDigit);
fails for any other lot step (like 0.05)Lot= MathFloor(LotSize/lotStep)*lotStep;
//---- go trading only for first tiks of new bar if(Volume[0]>1) return;
Volume is unreliable, you can miss ticks. Bars is unreliable, doesn't change past max bars on chart. Always use timeint start(){ //---- go trading only for first tiks of new bar static datetime Time0; if (Time0 == Time[0]) return(0); Time0 = Time[0];
- You MUST count down when closing in the presence of multiple orders (multiple charts)
for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() ){ // and my pair.
- You're adjusting TP and SL for 5 digit brokers, but you must ALSO adjust slippage
- On ECN brokers you must open and THEN set stops.
- Always check return codes so you know WHY
- fails for any other lot step (like 0.05)
- Volume is unreliable, you can miss ticks. Bars is unreliable, doesn't change past max bars on chart. Always use time
- You MUST count down when closing in the presence of multiple orders (multiple charts)
Hello,
Thank you very much for your help! I made the changes you suggested and hope it will work well on my server. However, I couldn't manage to adjust the slippage for 5 digit brokers. Could you change it for me directly in the code (in the attachement)?
Hello,
Thank you very much for your help! I made the changes you suggested and hope it will work well on my server. However, I couldn't manage to adjust the slippage for 5 digit brokers. Could you change it for me directly in the code (in the attachement)?
However, I couldn't manage to adjust the slippage for 5 digit brokers. Could you change it for me directly in the code (in the attachement)?
Look at #1 your code and the comment at the bottom of mine.
I am at a dead end with the slippage adjusting... I did the following changes as suggested:
void CheckForOpen()
{
double ma;
int res;
int pips2points;
double pips2dbl;
int Digits.pips;
//---- go trading only for first tiks of new bar
static datetime Time0; if (Time0 == Time[0]) return(0); Time0 = Time[0];
//---- get Moving Average
ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//---- sell conditions
if(Open[1]>ma && Close[1]<ma)
{
res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3*pips2point,Bid+StopLoss*pips2dbl(),Bid-TakeProfit*pips2dbl(),"",MAGICMA,0,Red);
if (res<0) Alert("OpenOrder failed: ", GetLastError());
return;
}
//---- buy conditions
if(Open[1]<ma && Close[1]>ma)
{
res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3*pips2point,Ask-StopLoss*pips2dbl(),Ask+TakeProfit*pips2dbl(),"",MAGICMA,0,Blue);
if (res<0) Alert("OpenOrder failed: ", GetLastError());
return;
}
}
but I still have problems with placing these lines:
int init(){
if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers.
pips2dbl = Point*10; pips2points = 10; Digits.pips = 1;
} else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; }
Where exactly do I have to place it? i guess I should replace this part:
//DIGITS PART//
double DigitPoint()
{
double MYpoint=Point;
////////////////////////////////////
if(Digits==5||Digits==3)
{
MYpoint=Point*10;
}
return(MYpoint);
}
But it shows many errors when doing so...
But it shows many errors when doing so...
3*pips2point,Bid+StopLoss*pips2dbl(),Bid-TakeProfit*pips2dbl(),
The error message points to this line. pips2dbl is a variable, why do you have ()'sint init(){ if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // Where exactly do I have to place it? i guess I should replace this part:
Where's the closing brace for the init.- When in doubt, THINK. /*comment*/ out portions until you isolate the problem.
- The error message points to this line. pips2dbl is a variable, why do you have ()'s
- Where's the closing brace for the init.
- When in doubt, THINK. /*comment*/ out portions until you isolate the problem.
Hi,
I finally adjusted the slippage. Thank you very much for your help.
I have just one last question.
Always check return codes so you know WHY:
res=OpenOrder(...); if (res<0) Alert("OpenOrder failed: ", GetLastError());
- What does the alert "Open order failed" signals? Why does it show the alert even when no indicator signals to open a trade?
Hi,
I finally adjusted the slippage. Thank you very much for your help.
I have just one last question.
Always check return codes so you know WHY:
- What does the alert "Open order failed" signals? Why does it show the alert even when no indicator signals to open a trade?
It is strange, that the robot works on Alpari, XTB and FX Pro without any problems, but it does not work on IBFX - every time it should open a trade, it shows the alert "OpenOrder failed: ". Do you have any idea, where the problem is?
why does it show the alert even when no indicator signals to open a trade?
- You have something still wrong with OrderSend()
- You are calling OrderSend() even when "no indicator signal to open a trade."
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello guys,
I am attaching a very good EA which I trade successfully for some time. But there is probably some feature missing in the source code, because when I set it on VPS a few weeks ago, it did not trade at all. It only works if it is the only EA but not work at all, if I set up other EAs at the same time... Is there any mistake in my coding? Could you help me to fix it?
Thank you in advance!
Martin