stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Flying Slope auto-trading EA
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=680
Page 25 of 28
Author:  SteveHopwood [ Sun Aug 12, 2012 3:39 pm ]
Post subject:  Re: Flying Slope auto-trading EA

pah wrote:The freeze on opening a trade appears to be fixed by adding a return value to the following two lines in LookForTradeClosure()

Code: Select all

if (HtfSlopeTrend == buyhold) return(false);

Code: Select all

if (HtfSlopeTrend == sellhold) return(false);
Regards, Paul.
Nice one. Thanks.

:D
Author:  SteveHopwood [ Sun Aug 12, 2012 3:55 pm ]
Post subject:  Re: Flying Slope auto-trading EA

pah wrote:And now it only trades once which is caused by the check in TooClose()

Code: Select all

if (TimeHour(TimeCurrent()) - TimeHour(OrderCloseTime()) < (MinMinutesBetweenTrades * 60) )
This is checking the hour but could be checking a trade from yesterday for example, which happened to have occurred at an earlier hour.
Another great spot, Paul. Thanks again.

The conditional was completely wrong. I want to check that enough time has elapsed between the closing of one trade and the open of another, so the conditional should be:

Code: Select all

if (OrderCloseTime() - TimeCurrent() < (MinMinutesBetweenTrades * 60))
Also, I'm a bit puzzled by it only checking history here, should it not also be looking at open trades that were taken recently and ensuring it doesn't open another too soon after?

Since it only opens market orders direct (no stop or limit orders) might it not be easier to set a datetime variable called e.g. NextTradeAllowed which you can set when you open a trade ( TimeCurrent() + (MinMinutesBetweenTrades * 60) ) and then disallow any subsequent trades that fire before this time has passed?
Rogue trade behaviour will only become apparent when a trade closes, so we are only concerned with the history of closed trades. The stacking function does not work, so there can only be one open trade at a time. We need to prevent it being sent at all if the previous one was a rogue.

Thanks for your help, Paul. Much appreciated by us all, but especially me.

Version 1k is in post 1 folks, with the appropriate fixes so far. Unless you want to play with strategy tester, you may as well hold on until later, in case anything else crops up.

:D
Author:  pah [ Mon Aug 13, 2012 2:11 am ]
Post subject:  Re: Flying Slope auto-trading EA

SteveHopwood wrote: Nope. The order opened before it closed, so I need to know how soon after its open that it closed.
I'm still pretty sure you want to check OrderCloseTime() - OrderOpenTime(). The close will always occur later than the open and so, open - close will always return a negative value. Do you need a bath? :idea: :)
SteveHopwood wrote:Can you do me a favour, please, and resend me this, or post it here? I don't remember this and it would be most helpful.
I can't find the original but I think this should do what you want - note: I've not tested it in anger...

Code: Select all

bool IsLastTradeClosedRogue()
{
  // look for trades that closed within the last 5 minutes
  // otherwise we will always find the last rogue trade
  // even when that happened some time ago and can be ignored
  
  datetime latest.time = TimeCurrent() - ( 5 * 60 );
  
  datetime duration = -1; //impossible value
  
  for ( int i = OrdersHistoryTotal()-1; i >= 0; i-- )
  {
    if ( ! OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) ) continue;
    
    if ( OrderMagicNumber() != MagicNumber || OrderSymbol() != Symbol() ) continue;
     
    if ( OrderCloseTime() >= latest.time )
    {
      latest.time = OrderCloseTime();
      duration    = OrderCloseTime() - OrderOpenTime();
    }  
  }
  
  bool rogue = ( duration >= 0 ) && ( duration < ( MinMinutesBetweenTradeOpenClose * 60) );
  
  if ( rogue )
  {
    //do your rouge stuff here
  }
 
  return(rogue);
   
}
Author:  pah [ Mon Aug 13, 2012 4:10 am ]
Post subject:  Re: Flying Slope auto-trading EA

SteveHopwood wrote: Rogue trade behaviour will only become apparent when a trade closes, so we are only concerned with the history of closed trades. The stacking function does not work, so there can only be one open trade at a time. We need to prevent it being sent at all if the previous one was a rogue.
I realize that but isn't that dealt with by the rogue trade routine?

I was referring to the TooClose() function which I thought was trying to prevent opening another trade too soon after the last one (whether rogue or not), in which case, the last trade could still be open.

However, if you can only have one open then this point is purely academic...

Regards, Paul.
Author:  SteveHopwood [ Mon Aug 13, 2012 9:34 am ]
Post subject:  Re: Flying Slope auto-trading EA

pah wrote:
SteveHopwood wrote: Nope. The order opened before it closed, so I need to know how soon after its open that it closed.
I'm still pretty sure you want to check OrderCloseTime() - OrderOpenTime(). The close will always occur later than the open and so, open - close will always return a negative value. Do you need a bath? :idea: :)
Nope. I need a firing brain-cell. Obviously you are correct - I was just being dim. In case any of you are wondering why Paul is right, the reason is that Crapql4 counts time forward from Jan 1st 1970, not backwards from now. If any of you have trades in your History tab, the latest version should have shut up shop immediately. Fix coming soon.
SteveHopwood wrote:Can you do me a favour, please, and resend me this, or post it here? I don't remember this and it would be most helpful.
I can't find the original but I think this should do what you want - note: I've not tested it in anger...

Code: Select all

bool IsLastTradeClosedRogue()
{
  // look for trades that closed within the last 5 minutes
  // otherwise we will always find the last rogue trade
  // even when that happened some time ago and can be ignored
  
  datetime latest.time = TimeCurrent() - ( 5 * 60 );
  
  datetime duration = -1; //impossible value
  
  for ( int i = OrdersHistoryTotal()-1; i >= 0; i-- )
  {
    if ( ! OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) ) continue;
    
    if ( OrderMagicNumber() != MagicNumber || OrderSymbol() != Symbol() ) continue;
     
    if ( OrderCloseTime() >= latest.time )
    {
      latest.time = OrderCloseTime();
      duration    = OrderCloseTime() - OrderOpenTime();
    }  
  }
  
  bool rogue = ( duration >= 0 ) && ( duration < ( MinMinutesBetweenTradeOpenClose * 60) );
  
  if ( rogue )
  {
    //do your rouge stuff here
  }
 
  return(rogue);
   
}
Thanks Paul.

:D
Author:  SteveHopwood [ Mon Aug 13, 2012 10:19 am ]
Post subject:  Re: Flying Slope auto-trading EA

Version 1l is in post 1, incorporating Paul's improvements. Also, if suspended because of possible rogue trading, FS will continue to manage open trades.

:D
Author:  jiaxingx [ Sat Aug 18, 2012 3:15 pm ]
Post subject:  Re: Flying Slope auto-trading EA

I run version 1l on demo for one week,
but no trade happen,anyone have trade?
Author:  fxshadow [ Sat Aug 18, 2012 3:23 pm ]
Post subject:  Re: Flying Slope auto-trading EA

jiaxingx wrote:I run version 1l on demo for one week,
but no trade happen,anyone have trade?
Check your screen info and you will probably see that trade conditions were not met.
Author:  gaheitman [ Mon Aug 27, 2012 4:25 pm ]
Post subject:  Re: Flying Slope auto-trading EA

SteveHopwood wrote:Version 1l is in post 1, incorporating Paul's improvements. Also, if suspended because of possible rogue trading, FS will continue to manage open trades.

:D
I haven't been involved in the conversation about Rogue trades, but that's apparently not going to stop me from chiming in... :D

It seems to me an important distinction for a trade to be rogue is that our code closed the trade. If we enter a trade and it is stopped out in a fast moving market it may look like a rogue trade when it was simply an unfortunate one. I think to really catch the rogue behavior we need to have our code check at the time of closure to see if we just opened the trade we are closing. Or, we could do something to track the number of high-frequency trading decisions we have made. For example, if we add two global variables...

Code: Select all

// holds the result of GetTickCount(), set after every call to a OrderClose(), OrderOpen() or
// OrderModify()
int LastTradingDecision = 0;

// number of times we called OrderClose(), OrderOpen(), or OrderModify() when 
// GetTickCount() - LastTradingDecision < HighFrequencyTradeThresholdMilliseconds
int HighFreqCount  = 0;      
Then we can evaluate HighFreqCount and if it is above 2-3, we know that we are trading like maniacs and need to stop. We would reset HighFreqCount to 0 when we make a trading decision that is not within the High Frequency window.

George
Author:  SWG123 [ Mon Aug 27, 2012 9:05 pm ]
Post subject:  Re: Flying Slope auto-trading EA

Welcome back George :)
All times are UTC Page 25 of 28