ONLY CANDLE / BAR - How to catalog or segregate Candle? - PLEASE CORRECT ME! - page 5

 
Wodzuuu:

Question 1. Do I have use MyPips in candle, in these function? bool BULL4()  

Yes. However, is the if statement correct in the BULL4() function? I mean, are you looking for that candle you are calculating?

Wodzuuu:

AND I WROTE PROGRAM for me is good :) how about You?  

It is yours, so it has to be good for you, not form me.

 

Some comments: 

bool CheckForCloseBULL4()
{
   int i;
   for(i=OrdersTotal()-1;i>=0;i--)
      if( ! OrderSelect(i, SELECT_BY_POS, MODE_TRADES) ) continue;
         if( OrderMagicNumber() == MAGICMA1 && OrderSymbol() == Symbol()  && OrderType() == OP_BUY )
            if(OrderOpenPrice()+8*MyPips < Ask) return(true);
            
   else return(false);   // <-- the else here is wrong. Use {} if you are unsure what is processed where
}


int OpenOrders_BULL4(string symbol)
  {
   int buys=0;

   for(int i=0;i<OrdersTotal();i++)   // <-- do it like you do it in the other loops!
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;  // <-- break? Why not using always the same code for the same thing? 
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA1) //     Look at the for loop you used in CheckForCloseBULL4().       
        {
         if(OrderType()==OP_BUY) buys++; // <-- why this additional if? Simplify it to: 
        }                                //     if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA1 && OrderType()==OP_BUY) buys++;  
     }
   return(buys);
  }
 

I correct last errors

 

bool CheckForCloseBULL41()
{
   int i;
   for(i=OrdersTotal()-1;i>=0;i--)
      if( ! OrderSelect(i, SELECT_BY_POS, MODE_TRADES) ) continue;
         if( OrderMagicNumber() == MAGICMA1 && OrderSymbol() == Symbol()  && OrderType() == OP_BUY )
            if(OrderOpenPrice()+8*MyPips < Ask) return(true);
            else return(false);                                                                              // <-- the else is correct now
}

int OpenOrders_BULL4(string symbol)
  {
   int buys=0;
   int i;
   for(i=OrdersTotal()-1;i>=0;i--)                                                                     // Loop is correct and use the same code
     {
      if( ! OrderSelect(i, SELECT_BY_POS, MODE_TRADES) ) continue;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA1 && OrderType()==OP_BUY)buys++;
     }
   return(buys);
  }

I add second buy

condition to open :

bool BULL42send()
   {
   int i;
   for(i=OrdersTotal()-1;i>=0;i--)
      if( ! OrderSelect(i, SELECT_BY_POS, MODE_TRADES) ) continue;
         if( OrderMagicNumber() == MAGICMA1 && OrderSymbol() == Symbol()  && OrderType() == OP_BUY )
            if(OrderOpenPrice()+8*MyPips < Ask) return(true);
      else return(false);
   }

Open and CheckForClose and Close the same code like for BULL41 (pips difrent only)

Start function look like that:

void start()
  {
   if(BULL4() && BULL41send() && OpenOrders_BULL4(Symbol())==0)             
     {
       OpenBULL41();//do open buy position
     }
   if(BULL42send() && OpenOrders_BULL4(Symbol())==1)             
     {
       OpenBULL42();//do open buy position
     }     
     

   if(CheckForCloseBULL41()==true && OpenOrders_BULL4(Symbol())==1) CloseBULL4();
   if(CheckForCloseBULL42()==true && OpenOrders_BULL4(Symbol())==2) CloseBULL4();      
  }
//+------------------------------------------------------------------+

And now I need flag, resetsignals and change start function

My  imagination say:

  New Bar: 

bool New_Bar = false;

bool Fun_New_Bar()
   {
   static datetime New_Time=0;
   New_Bar=false;   
   if(New_Time!=Time[0])
      {
         New_Time=Time[0];
         New_Bar=true;
      }
   }

 

 and start is look like that 

void start()
  {
   bool SignalBULL41Executed=false;
   bool SignalBULL42Executed=false;
   
   if(Fun_New_Bar()==true)
      {
      SignalBULL41Executed=false;
      SignalBULL42Executed=false;
      }   
   
   if(BULL4() && BULL41send() && !SignalBULL41Executed && OpenOrders_BULL4(Symbol())==0)             
     {
       OpenBULL41();//do open buy position
       SignalBULL41Executed=true;
     }
   if(BULL42send() &&  !SignalBULL42Executed && OpenOrders_BULL4(Symbol())==1)             
     {
       OpenBULL42();//do open buy position
       SignalBULL42Executed=true;
     }     
     

   if(CheckForCloseBULL41()==true && OpenOrders_BULL4(Symbol())==1) CloseBULL4();
   if(CheckForCloseBULL42()==true && OpenOrders_BULL4(Symbol())==2) CloseBULL4();      
  }

  Code is working but maybe I have some errors

 
 

I miss ResetSignals() so it not work good

 
Wodzuuu:

I correct last errors
...
...
...

Code is working but maybe I have some errors


I did not say, the else is wrong in the CheckForCloseBULL41() function, because it was not nice formated. You didn't change anything. If more than one of the open orders matching to the below, you'll have problems as the loop does not run through all orders.

if( OrderMagicNumber() == MAGICMA1 && OrderSymbol() == Symbol()  && OrderType() == OP_BUY )

You don't need the signal flags as long as you only open new orders on a specific numbers of already open orders. This also prevents the code from opening more orders.

if(BULL4() && BULL41send() && !SignalBULL41Executed && OpenOrders_BULL4(Symbol())==0)

 

Your Fun_New_Bar() function is not correct. 

 

1. else problem

if this is not correct I will searching again.

 

bool CheckForCloseBULL41()
{
   int i;
   for(i=OrdersTotal()-1;i>=0;i--)
   {
      if( ! OrderSelect(i, SELECT_BY_POS, MODE_TRADES) ) continue;
        {
         if( OrderMagicNumber() == MAGICMA1 && OrderSymbol() == Symbol() && OrderType() == OP_BUY )
            {
            if(OrderOpenPrice()+8*MyPips < Ask)
               {
                  return(true);
               }
            }
         }
    }    
   return(false); 
}

 2. New Bar problem

bool Fun_New_Bar()                
   {                                
   static datetime New_Time=0;      
                     
   if(New_Time!=Time[0])           
      {
      New_Time=Time[0];                
      return(true);            
      }

   return(false);
   }

3. reset signal problem 

void start()
  {
   bool SignalBULL41Executed;
   bool SignalBULL42Executed;
   
   if(Fun_New_Bar()==true)
      {
      SignalBULL41Executed=false;
      SignalBULL42Executed=false;
      }   
   
   if(BULL4() && BULL41send() && !SignalBULL41Executed && OpenOrders_BULL4(Symbol())==0)             
     {
       OpenBULL41();//do open buy position
       SignalBULL41Executed=true;
     }
   if(BULL42send() &&  !SignalBULL42Executed && OpenOrders_BULL4(Symbol())==1)             
     {
       OpenBULL42();//do open buy position
       SignalBULL42Executed=true;
     }     
     

   if(CheckForCloseBULL41()==true && OpenOrders_BULL4(Symbol())==1) CloseBULL4();
   if(CheckForCloseBULL42()==true && OpenOrders_BULL4(Symbol())==2) CloseBULL4();      
  }

 

if I wrote bad points 2 and 3, I'll have no ideas to fix them, I'll ask for biggest directions If I could.

 

1. else problem
Fixed

2. New Bar problem
Fixed

3. reset signal problem  

void start()
  {
   bool SignalBULL41Executed;  //<-- if defined inside the start function, the flags get reset with every tick.
   bool SignalBULL42Executed;  //    define it outside in global scope.
   
   if(Fun_New_Bar()==true)
      {
      SignalBULL41Executed=false;
      SignalBULL42Executed=false;
      }   
   
   if(BULL4() && BULL41send() && !SignalBULL41Executed && OpenOrders_BULL4(Symbol())==0)             
     {
       OpenBULL41();//do open buy position   //<-- As far as I remember, you defined this as bool. Do only set the flag, if the function returns true.
       SignalBULL41Executed=true;            //    change to: if(OpenBULL41())SignalBULL41Executed=true;
     }
The above corrections are for the flags. But the open question is, do you need it? If you only open a new order, if a specific numbers of orders is already open, you probably don't need it. This is what I meant with the yellow marked expression:
if(BULL4() && BULL41send() && !SignalBULL41Executed && OpenOrders_BULL4(Symbol())==0)

But no worries, it works also with the flags and you can eliminate them later, when it turns out they are obsolete. 

 

I think that the flag is not required, but can be useful someday.

How to have two EA in one EA?
I made copies of the EA BULL4 and changed the BULL6 idex and the spacing pips.
Copy EA Bull4 + EA Bull6 too new EA (everything after the digit ()) Do changes within the function start () and magicma2...

My EA works very well, the scenarios do not interfere with each other. I'm happy.

I wanted to thank you for your help, without your help and especially your support Kronin I would not write it.

 

Subject is end in my opinion.

 

Regards

 
Wodzuuu:

My EA works very well, the scenarios do not interfere with each other. I'm happy.

I wanted to thank you for your help, without your help and especially your support Kronin I would not write it.

You're welcome. Thanks for the nice feedback.

Reason: