Should Martin only be activated when the indicator signal is opposite or regardless?
Example: A Buy position was opened according to the indicator. The price has fallen by the set distance and the indicator is already showing Sell. A Buy position shall be opened?
To make it short, .....Martin works only against the trend, with orders to the downside, while the indicator works only with the trend.
Tomorrow I will try to draw it on Photoshop and I will post the file
In short - At the same time ..... Martin works only against the trend, with orders in the red, and according to the indicator, we work only with the trend.
Tomorrow I'll try to draw on photoshop and post the file
I’ve done something here - that I myself don’t understand with 100,000 rubles. up to two million
//+------------------------------------------------------------------+//| 6 Sprut 185.mq5 |//| Copyright 2021, MetaQuotes Ltd. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2021, MetaQuotes Ltd."#property link" https://www.mql5.com "#property version"1.00"//---#define MACD_MAGIC 1234502//---#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\AccountInfo.mqh>
//---double m_adjusted_point; // point value adjusted for 3 or 5 points
CTrade m_trade; // trading object
CSymbolInfo m_symbol; // symbol info object
CPositionInfo m_position; // trade position object
CAccountInfo m_account; // account info wrapperinput group "---- : Parameters: ----"inputint InpTProfit = 100000 ; // : Take Profit --> (In currency the amount)inputdouble InpLotsRisk = 0.1 ; // : Maximum Risk in percentageinput group "---- : Parameters: ----"inputbool InpClOp = false ; // : Close opposite//---int m_price_uno;
int m_handle_macd; // MACD indicator handleint ExtTimeOut= 10 ; // time out in seconds between trade operations//+------------------------------------------------------------------+//| Calculate optimal lot size |//+------------------------------------------------------------------+double OptimizedBuy( void )
{
double PROFIT_BUY= 0.00 ;
int total= PositionsTotal ();
for ( int i=total- 1 ; i>= 0 ; i--) // returns the number of open positions
{
string position_GetSymbol= PositionGetSymbol (i); // GetSymbol позицииif (position_GetSymbol==m_symbol.Name())
{
if (m_position.PositionType()== POSITION_TYPE_BUY )
{
PROFIT_BUY=PROFIT_BUY+m_position.Select( Symbol ());
}
}
}
double Lots=InpLotsRisk;
double ab=PROFIT_BUY;
if (ab> 0 && ab<= 1 )
Lots=InpLotsRisk* 2 ;
if (ab> 1 && ab<= 2 )
Lots=InpLotsRisk* 4 ;
if (ab> 2 && ab<= 3 )
Lots=InpLotsRisk* 8 ;
if (ab> 3 )
Lots=InpLotsRisk* 16 ;
return (Lots);
}
//+------------------------------------------------------------------+//| Calculate optimal lot size |//+------------------------------------------------------------------+double OptimizedSell( void )
{
double PROFIT_SELL= 0.00 ;
int total= PositionsTotal ();
for ( int i=total- 1 ; i>= 0 ; i--) // returns the number of open positions
{
string position_GetSymbol= PositionGetSymbol (i); // GetSymbol позицииif (position_GetSymbol==m_symbol.Name())
{
if (m_position.PositionType()== POSITION_TYPE_SELL )
{
PROFIT_SELL=PROFIT_SELL+m_position.Select( Symbol ());
}
}
}
double Lots=InpLotsRisk;
double ab=PROFIT_SELL;
if (ab> 0 && ab<= 1 )
Lots=InpLotsRisk* 2 ;
if (ab> 1 && ab<= 2 )
Lots=InpLotsRisk* 4 ;
if (ab> 2 && ab<= 3 )
Lots=InpLotsRisk* 8 ;
if (ab> 3 )
Lots=InpLotsRisk* 16 ;
return (Lots);
}
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit ()
{
//--- initialize common information
m_symbol.Name( Symbol ()); // symbol
m_trade.SetExpertMagicNumber(MACD_MAGIC); // magic
m_trade.SetMarginMode();
m_trade.SetTypeFillingBySymbol( Symbol ());
//--- tuning for 3 or 5 digitsint digits_adjust= 1 ;
if (m_symbol. Digits ()== 3 || m_symbol. Digits ()== 5 )
digits_adjust= 10 ;
m_adjusted_point=m_symbol. Point ()*digits_adjust;
//--- set default deviation for trading in adjusted points
m_trade.SetDeviationInPoints( 3 *digits_adjust);
//--- create MACD indicator
m_handle_macd= iCustom ( NULL , 0 , "StepMA_NRTR" );
if (m_handle_macd== INVALID_HANDLE )
{
printf ( "Error creating MACD indicator" );
return ( false );
}
//---return ( INIT_SUCCEEDED );
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit ( constint reason)
{
//---
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick ( void )
{
//---if (ProfitBuy() || ProfitSell())
{
return ;
}
staticdatetime limit_time= 0 ; // last trade processing time + timeout//--- don't process if timeoutif ( TimeCurrent ()>=limit_time)
{
//--- check for dataif ( Bars ( Symbol (), Period ())> 2 )
{
//--- change limit time by timeout in seconds if processedif (Processing())
limit_time= TimeCurrent ()+ExtTimeOut;
}
}
}
//+------------------------------------------------------------------+//| main function returns true if any position processed |//+------------------------------------------------------------------+bool Processing( void )
{
//--- refresh ratesif (!m_symbol.RefreshRates())
return ( false );
double m_buff_MACD_main[],m_buff_MACD_signal[];
bool StNRUp,StNRDn;
ArraySetAsSeries (m_buff_MACD_main, true );
ArraySetAsSeries (m_buff_MACD_signal, true );
int start_pos= 1 ,count= 3 ;
if (!iGetArray(m_handle_macd, 0 ,start_pos,count,m_buff_MACD_main)||
!iGetArray(m_handle_macd, 1 ,start_pos,count,m_buff_MACD_signal))
{
return ( false );
}
//---
StNRUp=m_buff_MACD_main[ 0 ]<m_buff_MACD_signal[ 0 ];
StNRDn=m_buff_MACD_main[ 0 ]>m_buff_MACD_signal[ 0 ];
//--- BUY Signalif (StNRUp)
{
if (InpClOp)
if (ShortClosed())
Sleep ( 1000 );
if (m_price_uno< 0 )
LongOpened();
m_price_uno=+ 1 ;
return ( true );
}
//--- SELL Signalif (StNRDn)
{
if (InpClOp)
if (LongClosed())
Sleep ( 1000 );
if (m_price_uno> 0 )
ShortOpened();
m_price_uno=- 1 ;
return ( true );
}
//--- exit without position processingreturn ( false );
}
//+------------------------------------------------------------------+//| Check for long position closing |//+------------------------------------------------------------------+bool LongClosed( void )
{
bool res= false ;
//--- should it be closed?
ClosePositions( POSITION_TYPE_BUY );
//--- processed and cannot be modified
res= true ;
//--- resultreturn (res);
}
//+------------------------------------------------------------------+//| Check for short position closing |//+------------------------------------------------------------------+bool ShortClosed( void )
{
bool res= false ;
//--- should it be closed?
ClosePositions( POSITION_TYPE_SELL );
//--- processed and cannot be modified
res= true ;
//--- resultreturn (res);
}
//+------------------------------------------------------------------+//| Check for long position opening |//+------------------------------------------------------------------+bool LongOpened( void )
{
bool res= false ;
//--- check for long position (BUY) possibilitydouble price=m_symbol.Ask();
//--- check for free moneyif (m_account.FreeMarginCheck( Symbol (), ORDER_TYPE_BUY ,OptimizedBuy(),price)< 0.0 )
printf ( "We have no money. Free Margin = %f" ,m_account.FreeMargin());
else
{
//--- open positionif (m_trade.PositionOpen( Symbol (), ORDER_TYPE_BUY ,OptimizedBuy(),price, 0.0 , 0.0 ))
printf ( "Position by %s to be opened" , Symbol ());
else
{
printf ( "Error opening BUY position by %s : '%s'" , Symbol (),m_trade.ResultComment());
printf ( "Open parameters : price=%f" ,price);
}
PlaySound ( "ok.wav" );
}
//--- in any case we must exit from expert
res= true ;
//--- resultreturn (res);
}
//+------------------------------------------------------------------+//| Check for short position opening |//+------------------------------------------------------------------+bool ShortOpened( void )
{
bool res= false ;
//--- check for short position (SELL) possibilitydouble price=m_symbol.Bid();
//--- check for free moneyif (m_account.FreeMarginCheck( Symbol (), ORDER_TYPE_SELL ,OptimizedSell(),price)< 0.0 )
printf ( "We have no money. Free Margin = %f" ,m_account.FreeMargin());
else
{
//--- open positionif (m_trade.PositionOpen( Symbol (), ORDER_TYPE_SELL ,OptimizedSell(),price, 0.0 , 0.0 ))
printf ( "Position by %s to be opened" , Symbol ());
else
{
printf ( "Error opening SELL position by %s : '%s'" , Symbol (),m_trade.ResultComment());
printf ( "Open parameters : price=%f" ,price);
}
PlaySound ( "ok.wav" );
}
//--- in any case we must exit from expert
res= true ;
//--- resultreturn (res);
}
//+------------------------------------------------------------------+//| Refreshes the symbol quotes data |//+------------------------------------------------------------------+bool RefreshRates()
{
//--- refresh ratesif (!m_symbol.RefreshRates())
{
return ( false );
}
//--- protection against the return value of "zero"if (m_symbol.Ask()== 0 || m_symbol.Bid()== 0 )
{
return ( false );
}
//---return ( true );
}
//+------------------------------------------------------------------+//| Check Freeze and Stops levels |//+------------------------------------------------------------------+void FreezeStopsLevels( double &freeze, double &stops)
{
//--- check Freeze and Stops levelsdouble coeff=( double ) 1 ;
if (!RefreshRates() || !m_symbol.Refresh())
return ;
//--- FreezeLevel -> for pending order and modificationdouble freeze_level=m_symbol.FreezeLevel()*m_symbol. Point ();
if (freeze_level== 0.0 )
if ( 1 > 0 )
freeze_level=(m_symbol.Ask()-m_symbol.Bid())*coeff;
//--- StopsLevel -> for TakeProfit and StopLossdouble stop_level=m_symbol.StopsLevel()*m_symbol. Point ();
if (stop_level== 0.0 )
if ( 1 > 0 )
stop_level=(m_symbol.Ask()-m_symbol.Bid())*coeff;
//---
freeze=freeze_level;
stops=stop_level;
//---return ;
}
//+------------------------------------------------------------------+//| Close positions |//+------------------------------------------------------------------+void ClosePositions( constENUM_POSITION_TYPE pos_type)
{
double freeze= 0.0 ,stops= 0.0 ;
FreezeStopsLevels(freeze,stops);
for ( int i= PositionsTotal ()- 1 ; i>= 0 ; i--) // returns the number of current positionsif (m_position.SelectByIndex(i)) // selects the position by index for further access to its propertiesif (m_position. Symbol ()==m_symbol.Name() && m_position.Magic()==MACD_MAGIC)
if (m_position.PositionType()==pos_type)
{
if (m_position.PositionType()== POSITION_TYPE_BUY )
{
bool take_profit_level=((m_position.TakeProfit()!= 0.0 && m_position.TakeProfit()-m_position.PriceCurrent()>=freeze) || m_position.TakeProfit()== 0.0 );
bool stop_loss_level=((m_position.StopLoss()!= 0.0 && m_position.PriceCurrent()-m_position.StopLoss()>=freeze) || m_position.StopLoss()== 0.0 );
if (take_profit_level && stop_loss_level)
if (!m_trade.PositionClose(m_position.Ticket())) // close a position by the specified m_symbolPrint ( __FILE__ , " " , __FUNCTION__ , ", ERROR: " , "BUY PositionClose " ,m_position.Ticket(), ", " ,m_trade.ResultRetcodeDescription());
}
if (m_position.PositionType()== POSITION_TYPE_SELL )
{
bool take_profit_level=((m_position.TakeProfit()!= 0.0 && m_position.PriceCurrent()-m_position.TakeProfit()>=freeze) || m_position.TakeProfit()== 0.0 );
bool stop_loss_level=((m_position.StopLoss()!= 0.0 && m_position.StopLoss()-m_position.PriceCurrent()>=freeze) || m_position.StopLoss()== 0.0 );
if (take_profit_level && stop_loss_level)
if (!m_trade.PositionClose(m_position.Ticket())) // close a position by the specified m_symbolPrint ( __FILE__ , " " , __FUNCTION__ , ", ERROR: " , "SELL PositionClose " ,m_position.Ticket(), ", " ,m_trade.ResultRetcodeDescription());
}
PlaySound ( "ok.wav" );
}
}
//+------------------------------------------------------------------+//| Filling the indicator buffers from the indicator |//+------------------------------------------------------------------+bool iGetArray( constint handle, constint buffer, constint start_pos,
constint count, double &arr_buffer[])
{
bool result= true ;
if (! ArrayIsDynamic (arr_buffer))
{
return ( false );
}
ArrayFree (arr_buffer);
//--- reset error codeResetLastError ();
//--- fill a part of the iBands array with values from the indicator bufferint copied= CopyBuffer (handle,buffer,start_pos,count,arr_buffer);
if (copied!=count)
{
return ( false );
}
return (result);
}
//+------------------------------------------------------------------+//| ProfitOnTick closing |//+------------------------------------------------------------------+bool ProfitBuy( void )
{
bool res= false ;
double PROFIT_BUY= 0.00 ;
int total= PositionsTotal ();
for ( int i=total- 1 ; i>= 0 ; i--)
{
string position_GetSymbol= PositionGetSymbol (i);
if (position_GetSymbol==m_symbol.Name())
{
if (m_position.PositionType()== POSITION_TYPE_BUY )
{
PROFIT_BUY=PROFIT_BUY+ PositionGetDouble ( POSITION_PROFIT );
}
}
if (PROFIT_BUY>=InpTProfit)
{
if (LongClosed())
res= true ;
if (ShortOpened())
res= true ;
}
}
return (res);
}
//+------------------------------------------------------------------+//| ProfitOnTick closing |//+------------------------------------------------------------------+bool ProfitSell( void )
{
bool res= false ;
double PROFIT_SELL= 0.00 ;
int total= PositionsTotal ();
for ( int i=total- 1 ; i>= 0 ; i--)
{
string position_GetSymbol= PositionGetSymbol (i);
if (position_GetSymbol==m_symbol.Name())
{
if (m_position.PositionType()== POSITION_TYPE_SELL )
{
PROFIT_SELL=PROFIT_SELL+ PositionGetDouble ( POSITION_PROFIT );
}
}
if (PROFIT_SELL>=InpTProfit)
{
if (ShortClosed())
res= true ;
if (LongOpened())
res= true ;
}
}
return (res);
}
//+------------------------------------------------------------------+
I did the same, but the buffers remain 0, you can try it yourself. The only thing I don't understand is theIndicatorBuffers() functionin my mt5, I used #propertyindicatorbuffers
You shouldn't, they're about to launch it on the Market.
I don't care - at least I'll get something out of my studies. I've got more ideas in the back of my mind.
\\\\\\\\\\\\\\\\\\\\
There's only two functions you need. And they need to be properly rewritten by a programming expert because I'm an apprentice.
these are the functions
1. - 1. they are lot multipliers. the first position is opened, then the second one is multiplied, and so on. the first position is opened, then the second one is multiplied, and so on.
//+------------------------------------------------------------------+//| Calculate optimal lot size |//+------------------------------------------------------------------+double OptimizedBuy(void)
{
double PROFIT_BUY=0.00;
int total=PositionsTotal();
for(int i=total-1; i>=0; i--) // returns the number of open positions
{
string position_GetSymbol=PositionGetSymbol(i); // GetSymbol позицииif(position_GetSymbol==m_symbol.Name())
{
if(m_position.PositionType()==POSITION_TYPE_BUY)
{
PROFIT_BUY=PROFIT_BUY+m_position.Select(Symbol());
}
}
}
double Lots=InpLotsRisk;
double ab=PROFIT_BUY;
if(ab>0 && ab<=1)
Lots=InpLotsRisk*2;
if(ab>1 && ab<=2)
Lots=InpLotsRisk*4;
if(ab>2 && ab<=3)
Lots=InpLotsRisk*8;
if(ab>3)
Lots=InpLotsRisk*16;
return(Lots);
}
//+------------------------------------------------------------------+
and 2 - it closes the total amount in currency, opened positions in Buy
This is the first EA I have run in the tester in more than 2 years.
I am trying to understand the tester, everything has changed so much, so many different buttons have appeared.
So far I've come to the conclusion that I should put it on demo and run it for a couple of weeks.
In short, I stole it ;)
I also tested it with Expert Advisor - it somehow depends on the closing amount. If you put a smaller amount, it would lose if you put more, it would also lose.
I was testing 100 000 Rbls and 100 000 Rbls of profit and it went up to two million (last year on EUR/USD for 1 hour).
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.
Should Martin only be activated when the indicator signal is opposite or regardless?
Example: A Buy position was opened according to the indicator. The price has fallen by the set distance and the indicator is already showing Sell. A Buy position shall be opened?
To make it short, .....Martin works only against the trend, with orders to the downside, while the indicator works only with the trend.
Tomorrow I will try to draw it on Photoshop and I will post the file
In short - At the same time ..... Martin works only against the trend, with orders in the red, and according to the indicator, we work only with the trend.
Tomorrow I'll try to draw on photoshop and post the file
I’ve done something here - that I myself don’t understand with 100,000 rubles. up to two million
Need to rename it now, with a test like that it's sure to be sprat, or stolen, not sure what's right.
We need to rename it now, with a test like that it's sure to get sprung, or stolen, I'm not sure what's the right word.
Maybe someone will get rich - I don't get it, I like to live modestly.
Maybe someone will get rich - I don't get it, I just like to live modestly.
This is the first EA I have run in the tester in more than 2 years.
I am dealing with the tester now, everything has changed so much, so many different buttons have appeared.
So far I have come to the conclusion that I should put it on demo and run it for a couple of weeks.
Anyway, I've already stolen it ;)
Isn't that how it works?
I've done something wrong here - I don't know what went from 100,000 roubles to two million.
You shouldn't have, they're about to launch it in the Market.
You shouldn't, they're about to launch it on the Market.
I don't care - at least I'll get something out of my studies. I've got more ideas in the back of my mind.
\\\\\\\\\\\\\\\\\\\\
There's only two functions you need. And they need to be properly rewritten by a programming expert because I'm an apprentice.
these are the functions
1. - 1. they are lot multipliers. the first position is opened, then the second one is multiplied, and so on. the first position is opened, then the second one is multiplied, and so on.
and 2 - it closes the total amount in currency, opened positions in Buy
and of course the second halves
I've got more ideas in the back of my mind. I've got more ideas in the back of my mind.
Then you should put it in the codebase, if it's worthy.
This is the first EA I have run in the tester in more than 2 years.
I am trying to understand the tester, everything has changed so much, so many different buttons have appeared.
So far I've come to the conclusion that I should put it on demo and run it for a couple of weeks.
In short, I stole it ;)
I also tested it with Expert Advisor - it somehow depends on the closing amount. If you put a smaller amount, it would lose if you put more, it would also lose.
I was testing 100 000 Rbls and 100 000 Rbls of profit and it went up to two million (last year on EUR/USD for 1 hour).