This function writes a number on each order, or rather lot*100.
Now we need an inverse function which shows what was the last number
Try it:
double value = StringToDouble(ObjectGetString(0,object_name,OBJPROP_TEXT));
If the object contains text (not numeric), you need to add StringSubstr():
double value = StringToDouble( StringSubstr(ObjectGetString(0,object_name,OBJPROP_TEXT),begin_index,length));
begin_index - index of the character in the string, starting from zero, length - length of the numeric value (how many characters the number occupies)... I think so
If the object has text (not numeric), add StringSubstr():
begin_index - index of the character in the string , starting from zero, length - length of the numeric value (how many characters the number occupies)... I think so
Well initially you would have to look for these all numbers on the graph. It just won't work that way. That's the problem. Already checked.
If object has text (not numeric), add StringSubstr():
begin_index - index of the character in the string, starting from zero, length - length of the numeric value (how many characters the number occupies)... I think so
Like this one, but it doesn't work. It shows zero.
Do you want to set a value or take a value? The ObjectSetString() functionsets a text value and returns a bool value. This is not it. And in the loop head I think it's not the right one... Where ObjectsTotal()... I am guided by mt4 reference. Or is it mt5 code?
Do you need to set a value or take a value? The ObjectSetString() functionsets a text value and returns a bool value. This is not it. And in the head of the loop I think it's not the right one... Where ObjectsTotal()... I am guided by mt4 reference. Or is it mt5 code?
#property copyright"Copyright 2019, MetaQuotes Software Corp."#property link"https://www.mql5.com"#property version"1.00"//---- показывать входные параметры#property script_show_inputs//---#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
CTrade m_trade; // trading object
CSymbolInfo m_symbol; // symbol info object//+------------------------------------------------------------------+//| Enum Stop or Limit |//+------------------------------------------------------------------+enum ENUM_STOP_OR_LIMIT
{
stop=0, // Buy stop and Sell stop
limit=1// Buy limit and Sell limit
};
//--- input parametersinputushort InpUpGap = 15; // Gap for pending orders UP from the current price (in points)inputushort InpUpStep = 30; // Step between orders UP (in points)inputushort InpDownGap = 15; // Gap for pending orders DOWN from the current price (in points)inputushort InpDownStep = 30; // Step between orders DOWN (in points)input ENUM_STOP_OR_LIMIT InpPending = stop; // Type of pending ordersinputuchar InpUpQuantity = 1; // UP quantity ordersinputuchar InpDownQuantity = 1; // DOWN quantity ordersinputdouble InpLots = 0.01; // Lotsinputushort InpStopLoss = 50; // Stop Loss (in points)inputushort InpTakeProfit = 50; // Take Profit (in points)//---ulong m_slippage=30; // slippagedouble ExtUpGap=0.0;
double ExtUpStep=0.0;
double ExtDownGap=0.0;
double ExtDownStep=0.0;
double ExtStopLoss=0.0;
double ExtTakeProfit=0.0;
//+------------------------------------------------------------------+//| Script program start function |//+------------------------------------------------------------------+voidOnStart()
{
//---if(InpLots<=0.0)
{
Print("The \"Lots\" can't be smaller or equal to zero");
return;
}
//---if(!m_symbol.Name(Symbol())) // sets symbol namereturn;
if(!RefreshRates())
return;
string err_text="";
if(!CheckVolumeValue(InpLots,err_text))
{
Print(err_text);
return;
}
//---if(IsFillingTypeAllowed(SYMBOL_FILLING_FOK))
m_trade.SetTypeFilling(ORDER_FILLING_FOK);
elseif(IsFillingTypeAllowed(SYMBOL_FILLING_IOC))
m_trade.SetTypeFilling(ORDER_FILLING_IOC);
else
m_trade.SetTypeFilling(ORDER_FILLING_RETURN);
//---
m_trade.SetDeviationInPoints(m_slippage);
m_trade.SetAsyncMode(true);
//---
ExtUpGap = m_symbol.Point() * InpUpGap;
ExtUpStep = m_symbol.Point() * InpUpStep;
ExtDownGap = m_symbol.Point() * InpDownGap;
ExtDownStep = m_symbol.Point() * InpDownStep;
ExtStopLoss = m_symbol.Point() * InpStopLoss;
ExtTakeProfit = m_symbol.Point() * InpTakeProfit;
//--- start workdouble start_price_ask=m_symbol.Ask()-ExtUpGap;
double start_price_bid=m_symbol.Bid()+ExtDownGap;
//--- set pending ordersfor(int i=0; i<InpUpQuantity; i++)
{
double price_ask = start_price_ask+i*ExtUpStep;
double price_bid = start_price_bid+i*ExtUpStep;
if(InpPending==stop)
{
double sl = (ExtStopLoss==0.0) ? 0.0 : price_ask - ExtStopLoss;
double tp = (ExtTakeProfit==0.0) ? 0.0 : price_ask + ExtTakeProfit;
m_trade.BuyStop(InpLots,m_symbol.NormalizePrice(price_ask),m_symbol.Name(),
m_symbol.NormalizePrice(sl),
m_symbol.NormalizePrice(tp));
}
else
{
double sl = (ExtStopLoss==0.0) ? 0.0 : price_bid + ExtStopLoss;
double tp = (ExtTakeProfit==0.0) ? 0.0 : price_bid - ExtTakeProfit;
m_trade.SellLimit(InpLots,m_symbol.NormalizePrice(price_bid),m_symbol.Name(),
m_symbol.NormalizePrice(sl),
m_symbol.NormalizePrice(tp));
}
}
for(int i=0; i<InpDownQuantity; i++)
{
double price_ask = start_price_ask-i*ExtDownStep;
double price_bid = start_price_bid-i*ExtDownStep;
if(InpPending==limit)
{
double sl = (ExtStopLoss==0.0) ? 0.0 : price_ask - ExtStopLoss;
double tp = (ExtTakeProfit==0.0) ? 0.0 : price_ask + ExtTakeProfit;
m_trade.BuyLimit(m_symbol.LotsMin(),m_symbol.NormalizePrice(price_ask),m_symbol.Name(),
m_symbol.NormalizePrice(sl),
m_symbol.NormalizePrice(tp));
}
else
{
double sl = (ExtStopLoss==0.0) ? 0.0 : price_bid + ExtStopLoss;
double tp = (ExtTakeProfit==0.0) ? 0.0 : price_bid - ExtTakeProfit;
m_trade.SellStop(m_symbol.LotsMin(),m_symbol.NormalizePrice(price_bid),m_symbol.Name(),
m_symbol.NormalizePrice(sl),
m_symbol.NormalizePrice(tp));
}
}
}
The script should place either pending limit orders at a certain distance from ask and bid, or stop ones. The limit pending orders are set without any problems but the stop ones are not. Please help me to understand why pending Buy Stop and Sell Stop orders are not set.
Yours sincerely, Vladimir.
Just to follow up with another question: is there any way to test the script when the market is closed (e.g. at the weekend)?
No one has responded to the question I posed earlier, but I'm still asking for help with the code.
One more question: is there any way to test the script when the market is closed (e.g. on weekends)?
Sincerely, Vladimir.
No, the script will not work in a closed market - it will not place orders.
To understand the errors, try printing into the log the value of the price relative to which you are calculating the setting levels and the values of all price levels you are sending to the trade order.
You need to find the last order that was opened. Find its ticket. Then use the list of object names to find the occurrence of a substring with the found ticket of the last order in the object name line. As soon as the ticket of the last order is found in the object name, this is the necessary graphical object. All that remains is to extract what you need from this graphical object.
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.
This function writes a number on each order, or rather lot*100.
Now we need an inverse function which shows what was the last number
Try it:
If the object contains text (not numeric), you need to add StringSubstr():
begin_index - index of the character in the string, starting from zero, length - length of the numeric value (how many characters the number occupies)... I think so
Try this:
If the object has text (not numeric), add StringSubstr():
begin_index - index of the character in the string , starting from zero, length - length of the numeric value (how many characters the number occupies)... I think so
Well initially you would have to look for these all numbers on the graph. It just won't work that way. That's the problem. Already checked.
Try this:
If object has text (not numeric), add StringSubstr():
begin_index - index of the character in the string, starting from zero, length - length of the numeric value (how many characters the number occupies)... I think so
Similar to this one, but it doesn't work. It shows zero.
Like this one, but it doesn't work. It shows zero.
Do you want to set a value or take a value? The ObjectSetString() function sets a text value and returns a bool value. This is not it. And in the loop head I think it's not the right one... Where ObjectsTotal()... I am guided by mt4 reference. Or is it mt5 code?
Do you need to set a value or take a value? The ObjectSetString() function sets a text value and returns a bool value. This is not it. And in the head of the loop I think it's not the right one... Where ObjectsTotal()... I am guided by mt4 reference. Or is it mt5 code?
This is MT4.
Once again, good day everyone!
I am not getting a response to my question posed earlier, but I am asking for help with the code anyway.
This is the forum for trading, automated trading systems and strategy testing.
Any newbie questions on MQL4 and MQL5, help and discussion on algorithms and codes
MrBrooklin, 2019.08.30 14:15
Good day everyone!!!
Here is part of the script code for Metatrader5:
The script should place either pending limit orders at a certain distance from ask and bid, or stop ones. The limit pending orders are set without any problems but the stop ones are not. Please help me to understand why pending Buy Stop and Sell Stop orders are not set.
Yours sincerely, Vladimir.
Just to follow up with another question: is there any way to test the script when the market is closed (e.g. at the weekend)?
Sincerely, Vladimir.
From which list?
And please use the styler in the editor (Ctrl+<):
What should be taken from where?
Can you give me a hint?
Once again, good day everyone!
No one has responded to the question I posed earlier, but I'm still asking for help with the code.
One more question: is there any way to test the script when the market is closed (e.g. on weekends)?
Sincerely, Vladimir.
No, the script will not work in a closed market - it will not place orders.
To understand the errors, try printing into the log the value of the price relative to which you are calculating the setting levels and the values of all price levels you are sending to the trade order.
Can you give me a hint?
You need to find the last order that was opened. Find its ticket. Then use the list of object names to find the occurrence of a substring with the found ticket of the last order in the object name line. As soon as the ticket of the last order is found in the object name, this is the necessary graphical object. All that remains is to extract what you need from this graphical object.