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 20, 2024 10:10 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: buy and sell at the same time only when no existing trade
PostPosted: Wed Jan 22, 2014 10:52 pm 
Offline

Joined: Wed May 22, 2013 8:07 pm
Posts: 7
Hello molanis forum,

I would like my EA to open a buy and sell position at the same time but only when no existing trades (regardless if the existing trade is a buy or sell) is open.

Eg. when price is above bollinger band dev 2, buy with take profit of 50 pips and stop loss 10 and sell at the same time with take profit 10 pips and stop loss of 10 pips.

the sell trade is used to hedge the buy trade.

Lets say the buy trade is still open and has made 20 pips and the sell trade has hit the stop loss. If the price goes above bollinger band dev 2 again, i do not want it to trigger another sell/buy trade until the existing buy trade has closed.

Is it possible to create this on molanis? I have looked at "next trade management" feature and i don't think it will work in this situation. I have made the other parts of the EA work, but i can't stop it from opening new trades when the existing one is still open.

Thanks for your help


Top
 Profile  
 
 Post subject: Re: buy and sell at the same time only when no existing trade
PostPosted: Mon Jan 27, 2014 3:03 am 
Offline

Joined: Wed May 22, 2013 8:07 pm
Posts: 7
I know Molanis doesn't like it when people fiddle with the code, however,
I kind of figured out how to do it, so I thought I would share with those who may look it up in the future (especially since a few people had a look at the topic).

It does not involve using Molanis, instead I changed the EA Mql4 code. I am not an expert in coding so if anybody has a better suggestion or if this is incorrect, please say so. As always, make sure you try it out on demo first.

I added this into the EA code:

int start(){

//manage open orders here

if (OrdersTotal() > 0){
return(0);
}

//open new orders here

}

This checks how many orders are already open. So if there is more than 0 orders open, (regardless if they are buy or sell orders) then it will not open new orders. If you want a buy and sell order to be happening at the same time, then the setting for "hedge" must be "true" and the broker must allow it.


Top
 Profile  
 
 Post subject: Re: buy and sell at the same time only when no existing trade
PostPosted: Mon Jan 27, 2014 10:32 am 
Offline

Joined: Tue Dec 22, 2009 12:22 am
Posts: 1761
"open a buy and sell position at the same" just to be clear 2 trades cannot be opened at exactly the same time. You will have a difference of 1 second or less between trades
You can open the 2 trades if you turn hedging on in the start icon and set the number of max trades to 2 (mind you, if you do not use overlapping conditions you may end up with 2 long or 2 short trades)

I think this is not possible "Lets say the buy trade is still open and has made 20 pips and the sell trade has hit the stop loss. If the price goes above bollinger band dev 2 again, i do not want it to trigger another sell/buy trade until the existing buy trade has closed." because cannot create a condition like if trade a was closed with at least 20 pips profit and trade b was closed with a stop loss... You need a custom development to create that logic that is quite complex


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 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