Changing code of one of Steves old EA's...

Ask your basic questions confidently here. Flaming is not allowed. Sympathetic help is the order of the day.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Changing code of one of Steves old EA's...

Post by SteveHopwood »

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
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
SpiderX
Trader
Posts: 554
Joined: Thu Aug 22, 2013 4:50 pm

Re: Changing code of one of Steves old EA's...

Post by SpiderX »

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
"Love is patient, love is kind. It does not envy, it does not boast, it is not proud. It does not dishonor others, it is not self-seeking, it is not easily angered, it keeps no record of wrongs.Love does not delight in evil but rejoices with the truth. It always protects, always trusts, always hopes, always perseveres."
-Corinthians 13:4-8
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Changing code of one of Steves old EA's...

Post by SteveHopwood »

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
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
SpiderX
Trader
Posts: 554
Joined: Thu Aug 22, 2013 4:50 pm

Re: Changing code of one of Steves old EA's...

Post by SpiderX »

Thanks Steve,

Looking forward to it.

Cheers
"Love is patient, love is kind. It does not envy, it does not boast, it is not proud. It does not dishonor others, it is not self-seeking, it is not easily angered, it keeps no record of wrongs.Love does not delight in evil but rejoices with the truth. It always protects, always trusts, always hopes, always perseveres."
-Corinthians 13:4-8
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Changing code of one of Steves old EA's...

Post by SteveHopwood »

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
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
SpiderX
Trader
Posts: 554
Joined: Thu Aug 22, 2013 4:50 pm

Re: Changing code of one of Steves old EA's...

Post by SpiderX »

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
"Love is patient, love is kind. It does not envy, it does not boast, it is not proud. It does not dishonor others, it is not self-seeking, it is not easily angered, it keeps no record of wrongs.Love does not delight in evil but rejoices with the truth. It always protects, always trusts, always hopes, always perseveres."
-Corinthians 13:4-8
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Changing code of one of Steves old EA's...

Post by SteveHopwood »

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
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
SpiderX
Trader
Posts: 554
Joined: Thu Aug 22, 2013 4:50 pm

Re: Changing code of one of Steves old EA's...

Post by SpiderX »

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
You do not have the required permissions to view the files attached to this post.
"Love is patient, love is kind. It does not envy, it does not boast, it is not proud. It does not dishonor others, it is not self-seeking, it is not easily angered, it keeps no record of wrongs.Love does not delight in evil but rejoices with the truth. It always protects, always trusts, always hopes, always perseveres."
-Corinthians 13:4-8
HannesJoubert
Trader
Posts: 282
Joined: Wed Oct 30, 2013 11:06 am
Location: South Africa

Re: Changing code of one of Steves old EA's...

Post by HannesJoubert »

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
HannesJoubert
Trader
Posts: 282
Joined: Wed Oct 30, 2013 11:06 am
Location: South Africa

Re: Changing code of one of Steves old EA's...

Post by HannesJoubert »

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?
Post Reply

Return to “EA's for Dummies.”