Topic: Possible to modificate 2 Strategies in one without protfolio
Hi,
i have tried to put from 2 generated ea strategies one. Have someone an idea? I checked and get problems with Copybuffer
Create and Test Forex Strategies
You are not logged in. Please login or register.
Forex Software → Expert Advisor Modifications → Possible to modificate 2 Strategies in one without protfolio
Hi,
i have tried to put from 2 generated ea strategies one. Have someone an idea? I checked and get problems with Copybuffer
I have now checked if it it possible to create 1 strategy of two generated strategys.
If someone have an Idea how to handle the different Take Profits and Stop losses it would be great!
Here are the works i done yet.
//Parameters for Strategy 1
[b]input bool EnableStrategy1 = true; //Enable/Disable Strategy 1[/b]
static input string Ind0 = "------------";// ----- Momentum -----
input int Ind0Param0 = 38; // Period
input double Ind0Param1 = 99.9995; // Level
static input string Ind1 = "------------";// ----- Money Flow Index -----
input int Ind1Param0 = 45; // Period
input int Ind1Param1 = 20; // Level
static input string Ind2 = "------------";// ----- Moving Averages Crossover -----
input int Ind2Param0 = 16; // Fast MA period
input int Ind2Param1 = 43; // Slow MA period
static input string Ind3 = "------------";// ----- Standard Deviation -----
input int Ind3Param0 = 48; // Period
input double Ind3Param1 = 0.0025; // Level
[b]//Parameters for Strategy 2
input bool EnableStrategy2 = true; //Enable/Disable Strategy 2
static input string s2Ind0 = "------------";// ----- Bollinger Bands -----
input int s2Ind0Param0 = 27; // Period
input double s2Ind0Param1 = 3.21; // Deviation
static input string s2Ind1 = "------------";// ----- Williams' Percent Range -----
input int s2Ind1Param0 = 43; // Period
input int s2Ind1Param1 = -36; // Level[/b]
added this
int ind0handler;
int ind1handler;
int ind2handler;
int ind21handler;
int ind3handler;
//S2
int s2ind0handler;
int s2ind1handler;
In OnInit() added the handler of the other strategy
int OnInit()
{
barTime = Time(0);
digits = (int) SymbolInfoInteger(_Symbol, SYMBOL_DIGITS);
pip = GetPipValue(digits);
stopLevel = (int) SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL);
orderFillingType = GetOrderFillingType();
isTrailingStop = isTrailingStop && Stop_Loss > 0;
ind0handler = iMomentum(NULL,0,Ind0Param0,PRICE_CLOSE);
ind1handler = iMFI(NULL,0,Ind1Param0,VOLUME_TICK);
ind2handler = iMA(NULL,0,Ind2Param0,0,MODE_SMA,PRICE_CLOSE);
ind21handler= iMA(NULL,0,Ind2Param1,0,MODE_SMA,PRICE_CLOSE);
ind3handler = iStdDev(NULL,0,Ind3Param0,0,MODE_SMA,PRICE_CLOSE);
[b] //s2
s2ind0handler = iBands(NULL,0,Ind0Param0,0,Ind0Param1,PRICE_CLOSE);
s2ind1handler = iWPR(NULL,0,Ind1Param0); [/b]
return (INIT_SUCCEEDED);
}
The Onbar function i changed like this
void OnBar()
{
UpdatePosition();
if(posType!=OP_FLAT && IsForceSessionClose())
{
ClosePosition();
return;
}
if(IsOutOfSession())
return;
if(posType!=OP_FLAT)
{
[b] if(EnableStrategy1==true)
{
ManageClose();
UpdatePosition();
}[/b]
[b] if(EnableStrategy2==true)
ManageClose2();
UpdatePosition();
}
[/b]
if(posType!=OP_FLAT && isTrailingStop)
{
double trailingStop=GetTrailingStop();
ManageTrailingStop(trailingStop);
UpdatePosition();
}
if(posType==OP_FLAT)
{
[b] if(EnableStrategy1==true)
{
ManageOpen();
UpdatePosition();
}[/b]
[b] if(EnableStrategy2==true)
{
ManageOpen2();
UpdatePosition();
}[/b]
}
}
than i make a ne funtion called ManageOpen2
void ManageOpen2()
{
double s2ind0buffer0[]; CopyBuffer(s2ind0handler,1,1,2,s2ind0buffer0);
double s2ind0buffer1[]; CopyBuffer(s2ind0handler,2,1,2,s2ind0buffer1);
double s2ind0upBand1 = s2ind0buffer0[1];
double s2ind0dnBand1 = s2ind0buffer1[1];
double s2ind0upBand2 = s2ind0buffer0[0];
double s2ind0dnBand2 = s2ind0buffer1[0];
bool s2ind0long = Open(0) > s2ind0upBand1 + sigma && Open(1) < s2ind0upBand2 - sigma;
bool s2ind0short = Open(0) < s2ind0dnBand1 - sigma && Open(1) > s2ind0dnBand2 + sigma;
bool s2canOpenLong = s2ind0long;
const bool s2canOpenShort = s2ind0short;
if(s2canOpenLong && s2canOpenShort) return;
if(s2canOpenLong)
OpenPosition(OP_BUY);
else if(s2canOpenShort)
OpenPosition(OP_SELL);
}
and a new ManageClose function:
void ManageClose2()
{
double s2ind1buffer[]; CopyBuffer(s2ind1handler,0,1,3,s2ind1buffer);
double s2ind1val1 = s2ind1buffer[2];
double s2ind1val2 = s2ind1buffer[1];
bool s2ind1long = s2ind1val1 > s2Ind1Param1 + sigma && s2ind1val2 < s2Ind1Param1 - sigma;
bool s2ind1short = s2ind1val1 < -100 - s2Ind1Param1 - sigma && s2ind1val2 > -100 - s2Ind1Param1 + sigma;
if(posType==OP_BUY && s2ind1long)
ClosePosition();
else if(posType==OP_SELL && s2ind1short)
ClosePosition();
}
For now all is working well but the Ea uses only one Stop Loss. Have someone an idea how to handle different stop Losses and Take Profits.
Forex Software → Expert Advisor Modifications → Possible to modificate 2 Strategies in one without protfolio
Powered by PunBB, supported by Informer Technologies, Inc.