Forex Factory (https://www.forexfactory.com/forum.php)
-   Platform Tech (https://www.forexfactory.com/forumdisplay.php?f=69)
-   -   I will code your EAs and Indicators for no charge (https://www.forexfactory.com/showthread.php?t=166758)

Nicholishen Mar 26, 2019 11:53pm | Post# 28501

Hello Guys, How to disable Obj_Button from clicking in OnTick Function at Testing mode. I want to disable a button after pressing one time only. it will stay pressed state until i press other button.
You should be using CChartObjectButton instead of CButton. CButton is for use with CAppDialog. This is how I do it.
Inserted Code
#property strict
#include <chartobjects/chartobjectstxtcontrols.mqh>
#include <arrays/list.mqh>
class Buttons;
//+------------------------------------------------------------------+
class MyButton : public CChartObjectButton {
protected:
   static int     s_num;
   Buttons       *m_mgr;
public:
   MyButton(Buttons *mgr):m_mgr(mgr){}
   bool create(string title, int x,int y,int xsize, int ysize);
   bool onclick(string button_name);
};
int MyButton::s_num = 0;
bool MyButton::create(string title, int x,int y,int xsize, int ysize) {
   return (
      this.Create(0, "__button__" + string(++s_num), 0, x, y, xsize, ysize)
      && this.Description(title)
   );
}
bool MyButton::onclick(string button_name) {
   if (button_name != this.Name())
      return false;
   if (!this.State())
      this.State(true);
   else
      for (MyButton *b=m_mgr.GetFirstNode(); CheckPointer(b); b=b.Next())
         if (&this != b)
            b.State(false);
   return true;
}
//+------------------------------------------------------------------+
class Buttons : public CList {
public:
   bool init(int num_buttons);
   bool newButton(string title="Button");
   void onclick(string button);
};
bool Buttons::init(int num_buttons) {
   for (int i=0; i<num_buttons; i++)
      if (!this.newButton(string(i+1)))
         return false;
   return true;
}
void Buttons::onclick(string button_name) {
   for (MyButton *b=this.GetFirstNode(); CheckPointer(b); b=b.Next())
      if (b.onclick(button_name))
         break;
}
bool Buttons::newButton(string title="Button") {
   MyButton *b = new MyButton(&this);
   int n = this.Total();
   return (b.create(title, n * 50, 50, 50, 50) && this.Add(b) >= 0);
}
//+------------------------------------------------------------------+
Buttons *g_buttons;
//+------------------------------------------------------------------+
int OnInit() {  
   g_buttons = new Buttons();
   return g_buttons.init(20) ? INIT_SUCCEEDED : INIT_FAILED;
}
void OnDeinit(const int reason) {
   delete g_buttons;  
}
//+------------------------------------------------------------------+
void OnTick() {}
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   if (id == CHARTEVENT_OBJECT_CLICK)
      g_buttons.onclick(sparam);
}
//+------------------------------------------------------------------+

Tilltheend Mar 27, 2019 1:08am | Post# 28502

{quote} HiTilltheend, I tried uploading the image from investopedia with the formula, but the file format was not valid. I have the link pasted below with the formula. https://www.investopedia.com/terms/f/force-index.asp Force Index (1) = (Current Close Price - Prior Close Price) * Volume Force Index (13) = 13 Period EMA of Force Index (1)
Hi, sorry I don't get it.
What is Force Index to do with my issue of refreshing sub-window indicator data?

ben862000 Mar 27, 2019 1:57am | Post# 28503

{quote} You should be using CChartObjectButton instead of CButton. CButton is for use with CAppDialog. This is how I do it. #property strict #include <chartobjects/chartobjectstxtcontrols.mqh> #include <arrays/list.mqh> class Buttons; //+------------------------------------------------------------------+ class MyButton : public CChartObjectButton { protected: static int s_num; Buttons *m_mgr; public: MyButton(Buttons *mgr):m_mgr(mgr){} bool create(string title, int x,int y,int xsize, int ysize); bool onclick(string button_name); }; int MyButton::s_num...
How about in strategy testing mode?
i want to detect it in the OnTick() Function.

A725859 Mar 27, 2019 2:28am | Post# 28504

Hi Guys,

Any one here having an EA that opens two pending orders buy ad sell at given points as input. I need to use that i news time and with correlation pairs.

Thanks

PipBros Mar 27, 2019 5:40am | Post# 28505

1 Attachment(s)
Good day

Can someone please code an sound and email alert for this indicator. Alert must happen when MACD lines have crossed on the close of that candle
MACD-LWMA.mq4

Gr3Ch Mar 27, 2019 6:24am | Post# 28506

Hello Nicholishen, I have one question about FFEvents. Can u help me with that problem ?

Beerrun Mar 27, 2019 7:26am | Post# 28507

{quote} Thanks for revert. Can you please tell how to do it? Below is the code. It is very simple indicator. It displays ExtMapBuffer, as Line in subwindow
You would have to be more specific and actually show your code, this is only part of it.

Tilltheend Mar 27, 2019 8:07am | Post# 28508

{quote} You would have to be more specific and actually show your code, this is only part of it.
Below is entire code, its very simple indicator. It displays ExtMapBuffer, in form of a line in subwindow. This takes close price from other currencies.

Issue: refresh of data (shown as Line in subwindow) is not proper. When I change timeframe n come back to original timeframe (or edit indicator/ compile indicator), then data becomes proper.

Resolution needed: data should refresh, without need to change timeframe etc.
Thanks.

*****
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Gold
int Bull=0, Bear=0;
string MultiMkts[4] = {"EURUSD","GBPUSD","AUDUSD","USDCAD"};
double ExtMapBuffer[];
int Back = 15000;
int init()
{
SetIndexStyle(0,DRAW_LINE,0,2,Yellow);
SetIndexBuffer(0,ExtMapBuffer);
}
int start()
{
if(Bars<1) return(0);
int counted_bars = IndicatorCounted();
if (counted_bars > 0) counted_bars--;
int limit = MathMin(Back, (Bars - counted_bars));
for (int i = 0; i <= limit; i++)
{
Bull = 0; Bear = 0;
for(int j=0;j<ArraySize(MultiMkts);j++)
{
string Symbol_Name = MultiMkts[j];
if(iClose(Symbol_Name,0,i) > iMA(Symbol_Name,0,20,0,MODE_EMA,0,i))
Bull=Bull+1;
else
Bear=Bear+1;
}
ExtMapBuffer[i] = (Bull - Bear);
}
return(0);
}

*****

NewSim Mar 27, 2019 8:51am | Post# 28509

3 Attachment(s)
Hi, I got this indicator Click to Enlarge

Name: Capture.JPG
Size: 146 KBOpen Levels.ex4 from Cja on another thread, and it's been great. The only problem is that you can't shift the daily open start time. I was wondering if someone could make something similar to this, but with the ability to shift the daily open start time.

I've put an example of a shifted daily open indicator Click to Enlarge

Name: Capture2.JPG
Size: 119 KB but it doesn't have the -3x -2x -x DO +x +2x +3x pips levels etc.

Beerrun Mar 27, 2019 9:23am | Post# 28510

{quote} Below is entire code, its very simple indicator. It displays ExtMapBuffer, in form of a line in subwindow. This takes close price from other currencies. Issue: refresh of data (shown as Line in subwindow) is not proper. When I change timeframe n come back to original timeframe (or edit indicator/ compile indicator), then data becomes proper. Resolution needed: data should refresh, without need to change timeframe etc. Thanks. ***** #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Gold int Bull=0,...
I tried to clean it up, but I am doing this on my phone at work so I might have missed something. The only real changes I did were to your loops.
Inserted Code
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Gold
int Bull=0,Bear=0,Back=15000;
string MultiMkts[4]={"EURUSD","GBPUSD","AUDUSD","USDCAD"};
double ExtMapBuffer[];
int init() { SetIndexStyle(0,DRAW_LINE,0,2,Yellow); SetIndexBuffer(0,ExtMapBuffer);
return(0);}
int start() {
int counted_bars=IndicatorCounted();
if(counted_bars>0)counted_bars--;
for(int i=MathMin(Back,(Bars-counted_bars));i>=0;i—){
Bull=Bear=0;
for(int j=ArraySize(MultiMkts);j>=0;j—){
string Symbol_Name=MultiMkts[j];
if(iClose(Symbol_Name,0,i)> iMA(Symbol_Name,0,20,0,MODE_EMA,0,i))Bull++;
else Bear=++;}
ExtMapBuffer[i]=(Bull-Bear);}
return(0);}

Nicholishen Mar 27, 2019 9:24am | Post# 28511

{quote} How about in strategy testing mode? i want to detect it in the OnTick() Function.
Inserted Code
#property strict
#include <chartobjects/chartobjectstxtcontrols.mqh>
#include <arrays/list.mqh>
class Buttons;
//+------------------------------------------------------------------+
class MyButton : public CChartObjectButton {
protected:
   static int     s_num;
   Buttons       *m_mgr;
   int            m_status;
public:
   MyButton(Buttons *mgr):m_mgr(mgr){}
   bool create(string title, int x,int y,int xsize, int ysize);
   bool onclick(string button_name);
   int  status() { return m_status; }
};
int MyButton::s_num = 0;
bool MyButton::create(string title, int x,int y,int xsize, int ysize) {
   m_status = ++s_num;
   return (
      this.Create(0, "__button__" + string(m_status), 0, x, y, xsize, ysize)
      && this.Description(title)
   );
}
bool MyButton::onclick(string button_name) {
   if (button_name != this.Name())
      return false;
   if (!this.State()) {
      this.State(true);
   }
   else {
      for (MyButton *b=m_mgr.GetFirstNode(); CheckPointer(b); b=b.Next()) 
         if (&this != b) 
            b.State(false);
      m_mgr.active(&this);
   }
   return true;
}
//+------------------------------------------------------------------+
class Buttons : public CList {
protected:
   MyButton *m_active;
public:
   bool init(int num_buttons);
   bool newButton(string title="Button");
   void onclick(string button);
   void active(MyButton *b);
   int  status();
};
bool Buttons::init(int num_buttons) {
   for (int i=0; i<num_buttons; i++)
      if (!this.newButton(string(i+1)))
         return false;
   return true;
}
void Buttons::onclick(string button_name) {
   for (MyButton *b=this.GetFirstNode(); CheckPointer(b); b=b.Next())
      if (b.onclick(button_name))
         break;
}
bool Buttons::newButton(string title="Button") {
   MyButton *b = new MyButton(&this);
   int n = this.Total();
   return (b.create(title, n * 50, 50, 50, 50) && this.Add(b) >= 0);
}
void Buttons::active(MyButton *b) {
   m_active = b;
}
int Buttons::status(void) {
   if (!CheckPointer(m_active)) {
      for (MyButton *b=this.GetFirstNode(); CheckPointer(b); b=b.Next()) {
         if (b.State()) {
            m_active = b;
            break;
         }
      }
   }
   if (CheckPointer(m_active))
      return m_active.status();
   return WRONG_VALUE;
}
//+------------------------------------------------------------------+
Buttons *g_buttons;
//+------------------------------------------------------------------+
int OnInit() {   
   g_buttons = new Buttons();
   return g_buttons.init(20) ? INIT_SUCCEEDED : INIT_FAILED;
}
void OnDeinit(const int reason) {
   delete g_buttons;   
}
//+------------------------------------------------------------------+
void OnTick() {
   Comment(StringFormat("status(%d) from onTick", g_buttons.status()));
}
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   if (id == CHARTEVENT_OBJECT_CLICK)
      g_buttons.onclick(sparam);
}
//+------------------------------------------------------------------+

Tilltheend Mar 27, 2019 11:24am | Post# 28512

{quote} I tried to clean it up, but I am doing this on my phone at work so I might have missed something. The only real changes I did were to your loops. #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Gold int Bull=0,Bear=0,Back=15000; string MultiMkts[4]={"EURUSD","GBPUSD","AUDUSD","USDCAD"}; double ExtMapBuffer[]; int init() { SetIndexStyle(0,DRAW_LINE,0,2,Yellow); SetIndexBuffer(0,ExtMapBuffer); return(0);} int start() { int counted_bars=IndicatorCounted(); if(counted_bars>0)counted_bars--; for(int...
Thanks buddy for changes, but it has not resolved the issue.

Just thinking aloud.. May be need to trigger event thru code, (even periodic update is fine), which wud recalculate data properly. The way it does when timeframe changed/ indicator edited.

Beerrun Mar 27, 2019 12:16pm | Post# 28513

{quote} Thanks buddy for changes, but it has not resolved the issue. Just thinking aloud.. May be need to trigger event thru code, (even periodic update is fine), which wud recalculate data properly. The way it does when timeframe changed/ indicator edited.
Try this, a (-1) was missing from the symbols array loop initialization. You have probably been getting an “array out of range” error, which would stop your code at that place, allowing it to only work properly until the error.
Inserted Code
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Gold
string MultiMkts[4]={"EURUSD","GBPUSD","AUDUSD","USDCAD"};
double ExtMapBuffer[];
int init(){
SetIndexStyle(0,DRAW_LINE,0,2,Yellow);
SetIndexBuffer(0,ExtMapBuffer);
return(0);}
int start(){
for(int i=Bars-IndicatorCounted()-1;i>=0;i—){
int Bull=0,Bear=0;
for(int j=ArraySize(MultiMkts)-1;j>=0;j—){
string Symbol_Name=MultiMkts[j];
if(iClose(Symbol_Name,0,i)>iMA(Symbol_Name,0,20,0,MODE_EMA,0,i))Bull++;
else Bear=++;}
ExtMapBuffer[i]=(Bull-Bear);}
return(0);}

dmtrkostop Mar 27, 2019 12:33pm | Post# 28514

{quote} Hi, sorry I don't get it. What is Force Index to do with my issue of refreshing sub-window indicator data?
My mistake, this was the first time I received an email notification for the thread, and accidentally saw it as a response to my request. Disregard my reply.

Tilltheend Mar 27, 2019 2:02pm | Post# 28515

{quote} Try this, a (-1) was missing from the symbols array loop initialization. You have probably been getting an “array out of range” error, which would stop your code at that place, allowing it to only work properly until the error. #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Gold string MultiMkts[4]={"EURUSD","GBPUSD","AUDUSD","USDCAD"}; double ExtMapBuffer[]; int init(){ SetIndexStyle(0,DRAW_LINE,0,2,Yellow); SetIndexBuffer(0,ExtMapBuffer); return(0);} int start(){ for(int i=Bars-IndicatorCounted()-1;i>=0;i—){...
No worries. I had corrected that in your earlier code. Still the issue persists.

Beerrun Mar 27, 2019 2:53pm | Post# 28516

1 Attachment(s)
{quote} No worries. I had corrected that in your earlier code. Still the issue persists.
It works correctly for me
Inserted Code
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 clrGold
string MultiMkts[4]={"EURUSD","GBPUSD","AUDUSD","USDCAD"};
double ExtMapBuffer[];
int init(){
  SetIndexStyle(0,DRAW_LINE,0,2,Yellow);
  SetIndexBuffer(0,ExtMapBuffer);
  return(0);}
int start(){
  for(int i=Bars-IndicatorCounted()-1;i>=0;i--){
   int Bull=0,Bear=0;
   for(int j=ArraySize(MultiMkts)-1;j>=0;j--){
    string Symbol_Name=MultiMkts[j];
    if(iClose(Symbol_Name,0,i)>iMA(Symbol_Name,0,20,0,MODE_EMA,0,i))Bull++;
    else Bear++;}
  ExtMapBuffer[i]=(Bull-Bear);}
  return(0);}
ClosePrices.mq4

luisinho Mar 27, 2019 6:30pm | Post# 28517

2 Attachment(s)
Anyone ...

hi

ADR simple.mq4

Name:  Screenshot2.png
Views: 1249
Size:  3 KB

(:

classy Mar 27, 2019 7:42pm | Post# 28518

i am looking for one indicator /dashboard which show one pair how pip gains for example from open or start pair move up 20 pips and down 10 pips so dash borad show green or +10 pips opposite -10 i mean if pair go up 10 and down 20 from day start. by this tool we can watch and measure pair performane.which trending /ranging .showing strengths /dominatiing and i think it will great info for any trader

stesy Mar 27, 2019 7:45pm | Post# 28519

{quote} Not the same but anyhow try it... {file}
what TF is the 25%M.ex4, do you mind sharing the .mq4 to adjust a bit according to my trade? THX

PeterE Mar 27, 2019 8:40pm | Post# 28520

{quote} hi {file} {image} (:
Fantastic!! Big thank you.


© Forex Factory