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

ChangeTheColor EA
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=221
Page 9 of 24
Author:  spyderman [ Tue Jan 17, 2012 10:44 pm ]
Post subject:  Re: ChangeTheColor EA

magft wrote:Ok, this version has the code recommended by George added to it. I cannot test it as i need valid trades and the ATR filter is stopping any at the moment! It you get no trades in ST it is the ATR filter not working correctly, it seems to be a bug in Empty4 as there is plenty of history and still wont report the ATR value correctly so this is stopping the trading. This only effects back testing not forward testing.

Let me know any issues!! :roll:

Mike
New version won't seem to open. Just says "Only Runs on Demo Account" in upper left. I do have it on a demo account. :?

EDIT ___ Nevermind...reloaded previous version and its doing it too. Must be something with my broker Oanda. Maybe it's the day close.
Author:  magft [ Tue Jan 17, 2012 11:00 pm ]
Post subject:  Re: ChangeTheColor EA

spyderman wrote:
magft wrote:Ok, this version has the code recommended by George added to it. I cannot test it as i need valid trades and the ATR filter is stopping any at the moment! It you get no trades in ST it is the ATR filter not working correctly, it seems to be a bug in Empty4 as there is plenty of history and still wont report the ATR value correctly so this is stopping the trading. This only effects back testing not forward testing.

Let me know any issues!! :roll:

Mike
New version won't seem to open. Just says "Only Runs on Demo Account" in upper left. I do have it on a demo account. :?

EDIT ___ Nevermind...reloaded previous version and its doing it too. Must be something with my criminal Oanda. Maybe it's the day close.
Thats is Empty4 for you!! Here is a new version that fixes that (i didnt want anyone trying it on a live account yet but i'll turn that off)and the atr filter issue, you need M1 data for the period of interest at the mo. I have changed this so that it is user specifiable the update interval so for backtesting set to same or previous tf in minutes.

This is still a demo version until we are sure the trade context bit is fixed.

I'm going bed now, have fun.

Mike
Author:  spyderman [ Tue Jan 17, 2012 11:05 pm ]
Post subject:  Re: ChangeTheColor EA

magft wrote:

I'm going bed now, have fun.

Mike
Thanks Mike
Author:  gaheitman [ Wed Jan 18, 2012 7:17 am ]
Post subject:  Re: ChangeTheColor EA

magft wrote:Thats is Empty4 for you!! Here is a new version that fixes that (i didnt want anyone trying it on a live account yet but i'll turn that off)and the atr filter issue, you need M1 data for the period of interest at the mo. I have changed this so that it is user specifiable the update interval so for backtesting set to same or previous tf in minutes.

This is still a demo version until we are sure the trade context bit is fixed.

I'm going bed now, have fun.

Mike
I think you may be allowing too long of a wait for making the trades. For example, looking at the modify section of the BreakEvenStopLoss():

Code: Select all

   if (modify)
   {
      //RetryCount is declared as 10 in the Trading variables section at the top of this file
      for (int cc = 0; cc < RetryCount; cc++)
      {
         for (int d = 0; (d < RetryCount) && TradeIsBusy()<0; d++) Sleep(100);
         result = OrderModify(OrderTicket(), OrderOpenPrice(), NewStop, OrderTakeProfit(), OrderExpiration(), CLR_NONE);      
         if (!result) ReportError();
      }
      // set the trade context free
      TradeIsNotBusy();
   }//if (modify)
TradeIsBusy() will already wait 30 seconds for the semaphore to be available. You have it waiting for a considerably longer period (I got tired multiplying :D ). No doubt that would never happen, but I think this is sufficient:

Code: Select all

      
   if (modify)
   {
      //try to lock the trading thread for our use
      if (TradeIsBusy()<0) {
         Alert("Unable to modify stop loss, wait time exceeded.");
         return;
      }
      
     //ok, we can trade now
      for (int cc = 0; cc < RetryCount; cc++)
      {
         RefreshRates();  //make sure we have updated info
         result = OrderModify(OrderTicket(), OrderOpenPrice(), NewStop, OrderTakeProfit(), OrderExpiration(), CLR_NONE);      
         if (!result) ReportError();
      }
      // set the trade context free
      TradeIsNotBusy();
   }//if (modify)   

The pattern should be:

Lock Resource
Use Resource
Unlock Resource

In this case that's

TradeIsBusy() == 1
{ do some trading -- but do it quickly}
TradeIsNotBusy()

The names aren't very descriptive. What the author means is SetTradeIsBusyFlag() and ClearTradeIsBusyFlag(). It would be better if they were called LockTradingThread() and UnlockTradingThread() or something similar.

I also think you'll want to place a call to TradeIsNotBusy() in deinit().

George
Author:  Iamshakey [ Wed Jan 18, 2012 7:26 am ]
Post subject:  Re: ChangeTheColor EA

Hey guys, Glad to see it going so well. Rob had an excellent equity curve, and we wanted to see if the cycle recovery is sequencing the lot sizes correctly.
I ran a similar back test on the past year, and came up with a similar curve as rob, except for one huge drawdown in 11/11. For some reason, it allowed a 120 pip stop to be hit. This is on strat test, which of course, is pretty crappy, or a random bug. BUT,THE EXCITING THING IS, IT RECOVERED FROM IT. during this recovery, I think with a martingale, the account probably wouldn't have survived.

As for the sequencing, it is still a little off, but almost there. I have included a PDF with a sample of what the current EA is doing, compared to what the Cycle System would have done. Looks like the EA is increasing correctly, but isn't always returning to the ORIGINAL base lot. It may be returning to base lot + 1 base lot instead.

EA doing something like this: 1L 1L 1L 1W 2W 4L 2L 2L 2W 6W 8W
THE CYCLE WOULD BE: 1L 1L 1L 1W 2W 3L (RETURN TO BASE LOT) 1L 1L 1W 4W 5W

The thing is . . . THE EA is working pretty well the way it is. The difference, which the PDF demonstrates, is that drawdown is much smaller with cycle. I really do think cycle system would be safer. BUT, Take a look at the PDF and see what you guys think. Since Mike is the coder, and it's Robs system, it's kind of up to you guys if you want to continue to modify it.

This is really looking good!

Shake
Author:  ROBST3R [ Wed Jan 18, 2012 10:36 am ]
Post subject:  Re: ChangeTheColor EA

Guys try this settings on eur/usd m15

Rob
Author:  magft [ Wed Jan 18, 2012 10:40 am ]
Post subject:  Re: ChangeTheColor EA

George, thanks for the input. I have added your change which makes more sense. I had 4 trades on the go and the EA went into a endless loop! I have also renames the functions to LockTradingThread and UnlockTradingThread as this is what it is doing :D

Shake thanks for the input, i'll have another look at the sequence later on and see if there is something obviously wrong as i do like to have things correct. As you stated it works but doing it correctly would reduce DD and that is what we all want :mrgreen:

I think the EA seems to be ok on lower timeframes with ATRFilter, you need to adjust the MinATR value though, too low and too many crappy trades and too high no trades. I think 10 seems about right for M5 needs increasing for higher timeframes.

Ok, fixed version attached. Once we have tested and are sure it is sending trades correctly and the TS is working as it should i'll update post #1.

Thanks for your help guys with this.

I just watched the EU rocket up, i was in 3 trades so all nice and green :mrgreen: This got me thinking is it worth adding a news filter to stay out of trades or adding CBI module,Steve created a module that is in the shell EA and also a separate EA StuffTheNews on FF, to capture these spikes or close hedge trades in wrong direction?

Regards

Mike
Author:  gaheitman [ Wed Jan 18, 2012 10:55 am ]
Post subject:  Re: ChangeTheColor EA

magft wrote:George, thanks for the input. I have added your change which makes more sense. I had 4 trades on the go and the EA went into a endless loop! I have also renames the functions to LockTradingThread and UnlockTradingThread as this is what it is doing :D

Mike
Very exciting stuff! It will be nice when ERR_TRADE_CONTEXT_BUSY goes away for good! :D

I did a quick review of the changes, and you still need to update the code for SendSingleTrade() and ModifyOrder(). They both have the LockTradingThread() call as a direct replacement for IsTradeContextBusy(). When you do the SendSingleTrade() procedure, be sure to include the ECN Version of the calls. Right now they aren't in the Lock/Unlock section at all!

So, did you sleep at all last night? :>

George
Author:  magft [ Wed Jan 18, 2012 11:05 am ]
Post subject:  Re: ChangeTheColor EA

gaheitman wrote:
magft wrote:George, thanks for the input. I have added your change which makes more sense. I had 4 trades on the go and the EA went into a endless loop! I have also renames the functions to LockTradingThread and UnlockTradingThread as this is what it is doing :D

Mike
Very exciting stuff! It will be nice when ERR_TRADE_CONTEXT_BUSY goes away for good! :D

I did a quick review of the changes, and you still need to update the code for SendSingleTrade() and ModifyOrder(). They both have the LockTradingThread() call as a direct replacement for IsTradeContextBusy(). When you do the SendSingleTrade() procedure, be sure to include the ECN Version of the calls. Right now they aren't in the Lock/Unlock section at all!

So, did you sleep at all last night? :>

George
Yes, i over slept! The 2yr twins both woke several times in the night so i am taking a while to get up to speed today :?

I have added the ECN bit to the Modify order part so it locks and unlocks in there, i tried it outside as you suggested and i found i had several trades with no sl set! Running EU on 6 tfs today is proving useful for testing as i can watch M5 trades in between M15 trades and every half hr and hr M30 and H1 kick in as well. Quite a profitable morning on EU. I'll keep testing and see how it goes.

Thanks

Mike
Author:  gaheitman [ Wed Jan 18, 2012 11:35 am ]
Post subject:  Re: ChangeTheColor EA

magft wrote:Yes, i over slept! The 2yr twins both woke several times in the night so i am taking a while to get up to speed today :?

I have added the ECN bit to the Modify order part so it locks and unlocks in there, i tried it outside as you suggested and i found i had several trades with no sl set! Running EU on 6 tfs today is proving useful for testing as i can watch M5 trades in between M15 trades and every half hr and hr M30 and H1 kick in as well. Quite a profitable morning on EU. I'll keep testing and see how it goes.

Thanks

Mike
Mike,

Here's another crazy idea, how about we provide wrapper functions that replicate OrderSend() and OrderModify() that include the locking code. Then they would be drop-ins for existing EAs. Something like:

Code: Select all

int _OrderSend(string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment="", int magic=0, datetime expiration=0, color arrow_color=CLR_NONE) {

   int res = -1;
   
   //try to lock resource
   if (LockTradingThread()<0) {
      Alert("Unable to place trade, timeout exceeded.");
      return(res);
   }
   RefreshRates();
 
   //place trade
   res = OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment, magic, expiration, arrow_color);
   
   //unlock resource
   UnlockTradingThread();
   return(res);
}

bool _OrderModify( int ticket, double price, double stoploss, double takeprofit, datetime expiration, color arrow_color=CLR_NONE) {

   bool res = false;
   
   //try to lock resource
   if (LockTradingThread()<0) {
      Alert("Unable to modify trade, timeout exceeded.");
      return(res);
   }
   RefreshRates();
   
   //modify order
   res = OrderModify(ticket, price, stoploss, takeprofit, expiration, arrow_color);
   
   //unlock resource
   UnlockTradingThread();
   return(res);
}
Then you change all the calls to OrderSend() and OrderModify() to _OrderSend() and _OrderModify(). The only bad part is we would lose the error number for the trade if there is also an error updating the global variable.

Just a thought (as always :D ).

George
All times are UTC Page 9 of 24