I Need your help!!

Back to topics list To post a new topic, please log in or register
avatar
6
DlewisUK 2016.05.16 14:15
 

Hello everyone!!  I am pretty new to MQL4 and I've only been coding with this language for 3 months. I seem to have hit a major wall in coding today. and I am not sure how to go about this.

This is a section of meatgrinder, A trade recovery system that I have been building. This section of code works flawlessly  

 //-------------------------------------------------------------------------------------------------------------------------------------   

   //Stage 1 - if orders = 1

   if(OrdersTotal()==1)

   {//Select previous order

      if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==true)

      {//if it's a buy

         if(OrderType()==OP_BUY)

         {

         //if bid lower the upper recovery zone value and if bid above the lower recovery zone value       

            if(Bid<=Add_double(Main_Recovery_Zone,TWS)&&(Bid>=Sub_double(Main_Recovery_Zone,TWS))==true)

            {//do this

                    for(int i=1; i<=1; i++) //Loop ONCE!

                      {

                       //place sell recovery trade

                        Ticket_1= OrderSend(Main_Symbol,OP_SELL,RLS1,Bid,Slippage,0,0,"1st recovery trade",EA_MAGIC);

                           if(Ticket_1 < 0)

                           {

                             Alert("ERROR - The sell order has not been placed");

                           }

                      }//end of for loop

            }//end of if statement

         }//end of is buy      

//----------------------------------------------------      

      //if it's a sell

      if(OrderType()==OP_SELL)

      {//if Ask is above lower recovery zone value and if Ask is below upper recovery zone value

         if(Ask>=Sub_double(Main_Recovery_Zone,TWS)&&(Ask<=Add_double(Main_Recovery_Zone,TWS))==true)

         {//do this

                    for(int i=1; i<=1; i++) //Loop ONCE!

                      {

                       //place buy recovery trade

                        Ticket_1 = OrderSend(Main_Symbol,OP_BUY,RLS1,Ask,Slippage,0,0,"1st recovery trade",EA_MAGIC);

                           if(Ticket_1 < 0)

                              {

                              Alert("ERROR - The sell order has not been placed");

                              }

                      }//end of for loop

        }//end of if statement 1

      }//end of is sell

     }//end of order select

   }//end of order 1 / Stage 1

//--------------------------------------------------------------------------------------------------------------------------------------  

 

Now I would like to enter this section of code into the mix

 

//--------------------------------------------------------------------------------------------------------------------------------------  

 

               //Pip catcher system

            //if the bid price goes below the sell boundary and a recovery trade has not been placed? 

            if((Bid<Sub_double(Main_Recovery_Zone,TWS))&&(Ticket_1<=0)==true)

            {

            //Place trade immideately

             for(int i=1; i<=1; i++) //Loop ONCE!

                      {

                       //place sell recovery trade

                        Ticket_1= OrderSend(Main_Symbol,OP_SELL,RLS1,Bid,Slippage,0,0,"1st recovery trade",EA_MAGIC);

                           if(Ticket_1 < 0)

                           {

                             Alert("ERROR - The sell order has not been placed");

                           }

                      }//end of for loop

            }//end of pip catcher 

//--------------------------------------------------------------------------------------------------------------------------------------  

With this part of code in the mix, it now constantly places trades  

//-------------------------------------------------------------------------------------------------------------------------------------   

   //Stage 1 - if orders = 1

   if(OrdersTotal()==1)

   {//Select previous order

      if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==true)

      {//if it's a buy

         if(OrderType()==OP_BUY)

         {

         //if bid lower the upper recovery zone value and if bid above the lower recovery zone value       

            if(Bid<=Add_double(Main_Recovery_Zone,TWS)&&(Bid>=Sub_double(Main_Recovery_Zone,TWS))==true)

            {//do this

                    for(int i=1; i<=1; i++) //Loop ONCE!

                      {

                       //place sell recovery trade

                        Ticket_1= OrderSend(Main_Symbol,OP_SELL,RLS1,Bid,Slippage,0,0,"1st recovery trade",EA_MAGIC);

                           if(Ticket_1 < 0)

                           {

                             Alert("ERROR - The sell order has not been placed");

                           }

                      }//end of for loop

            }//end of if statement

             //Pip catcher system

            //if the bid price goes below the sell boundary and a recovery trade has not been placed? 

            if((Bid<Sub_double(Main_Recovery_Zone,TWS))&&(Ticket_1<=0)==true)

            {

            //Place trade immideately

             for(int i=1; i<=1; i++) //Loop ONCE!

                      {

                       //place sell recovery trade

                        Ticket_1= OrderSend(Main_Symbol,OP_SELL,RLS1,Bid,Slippage,0,0,"1st recovery trade",EA_MAGIC);

                           if(Ticket_1 < 0)

                           {

                             Alert("ERROR - The sell order has not been placed");

                           }

                      }//end of for loop

            }//end of pip catcher 

         }//end of is buy      

//----------------------------------------------------      

      //if it's a sell

      if(OrderType()==OP_SELL)

      {//if Ask is above lower recovery zone value and if Ask is below upper recovery zone value

         if(Ask>=Sub_double(Main_Recovery_Zone,TWS)&&(Ask<=Add_double(Main_Recovery_Zone,TWS))==true)

         {//do this

                    for(int i=1; i<=1; i++) //Loop ONCE!

                      {

                       //place buy recovery trade

                        Ticket_1 = OrderSend(Main_Symbol,OP_BUY,RLS1,Ask,Slippage,0,0,"1st recovery trade",EA_MAGIC);

                           if(Ticket_1 < 0)

                              {

                              Alert("ERROR - The sell order has not been placed");

                              }

                      }//end of for loop

        }//end of if statement 1

               //Pip catcher system

            //if the bid price goes below the sell boundary and a recovery trade has not been placed? 

            if((Ask>Add_double(Main_Recovery_Zone,TWS))&&(Ticket_1<=0)==true)

            {

            //Place trade immideately

             for(int i=1; i<=1; i++) //Loop ONCE!

                      {

                       //place sell recovery trade

                        Ticket_1= OrderSend(Main_Symbol,OP_SELL,RLS1,Bid,Slippage,0,0,"1st recovery trade",EA_MAGIC);

                           if(Ticket_1 < 0)

                           {

                             Alert("ERROR - The sell order has not been placed");

                           }

                      }//end of for loop

            }//end of pip catcher 

      }//end of is sell

     }//end of order select

   }//end of order 1 / Stage 1

//--------------------------------------------------------------------------------------------------------------------------------------  

 

i know that this is wrong because the 2 conflicting if statements produces unreliable results. I just want it to do

if price is above or below the boundary and the trade has not been placed place trade immediately.

Any help is greatly appreciated. Thank you for your time

 

avatar
1211
FMIC 2016.05.16 17:13 #
 

Please EDIT your post and use the SRC button to place your source code (or attach the file it if it is large).

avatar
6
DlewisUK 2016.05.16 20:50 #
 
this post has been updated
avatar
12995
WHRoeder 2016.05.16 22:46 #
 
  1.   if(OrdersTotal()==1){//Select previous order
          if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==true)
    No filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
  2. if((Ask>Add_double(Main_Recovery_Zone,TWS))&&(Ticket_1<=0)==true)
    You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.
avatar
6
DlewisUK 2016.05.16 23:46 #
 

Well I appreciate your input on this WHRoeder and yeah I must admit, I was using the ==true part for easier reading. it's superficial really  a filtering system is needed in this EA but not essential to me at the moment as I'm working on one chart at a time for the moment.

 What is essential to me is making these two if statements work. I was thinking of something like a switch statement for this. How would you go about this WHRoeder

avatar
6
DlewisUK 2016.05.17 00:00 #
 

Nice coding for the symbol filter by the way, I'm guessing that would go somewhere near the top of the EA on the OnTick() function. or the init function

 

avatar
6
DlewisUK 2016.05.17 00:31 #
 
if you want to have a play? Here's the file.
avatar
6
DlewisUK 2016.05.17 13:47 #
 

Ahh no need now I think I've cracked it

 

Back to topics list  

To add comments, please log in or register