Results 1 to 6 of 6
 0 Attachment(s)    

Thread: Open orders on current price plus x pips

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    22

    Default Open orders on current price plus x pips

    Hi,
    I'm trying to open orders based on current price.
    so, should be some thing like,
    if Bid > distance*point open Buy
    if Bid < Distance*point open Sell
    Could anyone show the right method to do this?

    Luis
    Last edited by luisneves; 12-07-2012 at 13:50.

  2. #2

    Default

    Hi Luis,

    You are on the right track but there are a lot of other things you also need to address...Normally I do this first:

    AskStart = NormalizeDouble((Ask),4);

    BidStart=NormalizeDouble((Bid),4);

    center =((AskStart+BidStart)/2);

    Now center is the value I use for my next operations.

    Then I set a GlobalVariable in case computer restarts it doesn't start trading wildly.

    GlobalVariableSet ("center",center);

    Then I trade based on:

    if(GlobalVariableGet("center")>(Ask+Distance))

    What you are asking is very basic...

    Bill

  3. #3
    Junior Member
    Join Date
    Dec 2009
    Posts
    22

    Default

    Hi Bill,
    Before all thank you for your prompt response to my issue.

    int init ()
    {
    if (Digits ==3 || Digits == 5) pt=10*Point;
    else pt=Point;

    AskStart=NormalizeDouble((Ask),2);
    BidStart=NormalizeDouble((Bid),2);
    center=((AskStart+BidStart)/1);
    GlobalVariableSet("center",center);

    start()

    if(GlobalVariableGet("center")>(Ask+Distance*pt))
    {
    if(martingale)ilots=mlots;else ilots=lots;
    ticket=OrderSend(Symbol(),OP_BUY,ilots,Ask,0,Ask-StopLoss*pt,Ask+TakeProfit*pt,"Market order",MagicNumber,0,Green);
    if(ticket>0)

    And seems that is working fine nevertheless some inconsistency running on mt4 tester !!!

    Could you tell why you use "4" ?

    Luis
    Last edited by luisneves; 12-06-2012 at 22:12.

  4. #4

    Default

    Hi Luis,
    Only to limit the size of the result. You can do this other ways too. It really depends on personal preference how to limit. Also be careful when you use GlobalVariable in tester... it will set actual registers of Metatrader.. so if you have actual trading with same GlobalVariables it will write to them also. It is a little known problem, but none the less very dangerous. That could be the reason you see problems or inconsitency. Clear/delete the GlobalVariables in the beginning may solve your problems.
    Bill
    Last edited by BillR; 12-07-2012 at 00:01.

  5. #5
    Junior Member
    Join Date
    Dec 2009
    Posts
    22

    Default

    Hi Bill,

    Yes you are right, Sorry to take your time with my ignorance (...)

    If I'm not taking your time I have more two issues;

    Say that instead of using a takeprofit is that possible to get a kind of trailing stop that moves a stop line to protect a minimum profit ?

    I explain, say that I want a minimum profit of 10 pips above the open, once the price picks those 10 pips level a stop goes next to 8 pips above the open but just close the order if the price bounces back from the 10 pips level and hits the 8 pips level. With that if price goes up from the 10 pips line then the stop line goes 2 pips under the price all the way up. I already put the code for a break even but can't achieve what I need.

    How could I open an opposite order if the order that still open not pick the minimum profit?
    For example, say that a Buy order is open and before the price reach the minimum profit of 10 pips the price bounces back and when it comes under the orderopenprice a Sell order will open but the Buy must still open as well. Here, this Sell order will open with a larger lot size to compensate for the loss of the
    last order ( the Buy that still open) and when the Sell order hits the minimum take profit all open orders should be closed.

    Thank you in advance

    Luis
    Last edited by luisneves; 12-07-2012 at 11:52.

  6. #6

    Default

    Hi Luis,
    Yes, both are possible and done all the time... I think you should look at the Metatrader web site and get more info about the code and concepts... If you are learning code, find an EA that actually does what you are hoping to do an the study the code itself for ideas how you can do.

Similar Threads

  1. Opening at price and alternating orders
    By luisneves in forum MQL programming
    Replies: 0
    Last Post: 01-15-2013, 11:15
  2. Replies: 0
    Last Post: 09-14-2010, 14:14
  3. Open & Close Orders after x pips
    By f1trader in forum Ideas for expert advisors
    Replies: 5
    Last Post: 08-15-2010, 23:18
  4. How to close open orders?
    By juhanimi in forum MQL programming
    Replies: 0
    Last Post: 03-05-2009, 08:49

Tags for this Thread

how to, magic, martingale, metatrader, mt4, pips, stop, stoploss, study, thank you, time, trading, trailing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •