EA Should Open trade Once per Signal. - page 2

 
Arav007:


Thanks for updating the code.

If there is problem in my code, then wont I get the Error:Invalid Price with every order?

I'm using Slippage=3. Is it too high?

Regards

Please search on the forum for "Invalid price error". Then if you can't deal with it, come again to ask.
 
angevoyageur:
Please search on the forum for "Invalid price error". Then if you can't deal with it, come again to ask.


Hello,

Got more or less the same Solution as you stated earlier.

If the code is ok i.e. Ask for Buying and Bid for Selling and other TP, SL etc. are on safe distance, then I should refreshrates with a pause to get the Actual Bid,Ask rate.

So will put like this and observe if I encounter this problem again or not. Also the Off Quotes one.

Could you please suggest the Shorter form of this for searching:

Any trade gone into even 1 cent of profit will be closed as soon as it's getting zero profit.

Is there any such function which doesn't use the pip distance, rather works on the amount of profit?

Regards

 
angevoyageur:
Please search on the forum for "Invalid price error". Then if you can't deal with it, come again to ask.


Hello,

I am trying another thing. That is identifying a range of price. Like I have set Resistance and Support Levels and check whether the price is within this range or not.

So I've written this:

if(RH>=OpenPrice>=RL)
{
 Range=true;
}

But after compiling getting a warning: Unsafe use of Type 'bool' in operation.

What the compiler is meaning by 'Unsafe' would you please explain a bit?

Regards

 
if(OpenPrice<=RH && OpenPrice>=RL)
Try splitting the condition.
 
deysmacro:
Try splitting the condition.


Hello,

Thanks. No warning is showing now.

By the way, I'm wanting to represent these ranges graphically in the chart like support,resistance lines or rectangular block.

I have been searching for such functions but not getting the right one.

Looked into this but couldn't get the idea of how to do it:

https://docs.mql4.com/objects/objectcreate

Regards

 

hello please i am having issue with my code

error is:

return value of OrderSelect should be checked

return value of orderdelete should be checked

this is this code below:

void deleteallpendingorders()

  {


   for(int x=OrdersTotal()-1;x>=0;x--)

       {

      OrderSelect(x,SELECT_BY_POS,MODE_TRADES);

      if((OrderType()==OP_BUY || OrderType()==OP_SELL)==true)

           {

         orderID = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),900,CLR_NONE);       //666

           }

           else

           {

           OrderDelete(OrderTicket());

           }   

       if((OrderType()==OP_BUY || OrderType()==OP_SELL)==false)

           {

       Alert("OrderSelectfalied, returned the error of ",GetLastError());

           }

       

       }

  }

 
tradegiant360:

Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.

 
tradegiant360: error is:

return value of OrderSelect should be checked

return value of orderdelete should be checked

  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  2. So check them.

    Check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler (MT5/MT4+strict), it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum 2012.05.20
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles 25 March 2014

  3. You should be able to read your code out loud and have it make sense. 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 where as Long_Entry sounds like a trigger price or a ticket number and “if long entry” is an incomplete sentence.

 
tradegiant360:


   Always use
   #property strict
   in your codes.
   When starting a project use the "New" button top left of the editor. #property strict will be included automatically.
   If the compiler issues a warning don't ignore it, fix it.
   OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
//will give you the error that the return value of OrderSelect should be checked. This is simple to do
   if(OrderSelect(0, SELECT_BY_POS, MODE_TRADES))
      {
      //code to deal with the selected order
      }
   OrderModify(OrderTicket(), OrderOpenPrice(),OrderStopLoss(),0,0, clrWhite);
//will give you the error that the return value of OrderModify should be checked. The minimum that should be done is to print the error if it fails
   if(!OrderModify(OrderTicket(), OrderOpenPrice(),OrderStopLoss(),0,0, clrWhite))
      {
      Print("Modifying Ticket #",OrderTicket()," failed with error code ",GetLastError());
      }
   OrderSend();
//may give you the error that the return value of OrderSend should be checked. The minimum that should be done is to print the error if it fails
//preferably also print the open price, TP, SL.
   int ticket=OrderSend(_Symbol,OP_BUY,0.1,Ask,20,0,0,NULL,12345,0,clrNONE);
   if(ticket==-1)
      {
      Print("OrderSend for Buy order failed with error code ",GetLastError());
      }
//You will often see people silence the compiler by using
   bool result=OrderModify(OrderTicket(), OrderOpenPrice(),OrderStopLoss(),0,0, clrWhite);
   int ticket=OrderSend(_Symbol,OP_BUY,0.1,Ask,20,0,0,NULL,12345,0,clrNONE); //No print if an error occurs!
//Sure, you don't get the compiler warnings, but it won't help you to track down any errors!
Reason: