MQL4 - automated forex trading   /  

Forum

Login | Register | Language: ru cn en
Freelancer services needed to perform 150+ jobs of traders

Recover a data type from an indicator

Back to topics list To post a new topic, please log in or register
avatar
36
natsirte 2007.11.24 01:50
 
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
Attached files:
  3gmadcrosscw_alertvv2.mq4  (5.88 KB)
 
Riots in Ferguson may have a negative impact on the dollar
Hundreds of American cities Ferguson (Missouri) came on Monday to the streets to protest against the decision of the jury not to prosecute white policeman Darren Wilson, who shot last summer unarmed African-American 18-year-old Michael Brown.  As protests began? On the eve of the verdict in this case the resonance huge crowd of people gathered at the city police department.
avatar
2646
phy 2007.11.24 08:32 #
 

Have the indicator use GlobalVariableSet() and the EA use GlobalVariableGet() for numerical data
transfer between indicator and EA.

 
avatar
36
natsirte 2007.11.26 17:01 #
 
phy wrote:

Have the indicator use GlobalVariableSet() and the EA use GlobalVariableGet() for numerical data
transfer between indicator and EA.


Hi

Thank you for your help

i'm gonna try it

avatar
36
natsirte 2007.11.26 23:37 #
 

Hi

in the indicator , I try to put a data type "ok_trade" in the GlobalVariableSet()

But I think , is not working in my EA (I put GlobalVariableGet("ok_trade") and it return 0)

Help me please

this is the code :

******************INDICATOR 3MACROSS***********************************************

// This is Not Tested , Use At Your Own Risk !

//+--------------------------------------------------------------------------+
//| 3 MA Cross w_Alert v2.mq4 |
//| Copyright © 2005, Jason Robinson (jnrtrading) |
//| http://www.jnrtading.co.uk |
//| 3 ma conversion and Alert , David Honeywell , transport.david@gmail.com |
//| http://finance.groups.yahoo.com/group/MetaTrader_Experts_and_Indicators/ |
//+--------------------------------------------------------------------------+

/*
+-------------------------------------------------------------------------------+
| Allows you to enter 3 ma periods and it will then show you and alert you at |
| which point the 2 faster ma's "OPEN" are both above or below the Slowest ma . |
+-------------------------------------------------------------------------------+
*/

#property copyright "Copyright © 2005, Jason Robinson (jnrtrading)"
#property link "http://www.jnrtrading.co.uk"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color2 Coral

double CrossUp[];
double CrossDown[];
double prevtime;
double Range, AvgRange;
double fasterMAnow, fasterMAprevious, fasterMAafter;
double mediumMAnow, mediumMAprevious, mediumMAafter;
double slowerMAnow, slowerMAprevious, slowerMAafter;

extern int FasterMA = 5;
extern int FasterShift = -5;
extern int FasterMode = 1; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma

extern int MediumMA = 20;
extern int MediumShift = -5;
extern int MediumMode = 1; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma

extern int SlowerMA = 34;
extern int SlowerShift = 0;
extern int SlowerMode = 1; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma

extern int SoundAlert = 1; // 0 = disabled

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_ARROW, EMPTY);
SetIndexArrow(0, 233);
SetIndexBuffer(0, CrossUp);
SetIndexStyle(1, DRAW_ARROW, EMPTY);
SetIndexArrow(1, 234);
SetIndexBuffer(1, CrossDown);


//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{

string ok_trade ="no_trade";


int limit, i, counter;

int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

for(i = 0; i <= limit; i++)
{

counter=i;
Range=0;
AvgRange=0;
for (counter=i ;counter<=i+9;counter++)
{
AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
}
Range=AvgRange/10;

fasterMAnow = iMA(NULL, 0, FasterMA, FasterShift, FasterMode, PRICE_CLOSE, i+1);
fasterMAprevious = iMA(NULL, 0, FasterMA, FasterShift, FasterMode, PRICE_CLOSE, i+2);
fasterMAafter = iMA(NULL, 0, FasterMA, FasterShift, FasterMode, PRICE_CLOSE, i-1);

mediumMAnow = iMA(NULL, 0, MediumMA, MediumShift, MediumMode, PRICE_CLOSE, i+1);
mediumMAprevious = iMA(NULL, 0, MediumMA, MediumShift, MediumMode, PRICE_CLOSE, i+2);
mediumMAafter = iMA(NULL, 0, MediumMA, MediumShift, MediumMode, PRICE_CLOSE, i-1);

slowerMAnow = iMA(NULL, 0, SlowerMA, SlowerShift, SlowerMode, PRICE_CLOSE, i+1);
slowerMAprevious = iMA(NULL, 0, SlowerMA, SlowerShift, SlowerMode, PRICE_CLOSE, i+2);
slowerMAafter = iMA(NULL, 0, SlowerMA, SlowerShift, SlowerMode, PRICE_CLOSE, i-1);

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


}

if ((fasterMAnow < slowerMAnow &&
fasterMAprevious >= slowerMAprevious &&
fasterMAafter < slowerMAafter &&
mediumMAnow < slowerMAnow )
||
(fasterMAnow < slowerMAnow &&
mediumMAnow < slowerMAnow &&
mediumMAprevious >= slowerMAprevious &&
mediumMAafter < slowerMAafter ))
{
CrossDown[i] = High[i] + Range*0. 5;
ok_trade="Short";
}

}

if ((CrossUp[0] > 2000) && (CrossDown[0] > 2000)) { prevtime = 0; }

if ((CrossUp[0] == Low[0] - Range*0.5) && (prevtime != Time[0]) && (SoundAlert != 0))
{
prevtime = Time[0];
Alert(Symbol()," 3 MA Cross Up @ Hour ", Hour(), " Minute ", Minute());
}

if ((CrossDown[0] == High[0] + Range*0.5) && (prevtime != Time[0]) && (SoundAlert != 0))
{
prevtime = Time[0];
Alert(Symbol()," 3 MA Cross Down @ Hour ", Hour(), " Minute ", Minute());
}

// Alert(ok_trade);
GlobalVariableSet("ok_trade",0);
return(0);
}

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

best regards

Attached files:
  3macross.mq4  (6.06 KB)
 
avatar
2646
phy 2007.11.27 05:05 #
 

Global Variables are numbers only. So setting text values as you tried to do above is no good...

If you go to Tools - Global Variables, you can manually set/change/delete them, and see what yo can store in a Global Variable.

Also, when you did actually set the GlobalVariable in your code, which you named "ok_trade", you set it to 0, which is why it is always 0 when you read it.

 
avatar
36
natsirte 2007.11.28 04:25 #
 

Hi phy

Thank you for your patience.

I try and I try but nothing is working


When I try to put

************
void init()
{
if (!GlobalVariableCheck(ok_trade)) GlobalVariableSet(ok_trade,0);
return(0);
}
************

in my EA it returns me :
init already definited and as a different type ; so I put only the condition "if (!GlobalVariableCheck(ok_trade)) GlobalVariableSet(ok_trade,0);
return(0);" in the init{...} ; and it returns me "ok_trade" is not defined;

So I set ok_trade and direction in my EA like this :

string ok_trade;
int direction;

But when I look into to my Alert ; Alert(direction);the result is always O

Help Please!!
I really don't know where I'm wrong

My EA is EA_GLOBAL and my indicator is 3MACROSS_GLOBAL


Thanks

Attached files:
  ea_global.mq4  (9.49 KB)
  3tmaecross_global.mq4  (5.04 KB)
 
avatar
36
natsirte 2007.11.30 02:23 #
 

Hi everybody

This is the correction. (Thanks to Jerome M)

Take the indicator and add in the EA this :

int start()

{

int recovering_direction = GlobalVariableGet("ok_trade");
}

// But now I saw that the Indicator is wrong because Order=SiGNAL_BUY never work!!

if (recovering_direction == 1 ) { Order = SIGNAL_BUY; }
if (recovering_direction == 2) { Order = SIGNAL_SELL; }

and if I do that :

if (recovering_direction == 2 ) { Order = SIGNAL_BUY; }
if (recovering_direction == 1) { Order = SIGNAL_SELL; }

Order = SIGNAL_SELL never work!!

Why?????

best regards

Attached files:
  3macross_1.mq4  (5.05 KB)
 
avatar
5
dneal5353 2010.01.20 00:21 #
 
natsirte:

Hi everybody

This is the correction. (Thanks to Jerome M)

Take the indicator and add in the EA this :

int start()

{

int recovering_direction = GlobalVariableGet("ok_trade");
}

// But now I saw that the Indicator is wrong because Order=SiGNAL_BUY never work!!

if (recovering_direction == 1 ) { Order = SIGNAL_BUY; }
if (recovering_direction == 2) { Order = SIGNAL_SELL; }

and if I do that :

if (recovering_direction == 2 ) { Order = SIGNAL_BUY; }
if (recovering_direction == 1) { Order = SIGNAL_SELL; }

Order = SIGNAL_SELL never work!!

Why?????

best regards


avatar
5
dneal5353 2010.01.20 00:25 #
 

hi everyone i attached a voice file to a 2ema cross over but the pop up box and bell alert keeps interupting my voice wav file.


how can i disable the bell alert. the program i used was; from jnrtrading.co.uk.


any help much appreciated. d.


 
avatar
Moderator
2029
gordon 2010.01.20 06:04 #
 

To disable built-in sounds:

MetaTrader4 Menu > Tools > Options > Events Tab > Untick 'Enable'


P.s. why r u resurrecting old threads that have nothing to do with your question?

 
Back to topics list  

To add comments, please log in or register