zhengzuodong:
I made this off the top of my head. So it will need to be tested. But this would be my 1st attempt at integrating the use of ATR for SL.
Please make any corrections you see fit. Again, if interested, I can send you my copy which will have the HardTP added to it with the ATR recalculation as well.
According to the forum the ATR can be used to provide the following:
SL= 1/2 ATR
I will assume a period of 14 days, I couldn't find where period is specified.
-----------So here are the additions that I would make to the code----------------
Declare and add in Init() function new variable pointz, that takes care of both 3 and 5 digit brokers, will be used later.
Code: Select all
double pointz;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
pointz=Point;
if (Digits==3 || Digits==5) pointz = 10 * pointz;
//---
return(INIT_SUCCEEDED);
}
Add variable Use_ATR to input section
Code: Select all
extern double EquityPercent = 0.2;
extern bool Use_ATR = true; // If set true then HardSL and HardTP are calculated using ATR
extern double HardSL = 45.0;
Add calculation of SL based on ATR right before checking for 1st Candle:
Code: Select all
//+--------- if 'Use_ATR' is true then use 1/2 ATR as SL----------------
if(Use_ATR) {
HardSL=(iATR(Symbol(),PERIOD_D1,14,0)/pointz)*0.5;
}
//+------Open a order at end of 1th h1 bar(or start of 2th h1 bar)
if(TimeHour(TimeCurrent())==TimeHour(LOTinBroker)+1)
I looked into the Murray approach but it was not clear on how to use it. Based on what I saw, looks like the author is going long if price is above the pivot and short if price is below. Is that corrrect?
I'll implement the ATR feature on my copy and test it later on.
Hope this helps... take care
Jess
xmess777@yahoo.com