Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 1096

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
In the order commentary look for [tp] if there is one...
Hello Profi.
help fix the error in the indicator.....
indicator is working.
The signal is triggered on bar 0.
But when other ticks are received on the current bar, it triggers again and gives new signals.
I need it to put this signal in a circle in the place of the current event price when Sell or Buy - event occurs, and no other events were processed on this open bar.
I want to avoid new signals and circles on this bar.
________________________
I understand that you will say it is nonsense, it is false signals, etc., but this is exactly what I need.
I know I should create a flag, a marker, etc. - but I have no time to study the language myself.
_________________________
I would be very grateful if you could add such a flag to the attached file and mark the added lines with the color.....
Thank you, and I hope someone will respond
Makes a couple of errors, can't get it right. What's wrong here?
//+------------------------------------------------------------------+Please help me to trade on the news. I am in need of an EA which has two main functions.
The first function: placingpending orders with a given TP and SL, at a given time at a given level of price.
The second function: to keep the pending orders parallel to the price. It means to move them together with the price (it is so bothersome to do it manually). At a given time, at the moment of news publication, we have to stop this action and wait until the price touches one of the orders. The second order is immediately deleted after that.
Once again:
2 minutes before the news release, put two opposite stop orders at a distance of 10 points from the price, immediately activate the function of moving parallel to the price, 2 minutes move together with the price, one order runs away from the price, the second one catches up with the price. At the news release, you should disable the function of pending order movement and then wait for the breakdown of one of the orders. The second order is deleted immediately after the breakdown of the first one.
Variable variables that are changed in properties of an EA (approximately as I imagine, I do not know what the realization is in reality)
TP - 600 (by default)
Trall - 300 (default)
SL - 100 (default)
Pips - 100 (distance from price by default)
Slippage - 100 (slippage in pips by default)
Lot - 0.1
Risk - 10 //percent (well, it is not necessary, I will ask it later if necessary)
TimeNews1On - true (use cells below to enter time, false - advisor does not trade them)
TimeNewsHour - hour (news release time 1)
TimeNewsMin - minutes (news release time 1)
TimeNews2On - false (by default)
TimeNewsHour - hours (news release time 2)
TimeNewsMin - minutes (news release time 2)
TimeNews3On - false
TimeNewsHour - hours (news release time 3)
TimeNewsMin - minutes (news release time 3)
TimeNews4On - false
TimeNewsHour - hours (news release time 4)
TimeNewsMin - minutes (news release time 4)
TimeNews5On - false
TimeNewsHour - hours (news release time 5)
TimeNewsMin - minutes (news release time 5)
Insta, five digits.
I am doing all this manually, it is too much trouble, and now I have no time to work out the news, I want to place the Expert Advisor in the morning or at night on pairs where there will be news on that day, so they will all work out.
--------------------------------------
If you know such an expert, please share.
Thank you in advance!
Let's go back to your source code. Try it like this:
int OnInit()
{
if (!GlobalVariableCheck("AllowNewOrders")) GlobalVariableSet("AllowNewOrders",1);
return(INIT_SUCCEED);
}
void OnDeInit()
{
GlobalVariableSet("AllowNewOrders",1);
}
void OnTick()
{
if (CountTrades() == 0) // The number of orders must be zero
{
if ((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) < PriceOpenLastHistOrder(OP_BUY))
|| (TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) > PriceOpenLastHistOrder(OP_SELL))
// If the last trade is losing, the same one is opened, but with bigger lot
{
GlobalVariableSet("AllowNewOrders", 0);
Type = TypeLastHistOrder();
if (Type == OP_BUY) Price = Ask;
if (Type == OP_SELL) Price = Bid;
Lot = NormalizeDouble(LotsLastHistOrder()*Multiplier, 2);
ticket = OrderSend(Symbol(), Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
if (PriceCloseLastHistOrder() == PriceOpenLastHistOrder() && CountHistTrades() > 0)
// if last trade's profit is equal to zero, the same trade will be opened
{
GlobalVariableSet("AllowNewOrders", 0);
Type = TypeLastHistOrder();
if (Type == OP_BUY) Price = Ask;
if (Type == OP_SELL) Price = Bid;
Lot = NormalizeDouble(LotsLastHistOrder(), 2);
ticket = OrderSend(Symbol(), Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
if (((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) > PriceOpenLastHistOrder(OP_BUY))
|| (TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) < PriceOpenLastHistOrder(OP_SELL))
|| CountHistTrades() == 0)// If the last trade is profitable, the order is opened
{
if (GlobalVariableGet("AllowNewOrders") > 0)return;
if (SignalBuy() && MaxOpenOrders > OrdersTotal())
{
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, IntegerToString(Exp), Magic);
if (ticket>0) GlobalVariableSet("AllowNewOrders", 0);
}
if (SignalSell() && MaxOpenOrders > OrdersTotal())
{
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, IntegerToString(Exp), Magic);
if (ticket>0) GlobalVariableSet("AllowNewOrders", 0);
}
}
}
}
I haven't checked it, because I don't understand how multiple copies of an EA with a total limit of 1 order will determine on which symbol (after a profitable series) it is better to start trading?
Please help to trade on the news. Really need an EA that should have two main functions.
First function: placingpending orders with a given TP and SL, at a given time at a given level from the price.
The second function: to keep the pending orders parallel to the price. It means to move them together with the price (it is so bothersome to do it manually). At a given time, at the moment of news publication, we have to stop this action and wait until the price touches one of the orders. The second order is immediately deleted after that.
Once again:
2 minutes before the news release, put two opposite stop orders at a distance of 10 points from the price, immediately activate the function of moving parallel to the price, 2 minutes move together with the price, one order runs away from the price, the second one catches up with the price. At the news release, you should disable the function of pending order movement and then wait for the breakdown of one of the orders. The second one will be deleted immediately after the breakdown of the first one.
If you know or have met such advisors, please share
Thank you in advance!
I can send you the code for reading news from a file, it may come in handy. Once a week, you look at the economic calendar and enter the data into the file folder_with_terminal\MQL4\Files\novosti.txt of the news that you should pay attention to, the advisor can be activated even just before the news (you can use this advisor to track the beginning of the American session, for example - in case there is a strong movement). I have not finished the trading code because I was seriously "cheated" a couple of times by the news :)) The latest version placed six orders (3 buy stops + 3 sell stops) at different distances with different Take Profit. Anyway, my news code works, but I have to improve my trading code.
#property strict
input string NewsFilename = "novosti.txt"; // Name of the text file containing news
input int MinutesBefore = 5; // How many minutes prior to news publication should the orders be placed
input int MinutesAfter1 = 15; // how many minutes after the news release remove orders of the 1st group
input int MinutesAfter2 = 30; // how many minutes after the news release remove Group 2 orders
input int MinutesAfter3 = 30; // how many minutes after news release remove Group 3 orders
input int PriceIndent1 = 15; // Indent from the price in points
input int PriceIndent2 = 5; // Step back from the previous TakeProfit in points
input int TakeProfit1 = 40; // TakeProfit size for the 1st group in points
input int TakeProfit2 = 60; // TakeProfit size for the 2nd group in points
input int TakeProfit3 = 100; // TakeProfit size for the 3rd group in points
input int StopLoss = 20; // StopLoss size for all orders in points
input double Multiplier1 = 1.0; // Coefficient to the order lot of the 2nd group
input double Multiplier2 = 2.0; // coefficient to the order lots of the 3rd group
input int MaximalRisk = 10; // Maximum risk in percents
//====================================================================================================
datetime Times[200]; // LastTime;
string Symbols[200];
bool NewsPassed[200];
int NewsCount;
//====================================================================================================
int OnInit()
{
// Loading fresh news
if (!LoadNews()) return(INIT_FAILED);
return(INIT_SUCCEEDED);
}
//====================================================================================================
void OnTick()
{
if (!IsTradeAllowed()) return;
datetime TestTime = iTime(Symbol(), PERIOD_H1, 0);
// Updating of news at the beginning of each day
if (TimeDay(TestTime) != TimeDay(LastTime))
{
LastTime = TestTime;
if (!LoadNews())
{
Alert("Update news error!");
return;
}
}
//-------------------------------------------------------------------------------------------------
for (int i = 0; i < NewsCount; i++)
{
// Till news release put orders for breakthrough
if (Times[i] > TimeCurrent() && Times[i] - TimeCurrent() <= MinutesBefore * 60 && !NewsPassed[i])
{
PrintFormat("The current time is %s, it's time to set currency orders - %s", TimeToStr(TimeCurrent(), TIME_DATE|TIME_MINUTES), Symbols[i]);
SetupOrders(Symbols[i];
NewsPassed[i] = true;
}
}
//-------------------------------------------------------------------------------------------------
}
//====================================================================================================
bool LoadNews()
{
int Count, Tick = 0;
string Str, Data[40];
ResetLastError();
if (!FileIsExist(NewsFilename, 0))
{
PrintFormat("The news file %s does not exist.", NewsFilename);
Print("The file must be in the folder \\MQL4\\Files, in case of testing - in the folder \\Tester\\Files.");
return(false);
}
int Handle = FileOpen(NewsFilename, FILE_READ|FILE_SHARE_READ|FILE_TXT);
if (Handle != INVALID_HANDLE)
{
while (!FileIsEnding(Handle))
{
Str = FileReadString(Handle);
Count = StringSplit(Str, StringGetChar(" ", 0), Data);
for (int i = 1; i < Count; i = i + 2)
{
Times[Tick] = StringToTime(Data[0] + " + Data[i]);
Symbols[Tick] = Data[i + 1];
Tick++;
}
}
FileClose(Handle);
NewsCount = Tick;
for (int i = 0; i < NewsCount; i++)
{
if (Times[i] > TimeCurrent()) NewsPassed[i] = false;
else NewsPassed[i] = false;
}
PrintFormat("Number of news uploaded - %i.", NewsCount);
return(true);
}
PrintFormat("Can't open file %s. Error code %d.", NewsFilename, GetLastError());
return(false);
}
//====================================================================================================
void SetupOrders(string Sym)
{
int Ticket, Dig, Count;
double Price, TP, SL, Lot;
datetime KeepAlive = TimeCurrent() + (MinutesBefore + MinutesAfter1) * 60;
string SymList[7];
//-------------------------------------------------------------------------------------------------
if (Sym == "AUD")
{
SymList[0] = "AUDCAD"; SymList[1] = "AUDCHF"; SymList[2] = "AUDJPY"; SymList[3] = "AUDNZD";
SymList[4] = "AUDUSD"; SymList[5] = "EURAUD"; SymList[6] = "GBPAUD";
}
//-------------------------------------------------------------------------------------------------
if (Sym == "CAD")
{
SymList[0] = "AUDCAD"; SymList[1] = "CADCHF"; SymList[2] = "CADJPY"; SymList[3] = "EURCAD";
SymList[4] = "GBPCAD"; SymList[5] = "NZDCAD"; SymList[6] = "USDCAD";
}
//-------------------------------------------------------------------------------------------------
if (Sym == "CHF")
{
SymList[0] = "AUDCHF"; SymList[1] = "CADCHF"; SymList[2] = "EURCHF"; SymList[3] = "GBPCHF";
SymList[4] = "CHFJPY"; SymList[5] = "NZDCHF"; SymList[6] = "USDCHF";
}
//-------------------------------------------------------------------------------------------------
if (Sym == "EUR")
{
SymList[0] = "EURAUD"; SymList[1] = "EURCAD"; SymList[2] = "EURCHF"; SymList[3] = "EURGBP";
SymList[4] = "EURJPY"; SymList[5] = "EURNZD"; SymList[6] = "EURUSD";
}
//-------------------------------------------------------------------------------------------------
if (Sym == "GBP")
{
SymList[0] = "EURGBP"; SymList[1] = "GBPAUD"; SymList[2] = "GBPCAD"; SymList[3] = "GBPCHF";
SymList[4] = "GBPJPY"; SymList[5] = "GBPNZD"; SymList[6] = "GBPUSD";
}
//-------------------------------------------------------------------------------------------------
if (Sym == "JPY")
{
SymList[0] = "AUDJPY"; SymList[1] = "CADJPY"; SymList[2] = "CHFJPY"; SymList[3] = "EURJPY";
SymList[4] = "GBPJPY"; SymList[5] = "NZDJPY"; SymList[6] = "USDJPY";
}
//-------------------------------------------------------------------------------------------------
if (Sym == "NZD")
{
SymList[0] = "AUDNZD"; SymList[1] = "EURNZD"; SymList[2] = "GBPNZD"; SymList[3] = "NZDCAD";
SymList[4] = "NZDCHF"; SymList[5] = "NZDJPY"; SymList[6] = "NZDUSD";
}
//-------------------------------------------------------------------------------------------------
if (Sym == "USD")
{
SymList[0] = "AUSUSD"; SymList[1] = "EURUSD"; SymList[2] = "GBPUSD"; SymList[3] = "NZDUSD";
SymList[4] = "USDCAD"; SymList[5] = "USDCHF"; SymList[6] = "USDJPY";
}
//-------------------------------------------------------------------------------------------------
for (int i = 0; i < 7; i++)
{
Count = 0;
Dig = int(MarketInfo(SymList[i], MODE_DIGITS));
Lot = NormalizeDouble(0.01, 2);
//Buy
KeepAlive = TimeCurrent() + (MinutesBefore + MinutesAfter1) * 60;
Price = NormalizeDouble(MarketInfo(SymList[i], MODE_ASK) + PriceIndent1 / pow(10, Dig-1), Dig);
TP = NormalizeDouble(Price + TakeProfit1 / pow(10, Dig-1), Dig);
SL = NormalizeDouble(Price - StopLoss / pow(10, Dig-1), Dig);
Ticket = OrderSend(SymList[i], OP_BUYSTOP, Lot, Price, 5, SL, TP, NULL, 0, KeepAlive, clrLimeGreen);
if (Ticket > 0) Count++; else PrintFormat("Error creating the order %i, symbol %s, price %f, Take %f, Stop %f, Lot %f.", GetLastError(), SymList[i], Price, TP, SL, Lot);
KeepAlive = TimeCurrent() + (MinutesBefore + MinutesAfter2) * 60;
Price = NormalizeDouble(TP + PriceIndent2 / pow(10, Dig-1), Dig);
TP = NormalizeDouble(Price + TakeProfit2 / pow(10, Dig-1), Dig);
SL = NormalizeDouble(Price - StopLoss / pow(10, Dig-1), Dig);
Ticket = OrderSend(SymList[i], OP_BUYSTOP, Lot * Multiplier1, Price, 5, SL, TP, NULL, 0, KeepAlive, clrLimeGreen);
if (Ticket > 0) Count++; else PrintFormat("Error creating the order %i, symbol %s, price %f, Take %f, Stop %f, Lot %f.", GetLastError(), SymList[i], Price, TP, SL, Lot*Multiplier1);
KeepAlive = TimeCurrent() + (MinutesBefore + MinutesAfter3) * 60;
Price = NormalizeDouble(TP + PriceIndent2 / pow(10, Dig-1), Dig);
TP = NormalizeDouble(Price + TakeProfit2 / pow(10, Dig-1), Dig);
SL = NormalizeDouble(Price - StopLoss / pow(10, Dig-1), Dig);
Ticket = OrderSend(SymList[i], OP_BUYSTOP, Lot*Multiplier2, Price, 5, SL, TP, NULL, 0, KeepAlive, clrLimeGreen);
if (Ticket > 0) Count++; else PrintFormat("Error creating the order %i, symbol %s, price %f, take %f, stop %f, lot %f.", GetLastError(), SymList[i], Price, TP, SL, Lot*Multiplier2);
// Selling
KeepAlive = TimeCurrent() + (MinutesBefore + MinutesAfter1) * 60;
Price = NormalizeDouble(MarketInfo(SymList[i], MODE_BID) - PriceIndent1 / pow(10, Dig-1), Dig);
TP = NormalizeDouble(Price - TakeProfit1 / pow(10, Dig-1), Dig);
SL = NormalizeDouble(Price + StopLoss / pow(10, Dig-1), Dig);
Ticket = OrderSend(SymList[i], OP_SELLSTOP, Lot, Price, 5, SL, TP, NULL, 0, KeepAlive, clrOrangeRed);
if (Ticket > 0) Count++; else PrintFormat("Error creating the order %i, symbol %s, price %f, Take %f, Stop %f, Lot %f.", GetLastError(), SymList[i], Price, TP, SL, Lot);
KeepAlive = TimeCurrent() + (MinutesBefore + MinutesAfter2) * 60;
Price = NormalizeDouble(TP - PriceIndent2 / pow(10, Dig-1), Dig);
TP = NormalizeDouble(Price - TakeProfit2 / pow(10, Dig-1), Dig);
SL = NormalizeDouble(Price + StopLoss / pow(10, Dig-1), Dig);
Ticket = OrderSend(SymList[i], OP_SELLSTOP, Lot, Price, 5, SL, TP, NULL, 0, KeepAlive, clrOrangeRed);
if (Ticket > 0) Count++; else PrintFormat("Error creating the order %i, symbol %s, price %f, Take %f, Stop %f, Lot %f.", GetLastError(), SymList[i], Price, TP, SL, Lot*Multiplier1);
KeepAlive = TimeCurrent() + (MinutesBefore + MinutesAfter3) * 60;
Price = NormalizeDouble(TP - PriceIndent2 / pow(10, Dig-1), Dig);
TP = NormalizeDouble(Price - TakeProfit3 / pow(10, Dig-1), Dig);
SL = NormalizeDouble(Price + StopLoss / pow(10, Dig-1), Dig);
Ticket = OrderSend(SymList[i], OP_SELLSTOP, Lot, Price, 5, SL, TP, NULL, 0, KeepAlive, clrOrangeRed);
PrintFormat("There are %i orders placed by the symbol %s", SymList[i], Count);0 }
}
The news file looks like this:
15.09.2016 01:45 NZD 04:30 AUD 10:30 CHF 14:00 GBP 15:30 USD
16.09.2016 15:30 USD 17:00 USD
and so on...
Let's go back to your source code. Try it like this:
int OnInit()
{
if (!GlobalVariableCheck("AllowNewOrders")) GlobalVariableSet("AllowNewOrders",1);
return(INIT_SUCCEED);
}
void OnDeInit()
{
GlobalVariableSet("AllowNewOrders",1);
}
void OnTick()
{
if (CountTrades() == 0) // The number of orders must be zero
{
if ((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) < PriceOpenLastHistOrder(OP_BUY))
|| (TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) > PriceOpenLastHistOrder(OP_SELL))
// If the last trade is losing, the same one is opened, but with bigger lot
{
GlobalVariableSet("AllowNewOrders", 0);
Type = TypeLastHistOrder();
if (Type == OP_BUY) Price = Ask;
if (Type == OP_SELL) Price = Bid;
Lot = NormalizeDouble(LotsLastHistOrder()*Multiplier, 2);
ticket = OrderSend(Symbol(), Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
if (PriceCloseLastHistOrder() == PriceOpenLastHistOrder() && CountHistTrades() > 0)
// if last trade's profit is equal to zero, the same trade will be opened
{
GlobalVariableSet("AllowNewOrders", 0);
Type = TypeLastHistOrder();
if (Type == OP_BUY) Price = Ask;
if (Type == OP_SELL) Price = Bid;
Lot = NormalizeDouble(LotsLastHistOrder(), 2);
ticket = OrderSend(Symbol(), Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
if (((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) > PriceOpenLastHistOrder(OP_BUY))
|| (TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) < PriceOpenLastHistOrder(OP_SELL))
|| CountHistTrades() == 0)// If the last trade is profitable, open order
{
if (GlobalVariableGet("AllowNewOrders") > 0)return;
if (SignalBuy() && MaxOpenOrders > OrdersTotal())
{
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, IntegerToString(Exp), Magic);
if (ticket>0) GlobalVariableSet("AllowNewOrders", 0);
}
if (SignalSell() && MaxOpenOrders > OrdersTotal())
{
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, IntegerToString(Exp), Magic);
if (ticket>0) GlobalVariableSet("AllowNewOrders", 0);
}
}
}
}
I haven't checked it, because I don't understand how several copies of an EA with a total limit of 1 order will detect at which symbol (after a profitable series) it is better to start trading?
Alexander, the bot has to wait for the specified number of candles in each symbol in one direction and then start a series, that is, at which symbol this condition is triggered first for that symbol and open the first trade. At the same time, you should prohibit opening a series for other symbols until the first series finishes with profit.
The last code you have given is a step forward - it does not open any deal at all (i.e., the ban is active). I have not understood why none at all. Attached is a screenshot of the log.
Maybe it's time to learn how to insert code!
The last code you gave is a step ahead - it doesn't open any trades at all (so the ban is in effect). I have not yet understood why none at all. Attached is a screenshot of the log.
At first, the variable was called ProfitableSerie and had opposite function. And I have something else to add.
Try it this way. I have a feeling something else will come up...