Download MetaTrader 5

How to set an order few pips above order initiation bar

To add comments, please log in or register
msrron
175
msrron 2014.10.13 10:18 
Hello, I would like to create a stoploss order that will be placed above the high of the previous order's initiation bar.
Here is a picture to Illustrate the issue (In the example (picture)  there is a sell order):
Problem Illustration
 
Any Idea how to do that? The code below works fine If I use stoploss that is fixed.If I replace the stoploss with  variables that are based on High or Low no orders are fired. 
double HH=High[1];
double LL=Low[1];
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+


#property copyright "Copyright 2014, Ron"
#property link      "http://www.Ron.com"
#property version   "1.00"
#property strict

extern int     StartHour      = 14; 
extern int     TakeProfit     = 70;
extern int     StopLoss       = 40;
extern double  Lots           = 0.01;
extern int     MA_period      = 20;
extern int     MA_period_1    = 45;
extern int     RSI_period14   = 14;
extern int     RSI_period12   = 12;
void OnTick()
{
   static bool IsFirstTick = true;
   static int  ticket = 0;
   double R_MA = iMA(Symbol(),Period(),MA_period,0,0,0,1);
   double R_MA_Fast = iMA(Symbol(),Period(),MA_period_1,0,0,0,1);
   double R_RSI14 = iRSI(Symbol(),Period(),RSI_period14,0,0);
   double R_RSI12 = iRSI(Symbol(),Period(),RSI_period12,0,0);
   double HH=High[1]; 
   double LL=Low[1];


   if(Hour() == StartHour)
   {
      if(IsFirstTick == true)
      {
         IsFirstTick = false;
         
         bool res1 = OrderSelect(ticket,SELECT_BY_TICKET);
         if(res1==true)
         {
            if(OrderCloseTime() ==0)
            {
            bool res2 = OrderClose(ticket,Lots,OrderClosePrice(),10);
               if(res2 == false)
               {
                  Alert("Error closing order # ",ticket);
               }
            
            }
         }            
         
             
         
            if(High[1] < R_MA && R_RSI12 > R_RSI14 && R_MA_Fast>=R_MA ) 
            {
            ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 10, Bid-LL*Point*10, Bid+TakeProfit*Point*10, "Set by SimpleSystem");
            }
            if(ticket < 0)
            {
               Alert("Error Sending Order!");
            }
         
         else
         {
            if (High[1] > R_MA && R_RSI12 > R_RSI14 && R_MA_Fast<=R_MA )
            {
            ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 10, Ask+HH*Point*10, Ask-TakeProfit*Point*10, "Set by SimpleSystem");
            }
            if(ticket < 0)
            {
               Alert("Error Sending Order!");
            }
         }

      }
    }  
   
   else
   {
      IsFirstTick = true;
   }

}
   


Thank you        

Carl Schreiber
6670
Carl Schreiber 2014.10.13 10:40  
There is an EA-example "Moving Average.mq4" look it up
msrron
175
msrron 2014.10.13 10:49  

Thanks @gooly, I'm new to MQL4 so I don't see the right place to look for in the "Moving Average.mq4".
Can you direct me a little bit?

Thanks,
Ron 

Carl Schreiber
6670
Carl Schreiber 2014.10.13 11:11  

It is in the expert folder.

whroeder1
14753
whroeder1 2014.10.13 12:25  
msrron: I used "High[1]" but It dosen't provide the right outcome.
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  3. You have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
  4. Show your attempt.
msrron
175
msrron 2014.10.13 12:54  
WHRoeder:

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  3. You have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
  4. Show your attempt.

Well @WHRoeder as for your points:
1.I edited it. This is my first time here.. 
2.The use of high[1] is not relevant as it is not the right solution.
3.Nobody asked for coding anything , I just asked for a help on a specific and well define problem.
4.I showed my code ( in the relevant part), I guess that is  an attempt, don't you think?

whroeder1
14753
whroeder1 2014.10.13 16:34  
msrron:

3.Nobody asked for coding anything , I just asked for a help on a specific and well define problem.
4.I showed my code ( in the relevant part), I guess that is  an attempt, don't you think?

  1. dosen't provide the right outcome
    nature of your problem is not well defined.
  2. double StopLossSell = High[1] +StopPoints*Point
    Where do you use StopLossSell. No where. No attempt in my book.

msrron
175
msrron 2014.10.14 03:46  
Thanks for the clarification @WHRoeder . I hope that after editing the post things are more clearer.
Carl Schreiber
6670
Carl Schreiber 2014.10.14 07:20  

Still don't really know what you want. A buy-order has to have a SL that is more than MODE_STOPLEVEL*Point lower than the entry.

Do you know OrderModify(..) and the example in the reference?

msrron
175
msrron 2014.10.14 07:47  
Hello @gooly, In the example (picture)  there is a sell order, I would like to know how can I extract the high of the bar before the sell order's bar (Initiation bar) so I'll be able to put the SL few pips above it.
I'll do the oposite for a buy order.
Regarding the  MODE_STOPLEVEL*Point  - I'll learn about it but I suspect that this can be only part of the solution.
Thanks
Ron
Carl Schreiber
6670
Carl Schreiber 2014.10.14 08:02  

look up in the reference:

High[ iBarShift(NULL,0, OrderOpenTime() ) +1 ] + aFewPips;

12
To add comments, please log in or register