Download MetaTrader 5

some error 130 about code

To add comments, please log in or register
Find out the latest MQL5.community news!
Fa Cao
1141
Fa Cao 2013.12.06 10:27 

about below codes, it is very different when the red code "if(Pro<10000*Point)" is activated or not when I test it on the history data;

In the fact the history data is very simple, about consecutive 5 days, and Pro never exceeds 10000*Point.

when the red code is activated, the order stop line seems never move whatever.

it is very confusing.

void Move_Stop_Loss()         
{                                 
  if(OrdersTotal()==0) return;    
 
  int Move_Stop;
  for(int i=OrdersTotal();i>0;i--)
  {
    OrderSelect(i-1,SELECT_BY_POS);
    double Pro=OrderProfit();
    if(OrderType()==OP_BUY)
    {
      if(Pro<200*Point) Move_Stop=100;
      else /*if(Pro<10000*Point) */Move_Stop=200;

      if(Close[0]-OrderStopLoss()>Move_Stop*Point)
      {iWait();OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]-Move_Stop*Point,0,0,0);}
    }  

  }


  return;
}

Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2013.12.06 11:01  
vx0532:

about below codes, it is very different when the red code "if(Pro<10000*Point)" is activated or not when I test it on the history data;

In the fact the history data is very simple, about consecutive 5 days, and Pro never exceeds 10000*Point.

when the red code is activated, the order stop line seems never move whatever.

it is very confusing.

What does point have to do with profit in your account currency ? do you understand what OrderProfit() is ?
Fa Cao
1141
Fa Cao 2013.12.06 12:17  
RaptorUK:
What does point have to do with profit in your account currency ? do you understand what OrderProfit() is ?


haha,sorry,

OrderProfit() returns the current unrealized profit of the selected order.

I want to change stop loss line when the profit is more than some value, shall I?

whroeder1
14470
whroeder1 2013.12.06 12:45  
vx0532: I want to change stop loss line when the profit is more than some value, shall I?
      if(Pro<200*Point) Move_Stop=100;
      else /*if(Pro<10000*Point) */Move_Stop=200;

  1. on EURUSD Point is 0.0001 (4 digit broker) or 0.00001 (5) so 10000*Point is 10 or 1. So your first test is when profit < $0.2 or <$0.02 and the second test is profit < $1.00 or profit < $10.00
  2. If you don't execute the first (because profit is more than 0.2) AND you don't execute the second (because profit is more than $1) Then what is the value of Move_Stop?
  3. You want to "change when profit is more" so why are you testing for less?
  4. "shall you?" We don't know - have you learn to code?
  5. If your orderSelect fails, so does your code - What are Function return values ? How do I use them ? - MQL4 forum If the OrderModify fails don't you want to know why. If it's not working don't you want to know whether its the OrderModify or the fact it's not being called?
  6. If you change brokers (from 4 to 5 digits or back or put is on a JPY or metals chart) are you going to remember to change every number? In the right direction? Don't use Point, auto-adjust using pips2dbl
Fa Cao
1141
Fa Cao 2013.12.06 13:36  
WHRoeder:
  1. on EURUSD Point is 0.0001 (4 digit broker) or 0.00001 (5) so 10000*Point is 10 or 1. So your first test is when profit < $0.2 or <$0.02 and the second test is profit < $1.00 or profit < $10.00
  1. my first test is profit <$0.2 or $0.02 and my second test is profit >$0.2&& <$10.0 or profit>$0.02 && <$1.0; in the other case (without if(Pro<10000*Point) ), just delete profit<$1.0 or <$10.0;

  • If you don't execute the first (because profit is more than 0.2) AND you don't execute the second (because profit is more than $1) Then what is the value of Move_Stop?
  1. yes, Move_Stop=0, that is why error 130.

  • You want to "change when profit is more" so why are you testing for less?
  1. testing less, because when less, Move_Stop will get "less" 's value just as "more".
  1. of course I have, that is why you see my post here.

  1. thanks for your advice.

  • If you change brokers (from 4 to 5 digits or back or put is on a JPY or metals chart) are you going to remember to change every number? In the right direction? Don't use Point, auto-adjust using pips2dbl
  1. thanks


Fa Cao
1141
Fa Cao 2013.12.06 14:25  

thanks all

I have understand the situation.

Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2013.12.06 16:13  
vx0532:

thanks all

I have understand the situation.

Well done
Fa Cao
1141
Fa Cao 2013.12.06 23:39  
RaptorUK:
Well done


I modify them as below:

if(OrderSelect(i-1,SELECT_BY_POS))
    {
      int Profit_Point=NormalizeDouble(OrderProfit()*Close[0]/100000/Point+50*Point,0); 
      int Move_Stop=100;
      if(Profit_Point>0&&Profit_Point<=500) Move_Stop=400;
      if(Pro*Close[0]/100000>500*Point)Move_Stop=50;
      if(MathAbs(Close[0]-OrderStopLoss())>Move_Stop*Point)
      if(OrderType()==OP_BUY) {iWait();OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]-Move_Stop*Point,0,0,0);}
      else if(OrderType()==OP_SELL) {iWait();OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]+Move_Stop*Point,0,0,0);}
    } 
whroeder1
14470
whroeder1 2013.12.07 02:47  
OrderProfit()*Close[0]/100000/Point
$n.nn profit * exchange rate / (1/Point) / Point = $n.nn profit * exchange rate = what? A meaningless value with meaningless units. What is the sound of the temperature of the sun - Huh?
Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2013.12.07 12:09  
WHRoeder:
$n.nn profit * exchange rate / (1/Point) / Point = $n.nn profit * exchange rate = what? A meaningless value with meaningless units. What is the sound of the temperature of the sun - Huh?
http://www.telegraph.co.uk/science/space/8114694/Stars-song-captured-by-scientists.html
12
To add comments, please log in or register