//+------------------------------------------------------------------+
//| LinearRegression EA.mq5 |
//| Joy D Moyo |
//| www.latvianfts.com |
//+------------------------------------------------------------------+
#property copyright "Joy D Moyo"
#property link "www.latvianfts.com"
#property version "1.00"
quero que o codigo sempre abra ordens de apenas 0.01 nada de aumentar o lote mesmo caso tenha maior probabilidade de asserto da analise!
altere isso e me entregue o codigo completo
Para garantir que o EA abra processos sempre com um volume fixo de 0.01 lotes e não aumente o lote baseado na análise, basta modificar a função LotSize() e outras áreas do código onde o lote é calculado. Vou retirar todas as referências a cálculo dinâmico de tamanho de lote e fixá-lo em 0.01.
Aqui está o código atualizado:
mql5
//+------------------------------------------------------------------+
//| LinearRegression EA.mq5 |
//| Joy D Moyo |
//| www.latvianfts.com |
//+------------------------------------------------------------------+
#property copyright "Joy D Moyo"
#property link "www.latvianfts.com"
#property version "1.00"
#include <Trade\Trade.mqh>
CTrade *Trade;
CPositionInfo PositionInfo;
input group "GENERAL INPUTS"
input int EAMagic = 1232;
input string MySymbol = "EURUSD";
input ENUM_TIMEFRAMES MyTimeFrame = PERIOD_M15;
input int MaxSlippage = 1;
input group "INDICATOR INPUTS"
input int RegressionPeriod = 1000;
input group "RISK INPUTS"
input double FixedLotSize = 0.01; // Fixed lot size
input group "TRADE MANAGEMENT INPUTS"
input int MinTradeDistance = 10;
int OldNumBars, LRHandle, MyDigits;
double RegressionLine[], OverBoughtLine[], OverSoldLine[], UpperExtremeLine[], LowerExtremeLine[], PriceClose[], Ask, Bid, MyPoint,
LotMax, LotMin, LotStep, NextBuyPrice, NextSellPrice, MinTradeDistancePnts;
string BuyComment = "Buy", SellComment = "Sell";
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool NewBar()
{
if (OldNumBars != Bars(MySymbol, MyTimeFrame))
{
OldNumBars = Bars(MySymbol, MyTimeFrame);
return true;
}
return false;
}
//+------------------------------------------------------------------+
//| |
int NumTrades(const ENUM_POSITION_TYPE PosType)
{
int Num = 0;
for (int i = PositionsTotal() - 1; i >= 0; i--)
{
if (PositionInfo.SelectByIndex(i))
{
if (PositionInfo.Magic() != EAMagic)
continue;
if (PositionInfo.Symbol() != MySymbol)
continue;
if (PositionInfo.PositionType() != PosType)
continue;
Num++;
}
}
return Num;
}
//+------------------------------------------------------------------+
//| |
double LotSize()
{
return FixedLotSize; // Always return the fixed lot size
}
//+------------------------------------------------------------------+
//| |
bool OSBuySignal()
{
if (PriceClose[1] > OverSoldLine[1] && PriceClose[2] < OverSoldLine[2])
return true;
return false;
}
//+------------------------------------------------------------------+
//| |
bool ExBuySignal()
{
if (PriceClose[1] > LowerExtremeLine[1] && PriceClose[2] < LowerExtremeLine[2])
return true;
return false;
}
//+------------------------------------------------------------------+
//| |
bool OBSellSignal()
{
if (PriceClose[1] < OverBoughtLine[1] && PriceClose[2] > OverBoughtLine[2])
return true;
return false;
}
//+------------------------------------------------------------------+
//| |
bool ExSellSignal()
{
if (PriceClose[1] < UpperExtremeLine[1] && PriceClose[2] > UpperExtremeLine[2])
return true;
return false;
}
//+------------------------------------------------------------------+
//| |
bool CloseBuySignal()
{
if (PriceClose[1] > RegressionLine[1] && PriceClose[2] < RegressionLine[2])
return true;
return false;
}
//+------------------------------------------------------------------+
//| |
bool CloseSellSignal()
{
if (PriceClose[1] < RegressionLine[1] && PriceClose[2] > RegressionLine[2])
return true;
return false;
}
//+------------------------------------------------------------------+
//| |
bool BullishGradient()
{
if (RegressionLine[1] > RegressionLine[2])
return true;
return false;
}
//+------------------------------------------------------------------+
//| |
bool BearishGradient()
{
if (RegressionLine[1] < RegressionLine[2])
return true;
return false;
}
//+------------------------------------------------------------------+
//| |
void OSBuy()
{
if (!OSBuySignal())
return;
if (NumTrades(POSITION_TYPE_BUY) != 0)
if (Ask > NextBuyPrice)
return;
double LotUsed = LotSize(); // Fixed lot size
if (Trade.Buy(LotUsed, MySymbol, Ask, 0, 0, BuyComment))
NextBuyPrice = Ask - MinTradeDistancePnts;
}
//+------------------------------------------------------------------+
//| |
void ExBuy()
{
if (!ExBuySignal())
return;
if (NumTrades(POSITION_TYPE_BUY) != 0)
if (Ask > NextBuyPrice)
return;
double LotUsed = LotSize(); // Fixed lot size
if (Trade.Buy(LotUsed, MySymbol, Ask, 0, 0, BuyComment))
NextBuyPrice = Ask - MinTradeDistancePnts;
}
//+------------------------------------------------------------------+
//| |
void OBSell()
{
if (!OBSellSignal())
return;
if (NumTrades(POSITION_TYPE_SELL) != 0)
if (Bid < NextSellPrice)
return;
double LotUsed = LotSize(); // Fixed lot size
if (Trade.Sell(LotUsed, MySymbol, Bid, 0, 0, SellComment))
NextSellPrice = Bid + MinTradeDistancePnts;
}
//+------------------------------------------------------------------+
//| |
void ExSell()
{
if (!ExSellSignal())
return;
if (NumTrades(POSITION_TYPE_SELL) != 0)
if (Bid < NextSellPrice)
return;
double LotUsed = LotSize(); // Fixed lot size
if (Trade.Sell(LotUsed, MySymbol, Bid, 0, 0, SellComment))
NextSellPrice = Bid + MinTradeDistancePnts;
}
//+------------------------------------------------------------------+
//| |
double AvgPrice(const ENUM_POSITION_TYPE PosType)
{
double tot = 0, avg = 0;
int Num = 0;
for (int i = PositionsTotal() - 1; i >= 0; i--)
{
if (PositionInfo.SelectByIndex(i))
{
if (PositionInfo.Magic() != EAMagic)
continue;
if (PositionInfo.Symbol() != MySymbol)
continue;
if (PositionInfo.PositionType() != PosType)
continue;
Num++;
tot += PositionInfo.PriceOpen();
}
}
avg = tot / Num;
return NormalizeDouble(avg, MyDigits);
}
//+------------------------------------------------------------------+
//| |
void CloseTrades(const ENUM_POSITION_TYPE PosType)
{
for (int i = PositionsTotal() - 1; i >= 0; i--)
{
if (PositionSelectByTicket(PositionGetTicket(i)))
{
if (PositionGetInteger(POSITION_MAGIC) != EAMagic)
continue;
if (PositionGetInteger(POSITION_TYPE) != PosType)
continue;
Trade.PositionClose(PositionGetInteger(POSITION_TICKET));
}
}
}
//+------------------------------------------------------------------+
//| |
void CloseBuy()
{
if (NumTrades(POSITION_TYPE_BUY) > 1)
{
if (Ask > AvgPrice(POSITION_TYPE_BUY))
CloseTrades(POSITION_TYPE_BUY);
else
return;
}
else
{
if (CloseBuySignal())
CloseTrades(POSITION_TYPE_BUY);
else
return;
}
}
//+------------------------------------------------------------------+
//| |
void CloseSell()
{
if (NumTrades(POSITION_TYPE_SELL) > 1)
{
if (Bid < AvgPrice(POSITION_TYPE_SELL))
CloseTrades(POSITION_TYPE_SELL);
else
return;
}
else
{
if (CloseSellSignal())
CloseTrades(POSITION_TYPE_SELL);
else
return;
}
}
//+------------------------------------------------------------------+
//| Expert initialization function |
int OnInit()
{
ChartSetInteger(0, CHART_SHOW_GRID, false);
ChartSetInteger(0, CHART_SHOW_VOLUMES, false);
ChartSetInteger(0, CHART_COLOR_STOP_LEVEL, clrGold);
ChartSetInteger(0, CHART_COLOR_BACKGROUND, clrBlack);
ChartSetInteger(0, CHART_COLOR_FOREGROUND, clrWhite);
ChartSetInteger(0, CHART_COLOR_CANDLE_BEAR, clrWhite);
ChartSetInteger(0, CHART_COLOR_CHART_DOWN, clrWhite);
ChartSetInteger(0, CHART_COLOR_CANDLE_BULL, clrDodgerBlue);
ChartSetInteger(0, CHART_COLOR_CHART_UP, clrDodgerBlue);
ChartSetInteger(0, CHART_MODE, CHART_CANDLES);
OldNumBars = Bars(MySymbol, MyTimeFrame);
Trade = new CTrade;
Trade.SetExpertMagicNumber(EAMagic);
Trade.SetDeviationInPoints(MaxSlippage * 10);
LRHandle = iCustom(MySymbol, MyTimeFrame, "LinearRegression", RegressionPeriod);
ArraySetAsSeries(RegressionLine, true);
ArraySetAsSeries(OverBoughtLine, true);
ArraySetAsSeries(OverSoldLine, true);
ArraySetAsSeries(UpperExtremeLine, true);
ArraySetAsSeries(LowerExtremeLine, true);
ArraySetAsSeries(PriceClose, true);
MyPoint = SymbolInfoDouble(MySymbol, SYMBOL_POINT);
MyDigits = (int)SymbolInfoInteger(MySymbol, SYMBOL_DIGITS);
LotMax = SymbolInfoDouble(MySymbol, SYMBOL_VOLUME_MAX);
LotMin = SymbolInfoDouble(MySymbol, SYMBOL_VOLUME_MIN);
LotStep = SymbolInfoDouble(MySymbol, SYMBOL_VOLUME_STEP);
MinTradeDistancePnts = MinTradeDistance * 10 * MyPoint;
return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
void OnDeinit(const int reason)
{
delete Trade;
}
//+------------------------------------------------------------------+
//| Expert tick function |
void OnTick()
{
if (!NewBar())
return;
Ask = SymbolInfoDouble(MySymbol, SYMBOL_ASK);
Bid = SymbolInfoDouble(MySymbol, SYMBOL_BID);
CopyBuffer(LRHandle, 0, 0, 4, RegressionLine);
CopyBuffer(LRHandle, 1, 0, 4, OverBoughtLine);
CopyBuffer(LRHandle, 2, 0, 4, OverSoldLine);
CopyBuffer(LRHandle, 3, 0, 4, UpperExtremeLine);
CopyBuffer(LRHandle, 4, 0, 4, LowerExtremeLine);
CopyClose(MySymbol, MyTimeFrame, 0, 4, PriceClose);
OSBuy();
ExBuy();
OBSell();
ExSell();
CloseBuy();
CloseSell();
}
//+------------------------------------------------------------------+
Alterações Realizadas:
Substituição do Cálculo Dinâmico de Lote: A função LotSize() agora sempre retorna um tamanho de lote fixo definido pela variável FixedLotSize, que é ajustado para 0.01.
Remoção de Ajustes de Lote Baseados em Análise: Qualquer lógica que considerasse as condições de mercado ou tendências para aumentar o lote foi removida, garantindo que sempre seja utilizado o lote fixo.
Ao usar este código, todas as ordens abertas pelo EA terão um tamanho de lote de 0.01, independentemente das condições do mercado.