Some part of my codes are not working ...... a little help here ^_^ ? - page 2

 
juniorlcq:

Hmmmph, good call, but I tried like this and it still doesn't work .....


Hi

I think usually orders are looped through downwards, i.e. use

for(int i=OrdersTotal(); i>=0;i--){ /*code goes here*/ }

Also try modifying the order AFTER you have set your stoploss/ take profit settings and not before as it seems to be the case.

 
juniorlcq:

Oh ya RaptorUK I also did this changes after reading the link you gave .... but the TP SL still not working .....

I add a bool Modify ;

and change the ordermodify to this .

But you are missing the point . . . where are you checking if the OrderModify() worked or failed ? and if it fails where are you Printing the error and associated variables ? don't you want to know why your OrderModify() didn't work ?
 
GumRai:

Once again, you are trying to use a value before it has been calculated

StopLossSettings and TakeProfitSettings are both zero when you try to modify the trade.


Even after reading my post you show more code that tries to use values in the OrderModify that have not been calculated yet!
 
Any examples ??? I still can't get it right
 
RaptorUK:
You need to check the return values from your trading functions . . . then report the error when they fail along with any relevant variables, please read this: What are Function return values ? How do I use them ?


Here ^ ^ ^ ^ ^
 
juniorlcq: WORKS WITH 2,3,4,5 digits broker . Can someone help me to double check it,
  1.          if ( Digits == 2 )
             Multiplier = 0.01 ;
             if ( Digits == 3 )
             Multiplier = 0.001 * 10 ;
             if ( Digits == 4 )
             Multiplier = 0.0001 ;
             if ( Digits == 5 )
             Multiplier = 0.00001 * 10 ;
    You also have to adjust SLIPPAGE Problems with a calculation - MQL4 forum
  2.             Ticket = OrderSend ( Symbol() , OP_BUY , FixedLotSize , MarketInfo ( Symbol() , MODE_ASK ) , Slippage , NULL , NULL , TradeComment , MagicNumber , 0 , CLR_NONE ) ;
    
    Are your books one column but two feet wide? No because that is unreadable. They are 6 inches, sometimes two columns, so you can read it easily. So should be your code. I'm not going to go scrolling back and forth trying to read it. Edit the post with formatted code and you might get additional help.

  3. MarketInfo ( Symbol() , MODE_ASK )
    Why are you using a function call instead of the predefined variable Ask?
  4. What are Function return values ? How do I use them ? - MQL4 forum
 
WHRoeder:
3. Why are you using a function call instead of the predefined variable Ask?


... one reason for 3 is that Ask does not refresh during a call to start() whereas MarketInfo(..., MODE_ASK) does refresh. If you do anything time-consuming in start(), e.g. closing or modifying multiple orders, then MarketInfo() is safer.

In other words: use of Ask and Bid can create a latent bug in your code which only emerges over time as the code becomes more complicated. The benefits of using Ask and Bid - a tiny speed gain - are very questionable compared to the latent bug which they create.

The two outputs of the following code will typically be different on any liquid symbol:

void start()
{
   MessageBox("About to go to sleep for 5 seconds...");
   Sleep(5000);
   MessageBox("Ask: " + Ask + "\r\nMarketInfo(): " + MarketInfo(Symbol(), MODE_ASK));
}
 
gchrmt4:


... one reason for 3 is that [...]

I think there is a very old discussion on this forum which shows that RefreshRates() + Ask is microseconds faster than MarketInfo(). But I would still prefer to use MarketInfo() because it is easier to use MarketInfo() throughout than to remember to put RefreshRates() in the potentially-necessary places, creating a bug if you forget one or more of these necessary uses.

 
gchrmt4:
In other words: use of Ask and Bid can create a latent bug in your code which only emerges over time as the code becomes more complicated. The benefits of using Ask and Bid - a tiny speed gain - are very questionable compared to the latent bug which they create.


... In particular, use of Ask rather than MarketInfo can lead to an EA which works correctly in back-testing (where trade placement is instant, and prices do not move during trading) but does not work properly in live trading (where placement is not instant, and prices do move during trading).

The fun part is that people will tend to view this as broker slippage - e.g. "I did a Print() of Ask just before trading, and that proves the broker filled me at a worse price" - when the actual issue is a software bug (i.e. the ask price in Print() is stale).

 
gchrmt4:

... In particular, use of Ask rather than MarketInfo can lead to an EA which works correctly in back-testing (where trade placement is instant, and prices do not move during trading) but does not work properly in live trading (where placement is not instant, and prices do move during trading).

Using MarketInfo() won't help in this situation . . . . if price moves between the time when you send your order and the time when it is executed it makes no odds if you have used Bid/Ask or Bid/Ask from MarketInfo().

The fun part is that people will tend to view this as broker slippage - e.g. "I did a Print() of Ask just before trading, and that proves the broker filled me at a worse price" - when the actual issue is a software bug (i.e. the ask price in Print() is stale).

That is incorrect, if the price is stale you will get error 135 with some Brokers, other Brokers will accept the price and fill you at the current price regardless of the slippage parameter. It's not a software bug it's ignorance of how to use mql4.
Reason: