Takeprofit and Stoploss is 0 - why ?

 

Hello,

I have downloaded a Timebased EA, its working like a charm with Strategy test, But when i start it with a practice account i get 0 takeprofit and stopless instead of what i have applied,

Im using OandA MT4 ...

Here is the code :

//+------------------------------------------------------------------+
//|                                                  time trader.mq4 |
//|                            Copyright © 2011, www.FxAutomated.com |
//|                                       http://www.FxAutomated.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, www.FxAutomated.com"
#property link      "http://www.FxAutomated.com"
//---- input parameters
extern string    time_trader_v1.1="visit www.FxAutomated.com for more!!!";
extern double    Lots=0.1;
extern int       TakeProfit=50;
extern int       StopLoss=25;
extern int       Slip=5;
extern int BuyMagicNumber =10001;
extern int SellMagicNumber =10002;
extern string TradeSettings="Mt4 time(min-max): hours 0-23, minutes 0-59, seconds 0-59";
extern bool AllowBuy=false;
extern bool AllowSell=true;
extern int  TradeHour=10;
extern int  TradeMinutes=00;
extern int  TradeSeconds=00;
extern string OurSite="www.FxAutomated.com";
extern string SignalsAndManagedAccounts="www.TradingBug.com";

//+------------------------------------------------------------------+
//| expert starts                                  |
//+------------------------------------------------------------------+
int start()
  {
//----
int StopMultd,Sleeper=1;



int digits=MarketInfo("EURUSD",MODE_DIGITS);
if(digits==5){StopMultd=10;} else{StopMultd=1;}
double TP=NormalizeDouble(TakeProfit*StopMultd,Digits);
double SL=NormalizeDouble(StopLoss*StopMultd,Digits);
int Slippage=Slip*StopMultd;

// Calculate stop loss
double slb=NormalizeDouble(Ask-SL*Point,Digits);
double sls=NormalizeDouble(Bid+SL*Point,Digits);

// Calculate take profit
double tpb=NormalizeDouble(Ask+TP*Point,Digits);
double tps=NormalizeDouble(Bid-TP*Point,Digits);

//-------------------------------------------------------------------+
//Check open orders
//-------------------------------------------------------------------+
if(OrdersTotal()>0){
  for(int i=1; i<=OrdersTotal(); i++)          // Cycle searching in orders
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
        {
          if(OrderMagicNumber()==BuyMagicNumber) {int halt1=1;}
          if(OrderMagicNumber()==SellMagicNumber) {int halt2=1;}
        }
     }
}
//-------------------------------------------------------------------+


if((halt1!=1)&&(AllowBuy==true)){// halt1

// Buy criteria
if ((TradeHour==Hour())&&(TradeMinutes==Minute())&&(TradeSeconds>=Seconds())) //Signal Buy
 {
   int openbuy=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,slb,tpb,"time trader buy order ",BuyMagicNumber,0,Blue);
   if(openbuy<1){int buyfail=1;}
 }
 
}// halt1
 
if((halt2!=1)&&(AllowSell==true)){// halt2
RefreshRates();
 // Sell criteria
 if ((TradeHour==Hour())&&(TradeMinutes==Minute())&&(TradeSeconds>=Seconds())) //Signal Sell
 {
   int opensell=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,sls,tps,"time trader sell order ",SellMagicNumber,0,Green);
   if(opensell<1){int sellfail=1;}
 }
 
}// halt2


//-------------------------------------------------------------------+
// Error processing
//-------------------------------------------------------------------+
if(buyfail==1||sellfail==1){
int Error=GetLastError();
  if(Error==130){Alert("Wrong stops. Retrying."); RefreshRates();}
  if(Error==133){Alert("Trading prohibited.");}
  if(Error==2){Alert("Common error.");}
  if(Error==146){Alert("Trading subsystem is busy. Retrying."); Sleep(500); RefreshRates();}

}

// if(openbuy==true||opensell==true)Sleep(1*60*1000*Sleeper);
//-------------------------------------------------------------------
   return(0);
  }
//+-----------------------------------

Could some help me please ?

Thanks

 

Oanda is an ECN Broker, you need to set TP and SL at 0.0 when you do an OrderSend and then do an OrderModify to place the correct SL & TP afterwards . . . . please read some other posts first, you would have seen at least 2 posts about this in the last couple of days.

ECN/130

 
int digits=MarketInfo("EURUSD",MODE_DIGITS);
Also this line has to be changed in this EA if your broker use prefix and/or suffix on currencysymbols
 
Or instead of digits use the predefine variable Digits
 

This is what i got so far, But still not working,, its shows me : unknown ticket 28281879 for OrderModify function

and its the correct ID for my open position ..

if((halt1!=1)&&(AllowBuy==true)){// halt1

// Buy criteria
if ((TradeHour==Hour())&&(TradeMinutes==Minute())&&(TradeSeconds>=Seconds())) //Signal Buy
 {
   int openbuy=OrderSend(Symbol(),OP_BUY,Lots,Ask,0,0,0,"time trader buy order ",0,0,Blue);

   OrderModify(OrderTicket(),OrderOpenPrice(),StopLoss,TakeProfit,0,Blue);
   if(openbuy<1){int buyfail=1;}
 }
 
}// halt1

I would appricate alittle help ...

Thanks

 

Read the Documentation . . . . OrderSend() "Returns number of the ticket assigned to the order by the trade server or -1 if it fails. " so check if openbuy is > 0 if it is use it as the ticket number for your OrderModify . . . if not report the error by printing it to the journal/experts log.

Alternatively if openbuy is > 0 use it in an OrderSelect()

 
Leopardos:

This is what i got so far, But still not working,, its shows me : unknown ticket 28281879 for OrderModify function

and its the correct ID for my open position ..

I would appricate alittle help ...

Thanks


// Buy criteria
if ((TradeHour==Hour())&&(TradeMinutes==Minute())&&(TradeSeconds>=Seconds())) //Signal Buy

   {int openbuy=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"time trader buy order ",0,0,Blue);}   //<== Don't remove Slippage
                                                                                                    //only slb  tpb is enough
if(openbuy>0)
            {
             if(OrderSelect(openbuy,SELECT_BY_TICKET,MODE_TRADES))
                {
                 OrderModify(openbuy,OrderOpenPrice(),slb,tpb,0,Blue);
                }
             else Print("Error opening new order : ",GetLastError());
             if(openbuy<1){int buyfail=1;}
            } 


not checked

 

You need to change into...

int digits=MarketInfo(Symbol(),MODE_DIGITS);

Than add this line...

if(digits<4)double Pnt=0.01; else Pnt=0.0001;

Than everywhere where there is StopMultd or Point replace with Pnt. Than everywhere where OrderSend(.... there are slb,tpb, or sls,tps, replace with 0,0,.

Than add this after line where is if(openbuy<1){int buyfail=1;}

else { //OrderSelect(... but I am not sure, maybe it is still selected
 OrderModify(openbuy,OrderOpenPrice(),slb,tpb,0); }

Repeat similar where the if(opensell<1){int sellfail=1;} is...

 
deVries: 2012.03.15 19:49

Sorry, haven't seen,... similar timings. ;)
 

Thank you very much..

I will try it when i arrive home, i hope it will work..

 
Leopardos:

Hello,

I have downloaded a Timebased EA, its working like a charm with Strategy test, But when i start it with a practice account i get 0 takeprofit and stopless instead of what i have applied,

Im using OandA MT4 ...

Here is the code :

Could some help me please ?

Thanks


I have a thread going on this myself and was just about to update it. It appears that the very first order you enter it wont let you read the values. Oddly enough you can still modify them however. I added an "if Position(STOP_LOSS)==0, to my trailing sl checks and it fixed it as far as that goes. Very strange it wont let you read it however. I spent hours trying to torubleshoot this issue. I am wondering if it is just on the test server or the live/demo environment will do it as well. Better make a mental note just in case it starts acting wonky at least you will know where to tool around. Here is my thread https://www.mql5.com/en/forum/380454

Stop Loss Not Showing Up After Order Entry
Stop Loss Not Showing Up After Order Entry
  • 2021.10.26
  • www.mql5.com
Hi Everyone, This is my first post, except for some code I posted to help someone determine if the market is open...
Reason: