Topic: What did the EAs do when using ECN Broker?
Hi,
is it possible to use the eas on ecn broker. Isn't it that on ecn broker the tp and Sl will be send later? First open trade than modifiy tp sl?
As i can see on code here
void OpenPosition(int command)
{
for(int attempt=0; attempt<TRADE_RETRY_COUNT; attempt++)
{
int ticket = 0;
int lastError = 0;
bool modified = false;
double stopLoss = GetStopLoss(command);
double takeProfit = GetTakeProfit(command);
string comment = IntegerToString(Magic_Number);
color arrowColor = command==OP_BUY ? clrGreen : clrRed;
if(IsTradeContextFree())
{
double price=MarketInfo(_Symbol,command==OP_BUY ? MODE_ASK : MODE_BID);
if(setProtectionSeparately)
{
ticket=OrderSend(_Symbol,command,Entry_Amount,price,10,0,0,comment,Magic_Number,0,arrowColor);
if(ticket>0 && (Stop_Loss>0 || Take_Profit>0))
{
modified=OrderModify(ticket,0,stopLoss,takeProfit,0,clrBlue);
}
}
else
{
ticket=OrderSend(_Symbol,command,Entry_Amount,price,10,stopLoss,takeProfit,comment,Magic_Number,0,arrowColor);
lastError=GetLastError();
if(ticket<=0 && lastError==130)
{
ticket=OrderSend(_Symbol,command,Entry_Amount,price,10,0,0,comment,Magic_Number,0,arrowColor);
if(ticket>0 && (Stop_Loss>0 || Take_Profit>0))
{
modified=OrderModify(ticket,0,stopLoss,takeProfit,0,clrBlue);
}
if(ticket>0 && modified)
{
setProtectionSeparately=true;
Print("Detected ECN type position protection.");
}
}
}
}
if(ticket>0)
break;
lastError=GetLastError();
if(lastError!=135 && lastError!=136 && lastError!=137 && lastError!=138)
break;
Sleep(TRADE_RETRY_WAIT);
Print("Open Position retry no: "+IntegerToString(attempt+2));
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
Can someone explain me how it works here?
I have tried some different Brokers and an exported ea works on broker a but not on broker b. Cause some brokers have different specifications.
Some brokers use minimum Lot size or maximum Lozsize that can be used. Also some brokers have volume step of 0.10 some can 0.01. So how about it to make it in code. For these i am using this code and works well.
double NormalizeEntrySize(double size) {
double minlot = MarketInfo(_Symbol, MODE_MINLOT);
double maxlot = MarketInfo(_Symbol, MODE_MAXLOT);
double lotstep = MarketInfo(_Symbol, MODE_LOTSTEP);
if (size <= minlot)
return (minlot);
int steps = (int) MathRound((size - minlot) / lotstep);
size = minlot + steps * lotstep;
if (size >= maxlot)
size = maxlot;
if (size >=Maximum_Lots)
size = Maximum_Lots;
size = NormalizeDouble(size, digits);
return (size);
}
So here the entry size will be checked if its compatible with your broker.
The same should be a check of TP and stop loss . Cause some brokers uses a minimum u have to use of pips for tp or sl.
But here i dont find out a code yet. to check if the sl and tp is working for the ea.
What exactly the differences between ecn brokers and normal brokers on working eas?