EA is not taking trades after first trade - page 2

 
cashcube:

Thank you for correcting.

      if( Bid > highest)                              //How can Bid be higher than today's high ???
         {
         bool Deleted = OrderDelete(BuyTicket,Green);

This part of the code added because, if highest high got changed, then calculation of S1 will be different. That's why to added the condition to check, if its true, then delete the pending order. If any better way is possible then please share.

You are not checking if the highest high has changed, you are checking if Bid is > than the day high which is, of course impossible.

But of course, this section of code will never be executed anyway.

if( (highest - Bid) > (20 * Point))     //if current price is more than 20 pips below today's high
   {
   if(Ticket < 100)                     //This may work in the strategy tester, it will not in real-time 
      {
      S1 = highest - (40 * Point);      //---Calculating Support at 40 pips below today's high
      OrderSelect(BuyTicket,SELECT_BY_TICKET);      //1
      if( Bid > highest)                              //How can Bid be higher than today's high ???
         {
         bool Deleted = OrderDelete(BuyTicket,Green);
         }

it is in the same block of code that will only be executed when the condition is met that Bid is more than 20 pips below the days high

It's basically the same as

if(x < 100 && x > 100)

which doesn't make sense as it can never be true.

If you want to use the condition

if( Bid > highest) 

Then it will HAVE to be before

highest = iHigh(NULL,PERIOD_D1,0);      // Today's high
 
cashcube:
      OrderSelect(BuyTicket,SELECT_BY_TICKET);      //1
      if( Bid > highest)                              //How can Bid be higher than today's high ???
         {
         bool Deleted = OrderDelete(BuyTicket,Green);
         }

About OrderSelect area, i deleted the orderclosetime part. Now will it be ok? I tested it.

Now about this part (corrected) is say high is 1.3680 bid is at 1.3659 greater than 20, so S1 is 1.3680-40=1.3640. It will place Buylimit. But if bid is below the S1 then it will place buystop, ( I checked the tester, sometimes it was giving ordersend error, so that's why added this condition)

Lastly about the Ticket < 100 condition, i added it because, i want to take only 1-2 trades per day.


Now you select an order and do nothing with the select?

I asked you what happens if the OrderSelect fails? See this example

      OrderSelect(AnotherTicket,SELECT_BY_TICKET);   // this order select succeeds
      //code
      //code
      //code
      //code  
      
      OrderSelect(BuyTicket,SELECT_BY_TICKET);     //  if this order select fails
      
      if(OrderCloseTime() == 0 && BuyTicket > 0 && OrderType() == OP_BUYLIMIT)
      //This if is using the close time and type from AnotherTicket, not BuyTicket
         {
         bool Deleted = OrderDelete(BuyTicket,Green); // You create the variable "Deleted" but only assign a 
         }                                            // value to it, you never reference it.

Get into the habit of using

      if(!OrderSelect(AnotherTicket,SELECT_BY_TICKET) )   
         Print ( "report the problem" );
      else
         {
         //code to process what you want to do
         }
      //code
      //code  
      
      if(!OrderSelect(BuyTicket,SELECT_BY_TICKET) )   
         Print ( "report the problem" );
      else 
         if(OrderCloseTime() == 0 && BuyTicket > 0 && OrderType() == OP_BUYLIMIT)
            {
            bool Deleted = OrderDelete(BuyTicket,Green); 
            }

I don't see how the condition Ticket<100 means you will only take 1 or 2 trades per day.

 

Ok corrected again. Working ok. But one thing is, in tester i see "report the problem " constantly. I guess orderselect is getting failed most the time. That's why its not coming to 2nd condition.

Why orderselect is getting failed, no idea.

Another thing, i am testing it on past data, i guess lowest will never get changed in this case. So orderdelete for the change has no use, right?

Thanks again.

Files:
kk_7.mq4  5 kb
Reason: