why show this results .!!!! (ECN broker)

 

hi 

i try study mql4

but i have problem with ECN Broker :(

 use JFD Brokers MetaTrader 4 and forex.com

but i have different result .!

StopLoss=3

TakeProfit=3

Lot=0.10

slipage=1

method Buy

int Buy(){
RefreshRates();
   
   if(StopLoss==0) double bsl=0;
   else bsl=Ask-(StopLoss*Point);
  
   if(TakeProfit==0) double btp=0;
   else btp=Ask+(TakeProfit*Point);
  
   if(MyRealOrdersTotal(Symbol())==0){
   int buyticket= OrderSend(Symbol(), OP_BUY, Lots, Ask, slipage, 0, 0,NULL , 1234556,0,Green);
     if(buyticket>0)OrderModify(buyticket,OrderOpenPrice(), bsl, btp,0,CLR_NONE);    } 
     

}

 

 method sell 

 

int Sell(){
RefreshRates();
   
   if(StopLoss==0)double ssl=0;
   else ssl=Bid+(StopLoss*Point);
   
   if(TakeProfit==0) double stp=0;
   else stp=Bid-(TakeProfit*Point);
   if(MyRealOrdersTotal(Symbol())==0){
   int sellticket=OrderSend(Symbol(), OP_SELL, Lots, Bid, slipage, 0, 0,NULL , 1234556,0,Red);
   if(sellticket>0)OrderModify(sellticket,OrderOpenPrice(), ssl, stp,0,CLR_NONE); }

}

 method MyRealOrdersTotal

 

int MyRealOrdersTotal(int Magic)
{
  int c=0;
  int total  = OrdersTotal();

  for (int cnt = 0 ; cnt < total ; cnt++)
  {
    OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol() && (OrderType()==OP_BUY || OrderType()==OP_SELL))
    {
      c++;
    }
  }
  return(c);
}

 

 result JFD Broker different

profit

-30.30

29.20

29.20

29.20

-30.80

-30.80

29.20

-30.80

-30.91

28.88

29.09

-31.12

-31.13

......... why this .?

please how fixed this problem  .?

 
forexplus:

hi 

i try study mql4


......... why this .?

please how fixed this problem  .?

 

int Buy(){
RefreshRates();
   
   if(StopLoss==0) double bsl=0;
   else bsl=Ask-(StopLoss*Point);
  
   if(TakeProfit==0) double btp=0;
   else btp=Ask+(TakeProfit*Point);
  
   if(MyRealOrdersTotal(Symbol())==0){
   int buyticket= OrderSend(Symbol(), OP_BUY, Lots, Ask, slipage, 0, 0,NULL , 1234556,0,Green);
     if(buyticket>0)OrderModify(buyticket,OrderOpenPrice(), bsl, btp,0,CLR_NONE);    } 
     

}

                          WRONG  

if(buyticket>0)
  {
   if(StopLoss>0)bsl=OrderOpenPrice()-(StopLoss*Point);
   if(TakeProfit>0)btp=OrderOpenPrice()+(TakeProfit*Point);
   if(OrderStopLoss()!=bsl||OrderTakeProfit()!=btp)OrderModify(buyticket,OrderOpenPrice(), bsl, btp,0,CLR_NONE);    
  }
 
  1. Don't use such bright back ground it is unreadable. Use the lightest background only or not at all.
  2.  if(StopLoss>0)bsl=OrderOpenPrice()-(StopLoss*Point);
    You aren't adjusting for 4 vs 5 digit brokers.
  3. You aren't adjusting for the spread. OrderOpePrice() after OrderSelect
 

thank you 

 i do that in method buy

 

int Buy(){
RefreshRates();
   
   if(StopLoss==0) double bsl=0;
   else bsl=Ask-(StopLoss*Point);
  
   if(TakeProfit==0) double btp=0;
   else btp=Ask+(TakeProfit*Point);
  
   if(MyRealOrdersTotal(Symbol())==0){
   int buyticket= OrderSend(Symbol(), OP_BUY, Lots, Ask, slipage, 0, 0,NULL , 1234556,0,Green);
     if(buyticket>0){
     if(StopLoss>0)bsl=OrderOpenPrice()-(StopLoss*Point);
     if(TakeProfit>0)btp=OrderOpenPrice()+(TakeProfit*Point);
     if(OrderStopLoss()!=bsl||OrderTakeProfit()!=btp)OrderModify(buyticket,OrderOpenPrice(), bsl, btp,0,CLR_NONE);
     }
     
     
         } 
}

 after and run backtest it's set StopLoss and TakeProfit just on time .!

second open order just open and do not set any StopLoss and TakeProfit

 and i edit method sell

 

int Sell(){
RefreshRates();
   
   if(StopLoss==0)double ssl=0;
   else ssl=Bid+(StopLoss*Point);
   
   if(TakeProfit==0) double stp=0;
   else stp=Bid-(TakeProfit*Point);
   
   if(MyRealOrdersTotal(Symbol())==0){
   int sellticket=OrderSend(Symbol(), OP_SELL, Lots, Bid, slipage, 0, 0,NULL , 1234556,0,Red);
   if(sellticket>0){
       if(StopLoss>0)ssl=OrderOpenPrice()-(StopLoss*Point);
     if(TakeProfit>0)stp=OrderOpenPrice()+(TakeProfit*Point);
     if(OrderStopLoss()!=ssl||OrderTakeProfit()!=stp)OrderModify(sellticket,OrderOpenPrice(), ssl, stp,0,CLR_NONE);
   }
    }

}

 it's just open order no stop and no profit 

please yo can edit method buy and sell and work with ECN broker :(

 

thank you 

 

I think the problem is you need to call OrderSelect before you call OrderOpenPrice.... because there are many orders, how does it know WHICH open price?

You need to do something like this:

int Sell(){
RefreshRates();
   
   if(StopLoss==0)double ssl=0;
   else ssl=Bid+(StopLoss*Point);
   
   if(TakeProfit==0) double stp=0;
   else stp=Bid-(TakeProfit*Point);
   
   if(MyRealOrdersTotal(Symbol())==0){
   int sellticket=OrderSend(Symbol(), OP_SELL, Lots, Bid, slipage, 0, 0,NULL , 1234556,0,Red);
   OrderSelect(buyticket,SELECT_BY_TICKET);
   if(sellticket>0){
       if(StopLoss>0)ssl=OrderOpenPrice()-(StopLoss*Point);
     if(TakeProfit>0)stp=OrderOpenPrice()+(TakeProfit*Point);
     if(OrderStopLoss()!=ssl||OrderTakeProfit()!=stp)OrderModify(sellticket,OrderOpenPrice(), ssl, stp,0,CLR_NONE);
   }
    }

}


Next time you have a problem like this, use your own ways to find the problem:

 

1) click the function and press F1 to see help. On the OrderOpenPrice page you see: "Order must be first selected by the OrderSelect() function." This means you will find the problem without asking on the forum.

2) on the OrderModify page, you can see it is a bool and "If the function succeeds, the returned value will be TRUE. If the function fails, the returned value will be FALSE". This means you can check for errors by using code like this:

 

if(!OrderModify(Ticket,OpenOrderPrice(),ssl,stp,0,CLR_NONE))
   {
   error = GetLastError();
   Alert("OrderModify failed:",error," !!  Did not set stops!!!!!");
   }
else Alert("modified order with no problems");
 

 OrderSelect  in method MyRealOrdersTotal

 

int MyRealOrdersTotal(int Magic)
{
  int c=0;
  int total  = OrdersTotal();

  for (int cnt = 0 ; cnt < total ; cnt++)
  {
    OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol() && (OrderType()==OP_BUY || OrderType()==OP_SELL))
    {
      c++;
    }
  }
  return(c);
}

 broker ecn it's very hard .!

i'am new learn Mql4

thank you  

 

forex plus, I editted my post, please see the new info. Try to use mql to find where the problem is happening.

You need to call OrderSelect BEFORE you use OrderOpenPrice

Also, I'm pretty sure the problem is NOT that it's an ECN broker. 

 

thak you 

 set this method

 

int Sell(){
RefreshRates();
   
   if(StopLoss==0)double ssl=0;
   else ssl=Bid+(StopLoss*Point);
   
   if(TakeProfit==0) double stp=0;
   else stp=Bid-(TakeProfit*Point);
   
   if(MyRealOrdersTotal(Symbol())==0){
   int sellticket=OrderSend(Symbol(), OP_SELL, Lots, Bid, slipage, 0, 0,NULL , 1234556,0,Red);
   OrderSelect(sellticket,SELECT_BY_TICKET);
   if(sellticket>0){
       if(StopLoss>0)ssl=OrderOpenPrice()-(StopLoss*Point);
     if(TakeProfit>0)stp=OrderOpenPrice()+(TakeProfit*Point);
     if(OrderStopLoss()!=ssl||OrderTakeProfit()!=stp)OrderModify(sellticket,OrderOpenPrice(), ssl, stp,0,CLR_NONE);
   }
    }

}

  but no't work .!

just open order but no stop and no profit

please try code in JFD Brokers

https://www.jfdbrokers.com/

please i want method buy and sell work with any ECN Broker 100%

 
Did you read the second half of my post? You will find the answer with your own error checking.
 

ok , thank you 

 

hi 

it's work now but have like problem

+2.20

-3.80 

just 2.20 or -3.80 all  result  

now i want all result  2.20 

-2.20

or

-3.80

+3.80

int Buy(){
RefreshRates();
   
   if(StopLoss==0) double bsl=0;
  // else bsl=Ask-(StopLoss*Point);
  
   if(TakeProfit==0) double btp=0;
  // else btp=Ask+(TakeProfit*Point);
    int buyticket= OrderSend(Symbol(), OP_BUY, Lots, Ask, slipage, 0, 0,NULL , 1234556,0,Green);
    OrderSelect(buyticket,SELECT_BY_TICKET);
   if(buyticket>0)
  {
   if(StopLoss>0)bsl=OrderOpenPrice()-(StopLoss*Point);
   if(TakeProfit>0)btp=OrderOpenPrice()+(TakeProfit*Point);
   if(OrderStopLoss()!=bsl||OrderTakeProfit()!=btp)OrderModify(buyticket,OrderOpenPrice(), bsl, btp,0,CLR_NONE);   
    
  }
     

}

int Sell(){
RefreshRates();
   
   if(StopLoss==0)double ssl=0;
  // else ssl=Bid+(StopLoss*Point);
   
   if(TakeProfit==0) double stp=0;
   //else stp=Bid-(TakeProfit*Point);
   int sellticket=OrderSend(Symbol(), OP_SELL, Lots, Bid, slipage, 0, 0,NULL , 1234556,0,Red);
   OrderSelect(sellticket,SELECT_BY_TICKET);
   if(sellticket>0)
  {
   if(StopLoss>0)ssl=OrderOpenPrice()+(StopLoss*Point);
   if(TakeProfit>0)stp=OrderOpenPrice()-(TakeProfit*Point);
   if(OrderStopLoss()!=ssl||OrderTakeProfit()!=stp)OrderModify(sellticket,OrderOpenPrice(), ssl, stp,0,CLR_NONE);    
  }
  

}
Reason: