Trading Future Candles

To add comments, please log in or register
Alpha Beta
81
Alpha Beta  

Hello, 

If I want to open a trade after x amount of bars ( say 10 bars )  , then close it after y amount of bars (say 20 bars ) , is that possible 

How to achieve that while avoid placing trades during Saturdays / Sundays and a void having the trade open though the weekends 

Alpha Beta
81
Alpha Beta  

Something of this type but I am not sure its correct 


void OnTick()
  {
//---
 int xBarOpen  =  10; // 4 bars 
 int yBarClose =  20;
 
 if (TimeCurrent() > xBarOpen && NotweekEnd)
 {
 int ticket=OrderSend(Symbol(),OP_BUY,1,price,3,stoploss,takeprofit,"My order",16384,0,clrGreen);
 }
 
 if (TimeCurrent() > xBarOpen)
 {
      
   for(int i=0;i<OrdersTotal() ;i++)
   { 
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Sym && OrderMagicNumber() == magic )
      { 
        // type=OrderType();
       OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Yellow)++;   
       } 
   } 
   
  }
Alpha Beta
81
Alpha Beta  

Any help  is highly appropriated 

Keith Watford
Moderator
16045
Keith Watford  
Alpha Beta:

Any help  is highly appropriated 

The code that you have posted makes no sense at all.

I think that what you are trying to achieve is far beyond your current level.

You will undoubtedly get some help here when you have problems with coding, but you will not likely find anyone that will code it for you.

 int xBarOpen  =  10; // 4 bars 
 int yBarClose =  20;
 
 if (TimeCurrent() > xBarOpen && NotweekEnd)

xBarOpen should be a datetime not an int

Look up datetime  in the documentation and you will see that TimeCurrent() will always be more than 10.

What is the value of Notweekend?

Alpha Beta
81
Alpha Beta  
Keith Watford:

The code that you have posted makes no sense at all.

I think that what you are trying to achieve is far beyond your current level.

You will undoubtedly get some help here when you have problems with coding, but you will not likely find anyone that will code it for you.

xBarOpen should be a datetime not an int

Look up datetime  in the documentation and you will see that TimeCurrent() will always be more than 10.

What is the value of Notweekend?

Thanks for the tip

Pimpinela
110
Pimpinela  

This is what I use to skip the weekend:

      if(TimeDayOfWeek(TimeLocal())!=6 && TimeDayOfWeek(TimeLocal())!=0) // Enter only if day is not Sat and not Sun.
        {
        }

Then, the "Bars" variable contains the number of bars in the chart. Just record it when you open position and check when it's 20 units larger, then 20 bars have elapsed and you can close your orders.

Keith Watford
Moderator
16045
Keith Watford  
Pimpinela:

Then, the "Bars" variable contains the number of bars in the chart. Just record it when you open position and check when it's 20 units larger, then 20 bars have elapsed and you can close your orders.

Not a good idea to use bars as they can vary, ie if the terminal is restarted.

Check the open time, find the relevant bar and check the shift.

To add comments, please log in or register