Good afternoon!
In Alpari on MT5, I generated an expert Advisor based on RSI signals. I started it and there was a problem:
an automatic Expert Advisor opens orders on a demo account. And with open orders in the history, sometimes negative trades occur, and at the same time the stop loss is either not set, or it is still very far away. what could it be? On the account of 10000 usd, the leverage is 1:1. the lot size is 0.01
vlad143
At the moment of opening any trade, there is a jump in the spread to the loss area. Opening Buy at the Ask rate, we immediately get the current rate at which the transaction can be closed, equal to Bid, which is worse than Ask for the spread. Are you talking about such disadvantages? How do they relate to setting a stop loss, deposit, leverage, and lot?
artur50000
I don’t think it’s the signals at all. when I put an Expert Advisor based on the MACD, it was all the same. I want to emphasize once again that a negative entry in the history occurs when
OPEN order. The order itself is closed by take profit on the total.
account details:
I trade on the five-minute frame EURUSD, GBPUSD after six in the evening in Moscow.
Here is the code of the RSI Expert Advisor:
#include
//— available money management
#include
//+——————————————————————+
//| Inputs |
//+——————————————————————+
//— inputs for expert
input string Expert_Title =”art6″; // Document name
ulong Expert_MagicNumber =32023; //
bool Expert_EveryTick =false; //
//— inputs for main signal
input int Signal_ThresholdOpen =10; // Signal threshold value to open [0…100]
input int Signal_ThresholdClose=10; // Signal threshold value to close [0…100]
input double Signal_PriceLevel =0.0; // Price level to execute a deal
input double Signal_StopLevel =50.0; // Stop Loss level (in points)
input double Signal_TakeLevel =0.50; // Take Profit level (in points)
input int Signal_Expiration =4; // Expiration of pending orders (in bars)
input int Signal_RSI_PeriodRSI =8; // Relative Strength Index(8,…) Period of calculation
input ENUM_APPLIED_PRICE Signal_RSI_Applied =PRICE_CLOSE; // Relative Strength Index(8,…) Prices series
input double Signal_RSI_Weight =1.0; // Relative Strength Index(8,…) Weight [0…1.0]
//— inputs for money
input double Money_FixLot_Percent =10.0; // Percent
input double Money_FixLot_Lots =0.1; // Fixed volume
//+——————————————————————+
//| Global expert object |
//+——————————————————————+
CExpert ExtExpert;
//+——————————————————————+
//| Initialization function of the expert |
//+——————————————————————+
int OnInit()
{
//— Initializing expert
if(!ExtExpert.Init(Symbol(),Period(),Expert_EveryTick,Expert_MagicNumber))
{
//— failed
printf(__FUNCTION__+”: error initializing expert”);
ExtExpert.Deinit();
return(INIT_FAILED);
}
//— Creating signal
CExpertSignal *signal=new CExpertSignal;
if(signal==NULL)
{
//— failed
printf(__FUNCTION__+”: error creating signal”);
ExtExpert.Deinit();
return(INIT_FAILED);
}
//—
ExtExpert.InitSignal(signal);
signal.ThresholdOpen(Signal_ThresholdOpen);
signal.ThresholdClose(Signal_ThresholdClose);
signal.PriceLevel(Signal_PriceLevel);
signal.StopLevel(Signal_StopLevel);
signal.TakeLevel(Signal_TakeLevel);
signal.Expiration(Signal_Expiration);
//— Creating filter CSignalRSI
CSignalRSI *filter0=new CSignalRSI;
if(filter0==NULL)
{
//— failed
printf(__FUNCTION__+”: error creating filter0″);
ExtExpert.Deinit();
return(INIT_FAILED);
}
signal.AddFilter(filter0);
//— Set filter parameters
filter0.PeriodRSI(Signal_RSI_PeriodRSI);
filter0.Applied(Signal_RSI_Applied);
filter0.Weight(Signal_RSI_Weight);
//— Creation of trailing object
CTrailingNone *trailing=new CTrailingNone;
if(trailing==NULL)
{
//— failed
printf(__FUNCTION__+”: error creating trailing”);
ExtExpert.Deinit();
return(INIT_FAILED);
}
//— Add trailing to expert (will be deleted automatically))
if(!ExtExpert.InitTrailing(trailing))
{
//— failed
printf(__FUNCTION__+”: error initializing trailing”);
ExtExpert.Deinit();
return(INIT_FAILED);
}
//— Set trailing parameters
//— Creation of money object
CMoneyFixedLot *money=new CMoneyFixedLot;
if(money==NULL)
{
//— failed
printf(__FUNCTION__+”: error creating money”);
ExtExpert.Deinit();
return(INIT_FAILED);
}
//— Add money to expert (will be deleted automatically))
if(!ExtExpert.InitMoney(money))
{
//— failed
printf(__FUNCTION__+”: error initializing money”);
ExtExpert.Deinit();
return(INIT_FAILED);
}
//— Set money parameters
money.Percent(Money_FixLot_Percent);
money.Lots(Money_FixLot_Lots);
//— Check all trading objects parameters
if(!ExtExpert.ValidationSettings())
{
//— failed
ExtExpert.Deinit();
return(INIT_FAILED);
}
//— Tuning of all necessary indicators
if(!ExtExpert.InitIndicators())
{
//— failed
printf(__FUNCTION__+”: error initializing indicators”);
ExtExpert.Deinit();
return(INIT_FAILED);
}
//— ok
return(INIT_SUCCEEDED);
}
//+——————————————————————+
//| Deinitialization function of the expert |
//+——————————————————————+
void OnDeinit(const int reason)
{
ExtExpert.Deinit();
}
//+——————————————————————+
//| “Tick” event handler function |
//+——————————————————————+
void OnTick()
{
ExtExpert.OnTick();
}
//+——————————————————————+
//| “Trade” event handler function |
//+——————————————————————+
void OnTrade()
{
ExtExpert.OnTrade();
}
//+——————————————————————+
//| “Timer” event handler function |
//+——————————————————————+
void OnTimer()
{
ExtExpert.OnTimer();
}
//+——————————————————————+
barabashkakvn
RSI trading signals.
Look at these signals, as well as the weights of the signals in your code. Also an article for review:
MQL5 Wizard: New version
Improvements continue to be made to the MetaTrader 5 terminal, and new functionality is being added. In the next (439) build of MetaTrader 5, the MQL5 Wizard has also been updated, which allows you to create Expert Advisors with even more flexible trading rules. In this article, we will show the new features of the MQL5 Wizard and tell you about the changes in the architecture of experts obtained when using it. From the very beginning, the MQL5 Wizard was conceived as a tool for easy creation of programs in MQL5. Already in the first version of the MQL5 Wizard, it was possible to quickly create a ready-to-use Expert Advisor as a set of simple modules in the form of source code in the MQL5 language. To do this, you did not even need to know the MQL5 language, it was enough to read the article “Build your trading advisor in the MQL5 Wizard”. In total, the Expert Advisor generated by the Master contains three modules: the trading signals module; the position tracking module; and the capital and risk management module. Each Expert Advisor module is based on its own…
Articles | 2011.04.27 18: 07 | MetaQuotes Software Corp. | Trading | MetaTrader 5
When will you get acquainted and if there are any questions: