What Rules Is Used For StopLoss Based on Order Open High or LOW

 

Hi,

Need a little help. Trying to find the code to use for the issues i have.

Example



So here is an example for a buy. I manage to get the rules to open order and take profit. so i'm trying to find a rules for the StopLoss.

Thank You

{ 
   int err;    
   for(int i = 0; i < OrdersTotal(); i++) 
      {
       bool OrSel = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);    
       if(OrderSymbol() == Symbol() && (MagicNumber == 0 || OrderMagicNumber() == MagicNumber)) 
         {
          if(OrderType() == OP_BUY && ((StopLoss && BuyRETEST) || (TakeProfit && BuyTP)) && iTime(NULL,0,0) > iTime(NULL,0,iBarShift(NULL,0,OrderOpenTime(),1))) 
            {
             bool close = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, clrBlue);CloseOrders(0);CloseOrders(2); 
             err = GetLastError(); if(err!=ERR_NO_ERROR){ Print("Error on Order closing = ", ErrorDescription(err));}
            }               
          if(OrderType() == OP_SELL && ((StopLoss && SellRETEST) || (TakeProfit && SellTP)) && iTime(NULL,0,0) > iTime(NULL,0,iBarShift(NULL,0,OrderOpenTime(),1)))   
            {
             bool close = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, clrRed);CloseOrders(1);CloseOrders(3); 
             err = GetLastError(); if(err!=ERR_NO_ERROR){ Print("Error on Order closing = ", ErrorDescription(err));}
             }}}  
}    


Here's my part of the order to be close. the one i indicate "BuyRetest" or "SellRetest" is one of the rules for stop loss. the one i requested is another rules for stop loss.

Anything to add up here?

Thank You

 
Mohammad Rizal Bin Rahmat: So here is an example for a buy. I manage to get the rules to open order and take profit. so i'm trying to find a rules for the StopLoss.
  1. You have to know your stop loss when you open to compute your risk.
    • You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
    • Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
    • Do NOT use TickValue by itself - DeltaPerLot
    • You must normalize lots properly and check against min and max.
    • You must also check FreeMargin to avoid stop out
    Your SL is Low[1] (You are opening on bar zero.)
  2. Set the SL in your OrderSend. Otherwise you have infinite risk. If you can loose connection, power, PC dies etc., no code can run.
  3. In the presence of multiple orders (one EA multiple charts, multiple EAs, manual trading)
 
whroeder1:
  1. You have to know your stop loss when you open to compute your risk.Your SL is Low[1] (You are opening on bar zero.)
  2. Set the SL in your OrderSend. Otherwise you have infinite risk. If you can loose connection, power, PC dies etc., no code can run.
  3. In the presence of multiple orders (one EA multiple charts, multiple EAs, manual trading)
Hi sir, if i set the SL on the order send, if price touches the price it will close order. That isn't what i needed. What i needed is if price close over the price which is the low or the high
 
I tried to put "iLow (NULL,0,1) or iHigh (NULL,0,1)"

But this if the price hit the SL price, it close order. What i wanted is the price close above or below the SL price
 
Mohammad Rizal Bin Rahmat:
I tried to put "iLow (NULL,0,1) or iHigh (NULL,0,1)"

But this if the price hit the SL price, it close order. What i wanted is the price close above or below the SL price

  1. Code a function in your EA, to draw a horizontal line.
  2. Then code a function (something like hidden stop loss), where if the price close above/below that horizontal line (https://docs.mql4.com/objects/objectfind), ea should close the order.

 
Mohamad Zulhairi Baba:

  1. Code a function in your EA, to draw a horizontal line.
  2. Then code a function (something like hidden stop loss), where if the price close above/below that horizontal line (https://docs.mql4.com/objects/objectfind), ea should close the order.

Meaning to say,  when Order Send,  it will place a horizontal line on the Low or the High. Then i code another function for the Stop Loss above or below the line correct? 

Hidden stop loss, any example? Not sure what is hidden stop loss
 
Mohammad Rizal Bin Rahmat:
I tried to put "iLow (NULL,0,1) or iHigh (NULL,0,1)"

But this if the price hit the SL price, it close order. What i wanted is the price close above or below the SL price
  1. Same as Predefined Variables - MQL4 Reference High[]/Low[]. Why would you "try" those?
  2. No need for a horizontal line. You know when you opened the order (OrderOpenTime) So find the shift of that bar, get the low of the previous bar, check against the last close.
  3. Don't use a hidden stop loss. #1 Item 1 and #1 Item 2
 
whroeder1:
  1. Same as Predefined Variables - MQL4 Reference High[]/Low[]. Why would you "try" those?
  2. No need for a horizontal line. You know when you opened the order (OrderOpenTime) So find the shift of that bar, get the low of the previous bar, check against the last close.
  3. Don't use a hidden stop loss. #1 Item 1 and #1 Item 2
I was actually looking at OrderOpenTime but i don't know how to quote OrderOpenTime to get the Low or High.
 
Mohammad Rizal Bin Rahmat:
I was actually looking at OrderOpenTime but i don't know how to quote OrderOpenTime to get the Low or High.
Can't help you much if you don't know how to code.
Perhaps try freelance service?
 
Mohamad Zulhairi Baba:
Can't help you much if you don't know how to code.
Perhaps try freelance service?
No worries. If everyone wants to learn but no guidance and was push to freelance,  then no one is learning. I want to learn not to simply get someone to code for me. Thanks by the way
 
Mohammad Rizal Bin Rahmat: I was actually looking at OrderOpenTime but i don't know how to quote OrderOpenTime to get the Low or High.
I just told you how. If you don't know how to code there is no common language for us to communicate. Learn to code it, or pay (Freelance) someone to code it. We're not going to code it for you.