Open Limit Order If

Back to topics list To post a new topic, please log in or register
avatar
87
FxTrader_ 2016.03.03 09:28
 
Hi,

I'm using this code to open Limit Order, Is it possible to have it to open Trad only if current bar fully closed?

#property show_inputs
//#property show_confirm

extern double Lots    = 1.0;
extern int Slippage   = 3;
extern int Stop_Loss  = 25;
extern int Take_Profit = 100;


   enum TimeToExp
     {
       M15 = 900,   //15 Minute
       M30 = 1800,  //30 Minute
       H1  = 3600,  //1 Hour
       H2  = 7200,  //2 Hours
       H3  = 10800, //3 Hours
       H4  = 14400, //4 Hours
       D1  = 86400, //1 Day
     };

   input TimeToExp  ExpirTime = H4;

//+------------------------------------------------------------------+
//| script "Open a new Buy Order"                                    |
//+------------------------------------------------------------------+
int start()
  {
   double Price = WindowPriceOnDropped();
   bool   result;
   int    /*cmd,total,error,*/slippage;
   
//----
   int NrOfDigits = MarketInfo(Symbol(),MODE_DIGITS);   // Nr. of decimals used by Symbol
   int PipAdjust;                                       // Pips multiplier for value adjustment
      if(NrOfDigits == 5 || NrOfDigits == 3)            // If decimals = 5 or 3
         PipAdjust = 10;                                // Multiply pips by 10
         else
      if(NrOfDigits == 4 || NrOfDigits == 2)            // If digits = 4 or 3 (normal)
         PipAdjust = 1;            
//----   
   slippage = Slippage * PipAdjust; 
   
   double stop_loss = Price - Stop_Loss * Point * PipAdjust;
   double take_profit = Price + Take_Profit * Point * PipAdjust; 
   
   if(Ask > Price)
   {
   result = OrderSend(Symbol(),OP_BUYLIMIT,Lots,Price,slippage,stop_loss,take_profit,"",0,TimeCurrent()+ExpirTime,CLR_NONE);
   }
   if(Ask < Price)
   {
   result = OrderSend(Symbol(),OP_BUYSTOP,Lots,Price,slippage,stop_loss,take_profit,"",0,TimeCurrent()+ExpirTime,CLR_NONE);
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
avatar
Moderator
3407
GumRai 2016.03.03 10:02 #
 
FxTrader_:
Hi,

I'm using this code to open Limit Order, Is it possible to have it to open Trad only if current bar fully closed?

Not sure what you want, do you mean that you want to wait until the current bar closes before opening the pending order?

You can calculate how much time is left until the candle is due to close. store the Time[0] and then sleep for the period. Check that it is a new bar and send the order.

You cannot check if the current bar is fully closed in one step because as soon as it closes. it becomes the previous bar and the new bar is the current bar.


avatar
87
FxTrader_ 2016.03.03 11:02 #
 

Hi GumRai

THank you for your reply.

YES exactly ( wait until the current bar closes before opening the pending order)

But See the attached photo.
assuming that i add my order at the time of (Bar 4 ) You can see that (Bar 3 and Bar 2 ) are go below my entry level and reverse. (I don't want to open the trad) I want to open trad with the bar that fully closed bellow my level ( In my case here is bar 1).



avatar
872
eevviill 2016.03.03 11:34 #
 
int prev_bars;

int start()
  {
 if(Bars==prevbars) return(0);
 prevbars=Bars;

avatar
87
FxTrader_ 2016.03.03 12:07 #
 

Hi,


I got undeclared identifier for prevbars

#property show_inputs
//#property show_confirm

extern double Lots    = 1.0;
extern int Slippage   = 3;
extern int Stop_Loss  = 25;
extern int Take_Profit = 100;

   enum TimeToExp
     {
     
       M15 = 900,   //15 Minute
       M30 = 1800,  //30 Minute
       H1  = 3600,  //1 Hour
       H2  = 7200,  //2 Hours
       H3  = 10800, //3 Hours
       H4  = 14400, //4 Hours
       D1  = 86400, //1 Day
     };

   input TimeToExp  ExpirTime = H4;

int prev_bars;
//+------------------------------------------------------------------+
//| script "Open a new Buy Order"                                    |
//+------------------------------------------------------------------+
int start()
  {
  
  if(Bars==prev_bars) return(0);
     prev_bars=Bars;
 
   double Price = WindowPriceOnDropped();
   bool   result;
   int    /*cmd,total,error,*/slippage;
   
//----
   int NrOfDigits = MarketInfo(Symbol(),MODE_DIGITS);   // Nr. of decimals used by Symbol
   int PipAdjust;                                       // Pips multiplier for value adjustment
      if(NrOfDigits == 5 || NrOfDigits == 3)            // If decimals = 5 or 3
         PipAdjust = 10;                                // Multiply pips by 10
         else
      if(NrOfDigits == 4 || NrOfDigits == 2)            // If digits = 4 or 3 (normal)
         PipAdjust = 1;            
//----   

   
   slippage = Slippage * PipAdjust; 
   
   double stop_loss = Price - Stop_Loss * Point * PipAdjust;
   double take_profit = Price + Take_Profit * Point * PipAdjust; 
   
   if(Close[1] > Price)
   {
   result = OrderSend(Symbol(),OP_BUYLIMIT,Lots,Price,slippage,stop_loss,take_profit,"",0,TimeCurrent()+ExpirTime,CLR_NONE);
   }
   if(Close[1] < Price)
   {
   result = OrderSend(Symbol(),OP_BUYSTOP,Lots,Price,slippage,stop_loss,take_profit,"",0,TimeCurrent()+ExpirTime,CLR_NONE);
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

And i change it to perb_bars and the script doesn't work at all


avatar
872
eevviill 2016.03.03 12:29 #
 
FxTrader_:

Hi,


I got undeclared identifier for prevbars

And i change it to perb_bars and the script doesn't work at all


I do not know why you have undeclared.

Dou you know difference between script and EA?

Script doing code once. EA each tick.  

avatar
87
FxTrader_ 2016.03.03 12:34 #
 
eevviill:

I do not know why you have undeclared.

Dou you know difference between script and EA?

Script doing code once. EA each tick.  

I follow your instruction and that what i got??
avatar
12985
WHRoeder 2016.03.03 14:05 #
 
FxTrader_:

I got undeclared identifier for prevbars

And i change it to perb_bars and the script doesn't work at all

I follow your instruction and that what i got??

  1. There are no mind readers here; we can't know where your error is.
  2. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  3. When in doubt, think. A script runs once. Therefor your newbar code is irrelevant.
avatar
87
FxTrader_ 2016.03.03 19:39 #
 

Hi,

After I edit the code as it showing above and attached to chart [There is NO Limit order Placed ] and the results for Journal as it show in the photo.

Please help



avatar
12985
WHRoeder 2016.03.03 19:53 #
 
FxTrader_: Please help
  1. Check your return codes (OrderSend) and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  2. Print your if statements (variable values,) and find out why.
avatar
872
eevviill 2016.03.03 20:08 #
 
WHRoeder:
  1. Check your return codes (OrderSend) and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  2. Print your if statements (variable values,) and find out why.

:)))))))

 

He want to use script like an EA.

All he needs is to put his file to EA folder and delete this.

#property show_inputs 

//#property show_confirm 

Back to topics list  

To add comments, please log in or register