Hello, I have a small bug of position size multiplication.
Example:
I have 3 position sizes (0.02, 0.07, 0.40 Lots) that should open if my
stop loss is hit but by the time I manually reset my stop loss there is a bug
instead of opening a position at 0.40 lots because the 0.02 then 0.07 lots are hit
it opens 0.02 or 0.07.
to know that I place several experts and that each expert has a
different magic number
#property copyright "xxx"
#property link "http://www.mql5.com"
#property version "1.00"
#property strict
extern double lots1 = 0.02;
extern double lots2 = 0.07;
extern double lots3 = 0.40;
input int TakeProfit1 = 10 ;
input int StopLoss1 = 50 ;
input int TakeProfit2 = 10 ;
input int StopLoss2 = 50;
input int TakeProfit3 = 10 ;
input int StopLoss3 = 50;
extern int magic = 222222;
bool RunOnce=false;
int last_order_check = false;
datetime EaStartTime=TimeCurrent();
double takeprofit1=TakeProfit1;
double stoploss1 =StopLoss1;
double takeprofit2=TakeProfit2;
double stoploss2 =StopLoss2;
double takeprofit3=TakeProfit3;
double stoploss3 =StopLoss3;
int OnInit()
{
RunOnce=false;
MathSrand(GetTickCount());
if(Digits==5 || Digits==3)
{
takeprofit1 =TakeProfit1*10;
stoploss1 =StopLoss1*10;
takeprofit2 =TakeProfit2*10;
stoploss2 =StopLoss2*10;
takeprofit3 =TakeProfit3*10;
stoploss3 =StopLoss3*10;
}
return(INIT_SUCCEEDED);
}
void OnTimer()
{
OnTick();
}
void OnDeinit(const int reason)
{
}
void OnTick()
{
if(IsLastOrderClose())
{
OnInit();
Print("Ea Closed Manually ");
EaStartTime=TimeCurrent();
}
int ticet;
int t=MathRand();
if(CountVsego()==0)
{
if(t>16384)
{
if(Counts()==0)
{
ticet=OrderSend(Symbol(),OP_BUY,lots1,Ask,3,Bid-stoploss1*Point,Ask+takeprofit1*Point,"1",magic,0,clrGreen);
if(ticet>0)
{
RunOnce=true;
}
}
}
else if(t<16384)
{
if(Counts()==0)
{
ticet=OrderSend(Symbol(),OP_SELL,lots1,Bid,3,Ask+stoploss1*Point,Bid-takeprofit1*Point,"1",magic,0,clrRed);
if(ticet>0)
{
RunOnce=true;
}
}
}
if(t>16384)
{
if(Counts()==1)
{
ticet=OrderSend(Symbol(),OP_BUY,lots2,Ask,3,Bid-stoploss2*Point,Ask+takeprofit2*Point,"2",magic,0,clrGreen);
if(ticet>0)
{
RunOnce=true;
}
}
}
else if(t<16384)
{
if(Counts()==1)
{
ticet=OrderSend(Symbol(),OP_SELL,lots2,Bid,3,Ask+stoploss2*Point,Bid-takeprofit2*Point,"2",magic,0,clrRed);
if(ticet>0)
{
RunOnce=true;
}
}
}
if(t>16384)
{
if(Counts()==2)
{
ticet=OrderSend(Symbol(),OP_BUY,lots3,Ask,3,Bid-stoploss3*Point,Ask+takeprofit3*Point,"3",magic,0,clrGreen);
if(ticet>0)
{
RunOnce=true;
}
}
}
else if(t<16384)
{
if(Counts()==2)
{
ticet=OrderSend(Symbol(),OP_SELL,lots3,Bid,3,Ask+stoploss3*Point,Bid-takeprofit3*Point,"3",magic,0,clrRed);
if(ticet>0)
{
RunOnce=true;
}
}
}
}
}
int CountSELL()
{
int count=0;
int i;
for(i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_SELL)
count++;
}
}
return(count);
}
int CountBUY()
{
int count=0;
int i;
for(i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_BUY)
count++;
}
}
return(count);
}
int Counts()
{
int count=0,i;
for(i=OrdersHistoryTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderCloseTime()>=EaStartTime)
{
if(OrderProfit()>0)
{
if(count==0)
{
OnInit();
EaStartTime=TimeCurrent();
}
return count;
}else
{
count++;
}
}
if(count > 2 && OrderCloseTime()>=EaStartTime) count=0;
}
}
return(count);
}
int CountVsego()
{
int Vsego;
Vsego=CountBUY()+CountSELL();
return(Vsego);
}
bool IsLastOrderClose()
{
bool signal = false;
for(int i=OrdersHistoryTotal()-1;i>=0;i--)
{
bool select = OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(select && OrderSymbol()==_Symbol && OrderMagicNumber()==magic)
{
if(OrderType()==OP_BUY && OrderCloseTime()>=EaStartTime)
{
if(OrderClosePrice()>OrderStopLoss() && OrderClosePrice()<OrderTakeProfit())
{
signal = true;
}
break;
}
else if(OrderType()==OP_SELL && OrderCloseTime()>=EaStartTime)
{
if(OrderClosePrice()<OrderStopLoss() && OrderClosePrice()>OrderTakeProfit())
{
signal = true;
}
break;
}
break;
}
}
return(signal);
}
Commandes similaires
//@version=4 study(title="UT Bot Alerts", overlay = true) // Inputs a = input(1, title = "Key Vaule. 'This changes the sensitivity'") c = input(10, title = "ATR Period") h = input(false, title = "Signals from Heikin Ashi Candles") xATR = atr(c) nLoss = a * xATR src = h ? security(heikinashi(syminfo.tickerid), timeframe.period, close, lookahead = false) : close xATRTrailingStop = 0.0 xATRTrailingStop := iff(src >
We’re building our team for an upcoming crypto project and are looking for skilled professionals to help us move development forward. We’re especially interested in developers experienced with React.js and Node.js, with Web3 knowledge being a strong advantage. We plan to launch the MVP by the mid of Dec and complete the project by Christmas. Our budget is $20–$30 per hour, depending on experience and skill level
Hello, I am from Tanzania. I am looking for a professional MQL5 programmer from Tanzania who can help me develop and improve my automated MT5 trading robot. The project is called SMC XAVAGE AI, and it trades XAUUSD (Gold). I would like to discuss the project with you. Are you based in Tanzania? Would it be possible to arrange a meeting or a call? Thank you
Here is a professional specification you can send directly to your developer. # Project Requirements Specification: MetaTrader 5 Trading Robot Development ### 1. Project Overview I want to develop an automated Forex trading robot (Expert Advisor) for MetaTrader 5 (MT5). The robot should analyse the financial markets, identify trading opportunities, and execute trades automatically based on predefined strategies. ###
1. Platform: MT4 The EA required is not linked, neither depending on trading strategy nor trading signals nor indicators. 2. Initial order is a pending order (buy stop/ sell stop) and it is created manually. It is open for a specified symbol (pair) at a specified price with a specified S/L 3. Example: buy stop 0.1 lot GBPUSD @ 1.3085 WITH S/L @1.3075 Once target price is reached, pending order will
I am looking for an experienced trading software developer interested in building a long-term working relationship. Im a professional Trader, Coach and Mentor, I work with traders and Student who require customized trading solutions, including automated trading bots, Expert Advisors, custom indicators, trading strategies and other algorithmic trading tools. I am looking for a technically skilled developer who can
MT5 ICT XAUUSD Sell-Only Trading Robot with Fibonacci Confirmation I am looking for an experienced MQL5 developer to create a custom Expert Advisor (EA) for MetaTrader 5, specifically for trading Gold (XAUUSD). 1. Trading Strategy The robot must use the ICT trading methodology and focus on SELL trades only. The strategy should include: * Identify important resistance and premium zones. * Use Fibonacci retracement
Objective: I am looking for an experienced MQL5 quantitative developer to code an Expert Advisor (EA) from scratch based on a fully defined, rule-based strategy, and then rigorously validate, optimize, and stress-test it before I deploy it on a live VPS environment. Note: The exact mathematical rules, indicator names, and chart screenshots will be shared privately with shortlisted candidates. Strategy Overview
Hi Team We are looking to commission an Expert Advisor (EA) for MetaTrader 5 (MT5) to trade XAUUSD (Gold) . The EA requires tight risk management with a strict $2.00 Stop Loss and a $3.00 to $5.00 Take Profit target. The goal is to achieve a 60%+ Win Rate . Please propose or implement a strategy algorithm capable of meeting the following performance requirements on XAUUSD tick data: Target Performance: $\ge 60\%$ Win
a trading bot that can open and close trade by its self a stop loss of 1.2 lot size and good tp it should be able to learn trends and learn from its mistakes