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

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

Multiple limit orders in opposite directions 9 replies

Managing your 100 pips trade on both directions (-) or (+) 5 replies

16/10/'07 - Crude oil and Greenback flying in opposite directions. 0 replies

Directions please? :what ive been doing 39 replies

Directions please! 0 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
Tags: Directions in an EA
Cancel

Directions in an EA

  • Post #1
  • Quote
  • First Post: Aug 19, 2012 7:31pm Aug 19, 2012 7:31pm
  •  Finsia
  • | Joined May 2011 | Status: Member | 62 Posts
Hi, I would like to know if is its possible in an EA to have it Buy again after a previous Buy trade has been opened and closed. In other words to buy every time there is a valid condition and not wait for the Sell signal before opening another trade. I am having a difficult time in making an EA take another buy trade in the trend direction after it has opened and closed a buy trade. Due to last direction and current direction.

If this is possible then at least I know its doable. Open on signal change was a way to make it try and take another trade. Though it will open on any subsequent bar whether the trade condition is true or not.

PHP Code
 if (  (OpenOnSignalChange && lastDirection != OP_BUY && curDirection == OP_BUY) 
         || (!
OpenOnSignalChange && curDirection == OP_BUY && TradeCount[OP_BUY] == 0)
         ) {
         
closeTrades(OP_SELL);
         if (
StopLossPips > 0) StopLoss = Ask - StopLossPips * MyPoint; else StopLoss = getZigZagStopLoss(OP_BUY);
         
Lots = getLotSize3( (Ask-StopLoss)/MyPoint );
         
OpenOrder(OP_BUY, Lots, Slippage, StopLoss, TakeProfitPips, "", MagicNumber, 3, Blue);
      } else if ( (
OpenOnSignalChange && lastDirection != OP_SELL && curDirection == OP_SELL)
               || (!
OpenOnSignalChange && curDirection == OP_SELL && TradeCount[OP_SELL] == 0)
               ) {
         
closeTrades(OP_BUY);
         if (
StopLossPips > 0) StopLoss = Bid + StopLossPips * MyPoint; else StopLoss = getZigZagStopLoss(OP_SELL);
         
Lots = getLotSize3( (StopLoss-Bid)/MyPoint );
         
OpenOrder(OP_SELL, Lots, Slippage, StopLoss, TakeProfitPips, "", MagicNumber, 3, Red);
      }
      
lastDirection = curDirection; 
Thanks
  • Post #2
  • Quote
  • Aug 20, 2012 1:14am Aug 20, 2012 1:14am
  •  futurespec
  • Joined May 2011 | Status: If you think I'm mad, I must be mad | 1,058 Posts
If you can write code like that I think that you know it must be possible.

Your code logic is wrong somewhere!

Cannot tell from the snippit but || (!OpenOnSignalChange ..... looks as though it should be || (OpenOnSignalChange
i.e without the "!" (re-looked and not sure about that now).

or maybe change where you are setting lastDirection = curDirection;


M.
If you think I'm mad, I must be mad
 
 
  • Post #3
  • Quote
  • Last Post: Aug 20, 2012 8:56pm Aug 20, 2012 8:56pm
  •  Finsia
  • | Joined May 2011 | Status: Member | 62 Posts
yeah but I can't think of alternatives. The !openonsignalchange is to take a trade before there is a signal change - ie it makes it false. This however opens trades on every bar subsequent regardless if conditions are true. Still working on this...
 
 
  • Platform Tech
  • /
  • Directions in an 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