Jump to content

Icustom? how to return a value from another indicator?


gringoh

Recommended Posts

Hello,

 

The i-ProfitTracker indicator gives different information’s about profit (in point, $, %, for today, the week)…

 

Here the link to download it:

http://www.forexfactory.com/showpost.php?p=3813782

 

What I would like to do for example is to call the iprofit indicator from another indicator in order to have only the current profit value in point displayed on my chart (to return the value “tu” for example). I think it is possible by using the icustom function but I am not a genius in mq4.

 

Help would be much appreciated.

 

Thank you in advance,

Regards,

Gringoh

Link to comment
Share on other sites

My understanding is that you can only access values that are "returned" to mq4 via one of the indicator buffers. The index of the buffer you are interested in is specified in the "Mode" parameter of the iCustom call. Otherwise, the values are local to the indi and I dont think there is any way of getting to them thru the iCustom call, or any other way for that matter (****).

A decompile of the iProfitTracker reveals that no indicator buffers are used, so all calculated values are local to the indi.

 

That said, you can modify the indi, add one or more indicator buffer(s), and write the value you are interested in to the buffer whenever it is calculated. Given that you are writing a new indi, I trust you should have no problem doing that.

 

****: As @Hacker correctly mentions below, the other way of passing variables between indis is thru the use of global variables!

Edited by josephR
Link to comment
Share on other sites

Im a real fan of passing values between modules using the GlobalVariables

You do this using

 

GlobalVariableCheck

GlobalVariableSet

GlobalVariableDel

 

Commands...

 

Inside one indicator you calculate/set a global variable to the value you want... And then inside the other module you check the global variable and use the returned value for you needs.

 

 

Here is an example I use in an indicator to tell an ea when it OK to trade..

 

//use global flags to signal time to trade to ea.

GlobalOkToTradeSymbolFlag="GlobalTradeFlag_"+MagicNumber;

 

 

if (GlobalVariableCheck(GlobalOkToTradeSymbolFlag)) GlobalVariableDel(GlobalOkToTradeSymbolFlag);

 

for(int cnt=1; cnt<=5; cnt++)

{

if (DebugLogFile) log( "Setting GlobalOkToTradeSymbolFlag - Try#: " +cnt+" "+Symbol()+ " "+ Period() );

Error = GetLastError();

GlobalVariableSet(GlobalOkToTradeSymbolFlag,0);

Error = GetLastError();

if (Error>0)

{

GlobalSymbolTrend=99;

if (DebugLogFile) log (" GlobalOkToTradeSymbolFlag Error: " + ErrorDescription(Error));

Sleep(500);

}

else

{

GlobalSymbolTrend=0;

if (DebugLogFile) log (" GlobalOkToTradeSymbolFlag SetOK: " + GlobalSymbolTrend);

break;

}

}

 

I also record a log file on my stuff so you will see code in here for error debugging

 

Now the EA has similiar code in it to READ the global variable an do actions based on that...

Edited by Hacker
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...