How to code? - page 50

 

Recover a data type from an indicator

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 = Low - 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 = High + 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

 
Julia:
Can someone be so kind and tell me how to code the following code?:

If my Ea is turned on the M30 chart, I want the code to say:

if(on the M5 timeframe, today's close is>yesterday's close)

{

.........

}

Today's close is the current BID; yesterday's close is timeframe independent, so doesn't matter M30 or M5 timeframe.

if(Bid > iClose(NULL,PERIOD_D1,1))

{

...

}

 
natsirte:
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 = Low - 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 = High + 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);

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 :

if(iCustom(NULL, 0, "3 MA Cross w_Alert v2", p1, , , , p10, 0, 0) > 0) // Buy

{

...

}

if(iCustom(NULL, 0, "3 MA Cross w_Alert v2", p1, , , , p10, 1, 0) > 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.

 

Thanks Michel.

But what if the code is in an indicator code?

Is it:

if(Close[pos]>iHigh(Symbol(),PERIOD_M5,[pos+1])?????

 
Beno:
Gidday I am slowly fixing the errors in some if my ea's ( and learning alot on the way) but what does this mean.

2007.10.24 21:22:24 1998.11.20 06:00 The Abyss GBPJPY,Daily: invalid double number as parameter 6 for OrderSend function

I can't find anything on that error what should I be looking at.

int OrderSend( string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)

As you can see parameter six is the stoploss. Make sure your stoploss is defined as an int. Next, make sure in your OrderSend() command that you are multiplying the stoploss by point. This converts to the right double for the currency you are trading.

Example for long:

ticketa=OrderSend(Symbol(),OP_BUY,lotsize,Ask,slip,Ask-intStopLoss*Point,Ask+intTakeProfit*Point,"Comment",magic,0,Green);

Example for short:

ticketb=OrderSend(Symbol(),OP_SELL,lotsize,Bid,slip,Bid+intStopLoss*Point,Bid-intTakeProfit*Point,"Comment",magic,0,Blue);

Hope this helps.

 

Thanks Wolfe

That helped alot but has open a new problem lol it now buys but no sell well not in the right place. I have been trying to buy what all three indi are blue and sell when all red.

I think I have picked the right name "The Abyss" for the ea. as that is where I am sitting trying to code my way out. LOL

2007.11.24 10:14:44 2007.11.23 12:00 The Abyss EURUSD,H4: Error opening SELL order : 0

void CheckForSignals() {

double TML=iCustom(NULL,0,"TrendManager",TM_Period,TM_Shift,0,shift);

double TMS=iCustom(NULL,0,"TrendManager",TM_Period,TM_Shift,1,shift);

double hasOpenLong=iCustom(NULL,0,"Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaPeriod2,1,shift) ;

double hasCloseLong=iCustom(NULL,0,"Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaPeriod2,3,shift) ;

double hasOpenShort=iCustom(NULL,0,"Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaPeriod2,0,shift) ;

double hasCloseShort=iCustom(NULL,0,"Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaPeriod2,2,shift) ;

double SDLL=iCustom(NULL,0,"Slope Direction Line",period,method,price,0,shift);

double SDLS=iCustom(NULL,0,"Slope Direction Line",period,method,price,1,shift);

buysig=false;

sellsig=false;

closebuy=false;

closesell=false;

bool Long1 = TML;

bool Short1 = TMS;

bool Long2 = SDLL;

bool Short2 = SDLS;

bool Long3 = hasOpenLong > hasCloseLong;

bool Short3 = hasOpenShort < hasCloseShort;

buysig = Long1 && Long2 && Long3;

sellsig = Short1 && Short2 && Short3;

closebuy=sellsig;

closesell=buysig;

}

void CheckForOpen() {

if (last==Time[0]) return;

int res,ord;

double entry,stop;

ord=CalculateCurrentOrders();

if (ord!=0) CheckForClose();

//---- buy conditions

if (buys< buysig) {

res=OpenAtMarket(OP_BUY,Lots);

if (res<0) Print("Error opening BUY order : ",(GetLastError()));

else last=Time[0];

}

//---- sell conditions

if (sells< sellsig) {

res=OpenAtMarket(OP_SELL,Lots);

if (res<=0) Print("Error opening SELL order : ",(GetLastError()));

else last=Time[0];

}

}

int OpenAtMarket(int mode,double lot) {

int tr,col;

double openprice;

tr=0; while (tr<5 && !IsTradeAllowed()) { tr++; Sleep(2000); }

RefreshRates();

if (mode==OP_SELL) {

openprice=Bid;

col=Red;

} else {

//openprice=nd(Ask);

openprice=Ask;

col=Blue;

}

OrderSend(Symbol(),mode,lot,openprice,slippage,sl,tp,EAName+Magic,Magic,0,col);

}

return;

//+------------------------------------------------------------------+

//| Check for close order conditions |

//+------------------------------------------------------------------+

void CheckForClose() {

int total;

//----

total=OrdersTotal();

for(int i=total;i>=0;i--)

{

if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;

if(OrderMagicNumber()!=Magic || OrderSymbol()!=Symbol()) continue;

//---- check order type

if(OrderType()==OP_BUY && closebuy) CloseAtMarket(OrderTicket(),OrderLots());

if(OrderType()==OP_SELL && closesell) CloseAtMarket(OrderTicket(),OrderLots());

}

}

bool CloseAtMarket(int ticket,double lot) {

bool bres=false; int tr;

tr=0; while (tr<5 && !IsTradeAllowed()) { tr++; Sleep(2000); }

RefreshRates();

bres=OrderClose(ticket,lot,OrderClosePrice(),slippage,White);

if (!bres) Print("Error closing order : ",(GetLastError()));

}

 
Julia:
Thanks Michel.

But what if the code is in an indicator code?

Is it:

if(Close[pos]>iHigh(Symbol(),PERIOD_M5,[pos+1])?????

Yes, it may be that; all depend of what you are intended to do...

 

Help Plz - Convert These Into Mq4 - Thanks Alot

Dear all:

I'm building a system I think it is very good, I tested the idea before for 3 months, Now I'm trying to coding an indicator which will be asap in the forum so we can test it and it will really will make good money i think:

Plz help me for now to convert these lines into mql4 coding:

1- I have vairable X , this will have a value and I'm calculating it now

SO We have X as an Integer

2- the indicator must check the currnet GMT Time, It must be 6:00am GMT - Time Frame 1 H

-- check GMT TIME 6:00am, WHEN this candle close, we need to calculate the following Variable Of this candle:

High - Low = A

A / 2 = B

B - High = C = SL

D = X * 30%

Buy_Entry= D + C

Buy_Target= C + (X * 60%)

Sell_Entry= C - D

Sell _Target= C - (X * 60%)

Then:

I want to drow the result as lines on the chart with GreaN Area for buy and red Area for Short According to Entry for Buy and Sell and SL

these must be automaticly apear as soon as GMT 6:00 candle finished , Time Frame 1H, so caluculation must be according to 6:00 to 6:59am GMT Candle high and low

PLZ Convert this to MQL4, so i can test it and get back again to puplish the result

THANKS ALOT

 
Beno:
Thanks Wolfe

That helped alot but has open a new problem lol it now buys but no sell well not in the right place. I have been trying to buy what all three indi are blue and sell when all red.

I think I have picked the right name "The Abyss" for the ea. as that is where I am sitting trying to code my way out. LOL

Beno, I'm not sure about this one. I have usually not had good experience with using color changing indicators in EA's. Open your data window with your indicators attached and find out what numerical value is returned for each color. That may help your coding, also make sure you are calling the correct indicator buffer at the right time. (I'm sure you have already done that) You may have better luck with help if you post the entire EA, if you really need help. Also, personally I would code it with 2 separate Ordersend() functions, one dedicated to shorts, and one dedicated to longs. That's just my opinion, it makes things easier to follow.

Good luck, we all have had our own versions of "the Abyss"!

 

Cheers Wolfe

I am going to try the 2 Ordersend option to see what happens. once I get this going I will post it.