Hi, I just started reading this thread, and it is really simple to use, AND Program So I made an EA for it.
The results was not so good, the last couple of years its been totally flat, whil working good up to around the end of 2008 where it just dipped, and went flat
Do you guys follow any other rules to maximize profit or filtering out bad trades?
[EDIT] There was a bug in my code(mixed Bid/Ask) at closing, this is fixed, but the graph is not updated(wich actually looks worse 65% Win ratio, average win 32$ average loss 76.6$
//+------------------------------------------------------------------+
//| EasyMoney.mq4 |
//| not available |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Richard Hagen."
#property link "not available"
extern bool Trade_Buy = true;
extern bool Trade_Sell = false;
extern string _description2 ="Money managment:";
extern double Risk = 0.02;
extern bool Compounding = false;
extern double Dollars = 100;
extern string _description3 = "Strategy:";
extern double StopLoss = 0.006;
extern double TakeProfit = 0.002;
extern double BuyHour = 7;
extern double BuyMinutes = 0;
extern double CloseHour = 11;
bool TradeOpen = false;
int TradeID = 0;
bool TradeBuy = false;
double TradeSL = 0;
double SL_Value = 0;
double SL_Pips = 0;
double TP_Pips = 0;
double TP_Value = 0;
double TP_Change = 0;
double TP_Level = 1.5;
int LOT_DIGIT = 1;
int priceStage = 0; //0: Unkown, 1: Over MA, 2: Under MA
double MaxPrice = 0;
double HighPrice = 0;
double LowPrice = 0;
double crossPrice = 0;
double myPrice = 0;
double lastPrice = 0;
double Lts = 0;
int iError = 0;
double orgProfit;
bool borgProfit;
int init() {
RefreshRates();
if(MarketInfo(Symbol(),MODE_MINLOT) == 0.1) LOT_DIGIT = 1;
else if(MarketInfo(Symbol(),MODE_MINLOT) == 0.01) LOT_DIGIT = 2;
else if(MarketInfo(Symbol(),MODE_MINLOT) == 0.001) LOT_DIGIT = 3;
return(0);
}
int start() {
if (TradeOpen) {
///////////////////////////////////////////////////
// MANAGE TRADE
// Max_SL, SL_Multiplier, Trialing_Stop, RiskTP
///////////////////////////////////////////////////
if (OrderSelect(TradeID, SELECT_BY_TICKET, NULL)) {
datetime ctm = OrderCloseTime();
if (ctm > 0) {
//Order is closed
TradeID=0;
TradeOpen=false;
} else {
if (Hour() >= CloseHour) {
RefreshRates();
if (TradeBuy) OrderClose(TradeID, OrderLots(), Bid, 3);
if (!TradeBuy) OrderClose(TradeID, OrderLots(), Ask, 3);
//OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), 3, Yellow);
}
}
} else {
//error selecting trade?? wtf
}
} else {
int i;
if (Function_New_Bar()) {
///////////////////////////////////////////////////
// Check if we are buying or selling
// (MinimumPipsForCross)
///////////////////////////////////////////////////
if ((Hour() == 7) && (Minute() == 0)) {
int signal = 0; // 1= Buy, 2= Sell
if (Close[1] > Open[1]) signal = 1;
if (Close[1] < Open[1]) signal = 2;
switch (signal) {
case (1): // Price has just crossed over ma_slow
//BUY!!!
//extern double StopLoss = 0.006;
//extern double TakeProfit = 0.002;
RefreshRates();
myPrice = Ask;
lastPrice = myPrice;
//SL_Value = Low[1];
SL_Value = myPrice - StopLoss;
SL_Pips = StopLoss;
TP_Value = myPrice + TakeProfit;
Lts = Function_LotSize(SL_Pips);
//LETS TRADE
Alert("Kjøp: Pris: ", myPrice, " SL: ", SL_Value, " TP: ", TP_Value);
while (Trade_Buy) {
i = OrderSend(Symbol(), OP_BUY, Lts, myPrice,2, SL_Value, TP_Value);
if (i > 0) {
//Completed
orgProfit = TP_Value;
borgProfit = false;
TradeOpen = true;
TradeID = i;
TradeBuy = true;
break;
} else {
iError=GetLastError(); // Failed :(
if (Function_Error(iError, Lts)) continue;
else break;
}
}
break;
case (2): // Price has just crossed under ma_slow
//SELL!!!
RefreshRates();
myPrice = Bid;
lastPrice = myPrice;
SL_Value = myPrice + StopLoss;
SL_Pips = StopLoss;
TP_Value = myPrice - TakeProfit;
Lts = Function_LotSize(SL_Pips);
//LETS TRADE
Alert("Selg: Pris: ", myPrice, " SL: ", SL_Value, " TP: ", TP_Value);
while (Trade_Sell) {
i = OrderSend(Symbol(), OP_SELL, Lts, myPrice,2, SL_Value, TP_Value);
if (i > 0) {
//Completed
TradeOpen = true;
TradeID = i;
TradeBuy = false;
orgProfit = TP_Value;
borgProfit = false;
break;
} else {
iError=GetLastError(); // Failed :(
if (Function_Error(iError, Lts)) continue;
else break;
}
}
break;
}
}
}
}
}
///////////////////////////////////////////////////
// SUPPORT FUNCTIONS
///////////////////////////////////////////////////
double Function_LotSize(double SL) {
//extern double Risk = 0.02;
//extern bool Compounding = true;
//extern double LotSize = 0.1;
//Get disposable cash
double Risk_D;
if (Compounding) {
Risk_D = AccountEquity() * Risk; // = 1%
} else {
Risk_D = Dollars;
}
double Min_Lot=MarketInfo(Symbol(),MODE_MINLOT);
double One_Lot=MarketInfo(Symbol(),MODE_MARGINREQUIRED);
double Free =AccountFreeMargin();
double PipValue = MarketInfo(Symbol(), MODE_TICKVALUE);
double Max_Lot = (AccountFreeMargin()*AccountLeverage() / 100000) * 1;
double Risk_pip_value= Risk_D / SL_Pips;
int LOT_DIGIT = 1;
if(MarketInfo(Symbol(),MODE_MINLOT) == 0.1) LOT_DIGIT = 1;
else if(MarketInfo(Symbol(),MODE_MINLOT) == 0.01) LOT_DIGIT = 2;
else if(MarketInfo(Symbol(),MODE_MINLOT) == 0.001) LOT_DIGIT = 3;
double Lts= (Risk_D/(SL_Pips) / 100000);
Lts = NormalizeDouble(Lts, LOT_DIGIT);
if (Min_Lot > Lts) Lts = 0;
if (0.02 > Lts) Lts = 0;
if (Max_Lot < Lts) Lts = Max_Lot;
return (Lts);
}
bool Function_Error(int iError, double Lts = 0.0) {
string msg = "";
bool ret = false;
switch(iError){
case 135:
msg="The price has changed. Retrying..";
RefreshRates(); // Update data
ret = true; // At the next iteration
case 136:
msg="No prices. Waiting for a new tick..";
while(RefreshRates()==false) // Up to a new tick
Sleep(1); // Cycle delay
ret = true; // At the next iteration
case 146:
msg="Trading subsystem is busy. Retrying..";
Sleep(500); // Simple solution
RefreshRates(); // Update data
ret = true; // At the next iteration
case 138:
msg="ReQute";
RefreshRates(); // Update data
ret = true; // At the next iteration
}
switch(iError){
case 131 :
msg="Invalid trade volume.";
break;
case 2 :
msg="Common error.";
break; // Exit 'switch'
case 5 :
msg="Outdated version of the client terminal.";
break; // Exit 'switch'
case 64:
msg="The account is blocked.";
break; // Exit 'switch'
case 133:
msg="Trading forbidden";
break; // Exit 'switch'
case 134:
msg="Not enough money.";
break;
default:
msg=("Occurred error " + iError);
break;// Other alternatives
}
if (!ret) Alert(msg, " Lots: ", Lts);
return(ret);
}
bool Function_New_Bar () {
static datetime New_Time;
bool New_Bar = false;
if (New_Time==0) {
New_Time = Time[0];
}
if (New_Time!= Time[0]) {
New_Time = Time[0];
New_Bar = true;
}
return(New_Bar);
}
[EDIT] Updated with new code 17:07 CET 19.01.12 [/EDIT]