Jump to content

[REQ] EA for modifying SL to previous swing low/high


konorti

Recommended Posts

  • 3 weeks later...

Re: [REQ] EA for modifying SL to previous swing low/high

 

Hi konorti,

 

Good day,

 

I'm not sure if I can do that or not, but I can try that if you like whenever I have time. what do you think??

 

sorry for the late reply.

 

Please let me know whenever you can.

 

Best wishes,

a New Year 2011 has come, and the challenge has just started 8-)
Link to comment
Share on other sites

Re: [REQ] EA for modifying SL to previous swing low/high

 

Does anybody has an EA for modifying the SL to previous swing high/low? I just want to trail my manual trades this way.

Probably zigzag or fractal indi could be used.

thanks

 

Mate,

 

Everything (I believe) you need to know on trailing with code samples (trailing by last swings, fractals etc.) is here:

http://codebase.mql4.com/ru/1101

 

Use Google Translator, it's all written by Russian in Russian, no English version.

 

Have a great day! :)

Link to comment
Share on other sites

Re: [REQ] EA for modifying SL to previous swing low/high

 

To look for the swings in code, the easiest method I could think of was to check for the lack of a new high/low starting from the current bar and back.

 

extern int LackOfNewPeak = 10;
int CheckBars = 20;

double previousPeak(int cmd)
{
  int j = 0;
  int shift = 0;
  double peak = 0;
  if (cmd == OP_BUY) {
     peak = 2 * Ask;
  }
  while(j < LackOfNewPeak) {
     if (cmd == OP_BUY) {
        if (peak > iLow(Symbol(), timeframe, iLowest(Symbol(), timeframe, MODE_LOW, CheckBars, shift))) {
           peak = iLow(Symbol(), timeframe, iLowest(Symbol(), timeframe, MODE_LOW, CheckBars, shift));
           j = 0;
        }
        else {
           j++;
        }
     }
     else if (cmd == OP_SELL) {
        if (peak < iHigh(Symbol(), timeframe, iHighest(Symbol(), timeframe, MODE_HIGH, CheckBars, shift))) {
           peak = iHigh(Symbol(), timeframe, iHighest(Symbol(), timeframe, MODE_HIGH, CheckBars, shift));
           j = 0;
        }
        else {
           j++;
        }
     }
     shift++;
  }
  return(peak);
}

 

Say you need the previous low swing. The above code will return the lowest value that has the previous 10 bars higher than it.

 

Note that the code is copied from an EA I wrote, pasted in the browser and modified here so it is entirely possible that it won't compile. If you pass it OP_BUY, it'll return the low swing, if you pass OP_SELL it'll return the high swing.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...