Modell on H4? How? Use ask and bid? Combine with lower timeframes as 1M?

 
Can I modell when something happens on H4 with ask and bid, or maybe by comparing price on H4 with price on lower timeframes as M1?
 
Per:
Can I modell when something happens on H4 with ask and bid, or maybe by comparing price on H4 with price on lower timeframes as M1?
If you want a useful answer you need to expand on your question. What do you want to do exactly?
 
dabbler:
If you want a useful answer you need to expand on your question. What do you want to do exactly?

Exactly: Open an order when the price is above the close price on previous bar. I don´t whant to wait until the current bar has closet, because I think that is to late. Can I use 1) ask 2) or close on M1 as trigger on the fourhour-modell to open the order earlier?
 
Per:

Exactly: Open an order when the price is above the close price on previous bar. I don´t whant to wait until the current bar has closet, because I think that is to late. Can I use 1) ask 2) or close on M1 as trigger on the fourhour-modell to open the order earlier?
You can open an order whenever you like . . . if you want the close price of the last M1, M5, M15, etc bar when you are on a H4 chart then yes you can get it . . . simply use iClose() ( <--- click me ! ) with the relevant parameters.
 

Hi,

I have an error in this EA that I can´t find: '\end_of_program' - unbalanced left parenthesis C:\Program Files\FXCM MetaTrader 4\experts\EURUSD T pyramid.mq4 (107, 2).
Have looked over the logic severel times and I´m quite sure that the code is according to my plan. The strategy is simple: Use DNC-linje for open and to determine limit and stop, if loss increase the volym.

- The first method "CalculateCurrentOrders" just calculate the orders.

- "Start" check if the last order was a profit, and don´t open a new order the same day if there already is a profit that day.

- "CheckForOpen" method look how many losses have been done and calculate the new volume. The limit and stop i also calculated here.

The error is on row 107, it´s after the last row in the code. Can you se what is wrong?

#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#define MAGICMA  20050610

#define TRIGGER 0.0001

int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;
//----
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }
//---- return orders volume
   if(buys>0) return(buys);
   else       return(-sells);
  }
  
//+------------------------------------------------------------------+
void start()
  {
  
//---- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false) return;


   if(CalculateCurrentOrders(Symbol())==0){
      
      if ((TimeHour(TimeCurrent())>6)&&(TimeHour(TimeCurrent())<21)){
         
         if((DayOfYear(TimeCurrent())>(DayOfYear(OrderCloseTime())){
            OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
            if(OrderProfit()>0)
               CheckForOpen();
      
         }
         if((DayOfYear(TimeCurrent())==(DayOfYear(OrderCloseTime())){
            OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
            if(OrderProfit()<0)
               CheckForOpen();
      
         }
      }
   }
}
  
  
void CheckForOpen()
  {
   
   double h,l,limit1,limit2,stop1,stop2,profitminus=0;
   int r;
   double volym=1;
         
   h=High[iHighest(NULL,0,MODE_HIGH,61,1)];
   l=Low[iLowest(NULL,0,MODE_LOW,61,1)];
   
   OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
   if((OrderProfit()<0)&&(DayOfYear()==TimeDayOfYear(TimeCurrent()))){
   profitminus=profitminus+1;
   } 
   
   OrderSelect(OrdersHistoryTotal()-2,SELECT_BY_POS,MODE_HISTORY);
   if((OrderProfit()<0)&&(DayOfYear()==TimeDayOfYear(TimeCurrent()))){
   profitminus=profitminus+1;
   }
   
   OrderSelect(OrdersHistoryTotal()-3,SELECT_BY_POS,MODE_HISTORY);
   if((OrderProfit()<0)&&(DayOfYear()==TimeDayOfYear(TimeCurrent()))){
   profitminus=profitminus+1;
   }    
   
   OrderSelect(OrdersHistoryTotal()-4,SELECT_BY_POS,MODE_HISTORY);
   if((OrderProfit()<0)&&(DayOfYear()==TimeDayOfYear(TimeCurrent()))){
   profitminus=profitminus+1;
   }    
   
   if(profitminus==1) 
   volym=2;
   if(profitminus==2) 
   volym=4;
   if(profitminus==3) 
   volym=8;
   if(profitminus==4) 
   volym=16;
   
   limit1=h+(h-l);
   limit2=l-(h-l);
   if((Ask-TRIGGER)>h)             
     { 
     r=OrderSend(Symbol(),OP_BUY,volym,Ask,3,l,limit1,"",MAGICMA,0,Blue);     
      return;
     }
   
   if((Ask+TRIGGER)<l)
     {
      r=OrderSend(Symbol(),OP_SELL,volym,Bid,3,h,limit2,"",MAGICMA,0,Red);  
      return;
     }
  }

 

You have more problems than your brace counts . . . DayOfYear() for example . . maybe you mean TimeDayOfYear() ?

try this, it fixes the braces issue only . . .

void start()
  {
  
//---- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false) return;


   if(CalculateCurrentOrders(Symbol())==0){
      
      if ( TimeHour(TimeCurrent()) > 6 && TimeHour(TimeCurrent()) < 21){
         
         if( DayOfYear(TimeCurrent()) > DayOfYear(OrderCloseTime()) ){
            OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
            if(OrderProfit()>0)
               CheckForOpen();
      
         }
         if( DayOfYear(TimeCurrent()) == DayOfYear(OrderCloseTime()) ){
            OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
            if(OrderProfit()<0)
               CheckForOpen();
      
         }
      }
   }
}
 

Ofcourse it shall be Time... hard to se everything sometimes, thanks.

I have minimized the code a bit:

- "CalculateCurrentOrders" is the same as before. Taken from the EA example in MT4.

- "Start" does this (or is supose to do):

* Only open a new trades if no other orders are open (2nd if statement).

* Only open trades between 6 and 21 (3rd if statement).

* Open trade if at least 1 day has past since last profitable trade (4rd and 5th if statement).

* If opening new trade the same day, last trade have to be a loss (6th and 7th)

* To be able to start the first time, open trade if there are no trades in the history (last if statement in the start method).

- "CheckForOpen"

* h and l are the values for the maximun and minimum line.

* Since last time I have done a for-loop to calculate the volume. If there is a loss the same day the volume will be multiplied with 2. The "break" is because only losses in one sequence are counted.

* The rest is just to feel the the entryprice and send the trades.

I STILL HAVE THE SAME ERROR IN THE LAST LINE (SE ATTACHED PICTURE). Are you able to se it?

#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#define MAGICMA  20050610

#define TRIGGER 0.0001

int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;
//----
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }
//---- return orders volume
   if(buys>0) return(buys);
   else       return(-sells);
  }
  
//+------------------------------------------------------------------+
void start()
  {
  
//---- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false) return;


   if(CalculateCurrentOrders(Symbol())==0){
      
      if ((TimeHour(TimeCurrent())>6)&&(TimeHour(TimeCurrent())<21)){
         
         OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
         if((TimeDayOfYear(TimeCurrent()))>(TimeDayOfYear(OrderCloseTime())){
            if(OrderProfit()>0){ CheckForOpen(); }
      
         }
         
         OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
         if((TimeDayOfYear(TimeCurrent()))==(TimeDayOfYear(OrderCloseTime())){
            if(OrderProfit()<0) { CheckForOpen(); }
      
         }
         
         if(OrdersHistoryTotal()==0) { CheckForOpen(); }
                 
      }  
   }
}
  
void CheckForOpen()
  {
   
   double h,l,limit1,limit2,stop1,stop2;
   int r;
   double volym=1;
         
   h=High[iHighest(NULL,0,MODE_HIGH,61,1)];
   l=Low[iLowest(NULL,0,MODE_LOW,61,1)];
   
   for(int i=1;i<5;i++){
      OrderSelect(OrdersHistoryTotal()-i,SELECT_BY_POS,MODE_HISTORY);
      if(OrderProfit()>0) break;
      if((OrderProfit()<0)&&((TimeDayOfYear(OrderCloseTime()))==(TimeDayOfYear(TimeCurrent())))){
      volym=volym*2;
      }
   }    
   limit1=h+(h-l);
   limit2=l-(h-l);
   if((Ask-TRIGGER)>h)             
     { 
     r=OrderSend(Symbol(),OP_BUY,volym,Ask,3,l,limit1,"",MAGICMA,0,Blue);     
      return;
     }
   
   if((Ask+TRIGGER)<l)
     {
      r=OrderSend(Symbol(),OP_SELL,volym,Bid,3,h,limit2,"",MAGICMA,0,Red);  
      return;
     }
  }
 
Per:

I STILL HAVE THE SAME ERROR IN THE LAST LINE (SE ATTACHED PICTURE). Are you able to see it?

Nope . . .

Learn to count braces . . . . count the left ones, count the right ones . . . they have to match

         OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
         if( (TimeDayOfYear(TimeCurrent())) > (TimeDayOfYear(OrderCloseTime())  )   ){
            if(OrderProfit()>0){ CheckForOpen(); }
      
         }
         
         OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
         if( (TimeDayOfYear(TimeCurrent()))==(TimeDayOfYear(OrderCloseTime())   )  ){
            if(OrderProfit()<0) { CheckForOpen(); }

if you get rid of the braces you DON'T need it will be even easier . . . for example

         OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
         
         if( TimeDayOfYear(TimeCurrent()) > TimeDayOfYear(OrderCloseTime()) )
            if(OrderProfit() > 0) CheckForOpen(); 
      
         
         OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
         
         if( TimeDayOfYear(TimeCurrent()) == TimeDayOfYear(OrderCloseTime()) )
            if(OrderProfit() < 0) CheckForOpen(); 
         
         if(OrdersHistoryTotal() == 0) CheckForOpen(); 
 
RaptorUK:

Nope . . .

Learn to count braces . . . . count the left ones, count the right ones . . . they have to match

if you get rid of the braces you DON'T need it will be even easier . . . for example


Hi, have deleted some of the braces you are refering to. Have counted them and I´m sure they are in balance. But still the same error after compiling. At one moment I had the idea that maybe the increase in volume is to agressiv, but it is not that. Now I´m out of ideas. Still the same error.

 
Per:


Hi, have deleted some of the braces you are refering to. Have counted them and I´m sure they are in balance. But still the same error after compiling. At one moment I had the idea that maybe the increase in volume is to agressiv, but it is not that. Now I´m out of ideas. Still the same error.

I gave you the code correction in my post above . . . do you see the yellow highlighted ) ? you needed to add them.
Reason: