You didn't post a topic yet. Let us show you how to make your first topic and upload your favorite forex robot. Guide me

Skip to forum content

Hide

IMPORTANT: Recommended Forex Broker!

Avatrade - Scalping: Allowed! Hedging: Allowed! Oppen an Account with Avatrade. - Bonus up to 50% up to €20,000! - Spreads from: 1 PIPs - Leverage up to 400:1 - Minimum deposit $1.

AvaTrade is regulated in Ireland by the Central Bank of Ireland, in Japan by Financial Futures Association and in Australia by ASIC.


Login with Facebook Username:  Password:  Login  |  Register

Registered members can download over 5000 forex robots and over 8000 forex indicators!

Pages 1

You must login or register to post a reply

RSS topic feed

Posts: 3
Please rate this topic
Current rating: 0
Votes: 0

1 (edited by junkstough 2015-04-09 10:54:55)

Topic: Close trade at end of candle

I have tried many different ways to do this, and Im not sure if the simulation part is what throws it off, but for some reason, i cannot get my trades to close at end of bar. I have a simple EA, which initiates a position, and then modifies the order with a SL and TP. All i want is that if the SL or TP is not hit within that bar, then close the trade at end of bar.
Ive tried the following 2 variations....neither works properly.


  if (OrdersTotal() > 0)
        {              
      if ( TimeToStr(TimeCurrent(),TIME_SECONDS) == Time[0])
        {
            OrderSelect(ShortTicket,SELECT_BY_TICKET);
            if(OrderCloseTime() == 0 && ShortTicket > 0)
                    {
                        Closed = OrderClose(ShortTicket,OrderLots(),OrderClosePrice(),0,Red);
                        ShortTicket = 0;
                    }        
            }
        }
 }

    if (Hour() == 0 && Minute() < 2 && OrdersTotal() > 0 && OrderType() == OP_BUY)

{OrderSelect(0,SELECT_BY_POS,MODE_TRADES);

OrderClose(OrderTicket(),OrderLots( ),Bid,5,Green);}

if (Hour() == 0 && Minute() < 2 && OrdersTotal() > 0 && OrderType() == OP_SELL)

{OrderSelect(0,SELECT_BY_POS,MODE_TRADES);

OrderClose(OrderTicket(),OrderLots( ),Ask,5,Yellow);}

Share

 

 

 

Re: Close trade at end of candle

Presumable your order opens at the start of the bar ?

One possible workaround would be to put an expiration time in the OrderSend function

instead of expiration = 0

use

TimeCurrent()+3600

I've used that a few times, although I've read that certain brokers need expiration to be equal to zero.

Share

Re: Close trade at end of candle

Hi, in you second case, you must call OrderSelect before calling OrderType.

Share

Posts: 3

Pages 1

You must login or register to post a reply

Last Posts

  • 20/01: XM.com Introducing broker agreement! Will you get paid?
  • 20/01: RULES OF TRADING
  • 20/01: A highly profitable Ea
  • 20/01: spartan bolt V6
  • 20/01: Wanted to success in option?
  • 20/01: How to select option broker?
  • 20/01: Playing forex successfully by using robot
  • 20/01: Monster Profit Forex Robot
  • 20/01: Real Account versus System Tester.
  • 20/01: how Optimize forex Robot
  • 20/01: AutoProfit set
  • 20/01: Ilan Expert Advisor for Metatrader 4
  • 20/01: which successfull forex robot
  • 20/01: Time and date to play forex successfully
  • 20/01: Successfull signal in playing option
  • 20/01: How to understand how to use the signal in playing option
  • 20/01: You must try on demo account first do not play on real account
  • 20/01: Spartan bolt EA
  • 20/01: Succeed in playing forex
  • 20/01: spartan bolt V3.3-3
  • Hot Topics

  • Profitable Scalper EA Free download!! (598)
  • Scalper_v5 (free) (534)
  • A highly profitable Ea (348)
  • spartan bolt V6 (326)
  • ASSAR v8 (297)
  • Assar_03_EA (296)
  • 2000 pips daily (286)
  • Trade-Arbitrage EA (192)
  • Fap Turbo Expert Advisor is now absolutely free! (174)
  • forex hacked pro (166)
  • Forex Earth Robot (157)
  • xmt scalper (151)
  • Rabbit3 £100 start Zero to Hero Updated EA (139)
  • Forex Math EA free for Mt4 (133)
  • Fracture 7.4.0 (132)
  • high profit EA (130)
  • EA SmartAssTrade. (128)
  • New to forex? (127)
  • Super Signal Scalping Profit Statement (126)
  • Ilan Expert Advisor for Metatrader 4 (121)
  • Popular Topics

  • Profitable Scalper EA Free download!! (47882)
  • Scalper_v5 (free) (21043)
  • A highly profitable Ea (20797)
  • Assar_03_EA (13520)
  • spartan bolt V6 (13092)
  • ASSAR v8 (13061)
  • Trade-Arbitrage EA (11205)
  • xmt scalper (10997)
  • 2000 pips daily (10913)
  • Super Signal Scalping Profit Statement (9917)
  • Fap Turbo Expert Advisor is now absolutely free! (9883)
  • forex hacked pro (9817)
  • Forex Earth Robot (9502)
  • Forex Math EA free for Mt4 (8922)
  • Ilan Expert Advisor for Metatrader 4 (8775)
  • WayGrow EA 1.7 (8655)
  • Fracture 7.4.0 (8578)
  • Rabbit3 £100 start Zero to Hero Updated EA (8152)
  • high profit EA (8015)
  • EA SmartAssTrade. (7980)

  • Forum statistics

     


    By posting a message, you automatically agree to the Forum Rules and Privacy Policy.