Could someone tell me how to add an ON/OFF button on this gap finder indicator I've recently modified?
I'm an amateur noobie programmer and I can only code basic things and this is getting pretty challenging for me.
I've tried to integrate and modify part of other codes with buttons template but no way.
This are the indicators inputs which are customizable
Indicator Input Parameters
This is how it prints gaps on charts
Indicator on chart
CODE
#property indicator_chart_window
#property indicator_buffers 1
#property description "Automatically render boxes for liquidity gaps "
#property indicator_color1 Black
extern double Gap_Size_Minimum = 100;
extern int ExtendBars = 1000;
extern int History = 1000;
extern color Gap_Up = Aqua;
extern color Gap_Down = Tomato;
input ENUM_LINE_STYLE Rectangle_Style = STYLE_SOLID;
double Pip;
int init()
{
Pip = Point;
if(Digits==3 || Digits==5) Pip = 10*Point;
return(0);
}
int deinit()
{
string ObjName;
for(int i = ObjectsTotal()-1; i>=0; i--)
{
ObjName = ObjectName(i);
if(StringFind(ObjName,"liquidity_gaps",0)>=0)
ObjectDelete(ObjName);
}
return(0);
}
int start()
{
int i, limit, counted_bars=IndicatorCounted();
limit = MathMin(History,Bars-counted_bars-1);
string ObjName;
for(i=limit; i>=0; i--)
{
if(i>Bars-2) continue;
if(MathAbs(Open[i]-Close[i+1]) > Gap_Size_Minimum*Pip)
{
ObjName = "liquidity_gaps_Up_"+Time[i];
color ObjColor;
if(Open[i] > Close[i+1]) ObjColor = Gap_Up;
else ObjColor = Gap_Down;
if(ObjectFind(ObjName)<0)
{
ObjectCreate(ObjName,OBJ_RECTANGLE,0,Time[i+1],Close[i+1],Time[i],Open[i]);
ObjectSet(ObjName,OBJPROP_BACK,0);
ObjectSet(ObjName,OBJPROP_COLOR,ObjColor);
ObjectSet(ObjName,OBJPROP_STYLE,Rectangle_Style);
}
}
//datetime thistime = Time[i];
int ib = i+ExtendBars;
while(ib>=0)
{
ObjName = "liquidity_gaps_Up_"+Time[ib];
if(ObjectFind(ObjName)>=0)
{
double pr2 = ObjectGet(ObjName,OBJPROP_PRICE2);
double pr1 = ObjectGet(ObjName,OBJPROP_PRICE2);
ObjectSet(ObjName,OBJPROP_TIME2,Time[i]);
ObjectSet(ObjName,OBJPROP_PRICE2,pr2);
}
ib--;
}
}
return(0);
}
Indicator download for MT4
Thanks in advance for you kind help
Related
I want to play local video file in Qt platform using ffmpeg to decode.Everything is OK except that play speed is as twice as normal.
The first thing I think about is that there must be a sampling frequency involved.But to be a new to ffmpeg,I don't know how to fix this problem.
Above is my code to read frame,is anyone can tell me what's wrong with the code ?
void VideoThread::run()
{
m_pInFmtCtx = avformat_alloc_context(); //ini struct
char path[] = "d:/test.mp4";
// open specific file
if(avformat_open_input(&m_pInFmtCtx, *path, NULL, NULL)){
{
qDebug()<<"get rtsp failed";
return;
}
else
{
qDebug()<<"get rtsp success";
}
if(avformat_find_stream_info(m_pInFmtCtx, NULL) < 0)
{
qDebug()<<"could not find stream information";
return;
}
int nVideoIndex = -1;
for(int i = 0; i < m_pInFmtCtx->nb_streams; i++)
{
if(m_pInFmtCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
{
nVideoIndex = i;
break;
}
}
if(nVideoIndex == -1)
{
qDebug()<<"could not find video stream";
return;
}
qDebug("---------------- File Information ---------------");
m_pCodecCtx = m_pInFmtCtx->streams[nVideoIndex]->codec;
m_pCodec = avcodec_find_decoder(m_pCodecCtx->codec_id);
if(!m_pCodec)
{
qDebug()<<"could not find codec";
return;
}
//start Decoder
if (avcodec_open2(m_pCodecCtx, m_pCodec, NULL) < 0) {
qDebug("Could not open codec.\n");
return;
}
//malloc space for stroring frame
m_pFrame = av_frame_alloc();
m_pFrameRGB = av_frame_alloc();
m_pOutBuf = (uint8_t*)av_malloc(avpicture_get_size(AV_PIX_FMT_RGB32, m_pCodecCtx->width, m_pCodecCtx->height));
avpicture_fill((AVPicture*)m_pFrameRGB, m_pOutBuf, AV_PIX_FMT_RGB32, m_pCodecCtx->width, m_pCodecCtx->height);
//for color switch,from YUV to RGB
struct SwsContext *pImgCtx = sws_getContext(m_pCodecCtx->width, m_pCodecCtx->height, m_pCodecCtx->pix_fmt,
m_pCodecCtx->width, m_pCodecCtx->height, AV_PIX_FMT_RGB32, SWS_BICUBIC, NULL, NULL, NULL);
int nSize = m_pCodecCtx->width * m_pCodecCtx->height;
m_pPacket = (AVPacket *)av_malloc(sizeof(AVPacket));
if(av_new_packet(m_pPacket, nSize) != 0)
{
qDebug()<<"new packet failed";
}
//isInterruptionRequested is a flag,determine whether the thread is over
// read each frame from specific video file
while (!isInterruptionRequested())
{
int nGotPic = 0;
if(av_read_frame(m_pInFmtCtx, m_pPacket) >= 0)
{
if(m_pPacket->stream_index == nVideoIndex)
{
//avcodec_decode_video2()transform from packet to frame
if(avcodec_decode_video2(m_pCodecCtx, m_pFrame, &nGotPic, m_pPacket) < 0)
{
qDebug()<<"decode failed";
return;
}
if(nGotPic)
{ // transform to RGB color
sws_scale(pImgCtx, (const uint8_t* const*)m_pFrame->data,
m_pFrame->linesize, 0, m_pCodecCtx->height, m_pFrameRGB->data,
m_pFrameRGB->linesize);
// save to QImage,for later use
QImage *pImage = new QImage((uchar*)m_pOutBuf, m_pCodecCtx->width, m_pCodecCtx->height, QImage::Format_RGB32);
}
}
}
av_free_packet(m_pPacket);
msleep(5);
}
exec();
}
So for some project i'm working with Xamarin.Forms.
Since one area is just unbearably slow with Xamarin.Forms i've used a CustomRenderer to solve one particular area where a list is involved.
After getting back to the project and upgrading packages, i've suddenly got the weirdest bug.
I am setting "1234" to an EditText, and the EditText.Text Property is suddenly "49505152" - the string is converted to its ascii equivalent.
Is this a known issue? Does anyone know how to fix it?
The cause of the issue was that my EditText had an InputFilter applied and that after updating a package suddenly another code path of FilterFormatted was executed.
public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend)
{
var startSection = dest.SubSequenceFormatted(0, dstart);
var insert = source.SubSequenceFormatted(start, end);
var endSection = dest.SubSequenceFormatted(dstart, dest.Length());
var merged = $"{startSection}{insert}{endSection}";
if (ValidationRegex.IsMatch(merged) && InputRangeCheck(merged, CultureInfo.InvariantCulture))
{
StringBuilder sb = new StringBuilder(end - start);
for (int i = start; i < end; i++)
{
char c = source.CharAt(i);
sb.Append(c);
}
if (source is ISpanned) {
SpannableString sp = new SpannableString(sb);
TextUtils.CopySpansFrom((ISpanned)source, start, sb.Length(), null, sp, 0);
return sp;
} else {
// AFTER UPDATE THIS PATH WAS ENTERED UNLIKE BEFORE
return sb;
}
}
else
{
return new SpannableString(string.Empty);
}
}
Is it possible to render in one progressbar the progress of 2 nested tasks?
I mean, if I have to read lines from several files in several directories. I have this snippet code:
EDIT:
final int steps = directories.size();
Task<Integer> task2 = new Task<Integer>() {
/**
*/
#Override
protected Integer call() throws Exception {
int len = files.length;
updateProgress(0, len);
for(int i = 0; i < files.length; i++) {
final String filename = files[i].getName();
final String file = files[i].getPath();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
}
String currentLine = null;
while ((currentLine = br.readLine()) != null) {
readlines(currentLine, filename);
}
} catch (IOException xs) {
xs.getMessage();
}
System.out.println("******* Working on: " + file + " ******************************");
updateProgress(i + 1, files.length);
}
System.out.println("done: " + directoryName);
return len;
}
};
task2.setOnRunning(r -> {
DoubleBinding totalProgress = null;
for(int i = 0; i < steps; i++) {
DoubleBinding increment = task2.progressProperty().divide(steps);
if (totalProgress == null) {
totalProgress = increment;
} else {
totalProgress = totalProgress.add(increment);
}
}
progressBar.progressProperty().bind(totalProgress);
status.textProperty().bind(task2.stateProperty().asString());
statusProcess.textProperty().bind(Bindings.when(totalProgress.isEqualTo(-1))
.then("0.00")
.otherwise(task2.progressProperty().multiply(100.00).asString("%.02f %%")));
console.textProperty().bind(task2.messageProperty());
});
new Thread(task2).start();
I am enable to access progress bar but as long as I have directories, the progress bar will restart to 0 and will check for files into the next directory and then populate the progress bar until 1 and then restart to 0 if there is another directory.
How can I do if I want to display these 2 tasks in one as I don't want to restart from 0 when the next directory is reading. If I have for example 4 directories, I expect to see a moving the progressbar until its quarter and so on.
Is anybody as an idea what I am doing wrong?
You can do something like
progressBar.progressProperty().bind(Bindings.createDoubleBinding(
() -> Math.max(0, task1.getProgress()) / 2 + Math.max(0, task2.getProgress()) /2 ,
task1.progressProperty(), task2.progressProperty());
If you can easily estimate or compute the relative times each task will take, you can weight the progress of each task accordingly, instead of simply averaging them as in the code above.
I'm creating line chart using Java FX. On update, I have a list of checkbox to select or deselect the series of linechart. When all are deselected but tick points or animated tick points are there and so on by doing the same thing again or adding new data for line chart it is same. I'm unable to add images to make it easier for you. Please do some help.
private static void printChartAnalysis(analysisResults r){
clearAnalsisChartData();
int [][]analysisResult=r.getAnalysisResult();
ArrayList<String> versionss=r.getVersions();
int k=0;
for(String x:versionss){
String z=new String();
for(int i=0;i<x.length();i++){
if(Character.isDigit(x.charAt(i))){
z+=x.charAt(i);
}
}
dataLOC.add(new XYChart.Data(z,(int)analysisResult[k][0]));
dataComm.add(new XYChart.Data(z,(int)analysisResult[k][1]));
dataCond.add(new XYChart.Data(z,(int)analysisResult[k][2]));
dataLoops.add(new XYChart.Data(z,(int)analysisResult[k][3]));
dataMem.add(new XYChart.Data(z,(int)analysisResult[k][4]));
k++;
}
seriesLOC.setData(dataLOC);
seriesCond.setData(dataCond);
seriesComm.setData(dataComm);
seriesLoop.setData(dataLoops);
seriesMem.setData(dataMem);
lineChart.getData().setAll(seriesLOC,seriesComm,seriesCond,seriesLoop,seriesMem);
lineChart.setTitle("Line Chart for "+r.getSoftwareName());
for (int i = 0; i < names.length; i++) {
final CheckBox cb = cbs[i];
cb.setSelected(true);
}
}
private static void printChartCost(cocomoResults est){
clearAnalsisChartData();
clearCostChartData();
for(COCOMO cost:est.getVersionsResult()){
String version=cost.getVersion();
String z=new String();
for(int i=0;i<version.length();i++){
if(Character.isDigit(version.charAt(i))){
z+=version.charAt(i);
}
}
dataEffort.add(new XYChart.Data(z,(int)cost.getEffort()));
dataDura.add(new XYChart.Data(z,(int)cost.getDuration()));
dataStaff.add(new XYChart.Data(z,(int)cost.getStaff()));
dataProd.add(new XYChart.Data(z,(int)cost.getProductivity()));
}
seriesEffort.setData(dataEffort);
seriesDura.setData(dataDura);
seriesStaff.setData(dataStaff);
seriesProd.setData(dataProd);
lineChart.getData().setAll(seriesEffort,seriesDura,seriesStaff,seriesProd);
}
private static void clearAnalsisChartData(){
lineChart.getData().removeAll(seriesLOC);
lineChart.getData().removeAll(seriesComm);
lineChart.getData().removeAll(seriesCond);
lineChart.getData().removeAll(seriesLoop);
lineChart.getData().removeAll(seriesMem);
dataLOC.clear();
dataLoops.clear();
dataComm.clear();
dataCond.clear();
dataMem.clear();
}
As far as I understood
cb.setOnAction(event -> {
if (lineChart.contains(*NAME_OF_YOUR_ELEMENT*))
lineChart.remove(*NAME_OF_YOUR_ELEMENT*)
else
lineChart.remove(*NAME_OF_YOUR_ELEMENT*)
});
I want to find out whether a button is pressed or not. This seems not to be an official property of a button (not a button-style checkbox!), but seems accessible, there is the BM_GETSTATE message for example that should get the desired result.
Problem is, frequently, I dont get window-handles for my buttons (they are just part of another Toolbar, though they can be distinguihed by the AutomationElement). And I would need such a handle for the SendMessage function.
So.. is there a way for me to access that property? I know it is accessible, since I have seen it in other automation-programmes, I just dont konw how to get at it.
I am going to use C#, but any C code would be fine.
Many thanks
(edit: so I finally managed to make the code format properly here - just insert 4 spaces at the beginning.)
Enjoy it, it took me quite a long time to get it to work.. but now I feel like having reached a new level. :)
(please tell me how to make it format properly - both quote and code failed on me)
int res;
#region direct method
int hwnd = ae.Current.NativeWindowHandle;
if (hwnd != 0)
{
const UInt32 BM_GETSTATE = 0x00F2;
res = SendMessage(hwnd, BM_GETSTATE, 0, 0);
}
#endregion
else
#region method via toolbar
{
AutomationElement parent = TreeWalker.RawViewWalker.GetParent(ae);
while ((parent != null) && (parent.Current.ControlType != ControlType.ToolBar))
parent = TreeWalker.RawViewWalker.GetParent(ae);
if (parent != null)
{
int toolBarHandle = parent.Current.NativeWindowHandle;
#region defines
const int WM_USER = 0x400;
const int TB_GETSTATE = (WM_USER + 18);
const int TB_GETBUTTON = (WM_USER + 23);
const int TB_BUTTONCOUNT = (WM_USER + 24);
#endregion
#region get correct child number
int numButtons = SendMessage(toolBarHandle, TB_BUTTONCOUNT, 0, 0);
AutomationElement sibling = ae;
int cnt = -1;
while (sibling != null)
{
sibling = TreeWalker.RawViewWalker.GetPreviousSibling(sibling);
++cnt;
}
if (cnt >= numButtons)
cnt = 0; // nonsense value, but pass a valid one
#endregion
#region get command id
TBBUTTON butInfo = new TBBUTTON();
butInfo.idCommand = 1234;
uint pid;
GetWindowThreadProcessId((IntPtr)toolBarHandle, out pid);
IntPtr process = OpenProcess(ProcessAccessFlags.VMOperation | ProcessAccessFlags.VMRead |
ProcessAccessFlags.VMWrite | ProcessAccessFlags.QueryInformation, false, pid);
IntPtr p = VirtualAllocEx(process, IntPtr.Zero, (uint)Marshal.SizeOf(typeof(TBBUTTON)), AllocationType.Commit
, MemoryProtection.ReadWrite);
int _res = SendMessage(toolBarHandle, TB_GETBUTTON, cnt, p.ToInt32());
#region getresult
int read;
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TBBUTTON)));
Marshal.StructureToPtr(butInfo, ptr, true);
bool __res = ReadProcessMemory(process, p, ptr, Marshal.SizeOf(typeof(TBBUTTON)), out read);
System.Diagnostics.Debug.Assert(read == Marshal.SizeOf(typeof(TBBUTTON)));
butInfo = (TBBUTTON)Marshal.PtrToStructure(ptr, typeof(TBBUTTON));
#endregion
int commandId = butInfo.idCommand;
VirtualFreeEx(process, p, 0, FreeType.Release);
#endregion
//!define BST_UNCHECKED 0
//!define BST_CHECKED 1
//!define BST_INDETERMINATE 2
//!define BST_PUSHED 4
//!define BST_FOCUS 8
#region get state
res = SendMessage(toolBarHandle, TB_GETSTATE, commandId, 0);
#endregion
}
}
#endregion
EDIT:
Here http://www.andreas-reiff.de/2011/06/c-speicher-anderen-prozess-befullen-lassen-checken-ob-ein-button-gedruckt/ with readable code and explanations in a strange, foreign language.. code comments are english, though. hope you find it useful.
Also, I would not have been able to solve this without the info here How come some controls don't have a windows handle?.