Hello, Please can some tell the code for using a martingale system and the martingale should follow only one open trade at a time.
The martingale will only trigger when the last closed trade is a loss so the next open trade is like multiplied by 2 lot, so instead of checking for open positions it would check for last closed positions.
Thank you
See that "Freelance" menu option at the top of this page?
Use it.
No one is going to code this for you for free. :)
-
Hedging, grid trading, same as Martingale.
Martingale, Hedging and Grid : MHG - General - MQL5 programming forum (2016)Martingale, guaranteed to blow your account eventually. If your strategy is not profitable without, it is definitely not profitable with.
Martingale vs. Non Martingale (Simplified RoR vs Profit and the Illusions) - MQL5 programming forum (2015)Why it won't work:
Calculate Loss from Lot Pips - MQL5 programming forum (2017)
THIS Trading Strategy is a LIE... I took 100,000 TRADES with the Martingale Strategy - YouTube (2020) -
You have only four choices:
-
Search for it (CodeBase or Market). Do you expect us to do your research for you?
- Beg at:
- Coding help - MQL4 programming forum
- Make It No Repaint Please! - MQL4 programming forum
- MT4 to MT5 code converter - MQL5 programming forum
- Please fix this indicator or EA - General - MQL5 programming forum
- Requests & Ideas (MQL5 only!) - Expert Advisors and Automated Trading - MQL5 programming forum
- Indicator to EA Free Service - General - MQL5 programming forum
-
MT4: Learn to code it.
MT5: Begin learning to code it.If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.
-
Or pay (Freelance) someone to code it. Top of every page is the link Freelance.
Hiring to write script - General - MQL5 programming forum (2019)
We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
No free help (2017) -
I coded a simple EMA crossover and it works but I just want to add only one open trade at a time.
//+------------------------------------------------------------------+
//| EMA Crossover Bot.mq4 |
//| Smiling D |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Smiling D"
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
datetime dt;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
dt = TimeCurrent();
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
if(isnewbar()){
double prev_ma8 = iMA(_Symbol, PERIOD_CURRENT,8,0,MODE_EMA,PRICE_CLOSE,2);
double prev_ma5 = iMA(_Symbol, PERIOD_CURRENT,5,0,MODE_EMA,PRICE_CLOSE,2);
double ma8 = iMA(_Symbol, PERIOD_CURRENT,8,0,MODE_EMA,PRICE_CLOSE,1);
double ma5 = iMA(_Symbol, PERIOD_CURRENT,5,0,MODE_EMA,PRICE_CLOSE,1);
if(prev_ma8>prev_ma5 && ma8<ma5){
if(OrdersTotal()!=0) closeexisting();
OrderSend(_Symbol, OP_BUY, 0.01, Ask, 10, 0, 0);
OrderModify(_Symbol, PERIOD_CURRENT, 320.0, 50.0, 0,clrNONE);
}
else if(prev_ma8<prev_ma5 && ma8>ma5){
if(OrdersTotal()!=0) closeexisting();
OrderSend(_Symbol, OP_SELL, 0.01, Bid, 10, 0, 0);
OrderModify(_Symbol, PERIOD_CURRENT, 320.0, 50.0, 0,clrNONE);
}
}
}
//+------------------------------------------------------------------+
void closeexisting(){
OrderSelect(0, SELECT_BY_POS);
OrderClose(OrderTicket(), OrderLots(), MarketInfo(_Symbol, MODE_BID+OrderType()), 10);
}
bool isnewbar(){
if(TimeCurrent() != dt){
dt = TimeCurrent();
return true;
}
return false;
}
![Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5 Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5](https://c.mql5.com/36/57/otkroy-novie-vozmozhnosti-v-metatrader.png)
- 2022.07.12
- www.mql5.com
Please edit your post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
Messages Editor
int countOrders() { int tickersum = 0; if(OrdersTotal() >0) { for(int i=1; i<=OrdersTotal(); i++) { if(OrderSelect(i-1,SELECT_BY_POS)==true) { if(OrderSymbol() == "XAUUSD" && (OrderMagicNumber()==2000 || OrderMagicNumber()==3000)) { tickersum += 1; } } } } return tickersum; }
Here's the code I use to limit the positions to only 1 open position for a certain symbol with certain magicnumbers. This way it won't count my manually placed orders.
Usage:
void OnTick(){
if(countOrders()> 0) return;
}
Here's the code I use to limit the positions to only 1 open position for a certain symbol with certain magicnumbers. This way it won't count my manual placed orders.
Usage:
for(int i=1; i<=OrdersTotal(); i++) { if(OrderSelect(i-1,SELECT_BY_POS)==true)
That seems a very strange way to do it and is easily misread.
Most coders would use
for(int i=0; i<OrdersTotal(); i++) { if(OrderSelect(i,SELECT_BY_POS)==true)
or
for(int i=OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS))
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, Please can some tell the code for using a martingale system and the martingale should follow only one open trade at a time.
The martingale will only trigger when the last closed trade is a loss so the next open trade is like multiplied by 2 lot, so instead of checking for open positions it would check for last closed positions.
Thank you