Hello. An author asserts:System has 3 bad trades and 221 good trades in the last 3 months.
It is needed to correct errors in a code.
//+------------------------------------------------------------------+
//| KurkaTrader.mq4 |
//| Copyright © 2006, KurkaFund. |
//|
http://www.kurkafund.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, KurkaFund."
#property link "http://www.kurkafund.com"
//---- input parameters
//trading parameters
extern int MagicNumber = 12345;
extern double Risk = 0.2; //percentag of AccountFreeMargin used to open position
extern double TrailingStop = 20;
extern double StopLoss = 20;
extern double TakeProfit = 150;
extern double Trend_Strength_1 = 0.25; //Trend strength, when true is used as a multiplier for entry
extern double Trend_Strength_2 = 0.25;
extern double Trend_Strength_3 = 0.5;
extern double Trend_Strength_4 = 0.5;
extern double Trend_Strength_5 = 1;
extern double Trend_Strength_6 = 1;
//Signal Parameters
extern int Ema_1 = 96;
extern int Ema_2 = 288;
extern int Ema_3 = 864;
extern int Ema_4 = 2592;
extern int EmaShift = 0;
extern int CciPer = 18;
extern int CciLagPer = 3;
extern int Cci_Level1 = 50;
extern int Cci_Level2 = 100;
extern int Cci_Level3 = 150;
extern int EnvelopePeriod = 2;
extern double Percent = 0.0032;
extern int OSMAFast = 5;
extern int OSMASlow = 30;
extern double OSMASignal = 2;
int start()
{
if(Bars<Ema_4)
{
Print("Not Enough Bars");
return(0);
}
if(AccountFreeMargin()<(1000*LotSize()))
{
Print("No Money. FreeMargin=",AccountFreeMargin());
return(0);
}
{
// Additional identifiers to make the code easy.
double SarCurrent = iSAR(NULL, 0, 0.02, 0.2, 0);
double SarPrevious = iSAR(NULL, 0, 0.02, 0.2, 1);
double CCI = iCCI(NULL,0,CciPer,PRICE_CLOSE,0);
double CCIPrevious = iCCI(NULL,0,CciPer,PRICE_CLOSE,1);
double HighEnvelope1 =
iEnvelopes(NULL,0,EnvelopePeriod,MODE_SMA,0,PRICE_ CLOSE,Percent,MODE_UPPER,0);
double LowEnvelope1 =
iEnvelopes(NULL,0,EnvelopePeriod,MODE_SMA,0,PRICE_ CLOSE,Percent,MODE_LOWER,0);
double CloseBar1 = iClose(NULL,0,0);
double HighEnvelope1Previous =
iEnvelopes(NULL,0,EnvelopePeriod,MODE_SMA,0,PRICE_ CLOSE,Percent,MODE_UPPER,1);
double LowEnvelope1Previous =
iEnvelopes(NULL,0,EnvelopePeriod,MODE_SMA,0,PRICE_ CLOSE,Percent,MODE_LOWER,1);
double CloseBar1Previous = iClose(NULL,0,1);
double Stoc = iCustom(NULL, 0, "Zerolagstochs", 0,0);
double StocPrevious = iCustom(NULL, 0, "Zerolagstochs", 0,1);
double OsMABar2=iOsMA(NULL,0,OSMASlow,OSMAFast,OSMASignal ,PRICE_CLOSE,2);
double OsMABar1=iOsMA(NULL,0,OSMASlow,OSMAFast,OSMASignal ,PRICE_CLOSE,1);
//Trend EMA's
double Ema1 = iMA(NULL,0,Ema_1, 0,MODE_EMA, PRICE_CLOSE, EmaShift);
double Ema2 = iMA(NULL,0,Ema_2, 0,MODE_EMA, PRICE_CLOSE, EmaShift);
double Ema3 = iMA(NULL,0,Ema_3, 0,MODE_EMA, PRICE_CLOSE, EmaShift);
double Ema4 = iMA(NULL,0,Ema_4, 0,MODE_EMA, PRICE_CLOSE, EmaShift);
double Ema1Previous = iMA(NULL,0,Ema_1, 0,MODE_EMA, PRICE_CLOSE,
EmaShift-1);
double Ema2Previous = iMA(NULL,0,Ema_2, 0,MODE_EMA, PRICE_CLOSE,
EmaShift-1);
double Ema3Previous = iMA(NULL,0,Ema_3, 0,MODE_EMA, PRICE_CLOSE,
EmaShift-1);
double Ema4Previous = iMA(NULL,0,Ema_4, 0,MODE_EMA, PRICE_CLOSE,
EmaShift-1);
//Up Trend Calcs
double up1 = 0 if (Ema1 > Ema2) up1 = Trend_Strength_1;
double up2 = 0 if ((Ema1 > Ema2) && (Ema1 > Ema3)) up2 =
Trend_Strength_2;
double up3 = 0 if ((Ema1 > Ema2) && (Ema1 > Ema3) && (Ema1 > Ema4))up3
= Trend_Strength_3;
double up4 = 0 if ((Ema1 > Ema2) && (Ema1 > Ema3) && (Ema1 > Ema4) &&
(Ema2 > Ema3))up4 = Trend_Strength_4;
double up5 = 0 if ((Ema1 > Ema2) && (Ema1 > Ema3) && (Ema1 > Ema4) &&
(Ema2 > Ema3) && (Ema2 > Ema4))up5 = Trend_Strength_5;
double up6 = 0 if ((Ema1 > Ema2) && (Ema1 > Ema3) && (Ema1 > Ema4) &&
(Ema2 > Ema3) && (Ema2 > Ema4) && (Ema3 > Ema4))up6 = Trend_Strength_6;
//Down Trend Calcs
double down1 = 0 if (Ema1 < Ema2) down1 = Trend_Strength_1;
double down2 = 0 if ((Ema1 < Ema2) && (Ema1 < Ema3))down1 =
Trend_Strength_2;
double down3 = 0 if ((Ema1 < Ema2) && (Ema1 < Ema3) && (Ema1 <
Ema4))down1 = Trend_Strength_3;
double down4 = 0 if ((Ema1 < Ema2) && (Ema1 < Ema3) && (Ema1 < Ema4)
&& (Ema2 < Ema3))down1 = Trend_Strength_4;
double down5 = 0 if ((Ema1 < Ema2) && (Ema1 < Ema3) && (Ema1 < Ema4)
&& (Ema2 < Ema3) && (Ema2 < Ema4))down1 = Trend_Strength_5;
double down6 = 0 if ((Ema1 < Ema2) && (Ema1 < Ema3) && (Ema1 < Ema4)
&& (Ema2 < Ema3) && (Ema2 < Ema4) && (Ema3 < Ema4))down1 =
Trend_Strength_6;
//Trend truths used to turn indicators on and off 0=off 1=on
bool up_1 = 0 if (up1 == 1) up_1 = 1;
bool up_2 = 0 if (up2 == 1) up_2 = 1;
bool up_3 = 0 if (up3 == 1) up_3 = 1;
bool up_4 = 0 if (up4 == 1) up_4 = 1;
bool up_5 = 0 if (up5 == 1) up_5 = 1;
bool up_6 = 0 if (up6 == 1) up_6 = 1;
bool down_1 = 0 if (down1 == 1) down_1 = 1;
bool down_2 = 0 if (down2 == 1) down_2 = 1;
bool down_3 = 0 if (down3 == 1) down_3 = 1;
bool down_4 = 0 if (down4 == 1) down_4 = 1;
bool down_5 = 0 if (down5 == 1) down_5 = 1;
bool down_6 = 0 if (down6 == 1) down_6 = 1;
// Long entry signals
double LongEntry = 0;
if (up_1 || up_2 = 1 && up_3 && up_4 && up_5 && up_6 =0)
{
//zero lag stoch conditions goes here
if (OsMABar2 < OsMABar1)
{LongEntry = 1; else LongEntry = 0 ;}
else LongEntry = 0;
}
if (up_3 || up_4 = 1 && up_5 && up_6 =0)
{
if (CCI > Cci_Level1 && CCIPrevious <= Cci_Level1)
{LongEntry = 1; else LongEntry = 0 ;}
if (CCI > Cci_Level2 && CCIPrevious <= Cci_Level2)
{LongEntry = 1; else LongEntry = 0 ;}
if (CCI > Cci_Level3 && CCIPrevious <= Cci_Level3)
{LongEntry = 1; else LongEntry = 0 ;}
else LongEntry = 0;
}
if (up_5 || up_6 = 1)
{
if (Ema1 > Ema2 && Ema1Previous <= Ema2Previous)
{LongEntry = 1; else LongEntry = 0 ;}
if (CCI > Cci_Level1 && CCIPrevious <= Cci_Level1)
{LongEntry = 1; else LongEntry = 0 ;}
if (CCI > Cci_Level2 && CCIPrevious <= Cci_Level2)
{LongEntry = 1; else LongEntry = 0 ;}
if (CCI > Cci_Level3 && CCIPrevious <= Cci_Level3)
{LongEntry = 1; else LongEntry = 0 ;}
if (CloseBar1 < LowEnvelope1 && CloseBar1Previous >=
LowEnvelope1Previous)
{LongEntry = 1; else LongEntry = 0 ;}
else LongEntry = 0;
}
double ShortEntry = 0;
if (down_1 || down_2 = 1 && down_3 && down_4 && down_5 && down_6 =0)
{
//zero lag stoch conditions go here
if (OsMABar2 > OsMABar1)
{ShortEntry = 1; else LongEntry = 0 ;}
else ShortEntry = 0;
}
if (down_3 || down_4 = 1 && down_5 && down_6 =0)
{
//CCI entry conditions need help
if (CCI < Cci_Level1 *-1 && CCIPrevious >= Cci_Level1 *-1)
{ShortEntry = 1; else ShortEntry = 0 ;}
if (CCI < Cci_Level2 *-1 && CCIPrevious >= Cci_Level2 *-1)
{ShortEntry = 1; else ShortEntry = 0 ;}
if (CCI < Cci_Level3 *-1 && CCIPrevious >= Cci_Level3 *-1)
{ShortEntry = 1; else ShortEntry = 0 ;}
else ShortEntry = 0;
}
if (down_5 || down_6 = 1)
{
if (Ema1 < Ema2 && Ema1Previous >= Ema2Previous)
{ShortEntry = 1; else ShortEntry = 0 ;}
if (CCI < Cci_Level1 *-1 && CCIPrevious >= Cci_Level1 *-1)
{ShortEntry = 1; else ShortEntry = 0 ;}
if (CCI < Cci_Level2 *-1 && CCIPrevious >= Cci_Level2 *-1)
{ShortEntry = 1; else ShortEntry = 0 ;}
if (CCI < Cci_Level3 *-1 && CCIPrevious >= Cci_Level3 *-1)
{ShortEntry = 1; else ShortEntry = 0 ;}
if (CloseBar1 < LowEnvelope1 && CloseBar1Previous <=
LowEnvelope1Previous)
{ShortEntry = 1; else ShortEntry = 0 ;}
else ShortEntry = 0;
}
//Entry
if (LongEntry>0)
{
double LongLots,Up_Trend_Score;
{
Up_Trend_Score = (up1 + up2 + up3 + up4 + up5 + up6);
LongLots = (Up_Trend_Score * AccountFreeMargin * Risk * LongEntry);
}
if(AccountFreeMargin()<(1000*LongLots()))
{
Print("Your Broke, Free Margin = ", AccountFreeMargin());
return(0);
}
OrderSend(Symbol(),OP_BUY,LongLots(),Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"Kurka",MagicN umber,0,Blue);
return;
}
if (ShortEntry>0)
{
double ShortLots,Down_Trend_Score;
{
Down_Trend_Score = (down1 + down2 + down3 + down4 + down5 + down6);
ShortLots = (Up_Trend_Score * AccountFreeMargin * Risk * ShortEntry);
}
if(AccountFreeMargin()<(1000*ShortLots()))
{
Print("Your Broke, Free Margin = ", AccountFreeMargin());
return(0);
}
OrderSend(Symbol(),OP_SELL,ShortLots(),Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"Kurka",MagicN umber,0,Blue);
return;
}
}
//Exit
bool LongExit = false;
{
if (OsMABar2 > OsMABar1)
LongExit = true;
if (CCI < 0 * && CCIPrevious >= 0)
LongExit = true;
if (CCI < Cci_Level1 * && CCIPrevious >= Cci_Level1)
LongExit = true;
if (CCI < Cci_Level2 * && CCIPrevious >= Cci_Level2)
LongExit = true;
if (CCI < Cci_Level3 * && CCIPrevious >= Cci_Level3)
LongExit = true;
if (Ema1 < Ema2 && Ema1Previous >= Ema2Previous)
LongExit = true;
if (CCI < Cci_Level1 * && CCIPrevious >= Cci_Level1)
LongExit = true;
if (CCI < Cci_Level2 * && CCIPrevious >= Cci_Level2)
LongExit = true;
if (CCI < Cci_Level3 * && CCIPrevious >= Cci_Level3)
LongExit = true;
if (CloseBar1 < LowEnvelope1 && CloseBar1Previous <=
LowEnvelope1Previous) LongExit = true;
}
bool ShortExit = false;
{
if (OsMABar2 < OsMABar1)
ShortExit = true;
if (CCI > 0 && CCIPrevious <= 0)
ShortExit = true;
if (CCI > Cci_Level1 *-1 && CCIPrevious <= Cci_Level1 *-1)
ShortExit = true;
if (CCI > Cci_Level2 *-1 && CCIPrevious <= Cci_Level2 *-1)
ShortExit = true;
if (CCI > Cci_Level3 *-1 && CCIPrevious <= Cci_Level3 *-1)
ShortExit = true;
if (Ema1 > Ema2 && Ema1Previous <= Ema2Previous)
ShortExit = true;
if (CCI > Cci_Level1 *-1 && CCIPrevious <= Cci_Level1 *-1)
ShortExit = true;
if (CCI > Cci_Level2 *-1 && CCIPrevious <= Cci_Level2 *-1)
ShortExit = true;
if (CCI > Cci_Level3 *-1 && CCIPrevious <= Cci_Level3 *-1)
ShortExit = true;
if (CloseBar1 > LowEnvelope1 && CloseBar1Previous <=
LowEnvelope1Previous) ShortExit = true;
}