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

Changing code of one of Steves old EA's...
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=3227
Page 3 of 4
Author:  SteveHopwood [ Thu Oct 31, 2013 4:35 pm ]
Post subject:  Re: Changing code of one of Steves old EA's...

SpiderX wrote:Hi Steve,

I am trying to modify your new file to the original logic.

Code: Select all

void GetCandleDirection()
{
   //Called at the start of each new candle.
   //Sets CandleDirection to up, down, none depending on the direction of the previous candlesitck
   
   CandleDirection = none;
   if (Close[1] > Open[1]) 
      if (Close[2] > Open[2]) 
         CandleDirection = up;
   
   if (Close[1] < Open[1]) 
      if (Close[2] < Open[2]) 
         CandleDirection = down;

}//void GetCandleDirection()
Is this the only portion that i need to edit ?

Cheers
Yes. Remove the [2] lines. Sing out if you have a problem.

:D
Author:  SpiderX [ Fri Nov 01, 2013 12:52 am ]
Post subject:  Re: Changing code of one of Steves old EA's...

Hi Steve,

Not sure if i missed out something, but so far on the EA there is only selling and no buying.

Edit:

1. Looking at the code under LookingForTradingOpportunities:

Code: Select all

   //Long 
   if (!UseRsi) RsiTrend = up;
   if (CandleDirection == up && RsiTrend == up)
   {
      SendLong = true;
      //Opposite direction trades
      if (TradeOppositeOfTrigger)
      {
         SendShort = true;
      }//if (TradeOppositeOfTrigger)
      
   }//if (CandleDirection == up)
   

   //Short   
   if (!UseRsi) RsiTrend = down;
   if (CandleDirection == down && RsiTrend == down)
   {
      if (TakeProfit > 0) take = NormalizeDouble(Bid - (TakeProfit * Point), Digits);
      if (StopLoss > 0) stop = NormalizeDouble(Bid + (StopLoss * Point), Digits);
      type = OP_SELL;
      price = Bid;
      SendTrade = true;
      //Opposite direction trades
      if (TradeOppositeOfTrigger)
      {
         if (TakeProfit > 0) take = NormalizeDouble(Ask + (TakeProfit * Point), Digits);
         if (StopLoss > 0) stop = NormalizeDouble(Ask - (StopLoss * Point), Digits);
         type = OP_BUY;
         price = Ask;
      }//if (TradeOppositeOfTrigger)
   }//if (CandleDirection == down && RsiTrend == down)
Would like to check, should the code of the long and short direction be similar ?
It seems the short side code has more material than the long.
Is this correct ?

2. Even though this bug has not emerged yet, but it seems that the EA does not take into consideration TradeOppositeOfTrigger for the closure of trades.
Closure of trade looks to be correct only for the existing logic.
There seems to be a need for additional code in trade closure to take opposite of trigger into account.

Please correct me if the above is wrong as i am much less familiar with the code than you.

Cheers
Author:  SteveHopwood [ Fri Nov 01, 2013 9:51 am ]
Post subject:  Re: Changing code of one of Steves old EA's...

SpiderX wrote:Hi Steve,

Not sure if i missed out something, but so far on the EA there is only selling and no buying.

Edit:

1. Looking at the code under LookingForTradingOpportunities:

Code: Select all

   //Long 
   if (!UseRsi) RsiTrend = up;
   if (CandleDirection == up && RsiTrend == up)
   {
      SendLong = true;
      //Opposite direction trades
      if (TradeOppositeOfTrigger)
      {
         SendShort = true;
      }//if (TradeOppositeOfTrigger)
      
   }//if (CandleDirection == up)
   

   //Short   
   if (!UseRsi) RsiTrend = down;
   if (CandleDirection == down && RsiTrend == down)
   {
      if (TakeProfit > 0) take = NormalizeDouble(Bid - (TakeProfit * Point), Digits);
      if (StopLoss > 0) stop = NormalizeDouble(Bid + (StopLoss * Point), Digits);
      type = OP_SELL;
      price = Bid;
      SendTrade = true;
      //Opposite direction trades
      if (TradeOppositeOfTrigger)
      {
         if (TakeProfit > 0) take = NormalizeDouble(Ask + (TakeProfit * Point), Digits);
         if (StopLoss > 0) stop = NormalizeDouble(Ask - (StopLoss * Point), Digits);
         type = OP_BUY;
         price = Ask;
      }//if (TradeOppositeOfTrigger)
   }//if (CandleDirection == down && RsiTrend == down)
Would like to check, should the code of the long and short direction be similar ?
It seems the short side code has more material than the long.
Is this correct ?

2. Even though this bug has not emerged yet, but it seems that the EA does not take into consideration TradeOppositeOfTrigger for the closure of trades.
Closure of trade looks to be correct only for the existing logic.
There seems to be a need for additional code in trade closure to take opposite of trigger into account.

Please correct me if the above is wrong as i am much less familiar with the code than you.

Cheers
The code isn't quite right. Using opposite direction would leave the ea wanting to send both long and short trades. I will have a look later.

:D
Author:  SpiderX [ Sat Nov 02, 2013 6:01 am ]
Post subject:  Re: Changing code of one of Steves old EA's...

Thanks Steve,

Looking forward to it.

Cheers
Author:  SteveHopwood [ Sat Nov 02, 2013 3:31 pm ]
Post subject:  Re: Changing code of one of Steves old EA's...

Hehe. Not sure what I was on when I coded the updated version. :oops:

I have hijacked the bottom of Hannes op and uploaded V 1a to post 1.

:D
Author:  SpiderX [ Sat Nov 02, 2013 4:14 pm ]
Post subject:  Re: Changing code of one of Steves old EA's...

Thanks Steve,

By the way, i observed that the code could be more efficient in some places, if "if..else" is used, instead of just "if ...if...if"

Just for example:

Code: Select all

if(type == OP_BUY)
     do  x;

if(type == OP_SELL)
    do   y;
might be better as:

Code: Select all

if(type == OP_BUY)
     do  x;

else if(type == OP_SELL)
    do   y;
In this way, we are clear that only one of them can trigger at one time (great for debugging and error proofing), also code would be more efficient.
I was wondering if there was something buggy with "if..else" that leads to "if...if..if..if".

Cheers
Author:  SteveHopwood [ Sat Nov 02, 2013 4:22 pm ]
Post subject:  Re: Changing code of one of Steves old EA's...

SpiderX wrote:Thanks Steve,

By the way, i observed that the code could be more efficient in some places, if "if..else" is used, instead of just "if ...if...if"

Just for example:

Code: Select all

if(type == OP_BUY)
     do  x;

if(type == OP_SELL)
    do   y;
might be better as:

Code: Select all

if(type == OP_BUY)
     do  x;

else if(type == OP_SELL)
    do   y;
In this way, we are clear that only one of them can trigger at one time (great for debugging and error proofing), also code would be more efficient.
I was wondering if there was something buggy with "if..else" that leads to "if...if..if..if".

Cheers
I was just looking through some code by one of our highly respected pro coders and saw lots of instances of what you describe. Thanks for the explanation.

:D
Author:  SpiderX [ Sun Nov 03, 2013 5:12 am ]
Post subject:  Re: Changing code of one of Steves old EA's...

Hi Steve, Hannes,

Uploaded v1a with original favour here for convenience.

Also made some of the minor optimizations which i mentioned.

The changes were made to the following lines in scite:
662, 687-691, 735, 742, 748
766, 773, 1118, 1154, 1405
1427, 1470, 1631, 1652
1667, 1677, 1717, 1720, 1724
1727, 1749, 1769-1771, 1782
1790-1792, 1802, 1863, 1907
2016, 2085, 2097, 2142, 2156
2185, 2200, 2240, 2265, 2389
2485, 2541, 2684, 2949, 2974

I placed the line positions here for you to review if you are free.
Probably it is worth considering adding the above" upgrades" to the shell code.

The only question that needs to be asked at each of these points are:
"If A executes, does that mean that B will NEVER EVER execute ?"

If the answer is yes, then it strongly justifies putting in the "else if", to make sure that never happens no matter what the circumstance is.

Probably you can find more places for enhancements than me.

Cheers
Author:  HannesJoubert [ Mon Nov 04, 2013 9:18 am ]
Post subject:  Re: Changing code of one of Steves old EA's...

Hi there Steve, Spider, everyone else :mrgreen:

Of course I missed the moves on Friday afternoon as I was waiting for the VPS to be setup, but that is the kind of move that I am looking to take advantage of.

So, I have set up the VPS over the weekend, and have installed the EA and pulled the trigger...So now we wait. Will keep you up to date on performance.

Many thanks for your input and help with the coding..

Cheers

H
Author:  HannesJoubert [ Mon Nov 04, 2013 9:49 am ]
Post subject:  Re: Changing code of one of Steves old EA's...

Hmm, the EA closed a sell trade after two bull candles, but did not open a long trade as a result of the two bull candles...i.e. the sell trade should have closed and the long trade opened immediately (hence, always in moniker)...

Does the code read like that?

Yes, I did download the newest version of the EA, after Spider pointed out that the EA only sells and does not buy...Is it possible that the bug is not yet fixed?
All times are UTC Page 3 of 4