The new "FileSave" function only saves the file in binary form?
Suggestion for class CGraphic.mqh.
In order to be able to delete a chart object, the GraphPlot methods need to be changed:
//| Create graphic of one curve and return resource name |
//+------------------------------------------------------------------+
string GraphPlot(const double &y[],ENUM_CURVE_TYPE type=CURVE_POINTS)
{
string name="Graphic"+(string)(GetTickCount()+MathRand());
ulong width = ChartGetInteger(0,CHART_WIDTH_IN_PIXELS);
ulong height= ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS);
CGraphic graphic;
//--- create graphic and add curves
graphic.Create(0,name,0,65,45,(int)(0.6*width),(int)(0.65*height));
graphic.CurveAdd(y,type);
//--- plot curves
graphic.CurvePlotAll();
graphic.Update();
//--- return resource name
//return graphic.ResourceName();
return graphic.ChartObjectName();
}
For example right now there is an object named "Graphic27489614" on the chart, graphic.ResourceName() method returns "::Graphic2748961427502758" and graphic.ChartObjectName() method returns "Graphic27489614". And if you make a change, you can call ObjectDelete with the object name and delete the chart object.
Suggestion for class CGraphic.mqh.
In order to be able to delete a chart object, the GraphPlot methods need to be changed:
For example right now there is an object named "Graphic27489614" on the chart, graphic.ResourceName() method returns "::Graphic2748961427502758" and graphic.ChartObjectName() method returns "Graphic27489614". And if you make a change, you can call ObjectDelete with the object name and delete the chart object.
But this possibility already exists. By callingCGraphic::ChartObjectName() method, we get the name of object to be deleted.
P.S. Or evenCGraphic::Destroy() method.
Proposal for class CGraphic.mqh.
This feature is already available. Just by callingCGraphic::ChartObjectName() method, we get the name of object to be deleted.
P.S. Or evenCGraphic::Destroy() method.
No. Both methods don't work (CGraphic::ChartObjectName() returns "NULL"), CGraphic::Destroy() is not for deleting chart at all.
Both work for me. Test this script and show me your version. I wonder why it didn't work for you.
You can test two methods in the script.
//| Test.mq5 |
//| Copyright 2016, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
//---
#include <Math/Stat/Binomial.mqh>
#include <Graphics/Graphic.mqh>
//--- Размер массива
#define ARRAY_SIZE 50
//---
double array_values[ARRAY_SIZE];
double array_results[ARRAY_SIZE];
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart(void)
{
string name ="Graphic";
ulong width =::ChartGetInteger(0,CHART_WIDTH_IN_PIXELS);
ulong height =::ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS);
//---
CGraphic graphic;
//--- create graphic
graphic.Create(0,name,0,65,45,(int)(0.6*width),(int)(0.65*height));
//---
InitArray();
CCurve *curve1=graphic.CurveAdd(array_values,CURVE_POINTS);
//---
graphic.CurvePlotAll();
graphic.Update();
//---
for(int i=0; i<10; i++)
{
InitArray();
curve1.Update(array_values);
//---
graphic.CurvePlotAll();
graphic.Update();
//---
Sleep(500);
}
//---
graphic.Destroy();
//---
::Print(__FUNCTION__," > graphic.ChartObjectName(): ",graphic.ChartObjectName());
if(!::ObjectDelete(0,graphic.ChartObjectName()))
Print(__FUNCTION__," > Объект уже удалён!");
}
//+------------------------------------------------------------------+
//| Генерация значений |
//+------------------------------------------------------------------+
void InitArray(void)
{
for(int j=0; j<ARRAY_SIZE; j++)
array_values[j]=j;
Shuffle(array_values);
}
//+------------------------------------------------------------------+
//| Тасование значений массива |
//+------------------------------------------------------------------+
void Shuffle(double &array[])
{
for(uint i=0; i<ARRAY_SIZE; i++)
RandomSwap(array_values,i);
}
//+------------------------------------------------------------------+
//| Случайно поменять элементы местами |
//+------------------------------------------------------------------+
void RandomSwap(double &array[],uint i)
{
//--- Случайный индекс для замены
uint j=::rand()%ARRAY_SIZE;
//--- Меняем местами
double temp =array[i];
array[i] =array[j];
array[j] =temp;
}
//+------------------------------------------------------------------+
I originally tortured this example (taken fromMetaTrader 5 build 1485: additional test and chart modes in the standard library)
//| Test_1.mq5 |
//| Copyright 2016, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#include <Math/Stat/Binomial.mqh>
#include <Graphics/Graphic.mqh>
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnStart(void)
{
double vars[101];
double results[101];
const int N=2000;
//---
MathSequence(0,N,20,vars);
MathProbabilityDensityBinomial(vars,N,M_PI/10,true,results);
GraphPlot(results);
//---
}
#include <Math\Stat\Normal.mqh>
#include <Graphics\Graphic.mqh>
void OnStart()
{
//---
double random_values[];
double pdf[];
double cdf[];
double x[];
if(MathRandomNormal(0,1,1000000,random_values))
{
if(MathProbabilityDensityEmpirical(random_values,200,x,pdf))
{
GraphPlot(x,pdf,CURVE_LINES);
//---
DebugBreak();
}
if(MathCumulativeDistributionEmpirical(random_values,200,x,cdf))
{
GraphPlot(x,cdf,CURVE_LINES);
//---
DebugBreak();
}
}
}
I originally tortured this example (taken fromMetaTrader 5 build 1485: additional testing and charting modes in the standard library)
//| Test_1.mq5 |
//| Copyright 2016, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#include <Math/Stat/Binomial.mqh>
#include <Graphics/Graphic.mqh>
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnStart(void)
{
double vars[101];
double results[101];
const int N=2000;
//---
MathSequence(0,N,20,vars);
MathProbabilityDensityBinomial(vars,N,M_PI/10,true,results);
GraphPlot(results);
//---
}
In general removal for the time being I'm doing this:
ChartRedraw();
How do I know if SL/TP is triggered in OnTradeTransaction()?
Here's what I've done, doesn't help:
const MqlTradeRequest &request, // структура запроса
const MqlTradeResult &result) // структура ответа
{
if(trans.type == TRADE_TRANSACTION_HISTORY_ADD)
{
datetime date = TimeCurrent ();
MqlDateTime dateT;
TimeToStruct (date, dateT);
dateT.hour += 1;
date = StructToTime (dateT);
if(HistorySelect (TimeCurrent (), date))
{
int dealsTotal = HistoryDealsTotal ();
ulong ticketD = HistoryDealGetTicket (dealsTotal - 1);
if(HistoryDealGetString (ticketD, DEAL_SYMBOL) == Symbol ())
{
ENUM_DEAL_ENTRY entry = (ENUM_DEAL_ENTRY)HistoryDealGetInteger (ticketD, DEAL_ENTRY);
if(entry == DEAL_ENTRY_OUT)
{
int ordersTotal = HistoryOrdersTotal ();
ulong ticketO = HistoryOrderGetTicket (ordersTotal - 1);
if(HistoryOrderGetString (ticketO, ORDER_SYMBOL) == Symbol ())
{
double orderPrice = HistoryOrderGetDouble (ticketO, ORDER_PRICE_OPEN);
double orderSL = HistoryOrderGetDouble (ticketO, ORDER_SL);
double orderTP = HistoryOrderGetDouble (ticketO, ORDER_TP);
if(orderPrice == orderSL)
Print ("Сработал SL");
if(orderPrice == orderTP)
Print ("Сработал TP");
}
}
}
}
}
}
And anyway, can't there be any simpler way!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
The new "FileSave" function only saves a file in binary form?
//| Scripts_Test.mq5 |
//| Copyright 2012, CompanyName |
//| http://www.companyname.net |
//+------------------------------------------------------------------+
//--- входные параметры
input int rates_to_save=1000; // количество
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
string filename=_Symbol+"_ticks.csv";
MqlRates rates[];
//---
int copied=CopyRates(Symbol(),Period(),0,rates_to_save,rates);
if(copied!=-1)
{
PrintFormat(" CopyRates(%s) copied %d rates",Symbol(),copied);
//--- запишем тики в файл
if(!FileSave(filename,rates,FILE_COMMON))
PrintFormat("FileSave() failed, error=%d",GetLastError());
}
else
PrintFormat("Failed CopyRates(%s), Error=",_Symbol,GetLastError());
}
//+------------------------------------------------------------------+
What I wanted to do: save the file in "csv" format To open in Excel.