• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 11:10pm
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 11:10pm
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

Need function to open one order at open of the candle, please 2 replies

Very simple EA open trade at open of next candle 3 replies

How to make EA that send Open Price of Candle for every new candle 5 replies

EA to open trade on Next Candle open (help please) 4 replies

How do I open only 1 buy/sell trade per bar? 10 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
Tags: How to only open 1 new trade per new candle using EA?
Cancel

How to only open 1 new trade per new candle using EA?

  • Post #1
  • Quote
  • First Post: Sep 23, 2021 2:09am Sep 23, 2021 2:09am
  •  Don_xyZ
  • | Joined Dec 2010 | Status: Member | 67 Posts
I'm still learning how to code an EA but I face a challenge while doing it. Here's what I'm trying to achieve...

I want the code to open a trade only if there is no open trade during that specific candle. I do not mind having a new trade opened on every candle (multiple trades running at the same time) but there should not be more than 1 new trade opened per new candle. I tried looking into magic number but a magic number only prevents a double entry so the code below does not solve my problem.

Inserted Code
{
   int openOrders = OrdersTotal();
   
   for(int i = 0; i < openOrders; i++)
   {
      if(OrderSelect(i,SELECT_BY_POS)==true)
      {
         if(OrderMagicNumber() == magicNBforbuy) 
         {
            return true;
         }  
      }
   }
   return false;
}

I also tried time based restriction but this code only allow the EA to execute the code once per candle so this code also does not solve my problem.

Inserted Code
{
   static datetime saved_candle_time;
   if(Time[0]==saved_candle_time)
      return false;
   else
      saved_candle_time=Time[0];
   return true;
   }

Can someone help me with this problem? Please.
Different/opposing ideas will make us learn and understand many things.
  • Post #2
  • Quote
  • Sep 23, 2021 2:31am Sep 23, 2021 2:31am
  •  rockit
  • Joined Oct 2013 | Status: Member | 917 Posts
Quoting Don_xyZ
Disliked
Can someone help me with this problem? Please.
Ignored
Try:

Inserted Code
if(OrderOpenTime(..) >= Time[0]) // you have to select the particular order first..
 return false; // do not trade
..
 
1
  • Post #3
  • Quote
  • Last Post: Sep 23, 2021 6:40am Sep 23, 2021 6:40am
  •  Don_xyZ
  • | Joined Dec 2010 | Status: Member | 67 Posts
Quoting rockit
Disliked
{quote} Try: if(OrderOpenTime(..) >= Time[0]) // you have to select the particular order first.. return false; // do not trade
Ignored
Wow, it works like a charm!

Thanks a billion @rockit!

I wish you have lots of blessings in your trading!
Different/opposing ideas will make us learn and understand many things.
 
 
  • Platform Tech
  • /
  • How to only open 1 new trade per new candle using EA?
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023