Open and Close on Same Bar - EA help
Results 1 to 1 of 1
 2 Attachment(s)    

Thread: Open and Close on Same Bar - EA help

  1. #1
    Junior Member
    Join Date
    Jan 2018
    Posts
    2

    Default Open and Close on Same Bar - EA help

    Hi Guys.

    A while ago I found an old manual trading system based on Percentage Change / Volatility. It was used on M1 in 2010 apparently to good results.
    I have (I am not an experienced coder) made a basic EA that trades using this indicator and has a fixed profit or stoploss etc and a trailing stop.
    It isnt profitable - with the normal trade management but it maybe if i can get it to close on the same bar it triggers open.
    Any help to get it to do what I need would be greatly appreciated!


    The 1st bar is the signal bar, the 2nd is a confirmation bar (in the opposite direction to the signal) and the 3rd bar is entry and exit in the same M! bar!!!
    See pic:



    Open and Close on Same Bar - EA help-3barpc-jpg



    Can someone help with the code?
    Code is as follows - apart from the usual external inputs/variable at the top:


    void OnTick()
    {
    if (OrdersTotal() > 0) {
    TrailStops();
    return;
    }

    double Buffer = OpenCloseBuffer*Point;

    for(int iArr = 0; iArr < nVALUES; iArr++) arr[iArr] = iCustom(NULL,0,"porcentagem",PeriodFactor,2,iArr);




    if ( (arr[2] <= (PVol*-1)) && (Close[1] >= (Close[2]+Buffer) )) {
    if (OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Ask - stopLoss * Point, Ask + takeProfit * Point, "perc order", 12345, 0, Red)) {
    Print("Buy order succeeded!");
    }
    }


    if ( arr[2] >= PVol && (Close[1] <= (Close[2]-Buffer))) {
    if (OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Bid + stopLoss * Point, Bid - takeProfit * Point, "perc order", 12345, 0, Red)) {
    Print("Sell order succeeded!");
    }
    }
    }

    //+------------------------------------------------------------------+
    //| Trailing stop function |
    //+------------------------------------------------------------------+
    void TrailStops()
    {


    double new_stop_loss;


    if(Bid-OrderOpenPrice()>=WhenToTrail*Point)
    {
    if(OrderOpenPrice()-OrderStopLoss()>Point)
    new_stop_loss=OrderOpenPrice();
    else
    new_stop_loss=Bid-WhenToTrail*Point;
    if(new_stop_loss-OrderStopLoss()>=(TrailingStep*Point))
    {
    bool buytstep=OrderModify(OrderTicket(),OrderOpenPrice( ),new_stop_loss,OrderTakeProfit(),0,clrBlue);
    }
    return;
    }

    if(Ask+OrderOpenPrice()<=WhenToTrail*Point)
    {
    if(OrderOpenPrice()+OrderStopLoss()<Point)
    new_stop_loss=OrderOpenPrice();
    else
    new_stop_loss=Ask+WhenToTrail*Point;
    if(new_stop_loss+OrderStopLoss()<=(TrailingStep*Po int))
    {
    bool sellstep=OrderModify(OrderTicket(),OrderOpenPrice( ),new_stop_loss,OrderTakeProfit(),0,clrBlue);
    }
    return;
    }

    }

    //+------------------------------------------------------------------+




    Indicator 'porcentagem.mq4" added below
    Attached Files Attached Files
    Last edited by prophetable; 06-14-2018 at 04:14. Reason: decsription added

Similar Threads

  1. MA4 Open Close
    By jobed in forum Ideas for expert advisors
    Replies: 0
    Last Post: 03-19-2014, 17:42
  2. Close open trade in second.
    By ecity999 in forum Ideas for expert advisors
    Replies: 0
    Last Post: 06-01-2013, 13:31
  3. Close all open trades after every x profit
    By begu in forum MQL programming
    Replies: 1
    Last Post: 04-09-2009, 18:03
  4. How to close open orders?
    By juhanimi in forum MQL programming
    Replies: 0
    Last Post: 03-05-2009, 07:49

Tags for this Thread

100, 2nd, age, ago, arr[2], attach, bar, based, bool, buy, change, close, coder, direction, double, entry, fixed, found, function, guys, iarr, icustom, indicator, inputs, lots, management, manual, manual trading, manual trading system, opposite, percentage, price, print, profit, profitable, red, results, return, return;, sell, sells, signal, stoploss, symbol, system, takeprofit, tick, trades, trading, trading system, trailing, trailingstep, void, volatility

Posting Permissions

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

Open and Close on Same Bar - EA help