EA doesn't open Bustop/Sellstop position for unclear reason

 

Hi all,

 i have a little problem with my EA which is not opening buystop/sellstop positions. The condition is quite simple, i also tried it with several indicator just to see if it opens any sellstop/buystop order but it doesnt. THe EA is in the attachement, and the code for opening the positions is below. I just want to open a sellstop position if the Close price is below the Low price of the 8th previous candle. Very simple condition but it doesnt open positions:

int open() {  

   double Lots;

   Scan ( Candles, PERIOD, shift ); // Here is example how to find the lowest, the highest value and range in the past.
  double CLOSE = iClose(Symbol(),0, 1);
   double HIGH = iHigh(Symbol(),0, shift);
   double LOW = iLow(Symbol(),0, shift);
  
   if ( AutoLots == False ) { Lots = Lot; }
   else { Lots = MathRound ( AccountBalance() / 100 ) / 100; } // First 100 say, that every 100$ will will increase lot by 1 point.
                                                               // Second 100 say, that 1 point is equal to 0.01 lot
   // Here you can place indicators and all stuff              // For ex. if you want to play 0.5 Lot with 1000$ account you can write MathRound ( AccountBalance() / 20 ) / 100;

double tu = iCustom(NULL,0,"super-trend",Nbr_Periods,Multiplier,0,2); // returns EMPTY_VALUE in downtrends
double td = iCustom(NULL,0,"super-trend",Nbr_Periods,Multiplier,1,2); // returns EMPTY_VALUE in uptrends
  double stup = iCustom(NULL,0,"ST_MTEI",0,2); // returns EMPTY_VALUE when no arrow occurs
double stdown = iCustom(NULL,0,"ST_MTEI",1,2);// returns EMPTY_VALUE when no arrow occurs

   RefreshRates();  // RefreshRate() update Bid and Ask value.
  
   if ( ( Ask - Bid ) / Point < MaxSpread ) { // Checking, if spread is less than MaxSpread from inputs. If its Bigger, orders wont open
  
      // Replace 1 == 0 to your conditions to buy order.up!=empty &&down == empty &&
      if (  stup!=empty && tu!=empty &&  stdown ==empty && td==empty &&OrderType()==1 && LastOrder != 1 ) { // LastOrder!= 1 prevent script from making a lot of same buy orders
         Ticket = OrderSend ( Symbol(), OP_BUY, Lots, Ask, Slippage, Ask - ( StopLoss * Point ), Ask + ( TakeProfit * Point ), NULL, Magic, 0, Green);
         LastOrder = 1; // It prevent script from making a lot of same buy orders
      }
  
      // Replace 1 == 0 to your conditions to buystop order.
      if ( CLOSE>HIGH && LastOrder != 1 ) {  // LastOrder!= 1 prevent script from making a lot of same buystop orders
         Ticket = OrderSend ( Symbol(), OP_BUYSTOP, Lots, Ask + ( Pips * Point ), Slippage, Ask + ( Pips * Point ) - ( StopLoss * Point ), Ask - ( Pips * Point ) + ( TakeProfit * Point ), NULL, MagicNumber, TimeCurrent() + ( 60 * Mins ), Green);
         LastOrder = 1; // It prevent script from making a lot of same buy orders
      }
  
      // Replace 1 == 0 to your conditions to sell order.down!=empty && up==empty&&
      if (   stdown!=empty && td!=empty &&   stup==empty && tu==empty &&OrderType()==0 && LastOrder != 0 ) { // LastOrder!= 0 prevent script from making a lot of same sell orders
         Ticket = OrderSend ( Symbol(), OP_SELL, Lots, Bid, Slippage, Bid + ( StopLoss * Point ), Bid - ( TakeProfit * Point ), NULL, Magic, 0, Red);
         LastOrder = 0; // It prevent script from making a lot of same sell orders
      }
  
      // Replace 1 == 0 to your conditions to sellstop order.
      if ( CLOSE<LOW && LastOrder != 0 ) {  // LastOrder!= 0 prevent script from making a lot of same sellstop orders
         Ticket = OrderSend ( Symbol(), OP_SELLSTOP, Lots, Bid - ( Pips * Point ) , Slippage, Bid - ( Pips * Point ) + ( StopLoss * Point ), Bid + ( Pips * Point ) - ( TakeProfit * Point ), NULL, MagicNumber, TimeCurrent() + ( 60 * Mins ), Red);
         LastOrder = 0; // It prevent script from making a lot of same sell orders
      }
      
   }

return ( 0 );
}

Maybe somebody of you sees the problem ?! 

 

Thank you in advance

 

cheers 

Files:
My_Try_EA.mq4  21 kb
 
akuh:

Hi all,

 i have a little problem with my EA which is not opening buystop/sellstop positions. The condition is quite simple, i also tried it with several indicator just to see if it opens any sellstop/buystop order but it doesnt. THe EA is in the attachement, and the code for opening the positions is below. I just want to open a sellstop position if the Close price is below the Low price of the 8th previous candle. Very simple condition but it doesnt open positions:


Hi, Check your lot and maybe this could help you, add this to manage on your Trade Volume

int prec=0;                          
  double lot,                          
         minlot,                        
         maxlot,                        
         maxlotX;                      
  minlot=MarketInfo(Symbol(),MODE_MINLOT);
  maxlot=MarketInfo(Symbol(),MODE_MAXLOT);
  if(minlot==0.01) prec=2;              
  if(minlot==0.1)  prec=1;            

1

 

         Ticket = OrderSend ( Symbol(), OP_BUYSTOP, Lots, Ask + ( Pips * Point ), Slippage, Ask + ( Pips * Point ) - ( StopLoss * Point ), Ask - ( Pips * Point ) + ( TakeProfit * Point ), NULL, MagicNumber, TimeCurrent() + ( 60 * Mins ), Green);
         if(Ticket==-1)
            Print("Error opening BuyStop, Error code ",GetLastError());

The highlighted - should be a +

Print your error when an OrderSend fails. Add as much information as you need to the print, entry price ,  SL, TP, Ask etc.

 
Keith Watford:

         Ticket = OrderSend ( Symbol(), OP_BUYSTOP, Lots, Ask + ( Pips * Point ), Slippage, Ask + ( Pips * Point ) - ( StopLoss * Point ), Ask - ( Pips * Point ) + ( TakeProfit * Point ), NULL, MagicNumber, TimeCurrent() + ( 60 * Mins ), Green);
         if(Ticket==-1)
            Print("Error opening BuyStop, Error code ",GetLastError());

The highlighted - should be a +

Print your error when an OrderSend fails. Add as much information as you need to the print, entry price ,  SL, TP, Ask etc.

Thank you very much for the tip ! I did print the error, but not all of them unfortunately.

 

cheers akuh 

 
akuh:

Thank you very much for the tip ! I did print the error, but not all of them unfortunately.

 

cheers akuh 

Ok i might found the reason. In the begining of the script i have the input int Pips = 500;.

as i opened this topic i had set it to 10, then i doesnt work. If i set it to 500 it sets  sell/buy stop positions but closes it immediately. Also it doesnt seem that the ea doesnt open the stop positions due to the condition.


input double Lot = 0.01;
input bool AutoLots = False; // if its True it will automatically calculate Lot based on Accont Balance. Go down to open() function to see how does it work.
input int TakeProfit = 1000;
input int StopLoss = 250;
input int TrailingStart = 500; // 200 mean tralingstop will start to work above 200 pips
input int TrailingStop = 200; // 150 mean it will move 150 pips above current order price
input int Ba = 1000; // BA at 100 mean, that order stop loss will be moved at open price + spread to make order safe.
input int Slippage = 3;
input int MaxOrders = 2; // How many orders script can open on current symbol
input int Magic = 666; // Magic number
input int Pips = 500; // How far ( in pips ) from actual price sellstop / buystop order will be placed.
input int Mins = 30; // Lifetime of buystop / sellstop order ( in minutes ) after it is deleted if not reached open price.
input int PERIOD = 15; // 15 mean it will work on M15, for exampe PERIOD = 240 mean it will work on H4
input int Candles = 8; // Number of candles scanned in Scan() function, which shows the highes and the lowest order price in the past.
input int shift = 1;// Shift = 1 mean it will start to scan from previous candle.
input int MaxSpread = 50;

To be honest i dont really understand the code from the stop positions 

   // Replace 1 == 0 to your conditions to buystop order.
      if ( CLOSE>HIGH && LastOrder != 1 ) {  // LastOrder!= 1 prevent script from making a lot of same buystop orders
         Ticket = OrderSend ( Symbol(), OP_BUYSTOP, Lots, Ask + ( Pips * Point ), Slippage, Ask + ( Pips * Point ) - ( StopLoss * Point ), Ask - ( Pips * Point ) + ( TakeProfit * Point ), NULL, MagicNumber, TimeCurrent() + ( 60 * Mins ), Green);
         LastOrder = 1; // It prevent script from making a lot of same buy orders
      }

what does (Pips*Point) calculate ?


 

Cheers

 

akuh 

 
akuh:
   // Replace 1 == 0 to your conditions to buystop order.
      if ( CLOSE>HIGH && LastOrder != 1 ) {  // LastOrder!= 1 prevent script from making a lot of same buystop orders
         Ticket = OrderSend ( Symbol(), OP_BUYSTOP, Lots, Ask + ( Pips * Point ), Slippage, Ask + ( Pips * Point ) - ( StopLoss * Point ), Ask - ( Pips * Point ) + ( TakeProfit * Point ), NULL, MagicNumber, TimeCurrent() + ( 60 * Mins ), Green);
         LastOrder = 1; // It prevent script from making a lot of same buy orders
      }

what does (Pips*Point) calculate ?


You are showing code where you have not corrected the error that I have already pointed out and still with no error checking.


what does (Pips*Point) calculate ?


Seriously?? Why put it in the code if you don't know what it calculates?
 

ok now I know what it calculates. Was a bad question I admit it. I found it easily of course. I  also got my buystop sellstop positions work correctly now. Thanks everyone for help.


cheers


akuh

Reason: