Thread: How to code?
View Single Post
  #489 (permalink)  
Old 11-23-2007, 11:38 PM
Michel Michel is online now
Senior Member
 
Join Date: Feb 2006
Posts: 547
Michel is on a distinguished road
Quote:
Originally Posted by natsirte View Post
Hi
Is it possible to recover a data type from an indicator (3 MA Cross w alert) to put it in a EA?

This is what I want to do :
In the indicator (3 MA Cross w alert) I put a data type :
double execute_trade = "ok_buy" or execute_trade = "ok_sell" here :

************Indicator ************
if ((fasterMAnow > slowerMAnow &&
fasterMAprevious <= slowerMAprevious &&
fasterMAafter > slowerMAafter &&
mediumMAnow > slowerMAnow )
||
(fasterMAnow > slowerMAnow &&
mediumMAnow > slowerMAnow &&
mediumMAprevious <= slowerMAprevious &&
mediumMAafter > slowerMAafter ))
{
CrossUp[i] = Low[i] - Range*0.5;
string execute_trade = "ok_buy";
}

if ((fasterMAnow < slowerMAnow &&
fasterMAprevious >= slowerMAprevious &&
fasterMAafter < slowerMAafter &&
mediumMAnow < slowerMAnow )
||
(fasterMAnow < slowerMAnow &&
mediumMAnow < slowerMAnow &&
mediumMAprevious >= slowerMAprevious &&
mediumMAafter < slowerMAafter ))
{
CrossDown[i] = High[i] + Range*0.5;
execute_trade = "ok_sell";
}

************************

and I'd like to recover "excute_trade" in my EA like this :


***********EA***************


if (excute_trade== "ok_buy")
Order = SIGNAL_BUY;

if (excute_trade== "ok_sell")
Order = SIGNAL_SELL;



****************************

But I don't know how to do

help please

Best regards
You must use iCustom function to retrieve the value of the buffers (ie the arrows);
Quote:
double iCustom( string symbol, int timeframe, string name, ..., int mode, int shift)
Calculates the specified custom indicator and returns its value. The custom indicator must be compiled (*.EX4 file) and be in the terminal_directory\experts\indicators directory.
Parameters:
symbol - Symbol the data of which should be used to calculate indicator. NULL means current symbol.
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.
name - Custom indicator compiled program name.
... - Parameters set (if necessary). The passed parameters and their order must correspond with the desclaration order and the type of extern variables of the custom indicator.
mode - Line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions.
shift - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:
double val=iCustom(NULL, 0, "SampleInd",13,1,0);

I your case the syntax should be :
PHP Code:
if(iCustom(NULL0"3 MA Cross w_Alert v2"p1, , ,     , p1000) > 0)    // Buy
{
   ...
}
if(
iCustom(NULL0"3 MA Cross w_Alert v2"p1, , ,     , p1010) > 0)    // Sell
{
   ...

The parameteres p1 to p10 are the values to send to the indicator as the extern parametres. For example, p1 means the value to be assigned to FasterMA, p2 to FasterShift, and so on up to the last extern declaration p10 SoundAlert. See the indicator's code to know the order and the signification of them.
Reply With Quote