molanis.com/forum - Tools for MetaTrader : The place to ask about the best expert advisor builder, expert advisor downloads, and expert advisor programming

AFTER YOU REGISTER SEND US AN EMAIL TO ACTIVATE YOUR ACCOUNT - Before posting:-1- Please read the user guide -2- Try the examples -3- Search in the forum
It is currently Mon May 13, 2024 5:29 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Best Way to Close on TP Current Candle using SB
PostPosted: Sat Aug 17, 2013 8:38 pm 
Offline

Joined: Mon Dec 26, 2011 5:41 am
Posts: 46
Hi,

While the current candle is being formed, it has an open, while the close is not known.

I am trying to get EA to close from current candle as it reaches a built in take profit. At times while the current candle is forming, it reaches it and goes over the TP, but EA won't close the trade.

I can't use open[0] to close at TP, close[0] won't work either as it works only at the same instant the next candle starts forming, and EA detects close[0] to be above TP.

If I use high[0] for BUY, and low[0] for SELL, will this close at TP on current ?

I will experiment to see on demo, but an answer would help as well.

Thank You.


Top
 Profile  
 
 Post subject: Re: Best Way to Close on TP Current Candle using SB
PostPosted: Sun Aug 18, 2013 5:02 pm 
Offline

Joined: Tue Dec 22, 2009 12:22 am
Posts: 1761
If you trade bars, the trade takes place at the open so all info that uses shift 0 or current bar is calculated with the first tick. Thus at that point close=open=high=low. if you trade ticks then is ok.

The tp is executed by the server and not by the ea. If you want to use TAs to close trades, or CL, CS icons as a simulated TA and you want to use the current bar you should trade all ticks


Top
 Profile  
 
 Post subject: Re: Best Way to Close on TP Current Candle using SB
PostPosted: Sun Aug 18, 2013 9:11 pm 
Offline

Joined: Mon Dec 26, 2011 5:41 am
Posts: 46
Quote:
If you want to use TAs to close trades, or CL, CS icons as a simulated TA and you want to use the current bar you should trade all ticks


so I use completed bars set to false, and I can use High[0] for buy to use CL, and Low[0] for sell to use CS to close short.

Only issue I have now is trading diagram use MQL with the condition with to the CL or CS block. However in expert log, if no trade is opened by specific MQL conditions for the BUY or SELL, and the conditions is met for TP occurs, it still sends the CLOSELONG() or CLOSESHORT() when it's not needed.

So cleaner way is to really check are there any trades running then run such TP conditions, to execute CL or CS. I can't see how to check for any open positions from SB trading diagrams with the blocks given, other than going in code and perhaps doing something along those lines where the MQL code block for such CS or CL occurs

Quote:

if (CalculateOpenPositions(Symbol(),OP_SELL,MagicNumberShort)>=0) {

if ( MQL CODE BLOCK AT TP ) { CLOSESHORT(Symbol()) ;}
}

if (CalculateOpenPositions(Symbol(),OP_BUY,MagicNumberLong)>=0) {

if ( MQL CODE BLOCK AT TP ) { CLOSELONG(Symbol()) ;}
}



Top
 Profile  
 
 Post subject: Re: Best Way to Close on TP Current Candle using SB
PostPosted: Tue Aug 20, 2013 8:29 am 
Offline

Joined: Tue Dec 22, 2009 12:22 am
Posts: 1761
Just to avoid confussing people here. A normal TP is set one the Buy and Sell icons. It is executed by the server when the right price is reached. In this post the strategy requires to close positions when another condition takes place. For that you use the CS and CL icons.
When you use CS and CL it does not matter if they are no positions. If you tell the ea close longs and there are no longs, the ea will tell you closing longs, and then it will not close any position because there are no positions. There is no need to see if there are existing positions. If you do, the final result will be the same (with less info on the logs)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by Molanis © 2009