I hope someone can help me with this code. I am testing an idea and need functionality
at this point (i.e. I know the code isn't pretty). The code is supposed to open
only 5 lots each time the previous closed trade was profitable. If the last closed
trade was a loss (stopped out) it should increase the number of lots to 40 for
the next trade. It does this just fine. The problem is that if there are two or more losses in a row it will only increase the lots to 40 not to 80 like it
should (or at least like I think it should). I have tried different logic but to
no avail. I am stumped! I am testing this code in Strategy tester using the dates
of 1/18/2007 to 2/28/2007 for my test window.
int start()
{
//+------------------------------------------------------------------+
//| Local variables |
//+------------------------------------------------------------------+
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
#include <stdlib.mqh>
//+------------------------------------------------------------------+
//| Lot Multiplier. mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
//+------------------------------------------------------------------+
//| Common External variables |
//+------------------------------------------------------------------+
extern double Lots = 5.00;
extern double StopLoss = 40.00;
extern double TakeProfit = 5.00;
extern double HourT = 01;
extern double Slippage = 3;
int init()
{
return(0);
}
int start()
{
//+------------------------------------------------------------------+
//| Local variables |
//+------------------------------------------------------------------+
double RealTP = 0;
double RealSL = 0;
double RealTPS = 0;
double RealSLS = 0;
double ticket = 0;
int Loss = 0;
static int ClosedTrades;
if(ClosedTrades==HistoryTotal()-1)
OrderSelect(ClosedTrades,SELECT_BY_POS,MODE_HISTORY);
if((OrderType()==OP_BUY)||(OrderType()==OP_SELL))
if(CompareDoubles(OrderClosePrice(), OrderTakeProfit()))
{ Print ("Take Profit");
Lots = 5;
Loss = 0;
Print ("Profit Loss Count = ", Loss);
}
if(CompareDoubles(OrderClosePrice(), OrderStopLoss()))
{ Print ("Stop Loss");
Loss = Loss + 1;
Lots = Loss * 40;
Print ("SL Loss Count = ", Loss);
}
ClosedTrades=HistoryTotal();
if(DayOfWeek()==1 || DayOfWeek()==2 || DayOfWeek()==3 || DayOfWeek()==4 || DayOfWeek()==5)
if (Hour() == HourT)
if (Minute() >= 01 && (Minute()< 05))
if (OrdersTotal()==0)
{
RealSL=Ask-(StopLoss*Point);
RealTP=Ask+(TakeProfit*Point);
ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask, Slippage, Ask-(StopLoss*Point), Ask+(TakeProfit*Point), "",16357,0,Red);
}
if(ticket<0)
{
Print("Buy OrderSend failed with error #",GetLastError());
}
return(0);
}
Thank you in advance for any help you can provide.
TeslaFX