Need help regarding OrderClose and OrderModify - page 2

 
hyunjeshin:
Its this. For Long Position it works, but it does not work for Short Position. Please Help.

What do you mean by "it does not work"?

Be more specific.

Print out the error when there is one.

Read William's post #3 carefully and address all the issues that he has pointed out and then re-post your updated code.

 
Keith Watford:

What do you mean by "it does not work"?

Be more specific.

Print out the error when there is one.

Read William's post #3 carefully and address all the issues that he has pointed out and then re-post your updated code.

Its OrderModify Error 130

I have read over those but i could not figure it out. Thus, I came here to ask for help

 
hyunjeshin:


Your new topic has been deleted.

It is concerning the same code that you have here.

Do not open new topics with different problems concerning the same code. Keep it all in one place.

 
Keith Watford:

Your new topic has been deleted.

It is concerning the same code that you have here.

Do not open new topics with different problems concerning the same code. Keep it all in one place.

Yo, i want to delete this forum, but i do not know how.


i asked for your help yet you wont help. Not to mention, this forum is old that people wont read it anymore.

How then should i solve? hmm?

 
Then delete this for me, because i do not know how. I searched but there seem to be no guide as to how to delete your forum
 

It took you less than 10 minutes to delete the new post

However, when i asked for your help not once but twice, you blatantly ignore and keep me stuck here, isnt this abit of power abuse? 

 
hyunjeshin:

It took you less than 10 minutes to delete the new post

However, when i asked for your help not once but twice, you blatantly ignore and keep me stuck here, isnt this abit of power abuse? 

What are you talking about, "Power abuse"?

Nobody is obligated to help you.

I told you some posts back

Keith Watford:

What do you mean by "it does not work"?

Be more specific.

Print out the error when there is one.

Read William's post #3 carefully and address all the issues that he has pointed out and then re-post your updated code.

and you replied

hyunjeshin:

Its OrderModify Error 130

I have read over those but i could not figure it out. Thus, I came here to ask for help

Which is not specific.

You have not even attempted to modify your code using William's suggestions. You will find that if you are prepared to put in some effort others are more likely to help you.

 
Keith Watford:

What are you talking about, "Power abuse"?

Nobody is obligated to help you.

I told you some posts back

and you replied

Which is not specific.

You have not even attempted to modify your code using William's suggestions. You will find that if you are prepared to put in some effort others are more likely to help you.

1. Regarding William's Suggestion, I did read his comments and incorporated it, thus I was able to successfully adjust CloseOrder and ModifyOrders.

2. The new post I posted was about making OrderModify run only once, which is not the same as getting error code.

3. About Power Abuse, thinking back it was not really an abuse, but when you deleted my post, which was about different issue, i was pissed so I wrote something that I regret, so about that I apologize. However, I really do not think you deleting my post was 100% fair either as when you create a forum, as days past, it gets sent back in the forums, so the exposure decreases exponentially, no?

So I created a different post regarding different issue

But, you did not even read my new post, you just assumed it was under the same name and the code looked similar, thus you deleted the post immediately, would you call that fair? I understand it was under same name, but atleast you could've read what i wrote.

Also, since this forum was not getting any exposure, I kept asking you for help, but you wouldn't really help. So I am stuck with this forum which is not getting any exposure, while I am not able to open another post because you will simply delete my post. I kind of do not think that is fair, no? Did you honestly read my edited code and question I was asking for? If you really did and it was same issue, I apologize as I am still new. But, the issue i was asking for help as making OrderModify work only once, i.e. Once i hit my first TP, modify SL & TP only once and close order after that.

4. About nobody is obligated to help, i fully agree, that is why i was trying to get exposure by creating another post, regarding different issue.

5. Lastly about "specific", I thought Error 130 was specific enough as that was the only code I saw in the EA error, so this might be miscommunication in my part.

 

What you did was post basically the same code that you have posted here.

The code still had the poor coding practice that William has already pointed out to you here.

If I left that topic open, somebody else may waste their time pointing out those same mistakes. That will waste their time, the same as it has wasted Williams time as you have not addressed the issues even though they have been pointed out to you.

William stated

  1. You can't just use OrderLots()/2 because that is not a multiple of LotStep, and you can't close or have remaining less than MinLot. See my code.
  2. You also must check if you have already done it, to avoid repeated closing. Alternatives:
    • Move SL to Break Even+1 before the partial close. That way you know that you already did it.
    • Set a flag in persistent storage (files, global variables w/flush)
    • Open two orders initially, and close one (manually or by TP.)

but you are still doing it.

He also said

if(Bid == OrderTakeProfit()-1*Point()) 

Doubles are rarely equal. Understand the links in:
          The == operand. - MQL4 programming forum #2  2013.06.07


Did you even read the link?

This is probably one of the most important issues that you need to understand because if you don't you will make the same mistakes over and over again.

So this is the first issue that you should address.

 
Keith Watford:

What you did was post basically the same code that you have posted here.

The code still had the poor coding practice that William has already pointed out to you here.

If I left that topic open, somebody else may waste their time pointing out those same mistakes. That will waste their time, the same as it has wasted Williams time as you have not addressed the issues even though they have been pointed out to you.

William stated

but you are still doing it.

He also said

Did you even read the link?

This is probably one of the most important issues that you need to understand because if you don't you will make the same mistakes over and over again.

So this is the first issue that you should address.

Okay First, thank u for replying.

1.  About OrderLots thing, I changed to normalizedouble, so that it will be able to always divide by 2, and yes i understand that it can not close or have remaining less than MinLot, but it was not an issue as starting lot was 2. 

Also regarding this, that is why I only want to ModifyOrder only once, so that it will never reach the MinLot. These are reasons why I believe I fixed the issue and why I am asking for help to limit OrderModify to only once.

2. Regarding moving SL to break even +1, I believe I did as my current stoploss is stoploss +/- 1, and modifying order before closing was not necessary because it never was an issue as I looked all every backtest orders and SL has always been moved up. 

3. Flags, I tried but I could not really understand so i skipped that first

4. Manual TP i thought and tried it but turns out the comission fee ate into all the profit. Nonetheless, these issues were fixed and issue I am currently talking about is limiting ModifyOrder to only once.

5. Bid == thing, yea I understand and in code I have both in form of <= and ==, and i did not really see it as an issue as in backtesting, it all closed, and if in forward testing, it still remains an issue, i will immediately change to <= or >=.

So I believe I followed his advice pretty much everything (aside from flag as I could not really fix it), so I do not think that I did not try.

If you do not believe, heres the code that i currently have. You will see that all these issues have been fixed and only issue left is that ModifyOrder function keeps looping everything the price reaches TP point.

extern double  Lots           = 2; //<----- This is above the int OnInint() and void ontick()//
   
for(int b = OrdersTotal()-1; b>=0; b--)
   {
      if(OrderSelect(b, SELECT_BY_POS, MODE_TRADES))  
      if(OrderSymbol() == Symbol())                   
      if(OrderType() == OP_BUY)                       
      {   
         if(Bid >= OrderTakeProfit()-1*Point()) 
            {
               bool CloseHalfLongPosition;
               CloseHalfLongPosition = OrderClose(OrderTicket(), (NormalizeDouble(((OrderLots())/2),2)), Bid, Slippage);
               if(CloseHalfLongPosition == true)
               {
                  Alert("Closing Half of the Long Position");
                  bool SelectLongPositionToModify;
                  SelectLongPositionToModify = OrderSelect(b, SELECT_BY_POS, MODE_TRADES);
                  if(SelectLongPositionToModify == true)
                  {
                     bool ModifyHalfLongPosition;
                     ModifyHalfLongPosition = OrderModify(OrderTicket(), Ask, OrderOpenPrice(), Bid + (OrderTakeProfit()- OrderOpenPrice()), 0);
                     if(ModifyHalfLongPosition == true)
                     {
                        Alert("Changing Long's TP & SL");   
                     }
                     else
                     {
                        Alert("Unable to Modify the Half of the Long Position");
                     } 
                  }
                  else
                  {
                     Alert("Unable to Select Long Position to Modify");
                  }
                  
               }
               else
               {
                  Alert("Unable to Close Half of the Long Position");   
               }
            }
      }
//1/2 TP for Short
         if(OrderSelect(b, SELECT_BY_POS, MODE_TRADES))
         if(OrderSymbol() == Symbol())
         if(OrderType() == OP_SELL)
         {   
            if(Ask <= OrderTakeProfit()+1*Point()) 
               {
                  bool CloseHalfShortPosition;
                  CloseHalfShortPosition = OrderClose(OrderTicket(), (NormalizeDouble(((OrderLots())/2),2)), Ask, Slippage);
                  if(CloseHalfShortPosition == true)
                  {
                     Alert("Closing Half of the Short Position");
                     bool SelectShortPositionToModify;
                     SelectShortPositionToModify = OrderSelect(b, SELECT_BY_POS, MODE_TRADES);
                     if(SelectShortPositionToModify == true)
                     {
                        bool ModifyHalfShortPosition;
                        ModifyHalfShortPosition = OrderModify(OrderTicket(), Bid, OrderOpenPrice(), Ask - (OrderOpenPrice() - OrderTakeProfit()), 0);
                        if(ModifyHalfShortPosition == true)
                        {
                           Alert("Changing Short's TP & SL");   
                        }
                        else
                        {
                           Alert("Unable to Modify the Half of the Short Position");
                        } 
                     }
                     else
                     {
                        Alert("Unable to Select Short Position to Modify");
                     }
                     
                  }
                  else
                  {
                     Alert("Unable to Close Half of the Short Position");   
                  }
               }
         }   
   } 
Reason: